diff --git a/lib/ast/basic_expressions.rb b/lib/ast/basic_expressions.rb index 5433798d..ba4cc8c4 100644 --- a/lib/ast/basic_expressions.rb +++ b/lib/ast/basic_expressions.rb @@ -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 diff --git a/lib/ast/function_expression.rb b/lib/ast/function_expression.rb index 27564555..88aadf56 100644 --- a/lib/ast/function_expression.rb +++ b/lib/ast/function_expression.rb @@ -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 \ No newline at end of file diff --git a/lib/ast/operator_expressions.rb b/lib/ast/operator_expressions.rb index c8b4edab..10dfa0a6 100644 --- a/lib/ast/operator_expressions.rb +++ b/lib/ast/operator_expressions.rb @@ -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