fixing fragment tests, most done

This commit is contained in:
Torsten Ruger
2014-06-07 23:22:32 +03:00
parent 6b715bbb1b
commit 0a14cffefb
16 changed files with 49 additions and 42 deletions

View File

@@ -12,14 +12,24 @@ module Ast
class NameExpression < Expression
# attr_reader :name
# compiling a variable resolves it.
# if it wasn't defined, nli is returned
# compiling a variable resolves it. if it wasn't defined, raise an exception
def compile context , into
raise "Undefined variable #{name}, defined locals #{context.locals.keys.join('-')}" unless context.locals.has_key?(name)
context.locals[name]
end
end
class ModuleName < NameExpression
def compile context , into
clazz = context.object_space.get_or_create_class name
raise "uups #{clazz}.#{name}" unless clazz
#class qualifier, means call from metaclass
clazz = clazz.meta_class
value = clazz
puts "CLAZZ #{value}"
function = clazz.get_or_create_function(name)
end
end
class StringExpression < Expression

View File

@@ -7,28 +7,20 @@ module Ast
def compile context , into
params = args.collect{ |a| a.compile(context, into) }
if receiver.name == :self
if receiver.is_a?(NameExpression) and (receiver.name == :self)
function = context.current_class.get_or_create_function(name)
value = Vm::Integer.new(Vm::Function::RECEIVER_REG)
elsif receiver.is_a? ModuleName
c_name = receiver.name
clazz = context.object_space.get_or_create_class c_name
raise "uups #{clazz}.#{c_name}" unless clazz
#class qualifier, means call from metaclass
clazz = clazz.meta_class
value = clazz
puts "CLAZZ #{value}"
function = clazz.get_or_create_function(name)
elsif receiver.is_a? VariableExpression
raise "not implemented instance var:#{receiver}"
value_receiver = Vm::Integer.new(Vm::Function::RECEIVER_REG)
else
# should be case switch for basic tyes and dynamic dispatch for objects reference
value = context.locals[receiver.name]
raise "no value" unless value
value_receiver = receiver.compile(context , into)
function = context.current_class.get_or_create_function(name)
end
raise "No such method error #{clazz.to_s}:#{name}" if function == nil
call = Vm::CallSite.new( name , value , params , function)
# this lot below should go, since the compile should handle all
if receiver.is_a? VariableExpression
raise "not implemented instance var:#{receiver}"
end
raise "No such method error #{3.to_s}:#{name}" if (function.nil?)
raise "No receiver error #{inspect}:#{value_receiver}:#{name}" if (value_receiver.nil?)
call = Vm::CallSite.new( name , value_receiver , params , function)
current_function = context.function
current_function.save_locals(context , into) if current_function
call.load_args into

View File

@@ -25,7 +25,9 @@ module Ast
parent_locals = context.locals
parent_function = context.function
puts "Locals #{locals.keys.join('-')}, #{locals.object_id}"
context.locals = locals
puts "Locals #{context.locals.keys.join('-')}, #{context.locals.object_id}"
context.function = function
into = function.body

View File

@@ -7,6 +7,7 @@ module Ast
#puts "compiled right #{r_val.inspect}"
if operator == "=" # assignment, value based
raise "Can only assign variables, not #{left}" unless left.is_a?(NameExpression)
puts context.inspect unless context.locals
l_val = context.locals[left.name]
if( l_val ) #variable existed, move data there
l_val = l_val.move( into , r_val)
@@ -18,7 +19,6 @@ module Ast
end
l_val = left.compile(context , into)
case operator
when ">"
code = l_val.greater_than into , r_val

View File

@@ -5,6 +5,7 @@ module Ast
while_block = into.new_block "#{into.name}_while"
ret = while_block.new_block "#{into.name}_return"
puts "compiling while condition #{condition}"
puts "Locals #{context.locals.keys.join('-')}, #{context.locals.object_id}"
cond_val = condition.compile(context , while_block)
while_block.b ret , condition_code: cond_val.not_operator
last = nil