Class: Ruspea::Code

Inherits:
Object
  • Object
show all
Defined in:
lib/ruspea/code.rb

Instance Method Summary collapse

Constructor Details

#initializeCode

Returns a new instance of Code.



3
4
5
6
7
# File 'lib/ruspea/code.rb', line 3

def initialize
  @reader = Ruspea::Interpreter::Reader.new
  @evaler = Ruspea::Interpreter::Evaler.new
  @printer = Ruspea::Printer.new
end

Instance Method Details

#load(file_path) ⇒ Object



9
10
11
12
# File 'lib/ruspea/code.rb', line 9

def load(file_path)
  raise "#{file_path} is not a file" if !File.exists?(file_path)
  exec(File.read(file_path))
end

#run(code, env: Ruspea::Language::Core.new) ⇒ Object



14
15
16
17
# File 'lib/ruspea/code.rb', line 14

def run(code, env: Ruspea::Language::Core.new)
  _, forms = @reader.call(code)
  @evaler.call(forms, context: env)
end