From 5a5e977b8f3ac3e6015a17f20c8f4666413eb923 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 9 Sep 2014 18:03:13 +0300 Subject: [PATCH] get some old builtin code backonline and improve imports --- lib/ast/call_site_expression.rb | 10 +++++----- lib/builtin/integer.rb | 2 +- lib/builtin/object.rb | 16 ++++++++-------- lib/register/register_machine.rb | 4 ++-- lib/register/set_implementation.rb | 2 +- lib/virtual/boot_class.rb | 2 +- lib/virtual/boot_space.rb | 1 + lib/virtual/compiled_method.rb | 2 +- lib/virtual/get_implementation.rb | 4 ++-- lib/virtual/meta_class.rb | 2 +- test/fragments/test_while_fibo.rb | 4 ++-- 11 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/ast/call_site_expression.rb b/lib/ast/call_site_expression.rb index 6b6fc15d..cffa7f8a 100644 --- a/lib/ast/call_site_expression.rb +++ b/lib/ast/call_site_expression.rb @@ -25,24 +25,24 @@ module Ast if receiver.is_a? ModuleName clazz = context.object_space.get_or_create_class receiver.name value_receiver = clazz.meta_class - function = value_receiver.resolve_function name + function = value_receiver.resolve_method name elsif receiver.is_a?(StringExpression) or receiver.is_a?(IntegerExpression) #TODO obviously the class is wrong, but you gotta start somewhere clazz = context.object_space.get_or_create_class :Object - function = clazz.resolve_function name + function = clazz.resolve_method name value_receiver = receiver.compile(context) elsif receiver.is_a?(NameExpression) if(receiver.name == :self) - function = context.current_class.resolve_function(name) + function = context.current_class.resolve_method(name) value_receiver = Virtual::Integer.new(Virtual::RegisterMachine.instance.receiver_register) else value_receiver = receiver.compile(context) # TODO HACK warning: should determine class dynamically - function = context.current_class.resolve_function(name) + function = context.current_class.resolve_method(name) end elsif receiver.is_a? VariableExpression value_receiver = receiver.compile(context) - function = context.current_class.resolve_function(name) + function = context.current_class.resolve_method(name) else #This , how does one say nowadays, smells. Smells of unused polymorphism actually raise "Not sure this is possible, but never good to leave elses open #{receiver} #{receiver.class}" diff --git a/lib/builtin/integer.rb b/lib/builtin/integer.rb index 39b99d24..9180bec1 100644 --- a/lib/builtin/integer.rb +++ b/lib/builtin/integer.rb @@ -31,7 +31,7 @@ module Builtin context.object_space.add_object buffer # and save it (function local variable: a no no) int = putint_function.receiver moved_int = putint_function.new_local - utoa = context.object_space.get_or_create_class(:Object).resolve_function(:utoa) + utoa = context.object_space.get_or_create_class(:Object).resolve_method(:utoa) putint_function.instance_eval do mov( moved_int , int ) # move arg up add( int , buffer ,nil ) # string to write to (add string address to pc) diff --git a/lib/builtin/object.rb b/lib/builtin/object.rb index 8d9d7f79..bdc451d1 100644 --- a/lib/builtin/object.rb +++ b/lib/builtin/object.rb @@ -24,22 +24,22 @@ module Builtin # The at_index is just "below" the api, something we need but don't want to expose, so we can't code the above in ruby def _get_instance_variable context , name = Virtual::Integer get_function = Virtual::CompiledMethod.new(:_get_instance_variable , [ Virtual::Reference ] , Virtual::Reference ,Virtual::Mystery ) - return get_function +# return get_function me = get_function.receiver var_name = get_function.args.first return_to = get_function.return_type - index_function = context.object_space.get_or_create_class(:Object).resolve_function(:index_of) - get_function.push( [me] ) - index = get_function.call( index_function ) + index_function = ::Virtual::BootSpace.space.get_or_create_class(:Object).resolve_method(:index_of) +# get_function.push( [me] ) +# index = get_function.call( index_function ) after_body = get_function.new_block("after_index") get_function.current after_body - get_function.pop([me]) - return_to.at_index( get_function , me , return_to ) +# get_function.pop([me]) +# return_to.at_index( get_function , me , return_to ) - get_function.set_return return_to +# get_function.set_return return_to return get_function end @@ -50,7 +50,7 @@ module Builtin me = set_function.receiver var_name = set_function.args.first return_to = set_function.return_type - index_function = context.object_space.get_or_create_class(:Object).resolve_function(:index_of) + index_function = context.object_space.get_or_create_class(:Object).resolve_method(:index_of) set_function.push( [me] ) set_function.call( index_function ) after_body = set_function.new_block("after_index") diff --git a/lib/register/register_machine.rb b/lib/register/register_machine.rb index ab7fb35c..26e6add7 100644 --- a/lib/register/register_machine.rb +++ b/lib/register/register_machine.rb @@ -146,9 +146,9 @@ module Register end require_relative "instruction" require_relative "register_reference" +require "arm/arm_machine" +require_relative "assembler" require_relative "set_implementation" require_relative "call_implementation" require_relative "enter_implementation" require_relative "return_implementation" -require "arm/arm_machine" -require_relative "assembler" diff --git a/lib/register/set_implementation.rb b/lib/register/set_implementation.rb index c2e9774f..fa59bed2 100644 --- a/lib/register/set_implementation.rb +++ b/lib/register/set_implementation.rb @@ -17,5 +17,5 @@ module Register end end end - Virtual::BootSpace.space.add_pass_after SetImplementation , GetImplementation + Virtual::BootSpace.space.add_pass_after SetImplementation , Virtual::GetImplementation end diff --git a/lib/virtual/boot_class.rb b/lib/virtual/boot_class.rb index 0346e72f..8a76b40e 100644 --- a/lib/virtual/boot_class.rb +++ b/lib/virtual/boot_class.rb @@ -28,7 +28,7 @@ module Virtual # get the method and if not found, try superclasses. raise error if not found def resolve_method name - fun = get_method name + fun = get_instance_method name unless fun or name == :Object supr = @context.object_space.get_or_create_class(@super_class_name) fun = supr.get_method name diff --git a/lib/virtual/boot_space.rb b/lib/virtual/boot_space.rb index 38768f0a..3cf8af90 100644 --- a/lib/virtual/boot_space.rb +++ b/lib/virtual/boot_space.rb @@ -43,6 +43,7 @@ module Virtual else @@space = BootSpace.new @@space.boot_classes! # boot is a verb here + @@space end end diff --git a/lib/virtual/compiled_method.rb b/lib/virtual/compiled_method.rb index 93862d28..2c6fe9f6 100644 --- a/lib/virtual/compiled_method.rb +++ b/lib/virtual/compiled_method.rb @@ -160,7 +160,7 @@ module Virtual # to the current block # also symbols are supported and wrapped as register usages (for bare metal programming) def method_missing(meth, *args, &block) - add_code Register::RegisterMachine.instance.send(meth , *args) + add_code ::Register::RegisterMachine.instance.send(meth , *args) end # position of the function is the position of the entry block, is where we call diff --git a/lib/virtual/get_implementation.rb b/lib/virtual/get_implementation.rb index 069d94a1..97b4d833 100644 --- a/lib/virtual/get_implementation.rb +++ b/lib/virtual/get_implementation.rb @@ -1,4 +1,4 @@ -module Register +module Virtual # This implements instance variable get (not the opposite of Set, such a thing does not exists, their slots) # Ivar get needs to acces the layout, find the index of the name, and shuffle the data to return register @@ -11,5 +11,5 @@ module Register end end end - Virtual::BootSpace.space.add_pass_after GetImplementation, Virtual::SendImplementation + Virtual::BootSpace.space.add_pass_after GetImplementation, SendImplementation end diff --git a/lib/virtual/meta_class.rb b/lib/virtual/meta_class.rb index 3d39a8b1..6cb74dfe 100644 --- a/lib/virtual/meta_class.rb +++ b/lib/virtual/meta_class.rb @@ -39,7 +39,7 @@ module Virtual end # get the function and if not found, try superclasses. raise error if not found - def resolve_function name + def resolve_method name fun = get_function name # TODO THE BOOK says is class A derives from B , then the metaclass of A derives from the metaclass of B # just get to it ! (and stop whimpering) diff --git a/test/fragments/test_while_fibo.rb b/test/fragments/test_while_fibo.rb index 55790289..5363dd08 100644 --- a/test/fragments/test_while_fibo.rb +++ b/test/fragments/test_while_fibo.rb @@ -31,12 +31,12 @@ HERE # not my hand off course, found in the net from a basic introduction def test_kernel_fibo int = Register::Integer.new(Register::RegisterMachine.instance.receiver_register) - fibo = @object_space.get_or_create_class(:Object).resolve_function(:fibo) + fibo = @object_space.get_or_create_class(:Object).resolve_method(:fibo) main = @object_space.main main.mov int , 10 main.call( fibo ) main.mov( Register::RegisterMachine.instance.receiver_register , Register::RegisterMachine.instance.return_register ) - putint = @object_space.get_or_create_class(:Object).resolve_function(:putint) + putint = @object_space.get_or_create_class(:Object).resolve_method(:putint) main.call( putint ) @should = [0x0,0x40,0x2d,0xe9,0x1,0x0,0x52,0xe3,0x2,0x0,0xa0,0xd1,0x7,0x0,0x0,0xda,0x1,0x30,0xa0,0xe3,0x0,0x40,0xa0,0xe3,0x4,0x30,0x83,0xe0,0x4,0x40,0x43,0xe0,0x1,0x20,0x42,0xe2,0x1,0x0,0x52,0xe3,0xfa,0xff,0xff,0x1a,0x3,0x0,0xa0,0xe1,0x0,0x80,0xbd,0xe8] @target = [:Object , :fibo]