more expressions compile
This commit is contained in:
parent
8e6297dcff
commit
7341586d15
@ -7,6 +7,9 @@ module Ast
|
|||||||
def initialize val
|
def initialize val
|
||||||
@value = val
|
@value = val
|
||||||
end
|
end
|
||||||
|
def compile context
|
||||||
|
Vm::Signed.new value
|
||||||
|
end
|
||||||
def == other
|
def == other
|
||||||
compare other , [:value]
|
compare other , [:value]
|
||||||
end
|
end
|
||||||
|
@ -7,5 +7,24 @@ module Ast
|
|||||||
def == other
|
def == other
|
||||||
compare other , [:name, :params, :block]
|
compare other , [:name, :params, :block]
|
||||||
end
|
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
|
||||||
end
|
end
|
@ -26,6 +26,12 @@ module Ast
|
|||||||
def initialize assignee, assigned
|
def initialize assignee, assigned
|
||||||
@assignee, @assigned = assignee, assigned
|
@assignee, @assigned = assignee, assigned
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def compile context
|
||||||
|
var = @assigned.compile(context)
|
||||||
|
context.locals[@assignee] = var
|
||||||
|
end
|
||||||
|
|
||||||
def == other
|
def == other
|
||||||
compare other , [:assignee, :assigned]
|
compare other , [:assignee, :assigned]
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user