more expressions compile

This commit is contained in:
Torsten Ruger 2014-05-10 10:58:25 +03:00
parent 8e6297dcff
commit 7341586d15
3 changed files with 28 additions and 0 deletions

View File

@ -7,6 +7,9 @@ module Ast
def initialize val
@value = val
end
def compile context
Vm::Signed.new value
end
def == other
compare other , [:value]
end

View File

@ -7,5 +7,24 @@ module Ast
def == other
compare other , [:name, :params, :block]
end
def compile context
args = params.collect{|p| Vm::Value.type p.name }
function = Vm::Function.new(name ,args )
parent_locals = context.locals
context.locals = {}
block.each do |b|
compiled = b.compile context
if compiled.is_a? Vm::Block
he.breaks.loose
else
function.body.add_code compiled
end
puts compiled.inspect
end
context.locals = parent_locals if parent_locals
function
end
end
end

View File

@ -26,6 +26,12 @@ module Ast
def initialize assignee, assigned
@assignee, @assigned = assignee, assigned
end
def compile context
var = @assigned.compile(context)
context.locals[@assignee] = var
end
def == other
compare other , [:assignee, :assigned]
end