diff --git a/lib/arm/arm_machine.rb b/lib/arm/arm_machine.rb index b81941b2..33e6515e 100644 --- a/lib/arm/arm_machine.rb +++ b/lib/arm/arm_machine.rb @@ -1,4 +1,4 @@ -require "vm/machine" +require "vm/c_machine" require_relative "stack_instruction" require_relative "logic_instruction" require_relative "move_instruction" @@ -7,7 +7,7 @@ require_relative "memory_instruction" require_relative "call_instruction" module Arm - class ArmMachine < Vm::Machine + class ArmMachine < Vm::CMachine # defines a method in the current class, with the name inst (first erg) # the method instantiates an instruction of the given class which gets passed a single hash as arg diff --git a/lib/core/kernel.rb b/lib/core/kernel.rb index 080a27a3..2570f594 100644 --- a/lib/core/kernel.rb +++ b/lib/core/kernel.rb @@ -6,21 +6,21 @@ module Core module ClassMethods def main_start #TODO extract args into array of strings - Vm::Machine.instance.main_start + Vm::CMachine.instance.main_start end def main_exit # Machine.exit mov r7 , 0 + swi 0 - Vm::Machine.instance.main_exit + Vm::CMachine.instance.main_exit end def function_entry f_name - Vm::Machine.instance.function_entry f_name + Vm::CMachine.instance.function_entry f_name end def function_exit f_name - Vm::Machine.instance.function_exit f_name + Vm::CMachine.instance.function_exit f_name end def putstring # should unwrap from string to char* - Vm::Machine.instance.putstring + Vm::CMachine.instance.putstring end end diff --git a/lib/crystal.rb b/lib/crystal.rb index fd03b5ac..d007f2b6 100644 --- a/lib/crystal.rb +++ b/lib/crystal.rb @@ -4,6 +4,6 @@ require "elf/object_writer" require 'parser/crystal' require 'parser/transform' require "vm/context" -require "vm/machine" +require "vm/c_machine" require "vm/program" require "stream_reader" \ No newline at end of file diff --git a/lib/support/hash_attributes.rb b/lib/support/hash_attributes.rb index 68c76716..92dfb0cf 100644 --- a/lib/support/hash_attributes.rb +++ b/lib/support/hash_attributes.rb @@ -8,17 +8,17 @@ module Support puts "NO -#{args.length} BLOCK #{block_given?}" super else - name = name.to_s + sname = name.to_s if args.length == 1 #must be assignemnt for ir attr= val - if name.include? "=" + if sname.include? "=" #puts "setting :#{name.chop}:#{args[0]}" - return @attributes[name.chop.to_sym] = args[0] + return @attributes[sname.chop.to_sym] = args[0] else super end else #puts "getting :#{name}:#{@attributes[name.to_sym]}" - return @attributes[name.to_sym] + return @attributes[sname.to_sym] end end end diff --git a/lib/vm/block.rb b/lib/vm/block.rb index 80bda66f..91179410 100644 --- a/lib/vm/block.rb +++ b/lib/vm/block.rb @@ -69,7 +69,7 @@ module Vm # (hopefully an instruction) added as code def method_missing(meth, *args, &block) if args.length == 1 - add_code Machine.instance.send(meth , *args) + add_code CMachine.instance.send(meth , *args) else super end diff --git a/lib/vm/machine.rb b/lib/vm/c_machine.rb similarity index 96% rename from lib/vm/machine.rb rename to lib/vm/c_machine.rb index 68715776..081ad2d6 100644 --- a/lib/vm/machine.rb +++ b/lib/vm/c_machine.rb @@ -1,6 +1,6 @@ module Vm - # Our virtual machine has a number of registers of a given size and uses a stack + # Our virtual c-machine has a number of registers of a given size and uses a stack # So much so standard # But our machine is oo, meaning that the register contents is typed. # Off course current hardware does not have that (a perceived issue), but for our machine we pretend. @@ -22,7 +22,7 @@ module Vm # Instructions work with options, so you can pass anything in, and the only thing the functions does # is save you typing the clazz.new. It passes the function name as the :opcode - class Machine + class CMachine # hmm, not pretty but for now @@instance = nil diff --git a/lib/vm/function_call.rb b/lib/vm/function_call.rb index da621a34..ede7f7a4 100644 --- a/lib/vm/function_call.rb +++ b/lib/vm/function_call.rb @@ -12,6 +12,7 @@ module Vm attr_reader :function , :args , :name def load_args into + raise args.inspect args.each_with_index do |arg , index| into.add_code arg.load("r#{index}".to_sym) end diff --git a/lib/vm/program.rb b/lib/vm/program.rb index 71713723..4be2bc9f 100644 --- a/lib/vm/program.rb +++ b/lib/vm/program.rb @@ -19,13 +19,13 @@ module Vm class Program < Block # Initialize with a string for cpu. Naming conventions are: for Machine XXX there exists a module XXX - # with a XXXMachine in it that derives from Vm::Machine + # with a XXXMachine in it that derives from Vm::CMachine def initialize machine = nil super("start") machine = RbConfig::CONFIG["host_cpu"] unless machine machine = "intel" if machine == "x86_64" machine = machine.capitalize - Machine.instance = eval("#{machine}::#{machine}Machine").new + CMachine.instance = eval("#{machine}::#{machine}Machine").new @context = Context.new(self) #global objects (data) @objects = [] diff --git a/test/test_runner.rb b/test/test_runner.rb index 621e2685..2b2e70c1 100644 --- a/test/test_runner.rb +++ b/test/test_runner.rb @@ -26,11 +26,11 @@ class TestRunner < MiniTest::Test # file is a list of expressions, al but the last must be a function # and the last is wrapped as a main parts.each_with_index do |part,index| - puts "parsing #{index}=#{part.inspect}" - expr = part.compile( program.context ) if index = parts.length + expr = part.compile( program.context , nil ) program.main = expr else + expr = part.compile( program.context , program.main ) raise "should be function definition for now" unless expr.is_a? Function program.add_function expr end diff --git a/test/test_small_program.rb b/test/test_small_program.rb index 914340eb..56fb7f19 100644 --- a/test/test_small_program.rb +++ b/test/test_small_program.rb @@ -28,7 +28,7 @@ class TestSmallProg < MiniTest::Test end def test_hello - hello = Vm::StringLiteral.new "Hello Raisa\n" + hello = Vm::StringConstant.new "Hello Raisa\n" @program.add_object hello @program.main.instance_eval do mov :left =>:r7, :right => 4 # 4 == write