more on classes, have to work on asm next
This commit is contained in:
parent
1d10c2c03e
commit
08bbad0fdc
@ -31,6 +31,12 @@ module Arm
|
|||||||
Vm::BranchCondition.new :gt
|
Vm::BranchCondition.new :gt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO wrong type, should be object_reference. But that needs the actual typing to work
|
||||||
|
def integer_at_index block , result ,left , right
|
||||||
|
block << ldr( result , left , right )
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
def integer_plus block , result , left , right
|
def integer_plus block , result , left , right
|
||||||
block << add( result , left , right )
|
block << add( result , left , right )
|
||||||
result
|
result
|
||||||
|
@ -16,13 +16,15 @@ module Ast
|
|||||||
end
|
end
|
||||||
def compile context , into
|
def compile context , into
|
||||||
clazz = context.object_space.get_or_create_class name
|
clazz = context.object_space.get_or_create_class name
|
||||||
|
puts "Created class #{clazz.name.inspect}"
|
||||||
context.current_class = clazz
|
context.current_class = clazz
|
||||||
expressions.each do |expression|
|
expressions.each do |expression|
|
||||||
# check if it's a function definition and add
|
# check if it's a function definition and add
|
||||||
# if not, execute it, but that does means we should be in crystal (executable), not ruby. ie throw an error for now
|
# if not, execute it, but that does means we should be in crystal (executable), not ruby. ie throw an error for now
|
||||||
raise "only functions for now #{expression.inspect}" unless expression.is_a? Ast::FunctionExpression
|
raise "only functions for now #{expression.inspect}" unless expression.is_a? Ast::FunctionExpression
|
||||||
|
puts "compiling expression #{expression.inspect}"
|
||||||
expression_value = expression.compile(context , nil )
|
expression_value = expression.compile(context , nil )
|
||||||
puts "compiled return expression #{expression_value.inspect}, now return in 7"
|
#puts "compiled expression #{expression_value.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -31,13 +31,14 @@ module Core
|
|||||||
get_function = Vm::Function.new(:_get_instance_variable , [Vm::Integer , Vm::Integer ] , Vm::Integer )
|
get_function = Vm::Function.new(:_get_instance_variable , [Vm::Integer , Vm::Integer ] , Vm::Integer )
|
||||||
me = get_function.args[0]
|
me = get_function.args[0]
|
||||||
var_name = get_function.args[1]
|
var_name = get_function.args[1]
|
||||||
|
return_to = get_function.return_type
|
||||||
index_function = context.object_space.get_or_create_class(:Object).get_or_create_function(:index_of)
|
index_function = context.object_space.get_or_create_class(:Object).get_or_create_function(:index_of)
|
||||||
b = get_function.body
|
b = get_function.body
|
||||||
b.push( me )
|
b.push( me )
|
||||||
index = b.call( index_function )
|
index = b.call( index_function )
|
||||||
b.pop(me)
|
b.pop(me)
|
||||||
b.mov( var_name , index )
|
return_to.at_index( get_function.body , me , index )
|
||||||
Vm::RegisterMachine.instance.at_index( get_function.body , number , remainder )
|
get_function.set_return return_to
|
||||||
return get_function
|
return get_function
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,11 +2,12 @@ module Vm
|
|||||||
# class is mainly a list of functions with a name (for now)
|
# class is mainly a list of functions with a name (for now)
|
||||||
# layout of object is seperated into Layout
|
# layout of object is seperated into Layout
|
||||||
class BootClass < Code
|
class BootClass < Code
|
||||||
def initialize name , context
|
def initialize name , context , superclass = :Object
|
||||||
@context = context
|
@context = context
|
||||||
# class functions
|
# class functions
|
||||||
@functions = []
|
@functions = []
|
||||||
@name = name.to_sym
|
@name = name.to_sym
|
||||||
|
@superclass = superclass
|
||||||
end
|
end
|
||||||
attr_reader :name , :functions
|
attr_reader :name , :functions
|
||||||
|
|
||||||
@ -24,6 +25,11 @@ module Vm
|
|||||||
# preferred way of creating new functions (also forward declarations, will flag unresolved later)
|
# preferred way of creating new functions (also forward declarations, will flag unresolved later)
|
||||||
def get_or_create_function name
|
def get_or_create_function name
|
||||||
fun = get_function name
|
fun = get_function name
|
||||||
|
unless fun or name == :Object
|
||||||
|
supr = @context.object_space.get_or_create_class(@superclass)
|
||||||
|
fun = supr.get_function name
|
||||||
|
puts "#{supr.functions.collect(&:name)} for #{name} GOT #{fun.class}" if name == :index_of
|
||||||
|
end
|
||||||
unless fun
|
unless fun
|
||||||
fun = Core::Kernel.send(name , @context)
|
fun = Core::Kernel.send(name , @context)
|
||||||
raise "no such function #{name}, #{name.class}" if fun == nil
|
raise "no such function #{name}, #{name.class}" if fun == nil
|
||||||
|
@ -45,6 +45,7 @@ module Vm
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_or_create_class name
|
def get_or_create_class name
|
||||||
|
raise "uups #{name}" unless name.is_a? Symbol
|
||||||
c = @classes[name]
|
c = @classes[name]
|
||||||
unless c
|
unless c
|
||||||
c = BootClass.new(name,@context)
|
c = BootClass.new(name,@context)
|
||||||
|
@ -118,6 +118,9 @@ module Vm
|
|||||||
def - other
|
def - other
|
||||||
class_for(LogicInstruction).new(nil , self , other , opcode: :sub )#, update_status: 1 )
|
class_for(LogicInstruction).new(nil , self , other , opcode: :sub )#, update_status: 1 )
|
||||||
end
|
end
|
||||||
|
def at_index block , left , right
|
||||||
|
RegisterMachine.instance.integer_at_index block , self , left , right
|
||||||
|
end
|
||||||
def plus block , first , right
|
def plus block , first , right
|
||||||
RegisterMachine.instance.integer_plus block , self , first , right
|
RegisterMachine.instance.integer_plus block , self , first , right
|
||||||
end
|
end
|
||||||
|
@ -6,14 +6,14 @@ class TestClass < MiniTest::Test
|
|||||||
def test_class
|
def test_class
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
|
def index_of( name )
|
||||||
|
return @layout.index_of(name)
|
||||||
|
end
|
||||||
def layout()
|
def layout()
|
||||||
return @layout
|
return @layout
|
||||||
end
|
end
|
||||||
def class()
|
def class()
|
||||||
return layout.class()
|
return @layout.class()
|
||||||
end
|
|
||||||
def index_of( name )
|
|
||||||
return layout.index_of(name)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class String
|
class String
|
||||||
@ -21,7 +21,7 @@ class String
|
|||||||
return @length
|
return @length
|
||||||
end
|
end
|
||||||
def plus(str)
|
def plus(str)
|
||||||
my_length = self.length()
|
my_length = @length
|
||||||
str_len = str.length()
|
str_len = str.length()
|
||||||
new_string = String.new(my_length + str_len)
|
new_string = String.new(my_length + str_len)
|
||||||
i = 0
|
i = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user