Lots of preloading for tests
so many relied (implicitly( on some builtin function after all can't do much in ruby without calling Now all those dependencies are explicit Small risc changes come because the macro version has a return label and unreachable label
This commit is contained in:
@ -1,6 +1,11 @@
|
||||
|
||||
module ScopeHelper
|
||||
|
||||
def compiler_with_main(options = {})
|
||||
compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options.merge(options))
|
||||
compiler.ruby_to_vool( "class Space;def main(arg);return;end;end" )
|
||||
compiler
|
||||
end
|
||||
def in_Test(statements)
|
||||
"class Test ; #{statements} ; end"
|
||||
end
|
||||
|
@ -1,13 +1,32 @@
|
||||
module Preloader
|
||||
def builtin
|
||||
{
|
||||
"Integer.div4" => "def div4; X.div4;end",
|
||||
"Integer.ge" => "def >; X.comparison(:>);end",
|
||||
"Object.get" => "def get_internal_word(at); X.get_internal_word;end",
|
||||
"Object.missing" => "def method_missing(at); X.method_missing;end",
|
||||
"Object.init" => "def __init__(at); X.init;end",
|
||||
"Object.exit" => "def exit; X.exit;end",
|
||||
"Integer.div4" => "def div4; X.div4;end",
|
||||
"Integer.div10" => "def div10; X.div10;end",
|
||||
"Integer.gt" => "def >; X.comparison(:>);end",
|
||||
"Integer.lt" => "def <; X.comparison(:<);end",
|
||||
"Integer.ge" => "def >=; X.comparison(:>=);end",
|
||||
"Integer.le" => "def <=; X.comparison(:<=);end",
|
||||
"Integer.plus" => "def +; X.int_operator(:+);end",
|
||||
"Integer.minus" => "def -; X.int_operator(:-);end",
|
||||
"Integer.mul" => "def *; X.int_operator(:*);end",
|
||||
"Integer.and" => "def &; X.int_operator(:&);end",
|
||||
"Integer.or" => "def |; X.int_operator(:|);end",
|
||||
"Integer.ls" => "def <<; X.int_operator(:<<);end",
|
||||
"Integer.rs" => "def >>; X.int_operator(:>>);end",
|
||||
"Word.put" => "def putstring(at); X.putstring;end",
|
||||
"Word.set" => "def set_internal_byte(at, val); X.set_internal_byte;end",
|
||||
"Word.get" => "def get_internal_byte(at); X.get_internal_byte;end",
|
||||
"Space.main" => "def main(args);return;end",
|
||||
}
|
||||
end
|
||||
def get_preload(preload)
|
||||
return "" unless preload
|
||||
preload = builtin.keys.join(";") if(preload == "all" )
|
||||
preload.split(";").collect do |loads|
|
||||
raise "no preload #{loads}" unless builtin[loads]
|
||||
clazz , meth = loads.split(".")
|
||||
|
@ -6,10 +6,11 @@ module Risc
|
||||
module Ticker
|
||||
include ScopeHelper
|
||||
include Output
|
||||
include Preloader
|
||||
|
||||
def setup
|
||||
compiler = RubyX::RubyXCompiler.new(RubyX.interpreter_test_options)
|
||||
@linker = compiler.ruby_to_binary(@string_input, :interpreter)
|
||||
@linker = compiler.ruby_to_binary(preload + @string_input, :interpreter)
|
||||
@interpreter = Interpreter.new(@linker)
|
||||
@interpreter.start_program
|
||||
end
|
||||
@ -103,17 +104,11 @@ module Risc
|
||||
# use the input as it, compile and run it
|
||||
# input muts contain a Space.main, but may contain more classes and methods
|
||||
def run_input(input)
|
||||
@string_input = input
|
||||
@string_input = preload + input
|
||||
do_setup
|
||||
run_all
|
||||
end
|
||||
|
||||
# wrap the input in Space (main is assumed to be part of it)
|
||||
def run_space(input)
|
||||
@string_input = in_Space(input)
|
||||
do_setup
|
||||
run_all
|
||||
end
|
||||
def run_all
|
||||
while(@interpreter.instruction)
|
||||
@interpreter.tick
|
||||
|
Reference in New Issue
Block a user