another step closer to a working oo system
This commit is contained in:
parent
ca19f5cb16
commit
72d4adc7af
@ -11,7 +11,7 @@ module Arm
|
||||
@attributes[:update_status] = 0 if @attributes[:update_status] == nil
|
||||
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil
|
||||
@operand = 0
|
||||
|
||||
raise "alert" if right.is_a? Vm::Block
|
||||
@pre_post_index = 0 #P flag
|
||||
@add_offset = 0 #U flag
|
||||
@is_load = opcode.to_s[0] == "l" ? 1 : 0 #L (load) flag
|
||||
@ -31,7 +31,10 @@ module Arm
|
||||
@rn = arg
|
||||
if @right
|
||||
@operand = @right
|
||||
#TODO better test, this operand integer (register) does not work. but sleep first
|
||||
@operand = @operand.register if @operand.is_a? Vm::Integer
|
||||
unless( @operand.is_a? Symbol)
|
||||
puts "operand #{@operand.inspect}"
|
||||
if (@operand < 0)
|
||||
@add_offset = 0
|
||||
#TODO test/check/understand
|
||||
|
@ -35,7 +35,7 @@ module Ast
|
||||
"#{self.class.name}.new(#{name})"
|
||||
end
|
||||
def to_s
|
||||
name
|
||||
name.to_s
|
||||
end
|
||||
def attributes
|
||||
[:name]
|
||||
@ -54,7 +54,7 @@ module Ast
|
||||
self.class.name + '.new("' + string + '")'
|
||||
end
|
||||
def to_s
|
||||
'"' + string + '"'
|
||||
'"' + string.to_s + '"'
|
||||
end
|
||||
def compile context , into
|
||||
value = Vm::StringConstant.new(string)
|
||||
|
@ -13,15 +13,21 @@ module Ast
|
||||
def compile context , into
|
||||
params = args.collect{ |a| a.compile(context, into) }
|
||||
|
||||
r = context.current_class.name
|
||||
if !receiver.nil? and receiver.name != :self
|
||||
r = receiver.name
|
||||
raise "uups #{receiver.class}.#{receiver.name.class}" unless r.is_a? Symbol
|
||||
if receiver.name == :self
|
||||
function = context.current_class.get_or_create_function(name)
|
||||
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
|
||||
function = clazz.get_or_create_function(name)
|
||||
elsif receiver.is_a? VariableExpression
|
||||
raise "not implemented instance var:#{receiver}"
|
||||
else
|
||||
raise "not implemented case (dare i say system error):#{receiver}"
|
||||
end
|
||||
clazz = context.object_space.get_or_create_class r
|
||||
|
||||
function = context.current_class.get_function(name)
|
||||
raise "Forward declaration not implemented for #{clazz.name}:#{name} #{inspect}" if function == nil
|
||||
raise "No such method error #{clazz.to_s}:#{name}" if function == nil
|
||||
call = Vm::CallSite.new( name , params , function)
|
||||
current_function = context.function
|
||||
current_function.save_locals(context , into) if current_function
|
||||
|
@ -24,10 +24,10 @@ module Boot
|
||||
return_to = get_function.return_type
|
||||
index_function = context.object_space.get_or_create_class(:Object).get_or_create_function(:index_of)
|
||||
b = get_function.body
|
||||
b.push( me )
|
||||
index = b.call( index_function )
|
||||
b.pop(me)
|
||||
return_to.at_index( get_function.body , me , index )
|
||||
b.push( [me] )
|
||||
b.call( index_function )
|
||||
b.pop([me])
|
||||
return_to.at_index( get_function.body , me , return_to )
|
||||
get_function.set_return return_to
|
||||
return get_function
|
||||
end
|
||||
|
@ -1,26 +1,6 @@
|
||||
# this is not a "normal" ruby file, ie it is not required by crystal
|
||||
# instead it is parsed by crystal to define part of the crystal that runs
|
||||
|
||||
class BaseObject
|
||||
|
||||
def _set_instance_variable(name , value)
|
||||
|
||||
end
|
||||
|
||||
def _get_instance_variable( name )
|
||||
|
||||
end
|
||||
|
||||
def _get_singleton_method(name )
|
||||
|
||||
end
|
||||
def _add_singleton_method(method)
|
||||
|
||||
end
|
||||
def initialize
|
||||
end
|
||||
end
|
||||
|
||||
class Array < BaseObject
|
||||
def initialize size
|
||||
|
||||
|
@ -21,9 +21,11 @@ module Vm
|
||||
@functions << function
|
||||
end
|
||||
|
||||
def get_function name
|
||||
name = name.to_sym
|
||||
@functions.detect{ |f| f.name == name }
|
||||
def get_function fname
|
||||
fname = fname.to_sym
|
||||
f = @functions.detect{ |f| f.name == fname }
|
||||
names = @functions.collect{|f| f.name }
|
||||
f
|
||||
end
|
||||
|
||||
# way of creating new functions that have not been parsed.
|
||||
@ -36,12 +38,15 @@ module Vm
|
||||
end
|
||||
unless fun
|
||||
fun = Core::Kernel.send(name , @context)
|
||||
raise "no such function #{name}, #{name.class}" if fun == nil
|
||||
return nil if fun == nil
|
||||
@functions << fun
|
||||
end
|
||||
fun
|
||||
end
|
||||
|
||||
def inspect
|
||||
"BootClass #{@name} , super #{@super_class} #{@functions.length} functions"
|
||||
end
|
||||
# Code interface follows. Note position is inheitted as is from Code
|
||||
|
||||
# length of the class is the length of it's functions
|
||||
|
@ -45,6 +45,7 @@ module Vm
|
||||
# dummies, just for the other to compile
|
||||
obj = get_or_create_class :Object
|
||||
[:index_of , :_get_instance_variable].each do |f|
|
||||
puts "adding #{f}"
|
||||
obj.add_function Boot::Object.send(f , @context)
|
||||
end
|
||||
end
|
||||
|
@ -26,6 +26,7 @@ module Vm
|
||||
attr_reader :string
|
||||
# currently aligned to 4 (ie padded with 0) and off course 0 at the end
|
||||
def initialize str
|
||||
str = str.to_s if str.is_a? Symbol
|
||||
length = str.length
|
||||
# rounding up to the next 4 (always adding one for zero pad)
|
||||
pad = ((length / 4 ) + 1 ) * 4 - length
|
||||
|
@ -26,8 +26,12 @@ module Vm
|
||||
|
||||
def get_function name
|
||||
name = name.to_sym
|
||||
@functions.detect{ |f| f.name == name }
|
||||
f = @functions.detect{ |f| f.name == name }
|
||||
puts "no function for #{name} in Meta #{@me_self.inspect}" unless f
|
||||
f
|
||||
end
|
||||
def inspect
|
||||
"#{@me_self}, #{@functions.length} functions"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -3,7 +3,7 @@ require_relative 'helper'
|
||||
class TestWhileFragment < MiniTest::Test
|
||||
include Fragments
|
||||
|
||||
def test_while
|
||||
def test_while_fibo
|
||||
@string_input = <<HERE
|
||||
def fibonaccit(n) # n == r0
|
||||
a = 0 # a == r1
|
||||
|
Loading…
Reference in New Issue
Block a user