Torsten Rüger
1ee01622c3
All preloading where it needs to be (some)tests for the preload split compiler test remembered binary tests (usually just run on travis)
40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
class RubyXC < Thor
|
|
|
|
desc "interpret FILE" , "Interpret given FILE "
|
|
long_desc <<-LONGDESC
|
|
Compiles the given file to an intermediate RISC format, and runs the
|
|
Interpreter.
|
|
|
|
RISC is the last abstract layer inside the compiler. It is in nature
|
|
very close to arm (without quirks and much smaller).
|
|
|
|
An interpreter was originally developed for the RISC layer for debugging purposes.
|
|
Running the interpreter is about 50k slower than binary, but it can be used
|
|
to veryfy simple programs.
|
|
|
|
No output file will be generated, the only output is generated by the
|
|
given program.
|
|
|
|
The program must define a main method on the Space class, which will be invoked.
|
|
LONGDESC
|
|
|
|
def interpret(file)
|
|
begin
|
|
ruby = File.read(file)
|
|
rescue
|
|
fail MalformattedArgumentError , "No such file #{file}"
|
|
end
|
|
code = get_preload + ruby
|
|
|
|
compiler = RubyX::RubyXCompiler.new(extract_options)
|
|
linker = compiler.ruby_to_binary(code, :interpreter)
|
|
|
|
puts "interpreting #{file}"
|
|
|
|
interpreter = Risc::Interpreter.new(linker , STDOUT )
|
|
interpreter.start_program
|
|
interpreter.tick while(interpreter.instruction)
|
|
|
|
end
|
|
end
|