brainstorming mode on the new way (tm)
This commit is contained in:
@ -22,5 +22,14 @@ module Virtual
|
||||
@binding = List.new
|
||||
end
|
||||
attr_reader :next_normal, :next_exception, :me, :binding
|
||||
|
||||
#
|
||||
def compile_get name , method
|
||||
method.add FrameGet.new(name)
|
||||
end
|
||||
|
||||
def compile_send name , method
|
||||
method.add FrameSend.new(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -9,7 +9,11 @@ module Virtual
|
||||
|
||||
# This is partly because jumping over this layer and doing in straight in assember was too big a step
|
||||
class Instruction
|
||||
attr_accessor :next
|
||||
|
||||
def inspect
|
||||
self.class.name + ".new()"
|
||||
end
|
||||
end
|
||||
|
||||
# the first instruction we need is to stop. Off course in a real machine this would be a syscall, but that is just
|
||||
@ -19,4 +23,30 @@ module Virtual
|
||||
class Halt < Instruction
|
||||
|
||||
end
|
||||
|
||||
# following classes are stubs. currently in brainstorming mode, so anything may change anytime
|
||||
class MethodEnter < Instruction
|
||||
end
|
||||
|
||||
class FrameGet < Instruction
|
||||
def initialize name
|
||||
@name = name
|
||||
end
|
||||
end
|
||||
|
||||
class FrameSend < Instruction
|
||||
|
||||
def initialize name
|
||||
@name = name.to_sym
|
||||
end
|
||||
attr_reader :name
|
||||
|
||||
def == other
|
||||
self.class == other.class && self.name == other.name
|
||||
end
|
||||
def inspect
|
||||
self.class.name + ".new(:#{@name})"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -37,7 +37,7 @@ module Virtual
|
||||
end
|
||||
|
||||
def initialize
|
||||
the_end = HaltInstruction.new
|
||||
the_end = Halt.new
|
||||
@frame = Frame.new(the_end , the_end , :Object)
|
||||
end
|
||||
attr_reader :frame
|
||||
@ -51,15 +51,12 @@ module Virtual
|
||||
instruction = next_instruction
|
||||
end
|
||||
end
|
||||
#return an anonymous new function (the top level) into which code is compiled
|
||||
def anonymous
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
require_relative "list"
|
||||
require_relative "instruction"
|
||||
require_relative "method"
|
||||
require_relative "frame"
|
||||
require_relative "value"
|
||||
require_relative "mystery"
|
||||
|
38
lib/virtual/method.rb
Normal file
38
lib/virtual/method.rb
Normal file
@ -0,0 +1,38 @@
|
||||
module Virtual
|
||||
# static description of a method
|
||||
# name
|
||||
# args (with defaults)
|
||||
# code
|
||||
# return arg (usually mystery, but for coded ones can be more specific)
|
||||
# known local variable names
|
||||
# temp variables (numbered)
|
||||
#
|
||||
class Method
|
||||
#return the main function (the top level) into which code is compiled
|
||||
def Method.main
|
||||
Method.new(:main)
|
||||
end
|
||||
def initialize name , args = []
|
||||
@name = name
|
||||
@args = args
|
||||
@locals = []
|
||||
@start = MethodEnter.new
|
||||
@current = @start
|
||||
end
|
||||
attr_reader :name
|
||||
|
||||
def add instruction
|
||||
@current.next = instruction
|
||||
@current = instruction
|
||||
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
|
||||
def has_var name
|
||||
var = @args.find {|a| a == name }
|
||||
var = @locals.find {|a| a == name } unless var
|
||||
var
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user