Module: Heist
- Defined in:
- lib/heist.rb,
lib/repl.rb,
lib/trie.rb,
lib/parser/ruby.rb,
lib/parser/nodes.rb,
lib/parser/scheme.rb,
lib/runtime/frame.rb,
lib/runtime/scope.rb,
lib/runtime/stack.rb,
lib/runtime/binding.rb,
lib/runtime/runtime.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
Heist is the root module for all of Heist’s components, and hosts a few utility methods that don’t belong anywhere else. See the README for an overview of Heist’s features.
Defined Under Namespace
Modules: Scheme Classes: BadIndexError, HeistError, ImmutableError, MacroError, MacroTemplateMismatch, REPL, RubyParser, Runtime, RuntimeError, SchemeParser, SyntaxError, Trie, TypeError, UndefinedVariable
Constant Summary collapse
- VERSION =
'0.3.2'- ROOT_PATH =
File.(File.dirname(__FILE__))
- PARSER_PATH =
ROOT_PATH + '/parser/'
- RUNTIME_PATH =
ROOT_PATH + '/runtime/'
- BUILTIN_PATH =
ROOT_PATH + '/builtin/'
- LIB_PATH =
ROOT_PATH + '/stdlib/'
- LOAD_PATH =
[BUILTIN_PATH, LIB_PATH]
- FILE_EXTS =
[""] + %w[.rb .scm .ss]
- BIN_SPEC =
Oyster.spec do name "heist -- Ruby-powered Scheme interpreter, v. #{Heist::VERSION}" 'James Coglan <[email protected]>' synopsis " heist -i [OPTIONS]\n heist FILE_NAME [OPTIONS]\n EOS\n \n flag :interactive, :desc =>\n 'Start an interactive Scheme session'\n \n flag :lazy, :default => false, :desc =>\n 'Use lazy evaluation order'\n \n flag :continuations, :default => false, :desc =>\n 'Enable first-class continuations and (call/cc)'\n \n flag :unhygienic, :default => false, :desc =>\n 'Use Common Lisp-style unhygienic macros'\nend\n"
Class Method Summary collapse
-
.divide(op1, op2) ⇒ Object
Returns the result of dividing the first argument by the second.
-
.evaluate(expression, scope) ⇒ Object
Returns the result of evaluating the given
Expressionin the givenScope. -
.parse(source) ⇒ Object
Accepts either a string of Scheme code or an array of Ruby data and parses into a
Conslist structure. -
.stringify(object) ⇒ Object
Returns a string representation of the object suitable for display on the command line.
Class Method Details
.divide(op1, op2) ⇒ Object
Returns the result of dividing the first argument by the second. If both arguments are integers, returns a rational rather than performing integer division as Ruby would normally do.
63 64 65 66 67 |
# File 'lib/heist.rb', line 63 def divide(op1, op2) [op1, op2].all? { |value| Integer === value } ? Rational(op1, op2) : op1.to_f / op2 end |
.evaluate(expression, scope) ⇒ Object
Returns the result of evaluating the given Expression in the given Scope. If the first argument is not an Expression it will be returned unaltered.
54 55 56 57 58 |
# File 'lib/heist.rb', line 54 def evaluate(expression, scope) Runtime::Expression === expression ? expression.eval(scope) : expression end |
.parse(source) ⇒ Object
Accepts either a string of Scheme code or an array of Ruby data and parses into a Cons list structure. Scheme code is converted to a Program, while a Ruby array is converted to a single list expression. Returns nil if the input cannot be parsed successfully.
45 46 47 48 49 50 |
# File 'lib/heist.rb', line 45 def parse(source) @scheme ||= SchemeParser.new @ruby ||= RubyParser.new parser = (String === source) ? @scheme : @ruby parser.parse(source) end |
.stringify(object) ⇒ Object
Returns a string representation of the object suitable for display on the command line. Some built-in Ruby types need special handling to display according to Scheme conventions.
72 73 74 75 76 77 78 79 |
# File 'lib/heist.rb', line 72 def stringify(object) case object when Runtime::Character, String then object.inspect when TrueClass then '#t' when FalseClass then '#f' else object.to_s end end |