rubyx/lib/vm/context.rb

33 lines
801 B
Ruby
Raw Normal View History

2014-05-02 07:02:25 +02:00
require_relative "kernel"
2014-05-03 14:13:44 +02:00
require_relative "program"
2014-05-02 07:02:25 +02:00
module Vm
2014-05-03 14:13:44 +02:00
#currently just holding the program in here so we can have global access
2014-05-02 07:02:25 +02:00
class Context
2014-05-03 14:13:44 +02:00
def initialize program
@attributes = {}
@attributes["program"] = program
2014-05-02 07:02:25 +02:00
end
2014-05-03 14:13:44 +02:00
# map any function call to an attribute if possible
def method_missing name , *args , &block
if args.length > 1 or block_given?
puts "NO -#{args.length} BLOCK #{block_given?}"
super
else
name = name.to_s
if args.length == 1 #must be assignemnt for ir attr= val
if name.include? "="
return @attributes[name.chop] = args[0]
else
super
end
else
return @attributes[name]
end
2014-05-02 07:02:25 +02:00
end
2014-05-03 14:13:44 +02:00
end
2014-05-02 07:02:25 +02:00
end
end