Module: Rbsiev

Defined in:
lib/rbsiev.rb,
lib/rbsiev/repl.rb,
lib/rbsiev/error.rb,
lib/rbsiev/printer.rb,
lib/rbsiev/version.rb,
lib/rbsiev/evaluator.rb,
lib/rbsiev/procedure.rb,
lib/rbsiev/primitives.rb,
lib/rbsiev/environment.rb,
lib/rbsiev/primitives/arithmetic.rb,
lib/rbsiev/primitives/comparison.rb,
lib/rbsiev/primitives/empty_list.rb

Defined Under Namespace

Modules: Primitives Classes: Components, CompoundProcedure, Environment, Error, Evaluator, PrimitiveProcedure, Printer, Procedure, Repl

Constant Summary collapse

SCM_EMPTY_LIST =
Scmo::EMPTY_LIST
SCM_TRUE =
Scmo::TRUE
SCM_FALSE =
Scmo::FALSE
VERSION =
"0.1.0"
RELEASE =
"2021-06-08"
PRIMITIVE_NAMES_MAP =
{
  # Some primitive procedure names in Scheme must be defined with
  # different names in Ruby.
  "+" => :add,
  "-" => :subtract,
  "*" => :mul,
  "/" => :div,
  "%" => :mod,
  "<" => :lt?,
  "<=" => :le?,
  ">" => :gt?,
  ">=" => :ge?,
  "=" => :same_value?,
}

Class Method Summary collapse

Class Method Details

.eval(scm_source) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/rbsiev.rb', line 77

def self.eval(scm_source)
  lexer = Rbscmlex.lexer(scm_source)
  parser = Rubasteme.parser
  eva = evaluator
  env = setup_environment
  eva.eval(parser.parse(lexer), env)
end

.evaluatorObject



58
59
60
# File 'lib/rbsiev.rb', line 58

def self.evaluator
  Evaluator.new
end

.printerObject



62
63
64
# File 'lib/rbsiev.rb', line 62

def self.printer
  Printer.new
end

.run(files:, verbose: false) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rbsiev.rb', line 85

def self.run(files:, verbose: false)
  parser = Rubasteme.parser
  evaluator = Evaluator.new
  env = setup_environment
  printer = Printer.new

  evaluator.verbose = verbose
  printer.verbose = verbose

  components = Components.new(parser, evaluator, printer, env)

  files.each {|f| components.load(f)}
end

.scheme_object?(obj) ⇒ Boolean



22
23
24
# File 'lib/rbsiev.rb', line 22

def self.scheme_object?(obj)
  Scmo.scheme_object?(obj)
end

.setup_environmentObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/rbsiev.rb', line 66

def self.setup_environment
  initial_env = Environment.the_empty_environment
  names = []
  values = []
  PRIMITIVE_NAMES_MAP.each { |name, sym|
    names << name
    values << Procedure.make_procedure(nil, sym, initial_env)
  }
  initial_env.extend(names, values)
end