prune builtin

will need much less, many more things can be expressed in soml
This commit is contained in:
Torsten Ruger 2015-10-23 15:13:05 +03:00
parent 147a77f4e4
commit 6754518daf
6 changed files with 4 additions and 83 deletions

View File

@ -146,19 +146,19 @@ module Register
# have to define some dummies, just for the other to compile
# TODO go through the virtual parfait layer and adjust function names to what they really are
obj = @space.get_class_by_name(:Object)
[:main , :_get_instance_variable , :_set_instance_variable].each do |f|
[:main ].each do |f|
obj.add_instance_method Builtin::Object.send(f , nil)
end
obj = @space.get_class_by_name(:Kernel)
# create __init__ main first, __init__ calls it
[:exit,:__send , :__init__ ].each do |f|
[:exit , :__init__ ].each do |f|
obj.add_instance_method Builtin::Kernel.send(f , nil)
end
@space.get_class_by_name(:Word).add_instance_method Builtin::Word.send(:putstring , nil)
obj = @space.get_class_by_name(:Integer)
[:putint,:fibo , :plus].each do |f|
[:putint,:fibo ].each do |f|
obj.add_instance_method Builtin::Integer.send(f , nil)
end
end

View File

@ -4,22 +4,6 @@ module Register
module Integer
module ClassMethods
include AST::Sexp
def plus c
plus_function = MethodSource.create_method(:Integer,:Integer,:plus , [:Integer] )
plus_function.source.set_return_type :Integer
plus_function.source.receiver = :Integer
tmp = Register.tmp_reg :Integer
index = Register.arg_index 1
plus_function.source.add_code Register.get_slot( plus_function , :message , index , tmp )
me = Register.tmp_reg :Integer
plus_function.source.add_code Register.get_slot(plus_function , :message , :receiver , me )
add = OperatorInstruction.new( plus_function, :add , me , tmp )
plus_function.source.add_code add
plus_function.source.add_code Register.set_slot(plus_function , me , :message , :return_value )
return plus_function
end
# The conversion to base10 is quite a bit more complicated than i thought.
# The bulk of it is in div10

View File

@ -33,11 +33,6 @@ module Register
function.set_return ret
function
end
def __send context
function = MethodSource.create_method(:Kernel,:Integer ,:__send , [] )
function.source.set_return_type :Integer
return function
end
def emit_syscall function , name
save_message( function )

View File

@ -10,62 +10,6 @@ module Register
return function
end
# in ruby, how this goes is
# def _get_instance_variable var
# i = self.index_of(var)
# return at_index(i)
# end
# 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 = :Integer
get_function = MethodSource.create_method(:Object,:Integer, :_get_instance_variable , [ ] )
return get_function
# me = get_function.receiver
# var_name = get_function.args.first
# return_to = get_function.return_type
#
# index_function = ::Register.machine.space.get_class_by_name(: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.set_return return_to
# return get_function
end
def _set_instance_variable(context , name = :Integer , value = :Integer )
set_function = MethodSource.create_method(:Object,:Integer,:_set_instance_variable ,[] )
return set_function
# receiver set_function
# me = set_function.receiver
# var_name = set_function.args.first
# return_to = set_function.return_type
# index_function = context.object_space.get_class_by_name(:Object).resolve_method(:index_of)
# set_function.push( [me] )
# set_function.call( index_function )
# after_body = set_function.new_block("after_index")
#
# set_function.current after_body
# set_function.pop([me])
# return_to.at_index( set_function , me , return_to )
# set_function.set_return return_to
# return set_function
end
def _get_singleton_method(context , name )
raise name
end
def _add_singleton_method(context, method)
raise "4"
end
def initialize(context)
raise "4"
end
end
extend ClassMethods
end

View File

@ -4,7 +4,6 @@ class HelloTest < MiniTest::Test
def check
machine = Register.machine.boot
Parfait::Space.object_space.get_class_by_name(:Integer).remove_instance_method :plus
#TODO remove this hack: write proper aliases
statements = machine.parse_and_compile @string_input
output_at = "Register::CallImplementation"

View File

@ -19,8 +19,7 @@ class TestSpace < MiniTest::Test
end
def test_integer
int = Parfait::Space.object_space.get_class_by_name :Integer
assert_equal 3, int.method_names.get_length
assert int.get_instance_method( :plus )
assert_equal 2, int.method_names.get_length
end
def test_classes_class