move compiler to bosl and get first test working (adjusting syntax as i go)

This commit is contained in:
Torsten Ruger
2015-09-19 16:28:41 +03:00
parent ab8bb55789
commit 2061097e88
18 changed files with 107 additions and 111 deletions

View File

@ -0,0 +1,23 @@
module Bosl
module Compiler
# attr_reader :name
# compiling name needs to check if it's a variable and if so resolve it
# otherwise it's a method without args and a send is issued.
# whichever way this goes the result is stored in the return slot (as all compiles)
def self.compile_name expression , method
name = expression.to_a.first
return Virtual::Self.new( Reference.new(method.for_class)) if name == :self
# either an argument, so it's stored in message
ret = Virtual::Return.new
if( index = method.has_arg(name))
method.source.add_code Virtual::Set.new( Virtual::ArgSlot.new(index ) , ret)
else # or a local so it is in the frame
index = method.ensure_local( name )
method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(index ) , ret )
end
return ret
end
end #module
end