somewhat correct that message at compile-time idea
This commit is contained in:
parent
8a7db6d4f2
commit
9bf5eb2621
@ -105,35 +105,35 @@ module Virtual
|
||||
return new_b
|
||||
end
|
||||
|
||||
|
||||
|
||||
# determine whether this method has a variable by the given name
|
||||
# variables are locals and and arguments
|
||||
# used to determine if a send must be issued
|
||||
# return index of the name into the message if so
|
||||
def has_var name
|
||||
name = name.to_sym
|
||||
var = @arg_names.find {|a| a == name }
|
||||
var = @locals.find {|a| a == name } unless var
|
||||
var = @tmps.find {|a| a == name } unless var
|
||||
var
|
||||
index = has_arg(name)
|
||||
return index if index
|
||||
has_local(name)
|
||||
end
|
||||
|
||||
# determine whether this method has an argument by the name
|
||||
def has_arg name
|
||||
name = name.to_sym
|
||||
var = @arg_names.find {|a| a == name }
|
||||
var
|
||||
@arg_names.index name.to_sym
|
||||
end
|
||||
|
||||
def set_var name , var
|
||||
v = has_var name
|
||||
if( v )
|
||||
v.type = var
|
||||
else
|
||||
v = Local.new(name , var)
|
||||
@locals << v
|
||||
end
|
||||
v
|
||||
# determine if method has a local variable or tmp (anonymous local) by given name
|
||||
def has_local name
|
||||
name = name.to_sym
|
||||
index = @locals.index(name)
|
||||
index = @tmps.index(name) unless index
|
||||
index
|
||||
end
|
||||
|
||||
def ensure_local name
|
||||
index = has_local name
|
||||
return index if index
|
||||
@locals << name
|
||||
@locals.length
|
||||
end
|
||||
|
||||
def get_var name
|
||||
|
@ -6,10 +6,9 @@ module Virtual
|
||||
# Derived classes make up the actual functionality of the machine.
|
||||
# All functions on the machine are captured as instances of instructions
|
||||
#
|
||||
# It is actually the point of the virtual machine layer to express oo functionality in the set of instructions,
|
||||
# thus defining a minimal set of instructions needed to implement oo.
|
||||
# It is actually the point of the virtual machine layer to express oo functionality in the set of
|
||||
# instructions, thus defining a minimal set of instructions needed to implement oo.
|
||||
|
||||
# This is partly because jumping over this layer and doing in straight in assember was too big a step
|
||||
class Instruction < Virtual::Object
|
||||
|
||||
# simple thought: don't recurse for Blocks, just check their names
|
||||
|
@ -11,7 +11,6 @@ module Virtual
|
||||
raise "From must be slot or constant, not symbol #{from}" if from.is_a? Symbol
|
||||
@from = from
|
||||
end
|
||||
attr_reader :to , :from
|
||||
attr_reader :from , :to
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -60,7 +60,7 @@ module Virtual
|
||||
syntax = @parser.parse_with_debug(bytes)
|
||||
parts = Parser::Transform.new.apply(syntax)
|
||||
main = Virtual::CompiledMethod.main
|
||||
Compiler.compile( parts , main , self.message )
|
||||
Compiler.compile( parts , main )
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -52,15 +52,5 @@ module Virtual
|
||||
end
|
||||
method.get_var(name)
|
||||
end
|
||||
|
||||
def compile_set method , name , val
|
||||
method.set_var(name,val)
|
||||
if method.has_arg(name)
|
||||
method.add_code MessageSet.new(name , val )
|
||||
else
|
||||
method.add_code FrameSet.new(name , val )
|
||||
end
|
||||
method.get_var(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user