Class: Heist::Runtime

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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 to true to enable call/cc

  • :lazy: set to true to enable lazy evaluation

  • :unhygienic: set to true 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(options = {})
  @lazy          = !!options[:lazy]
  @continuations = !!options[:continuations]
  @hygienic      = !options[: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

#stackObject

Returns the value of attribute stack.



27
28
29
# File 'lib/runtime/runtime.rb', line 27

def stack
  @stack
end

#top_levelObject

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_timeObject

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.

Returns:

  • (Boolean)


62
# File 'lib/runtime/runtime.rb', line 62

def hygienic?; @hygienic; end

#infoObject



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.

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


66
67
68
# File 'lib/runtime/runtime.rb', line 66

def stackless?
  lazy? or not @continuations
end

#to_sObject 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