From 46102e56ad2393db5862e7850e286d413c21a545 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 21 May 2014 19:43:46 +0300 Subject: [PATCH] rename c to register machine --- lib/arm/arm_machine.rb | 4 ++-- lib/core/kernel.rb | 14 +++++++------- lib/crystal.rb | 2 +- lib/vm/block.rb | 4 ++-- lib/vm/call_site.rb | 2 +- lib/vm/code.rb | 2 +- lib/vm/program.rb | 4 ++-- lib/vm/{c_machine.rb => register_machine.rb} | 2 +- lib/vm/values.rb | 14 +++++++------- 9 files changed, 24 insertions(+), 24 deletions(-) rename lib/vm/{c_machine.rb => register_machine.rb} (99%) diff --git a/lib/arm/arm_machine.rb b/lib/arm/arm_machine.rb index 46f4022a..1af3dcd5 100644 --- a/lib/arm/arm_machine.rb +++ b/lib/arm/arm_machine.rb @@ -1,4 +1,4 @@ -require "vm/c_machine" +require "vm/register_machine" require_relative "stack_instruction" require_relative "logic_instruction" require_relative "move_instruction" @@ -8,7 +8,7 @@ require_relative "call_instruction" require_relative "constants" module Arm - class ArmMachine < Vm::CMachine + class ArmMachine < Vm::RegisterMachine def integer_less_or_equal block , left , right block << cmp( left , right ) diff --git a/lib/core/kernel.rb b/lib/core/kernel.rb index 601754a3..f67a4c12 100644 --- a/lib/core/kernel.rb +++ b/lib/core/kernel.rb @@ -6,19 +6,19 @@ module Core module ClassMethods def main_start block #TODO extract args into array of strings - Vm::CMachine.instance.main_start block + Vm::RegisterMachine.instance.main_start block block end def main_exit block # Machine.exit mov r7 , 0 + swi 0 - Vm::CMachine.instance.main_exit block + Vm::RegisterMachine.instance.main_exit block block end def function_entry block , f_name - Vm::CMachine.instance.function_entry block , f_name + Vm::RegisterMachine.instance.function_entry block , f_name end def function_exit block , f_name - Vm::CMachine.instance.function_exit block , f_name + Vm::RegisterMachine.instance.function_exit block , f_name end #TODO this is in the wrong place. It is a function that returns a function object @@ -27,7 +27,7 @@ module Core function = Vm::Function.new(:putstring , [string , length ] , string) block = function.body # should be another level of indirection, ie write(io,str) - ret = Vm::CMachine.instance.write_stdout(block) + ret = Vm::RegisterMachine.instance.write_stdout(block) function.return_type = ret function end @@ -49,7 +49,7 @@ module Core # And now we "just" have to print it, using the write_stdout b.add( int , buffer , nil ) # string to write to b.mov( moved_int , buffer.length ) - Vm::CMachine.instance.write_stdout(putint_function.body) + Vm::RegisterMachine.instance.write_stdout(putint_function.body) putint_function end @@ -63,7 +63,7 @@ module Core str_addr = utoa_function.args[0] number = utoa_function.args[1] remainder = utoa_function.new_local - Vm::CMachine.instance.div10( utoa_function.body , number , remainder ) + Vm::RegisterMachine.instance.div10( utoa_function.body , number , remainder ) # make char out of digit (by using ascii encoding) 48 == "0" b = utoa_function.body.scope binding b.remainder = remainder + 48 diff --git a/lib/crystal.rb b/lib/crystal.rb index aed5477a..260ee282 100644 --- a/lib/crystal.rb +++ b/lib/crystal.rb @@ -3,7 +3,7 @@ require 'parslet' require "elf/object_writer" require 'parser/crystal' require 'parser/transform' -require "vm/c_machine" +require "vm/register_machine" require "vm/program" require "stream_reader" require "core/kernel" diff --git a/lib/vm/block.rb b/lib/vm/block.rb index b5ddea98..a95de72b 100644 --- a/lib/vm/block.rb +++ b/lib/vm/block.rb @@ -91,7 +91,7 @@ module Vm # b.variable = value looks like what it does, but actually generates # an instruction for the block (mov or add) # - # 2- any other method will be passed on to the CMachine and the result added to the block + # 2- any other method will be passed on to the RegisterMachine and the result added to the block # With this trick we can write what looks like assembler, # Example b.instance_eval # mov( r1 , r2 ) @@ -109,7 +109,7 @@ module Vm return super end end - add_code CMachine.instance.send(meth , *args) + add_code RegisterMachine.instance.send(meth , *args) end end diff --git a/lib/vm/call_site.rb b/lib/vm/call_site.rb index 6d0955a0..f7227762 100644 --- a/lib/vm/call_site.rb +++ b/lib/vm/call_site.rb @@ -22,7 +22,7 @@ module Vm end def do_call into - CMachine.instance.function_call into , self + RegisterMachine.instance.function_call into , self end end end diff --git a/lib/vm/code.rb b/lib/vm/code.rb index fb97f5b4..dfc146d5 100644 --- a/lib/vm/code.rb +++ b/lib/vm/code.rb @@ -12,7 +12,7 @@ module Vm class Code def class_for clazz - CMachine.instance.class_for(clazz) + RegisterMachine.instance.class_for(clazz) end # set the position to zero, will have to reset later diff --git a/lib/vm/program.rb b/lib/vm/program.rb index 6403207c..7aa5fff6 100644 --- a/lib/vm/program.rb +++ b/lib/vm/program.rb @@ -21,13 +21,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::CMachine + # with a XXXMachine in it that derives from Vm::RegisterMachine def initialize machine = nil super("start" , nil) machine = RbConfig::CONFIG["host_cpu"] unless machine machine = "intel" if machine == "x86_64" machine = machine.capitalize - CMachine.instance = eval("#{machine}::#{machine}Machine").new + RegisterMachine.instance = eval("#{machine}::#{machine}Machine").new @context = Context.new(self) #global objects (data) @objects = [] diff --git a/lib/vm/c_machine.rb b/lib/vm/register_machine.rb similarity index 99% rename from lib/vm/c_machine.rb rename to lib/vm/register_machine.rb index fbea9a35..3bbdda87 100644 --- a/lib/vm/c_machine.rb +++ b/lib/vm/register_machine.rb @@ -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 CMachine + class RegisterMachine # hmm, not pretty but for now @@instance = nil diff --git a/lib/vm/values.rb b/lib/vm/values.rb index 6ff6db36..7e805689 100644 --- a/lib/vm/values.rb +++ b/lib/vm/values.rb @@ -20,7 +20,7 @@ module Vm # just a base class for data. not sure how this will be usefull (may just have read too much llvm) class Value def class_for clazz - CMachine.instance.class_for(clazz) + RegisterMachine.instance.class_for(clazz) end end @@ -53,7 +53,7 @@ module Vm class Unsigned < Word def plus block , unsigned - CMachine.instance.unsigned_plus self , unsigned + RegisterMachine.instance.unsigned_plus self , unsigned end end @@ -75,7 +75,7 @@ module Vm end def less_or_equal block , right - CMachine.instance.integer_less_or_equal block , self , right + RegisterMachine.instance.integer_less_or_equal block , self , right end def == other code = class_for(CompareInstruction).new(self , other , opcode: :cmp) @@ -87,18 +87,18 @@ module Vm class_for(LogicInstruction).new(nil , self , other , opcode: :sub )#, update_status: 1 ) end def plus block , first , right - CMachine.instance.integer_plus block , self , first , right + RegisterMachine.instance.integer_plus block , self , first , right end def minus block , first , right - CMachine.instance.integer_minus block , self , first , right + RegisterMachine.instance.integer_minus block , self , first , right end def load block , right - CMachine.instance.integer_load block , self , right + RegisterMachine.instance.integer_load block , self , right end def move block , right - CMachine.instance.integer_move block , self , right + RegisterMachine.instance.integer_move block , self , right end end