rubyx/lib/vm/values.rb

64 lines
1.7 KiB
Ruby
Raw Normal View History

require_relative "code"
2014-04-28 21:08:09 +02:00
module Vm
2014-05-02 07:02:25 +02:00
# Values represent the information as it is processed. Different subclasses for different types,
# each type with different operations.
# The oprerations on values is what makes a machine do things.
2014-05-03 14:13:44 +02:00
# For compilation, values are moved to the machines registers and the methods (on values) map
# to machine instructions
2014-05-02 07:02:25 +02:00
# Values are immutable! (that's why they are called values)
# Operations on values _always_ produce new values (conceptionally)
2014-05-03 14:13:44 +02:00
# Values are a way to reason about (create/validate) instructions.
# In fact a linked lists of values is created by invoking instructions
# the linked list goes from value to instruction to value, backwards
2014-05-02 07:02:25 +02:00
# Word Values are what fits in a register. Derived classes
# Float, Reference , Integer(s) must fit the same registers
# just a base class for data. not sure how this will be usefull (may just have read too much llvm)
class Value < Code
2014-05-10 09:59:56 +02:00
def type
self.class
2014-05-10 09:59:56 +02:00
end
2014-05-02 07:02:25 +02:00
end
# This is what it is when we don't know what it is.
# Must be promoted to A Word-Value to to anything
# remembering that our oo machine is typed, no overloading or stuff
2014-05-02 07:02:25 +02:00
class Word < Value
attr_accessor :register
def initialize reg
register = reg
2014-05-05 08:35:40 +02:00
end
def length
4
end
2014-04-28 21:08:09 +02:00
end
2014-05-02 07:02:25 +02:00
class Unsigned < Word
2014-05-03 14:13:44 +02:00
def plus unsigned
2014-05-03 17:51:47 +02:00
Machine.instance.unsigned_plus self , unsigned
2014-05-02 07:02:25 +02:00
end
end
class Integer < Word
2014-05-02 07:02:25 +02:00
def less_or_equal right
Machine.instance.integer_less_or_equal self , right
2014-05-06 20:36:28 +02:00
end
def plus right
Machine.instance.integer_plus self , right
2014-05-03 14:13:44 +02:00
end
2014-05-02 07:02:25 +02:00
end
end
require_relative "constants"