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.0'
ROOT_PATH =
File.expand_path(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 =
[LIB_PATH]
FILE_EXT =
".scm"
BIN_SPEC =
Oyster.spec do
  name "heist -- Ruby-powered Scheme interpreter, v. #{Heist::VERSION}"
  author '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

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