2014-05-05 10:03:43 +02:00
|
|
|
require_relative "code"
|
2014-06-14 09:59:25 +02:00
|
|
|
require_relative "register_reference"
|
2014-05-05 10:03:43 +02:00
|
|
|
|
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.
|
2014-05-21 18:41:51 +02:00
|
|
|
# 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
|
|
|
|
|
2014-05-05 10:03:43 +02:00
|
|
|
# just a base class for data. not sure how this will be usefull (may just have read too much llvm)
|
2014-05-21 18:41:51 +02:00
|
|
|
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
|
|
|
|
|
2014-05-13 17:21:24 +02:00
|
|
|
# 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-13 17:21:24 +02:00
|
|
|
|
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
|
2014-05-24 09:41:57 +02:00
|
|
|
when :lt
|
|
|
|
:ge
|
2014-05-25 07:43:07 +02:00
|
|
|
when :eq
|
|
|
|
:ne
|
2014-05-22 20:38:57 +02:00
|
|
|
else
|
|
|
|
raise "no implemented #{@operator}"
|
|
|
|
end
|
|
|
|
end
|
2014-05-13 17:21:24 +02:00
|
|
|
end
|
2014-05-02 07:02:25 +02:00
|
|
|
end
|
2014-06-14 20:29:57 +02:00
|
|
|
require_relative "values/constants"
|
|
|
|
require_relative "values/word"
|
|
|
|
require_relative "values/integer"
|
|
|
|
require_relative "values/reference"
|
|
|
|
require_relative "values/mystery"
|