rename machine to c_machine

This commit is contained in:
Torsten Ruger
2014-05-13 17:06:42 +03:00
parent d7f31e7f39
commit b0302948dd
10 changed files with 21 additions and 20 deletions

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 = []