rubyx/lib/neumann/values.rb

53 lines
1.4 KiB
Ruby
Raw Normal View History

require_relative "code"
2014-06-14 09:59:25 +02:00
require_relative "register_reference"
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. Operations are captured as
# subclasses of Instruction and saved to Blocks
2014-05-02 07:02:25 +02:00
2014-05-03 14:13:44 +02:00
# Values are a way to reason about (create/validate) instructions.
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
def class_for clazz
2014-05-21 18:43:46 +02:00
RegisterMachine.instance.class_for(clazz)
2014-05-10 09:59:56 +02:00
end
2014-05-02 07:02:25 +02:00
end
# Just a nice way to write branches
2014-06-14 10:12:53 +02:00
# Comparisons produce them, and branches take them as argument.
2014-05-22 20:38:57 +02:00
class BranchCondition < Value
2014-05-22 20:38:57 +02:00
def initialize operator
@operator = operator
end
attr_accessor :operator
#needed to check the opposite, ie not true
def not_operator
case @operator
when :le
:gt
when :gt
:le
when :lt
:ge
when :eq
:ne
2014-05-22 20:38:57 +02:00
else
raise "no implemented #{@operator}"
end
end
end
2014-05-02 07:02:25 +02:00
end
require_relative "values/constants"
require_relative "values/word"
require_relative "values/integer"
require_relative "values/reference"
require_relative "values/mystery"