get some old builtin code backonline and improve imports

This commit is contained in:
Torsten Ruger 2014-09-09 18:03:13 +03:00
parent 61e80d4f28
commit 5a5e977b8f
11 changed files with 25 additions and 24 deletions

View File

@ -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}"

View File

@ -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)

View File

@ -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")

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -43,6 +43,7 @@ module Virtual
else
@@space = BootSpace.new
@@space.boot_classes! # boot is a verb here
@@space
end
end

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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]