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 "stack_instruction"
|
||||||
require_relative "logic_instruction"
|
require_relative "logic_instruction"
|
||||||
require_relative "move_instruction"
|
require_relative "move_instruction"
|
||||||
@ -8,7 +8,7 @@ require_relative "call_instruction"
|
|||||||
require_relative "constants"
|
require_relative "constants"
|
||||||
|
|
||||||
module Arm
|
module Arm
|
||||||
class ArmMachine < Vm::CMachine
|
class ArmMachine < Vm::RegisterMachine
|
||||||
|
|
||||||
def integer_less_or_equal block , left , right
|
def integer_less_or_equal block , left , right
|
||||||
block << cmp( left , right )
|
block << cmp( left , right )
|
||||||
|
@ -6,19 +6,19 @@ module Core
|
|||||||
module ClassMethods
|
module ClassMethods
|
||||||
def main_start block
|
def main_start block
|
||||||
#TODO extract args into array of strings
|
#TODO extract args into array of strings
|
||||||
Vm::CMachine.instance.main_start block
|
Vm::RegisterMachine.instance.main_start block
|
||||||
block
|
block
|
||||||
end
|
end
|
||||||
def main_exit block
|
def main_exit block
|
||||||
# Machine.exit mov r7 , 0 + swi 0
|
# Machine.exit mov r7 , 0 + swi 0
|
||||||
Vm::CMachine.instance.main_exit block
|
Vm::RegisterMachine.instance.main_exit block
|
||||||
block
|
block
|
||||||
end
|
end
|
||||||
def function_entry block , f_name
|
def function_entry block , f_name
|
||||||
Vm::CMachine.instance.function_entry block , f_name
|
Vm::RegisterMachine.instance.function_entry block , f_name
|
||||||
end
|
end
|
||||||
def function_exit block , f_name
|
def function_exit block , f_name
|
||||||
Vm::CMachine.instance.function_exit block , f_name
|
Vm::RegisterMachine.instance.function_exit block , f_name
|
||||||
end
|
end
|
||||||
|
|
||||||
#TODO this is in the wrong place. It is a function that returns a function object
|
#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)
|
function = Vm::Function.new(:putstring , [string , length ] , string)
|
||||||
block = function.body
|
block = function.body
|
||||||
# should be another level of indirection, ie write(io,str)
|
# 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.return_type = ret
|
||||||
function
|
function
|
||||||
end
|
end
|
||||||
@ -49,7 +49,7 @@ module Core
|
|||||||
# And now we "just" have to print it, using the write_stdout
|
# And now we "just" have to print it, using the write_stdout
|
||||||
b.add( int , buffer , nil ) # string to write to
|
b.add( int , buffer , nil ) # string to write to
|
||||||
b.mov( moved_int , buffer.length )
|
b.mov( moved_int , buffer.length )
|
||||||
Vm::CMachine.instance.write_stdout(putint_function.body)
|
Vm::RegisterMachine.instance.write_stdout(putint_function.body)
|
||||||
putint_function
|
putint_function
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ module Core
|
|||||||
str_addr = utoa_function.args[0]
|
str_addr = utoa_function.args[0]
|
||||||
number = utoa_function.args[1]
|
number = utoa_function.args[1]
|
||||||
remainder = utoa_function.new_local
|
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"
|
# make char out of digit (by using ascii encoding) 48 == "0"
|
||||||
b = utoa_function.body.scope binding
|
b = utoa_function.body.scope binding
|
||||||
b.remainder = remainder + 48
|
b.remainder = remainder + 48
|
||||||
|
@ -3,7 +3,7 @@ require 'parslet'
|
|||||||
require "elf/object_writer"
|
require "elf/object_writer"
|
||||||
require 'parser/crystal'
|
require 'parser/crystal'
|
||||||
require 'parser/transform'
|
require 'parser/transform'
|
||||||
require "vm/c_machine"
|
require "vm/register_machine"
|
||||||
require "vm/program"
|
require "vm/program"
|
||||||
require "stream_reader"
|
require "stream_reader"
|
||||||
require "core/kernel"
|
require "core/kernel"
|
||||||
|
@ -91,7 +91,7 @@ module Vm
|
|||||||
# b.variable = value looks like what it does, but actually generates
|
# b.variable = value looks like what it does, but actually generates
|
||||||
# an instruction for the block (mov or add)
|
# 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,
|
# With this trick we can write what looks like assembler,
|
||||||
# Example b.instance_eval
|
# Example b.instance_eval
|
||||||
# mov( r1 , r2 )
|
# mov( r1 , r2 )
|
||||||
@ -109,7 +109,7 @@ module Vm
|
|||||||
return super
|
return super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
add_code CMachine.instance.send(meth , *args)
|
add_code RegisterMachine.instance.send(meth , *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -22,7 +22,7 @@ module Vm
|
|||||||
end
|
end
|
||||||
|
|
||||||
def do_call into
|
def do_call into
|
||||||
CMachine.instance.function_call into , self
|
RegisterMachine.instance.function_call into , self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ module Vm
|
|||||||
class Code
|
class Code
|
||||||
|
|
||||||
def class_for clazz
|
def class_for clazz
|
||||||
CMachine.instance.class_for(clazz)
|
RegisterMachine.instance.class_for(clazz)
|
||||||
end
|
end
|
||||||
|
|
||||||
# set the position to zero, will have to reset later
|
# set the position to zero, will have to reset later
|
||||||
|
@ -21,13 +21,13 @@ module Vm
|
|||||||
class Program < Block
|
class Program < Block
|
||||||
|
|
||||||
# Initialize with a string for cpu. Naming conventions are: for Machine XXX there exists a module XXX
|
# 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
|
def initialize machine = nil
|
||||||
super("start" , nil)
|
super("start" , nil)
|
||||||
machine = RbConfig::CONFIG["host_cpu"] unless machine
|
machine = RbConfig::CONFIG["host_cpu"] unless machine
|
||||||
machine = "intel" if machine == "x86_64"
|
machine = "intel" if machine == "x86_64"
|
||||||
machine = machine.capitalize
|
machine = machine.capitalize
|
||||||
CMachine.instance = eval("#{machine}::#{machine}Machine").new
|
RegisterMachine.instance = eval("#{machine}::#{machine}Machine").new
|
||||||
@context = Context.new(self)
|
@context = Context.new(self)
|
||||||
#global objects (data)
|
#global objects (data)
|
||||||
@objects = []
|
@objects = []
|
||||||
|
@ -22,7 +22,7 @@ module Vm
|
|||||||
# Instructions work with options, so you can pass anything in, and the only thing the functions does
|
# 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
|
# 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
|
# hmm, not pretty but for now
|
||||||
@@instance = nil
|
@@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)
|
# just a base class for data. not sure how this will be usefull (may just have read too much llvm)
|
||||||
class Value
|
class Value
|
||||||
def class_for clazz
|
def class_for clazz
|
||||||
CMachine.instance.class_for(clazz)
|
RegisterMachine.instance.class_for(clazz)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ module Vm
|
|||||||
class Unsigned < Word
|
class Unsigned < Word
|
||||||
|
|
||||||
def plus block , unsigned
|
def plus block , unsigned
|
||||||
CMachine.instance.unsigned_plus self , unsigned
|
RegisterMachine.instance.unsigned_plus self , unsigned
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ module Vm
|
|||||||
end
|
end
|
||||||
|
|
||||||
def less_or_equal block , right
|
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
|
end
|
||||||
def == other
|
def == other
|
||||||
code = class_for(CompareInstruction).new(self , other , opcode: :cmp)
|
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 )
|
class_for(LogicInstruction).new(nil , self , other , opcode: :sub )#, update_status: 1 )
|
||||||
end
|
end
|
||||||
def plus block , first , right
|
def plus block , first , right
|
||||||
CMachine.instance.integer_plus block , self , first , right
|
RegisterMachine.instance.integer_plus block , self , first , right
|
||||||
end
|
end
|
||||||
def minus block , first , right
|
def minus block , first , right
|
||||||
CMachine.instance.integer_minus block , self , first , right
|
RegisterMachine.instance.integer_minus block , self , first , right
|
||||||
end
|
end
|
||||||
|
|
||||||
def load block , right
|
def load block , right
|
||||||
CMachine.instance.integer_load block , self , right
|
RegisterMachine.instance.integer_load block , self , right
|
||||||
end
|
end
|
||||||
|
|
||||||
def move block , right
|
def move block , right
|
||||||
CMachine.instance.integer_move block , self , right
|
RegisterMachine.instance.integer_move block , self , right
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user