Module: Heist
- Defined in:
- lib/heist.rb,
lib/heist/repl.rb,
lib/heist/trie.rb,
lib/heist/parser/ruby.rb,
lib/heist/parser/nodes.rb,
lib/heist/parser/scheme.rb,
lib/heist/runtime/frame.rb,
lib/heist/runtime/scope.rb,
lib/heist/runtime/stack.rb,
lib/heist/runtime/binding.rb,
lib/heist/runtime/runtime.rb,
lib/heist/runtime/data/cons.rb,
lib/heist/runtime/stackless.rb,
lib/heist/runtime/data/value.rb,
lib/heist/runtime/data/vector.rb,
lib/heist/runtime/callable/macro.rb,
lib/heist/runtime/data/character.rb,
lib/heist/runtime/callable/syntax.rb,
lib/heist/runtime/data/expression.rb,
lib/heist/runtime/data/identifier.rb,
lib/heist/runtime/callable/function.rb,
lib/heist/runtime/callable/macro/tree.rb,
lib/heist/runtime/callable/continuation.rb,
lib/heist/runtime/callable/macro/matches.rb,
lib/heist/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.3'
- ROOT_PATH =
File.(File.dirname(__FILE__)) + '/heist'
- 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]
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
Expression
in the givenScope
. -
.parse(source) ⇒ Object
Accepts either a string of Scheme code or an array of Ruby data and parses into a
Cons
list 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.
53 54 55 56 57 58 |
# File 'lib/heist.rb', line 53 def evaluate(expression, scope) return expression.value if Runtime::Value === expression 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.
44 45 46 47 48 49 |
# File 'lib/heist.rb', line 44 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 |