rename c to register machine
This commit is contained in:
parent
937f566b27
commit
46102e56ad
@ -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 )
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 = []
|
||||
|
@ -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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user