remoe hash attributes (less magic) and make attributes on context explicit

This commit is contained in:
Torsten Ruger 2014-06-07 22:41:02 +03:00
parent 36f237c633
commit 6b715bbb1b
2 changed files with 6 additions and 33 deletions

View File

@ -1,26 +0,0 @@
# Make hash attributes to object attributes
module Support
module HashAttributes
# 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
sname = name.to_s
if args.length == 1 #must be assignemnt for ir attr= val
if sname.include? "="
#puts "setting :#{name.chop}:#{args[0]}"
return @attributes[sname.chop.to_sym] = args[0]
else
super
end
else
#puts "getting :#{name}:#{@attributes[name.to_sym]}"
return @attributes[sname.to_sym]
end
end
end
end
end

View File

@ -1,17 +1,16 @@
require "support/hash_attributes"
module Vm
#currently just holding the object_space in here so we can have global access
class Context
# Make hash attributes to object attributes
include Support::HashAttributes
def initialize object_space
@attributes = {}
@attributes[:object_space] = object_space
@object_space = object_space
@locals = {}
end
attr_reader :attributes
attr_accessor :current_class
attr_reader :attributes ,:object_space
attr_accessor :current_class , :locals , :function
end
end