class Halunke::Interpreter
Attributes
root_context[R]
Public Class Methods
new()
click to toggle source
# File lib/halunke/interpreter.rb, line 9 def initialize @parser = Parser.new @root_context = Context.new @root_context["Class"] = Halunke::Runtime::HClass @root_context["Function"] = Halunke::Runtime::HFunction @root_context["Number"] = Halunke::Runtime::HNumber @root_context["String"] = Halunke::Runtime::HString @root_context["Array"] = Halunke::Runtime::HArray @root_context["Dictionary"] = Halunke::Runtime::HDictionary @root_context["UnassignedBareword"] = Halunke::Runtime::HUnassignedBareword @root_context["Regexp"] = Halunke::Runtime::HRegexp @root_context["stdio"] = Halunke::Runtime::HStdio.create_instance @root_context["web"] = Halunke::Runtime::HWeb.create_instance preludes.each do |prelude| self.eval(prelude) end end
Public Instance Methods
eval(str, error_mode: :raise, exit_on_error: false)
click to toggle source
# File lib/halunke/interpreter.rb, line 29 def eval(str, error_mode: :raise, exit_on_error: false) nodes = @parser.parse(str) result = nodes.eval(root_context) result.nil? ? nil : result.inspect(root_context) rescue HError => err raise err if error_mode == :raise puts err.source_code_position.reveal(str, error_mode) puts err.message exit(1) if exit_on_error nil end
preludes()
click to toggle source
# File lib/halunke/interpreter.rb, line 43 def preludes [ Pathname.new(__dir__).join("runtime", "true.hal").read, Pathname.new(__dir__).join("runtime", "false.hal").read ] end