somewhat correct that message at compile-time idea

This commit is contained in:
Torsten Ruger 2015-05-06 15:15:33 +03:00
parent 8a7db6d4f2
commit 9bf5eb2621
5 changed files with 22 additions and 34 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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