a lot of work to get one more test to pass
This commit is contained in:
@ -28,28 +28,18 @@ module Virtual
|
||||
|
||||
class StringConstant < ObjectConstant
|
||||
attr_reader :string
|
||||
# currently aligned to 4 (ie padded with 0) and off course 0 at the end
|
||||
def attributes
|
||||
[:string]
|
||||
end
|
||||
def initialize str
|
||||
str = str.to_s if str.is_a? Symbol
|
||||
length = str.length
|
||||
# rounding up to the next 4 (always adding one for zero pad)
|
||||
pad = ((length / 4 ) + 1 ) * 4 - length
|
||||
raise "#{pad} #{self}" unless pad >= 1
|
||||
@string = str + " " * pad
|
||||
@string = str
|
||||
end
|
||||
|
||||
def result= value
|
||||
class_for(MoveInstruction).new(value , self , :opcode => :mov)
|
||||
end
|
||||
|
||||
# the strings length plus padding
|
||||
def length
|
||||
string.length
|
||||
end
|
||||
|
||||
# just writing the string
|
||||
def assemble(io)
|
||||
io << string
|
||||
def inspect
|
||||
self.class.name + ".new('#{@string}')"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
module Vm
|
||||
require_relative "value"
|
||||
|
||||
module Virtual
|
||||
class Integer < Value
|
||||
|
||||
def initialize
|
||||
|
@ -31,10 +31,6 @@ module Virtual
|
||||
# that the the model is such that what is a variable in ruby, never ends up being just on the pysical stack.
|
||||
#
|
||||
class Machine
|
||||
# the main machine is the one that runs on the main thread, if it exists or receives an uncaught exception, that's it.
|
||||
def self.main
|
||||
@main || @main = Machine.new
|
||||
end
|
||||
|
||||
def initialize
|
||||
the_end = Halt.new
|
||||
@ -62,3 +58,4 @@ require_relative "value"
|
||||
require_relative "mystery"
|
||||
require_relative "object"
|
||||
require_relative "constants"
|
||||
require "boot/boot_space"
|
@ -12,10 +12,12 @@ module Virtual
|
||||
def Method.main
|
||||
Method.new(:main)
|
||||
end
|
||||
def initialize name , args = []
|
||||
def initialize name , args = [] , receiver = Virtual::Reference , return_type = Virtual::Reference
|
||||
@name = name
|
||||
@args = args
|
||||
@locals = []
|
||||
@receiver = receiver
|
||||
@return_type = return_type
|
||||
@start = MethodEnter.new
|
||||
@current = @start
|
||||
end
|
||||
|
@ -1,3 +1,7 @@
|
||||
module Boot
|
||||
class BootSoace
|
||||
end
|
||||
end
|
||||
module Virtual
|
||||
# our machine is made up of objects, some of which are code, some data
|
||||
#
|
||||
@ -21,6 +25,14 @@ module Virtual
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
def self.space
|
||||
if defined? @@space
|
||||
@@space
|
||||
else
|
||||
@@space = ::Boot::BootSpace.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Layout < Object
|
||||
@ -38,5 +50,7 @@ module Virtual
|
||||
@super_class = sup
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
require_relative "integer"
|
||||
require_relative "reference"
|
||||
|
@ -1,4 +1,6 @@
|
||||
module Vm
|
||||
require_relative "value"
|
||||
|
||||
module Virtual
|
||||
class Reference < Value
|
||||
|
||||
def initialize clazz = nil
|
||||
|
Reference in New Issue
Block a user