more expressions compile
This commit is contained in:
parent
8e6297dcff
commit
7341586d15
@ -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
|
||||
|
@ -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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user