introduce load_data instruction
which just loads data to a register (used internally) as opposed to integers, which are objects
This commit is contained in:
@ -20,7 +20,7 @@ module Risc
|
||||
private
|
||||
def constant_str
|
||||
case @constant
|
||||
when String , Symbol , Fixnum , Integer
|
||||
when String , Symbol
|
||||
@constant.to_s
|
||||
else
|
||||
if( @constant.respond_to? :sof_reference_name )
|
||||
|
27
lib/risc/instructions/load_data.rb
Normal file
27
lib/risc/instructions/load_data.rb
Normal file
@ -0,0 +1,27 @@
|
||||
module Risc
|
||||
# load raw data into a register
|
||||
#
|
||||
# This is not really used by the compiler, or to be more precise: not used during the
|
||||
# compilation of ruby code. Ruby code works on Objects only
|
||||
#
|
||||
# But for Builtin methods, methods that are created programatically and form the runtime,
|
||||
# it can be handy to load an integer directly withou the object overhead.
|
||||
#
|
||||
class LoadData < Instruction
|
||||
def initialize( source , constant , register)
|
||||
super(source)
|
||||
@register = register
|
||||
@constant = constant
|
||||
raise "Not Integer #{constant}" unless constant.is_a?(Integer)
|
||||
end
|
||||
attr_accessor :register , :constant
|
||||
|
||||
def to_s
|
||||
class_source "#{register} <- #{constant}"
|
||||
end
|
||||
|
||||
end
|
||||
def self.load_data( source , constant , register )
|
||||
LoadData.new( source , constant , register)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user