Class: Heist::Runtime
- Inherits:
-
Object
- Object
- Heist::Runtime
- Extended by:
- Forwardable
- Defined in:
- lib/runtime/runtime.rb,
lib/runtime/frame.rb,
lib/runtime/scope.rb,
lib/runtime/stack.rb,
lib/runtime/binding.rb,
lib/runtime/data/cons.rb,
lib/runtime/stackless.rb,
lib/runtime/data/vector.rb,
lib/runtime/callable/macro.rb,
lib/runtime/data/character.rb,
lib/runtime/callable/syntax.rb,
lib/runtime/data/expression.rb,
lib/runtime/data/identifier.rb,
lib/runtime/callable/function.rb,
lib/runtime/callable/macro/tree.rb,
lib/runtime/callable/continuation.rb,
lib/runtime/callable/macro/matches.rb,
lib/runtime/callable/macro/expansion.rb
Overview
Runtime
objects represent instances of the Heist runtime environment. Each Runtime
defines a top-level Scope
, into which are injected the standard set of primitive functions and special forms as defined in lib/builtin
.
Runtime
exposes several methods from the top-level Scope
object, allowing runtime objects to be used as interfaces for defining functions, eval’ing code and running source files.
Defined Under Namespace
Modules: Expression Classes: Binding, Body, Character, Cons, Continuation, FileScope, Frame, Function, Identifier, Macro, Scope, Stack, Stackless, Syntax, Vector
Instance Attribute Summary collapse
-
#stack ⇒ Object
Returns the value of attribute stack.
-
#top_level ⇒ Object
Returns the value of attribute top_level.
Instance Method Summary collapse
-
#elapsed_time ⇒ Object
Returns the length of time the
Runtime
has been alive for, as a number in microseconds. -
#hygienic? ⇒ Boolean
Returns
true
iff theRuntime
is using hygienic macros. - #info ⇒ Object
-
#initialize(options = {}) ⇒ Runtime
constructor
A
Runtime
is initialized using a set of options. -
#lazy? ⇒ Boolean
Returns
true
iff theRuntime
is using lazy evaluation. -
#stackless? ⇒ Boolean
Returns
true
iff theRuntime
is using the fasterStackless
evaluator, which does not support(call/cc)
. - #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(options = {}) ⇒ Runtime
A Runtime
is initialized using a set of options. The available options include the following, all of which are false
unless you override them yourself:
-
:continuations
: set totrue
to enablecall/cc
-
:lazy
: set totrue
to enable lazy evaluation -
:unhygienic
: set totrue
to disable macro hygiene
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/runtime/runtime.rb', line 37 def initialize( = {}) @lazy = !![:lazy] @continuations = !![:continuations] @hygienic = ![:unhygienic] @top_level = Scope.new(self) @stack = stackless? ? Stackless.new : Stack.new run("#{ BUILTIN_PATH }primitives.rb") run("#{ BUILTIN_PATH }syntax.scm") run("#{ BUILTIN_PATH }library.scm") @start_time = Time.now.to_f end |
Instance Attribute Details
#stack ⇒ Object
Returns the value of attribute stack.
27 28 29 |
# File 'lib/runtime/runtime.rb', line 27 def stack @stack end |
#top_level ⇒ Object
Returns the value of attribute top_level.
27 28 29 |
# File 'lib/runtime/runtime.rb', line 27 def top_level @top_level end |
Instance Method Details
#elapsed_time ⇒ Object
Returns the length of time the Runtime
has been alive for, as a number in microseconds.
54 55 56 |
# File 'lib/runtime/runtime.rb', line 54 def elapsed_time (Time.now.to_f - @start_time) * 1000000 end |
#hygienic? ⇒ Boolean
Returns true
iff the Runtime
is using hygienic macros.
62 |
# File 'lib/runtime/runtime.rb', line 62 def hygienic?; @hygienic; end |
#info ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/runtime/runtime.rb', line 77 def info [ "Heist Scheme interpreter v. #{ VERSION }", "Evaluation mode: #{ lazy? ? 'LAZY' : 'EAGER' }", "Continuations enabled? #{ stackless? ? 'NO' : 'YES' }", "Macros: #{ hygienic? ? 'HYGIENIC' : 'UNHYGIENIC' }\n\n" ] * "\n" end |
#lazy? ⇒ Boolean
Returns true
iff the Runtime
is using lazy evaluation.
59 |
# File 'lib/runtime/runtime.rb', line 59 def lazy?; @lazy; end |
#stackless? ⇒ Boolean
Returns true
iff the Runtime
is using the faster Stackless
evaluator, which does not support (call/cc)
.
66 67 68 |
# File 'lib/runtime/runtime.rb', line 66 def stackless? lazy? or not @continuations end |
#to_s ⇒ Object Also known as: inspect
70 71 72 73 74 |
# File 'lib/runtime/runtime.rb', line 70 def to_s "#<runtime: #{ stackless? ? 'call/cc disabled' : 'call/cc enabled' }, #{ hygienic? ? 'hygienic' : 'unhygienic' }, #{ lazy? ? 'lazy' : 'eager' }>" end |