rubyx/lib/neumann/values.rb

53 lines
1.4 KiB
Ruby
Raw Normal View History

require_relative "code"
2014-06-14 10:59:25 +03:00
require_relative "register_reference"
2014-04-28 22:08:09 +03:00
module Vm
2014-05-02 08:02:25 +03: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 08:02:25 +03:00
2014-05-03 15:13:44 +03:00
# Values are a way to reason about (create/validate) instructions.
2014-05-02 08:02:25 +03: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 19:43:46 +03:00
RegisterMachine.instance.class_for(clazz)
2014-05-10 10:59:56 +03:00
end
2014-05-02 08:02:25 +03:00
end
# Just a nice way to write branches
2014-06-14 11:12:53 +03:00
# Comparisons produce them, and branches take them as argument.
2014-05-22 21:38:57 +03:00
class BranchCondition < Value
2014-05-22 21:38:57 +03: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 21:38:57 +03:00
else
raise "no implemented #{@operator}"
end
end
end
2014-05-02 08:02:25 +03:00
end
require_relative "values/constants"
require_relative "values/word"
require_relative "values/integer"
require_relative "values/reference"
require_relative "values/mystery"