class GLOBAL_SCOPE
Attributes
variables[R]
Public Class Methods
new(variables={})
click to toggle source
# File lib/sdx/vm/scope.rb, line 8 def initialize(variables={}) @variables = variables end
Public Instance Methods
add_fn(fn_name, fn_class)
click to toggle source
# File lib/sdx/vm/scope.rb, line 16 def add_fn(fn_name, fn_class) @variables[fn_name] = fn_class end
add_obj(obj_name, obj_class)
click to toggle source
# File lib/sdx/vm/scope.rb, line 49 def add_obj(obj_name, obj_class) if obj_class.value.args.size == 0 scope = obj_class.value.fields["__new"].call [], self scope.variables.each do |k, v| add_var "#{obj_name}:#{k}", scope.variables[k] end else @variables[obj_name] = obj_class end end
add_var(var_name, var_class)
click to toggle source
# File lib/sdx/vm/scope.rb, line 12 def add_var(var_name, var_class) @variables[var_name] = var_class end
error(msg)
click to toggle source
# File lib/sdx/vm/scope.rb, line 4 def error(msg) puts "\x1b[0;31mError in VM: #{msg}\x1b[0;0m" end
get_fn(fn_name)
click to toggle source
# File lib/sdx/vm/scope.rb, line 45 def get_fn(fn_name) @variables[fn_name] end
get_var(var_name)
click to toggle source
# File lib/sdx/vm/scope.rb, line 20 def get_var(var_name) scope = self val = nil name = var_name.split "." name.each do |part| val = scope.variables[part] unless val return nil end case val.value when InstantiatedObj scope = val.value.internal else fields = {} if val.value.respond_to? :fields val.value.fields.each do |k, v| fields[k] = Variable.new v, (get_type v), self end scope = GLOBAL_SCOPE.new fields end end end return val end