rename machine to c_machine
This commit is contained in:
parent
d7f31e7f39
commit
b0302948dd
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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"
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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 = []
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user