first method test
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
module Ast
|
||||
class FunctionExpression < Expression
|
||||
# attr_reader :name, :params, :body , :receiver
|
||||
def compile context
|
||||
def compile frame , method
|
||||
method = Virtual::Method.new(name , params )
|
||||
end
|
||||
def scratch
|
||||
args = []
|
||||
locals = {}
|
||||
params.each_with_index do |param , index|
|
||||
|
@ -1,3 +1,4 @@
|
||||
require_relative "object"
|
||||
module Virtual
|
||||
# static description of a method
|
||||
# name
|
||||
@ -7,13 +8,16 @@ module Virtual
|
||||
# known local variable names
|
||||
# temp variables (numbered)
|
||||
#
|
||||
class Method
|
||||
class Method < Virtual::Object
|
||||
#return the main function (the top level) into which code is compiled
|
||||
def Method.main
|
||||
Method.new(:main)
|
||||
end
|
||||
def attributes
|
||||
[:name , :args]
|
||||
end
|
||||
def initialize name , args = [] , receiver = Virtual::Reference , return_type = Virtual::Reference
|
||||
@name = name
|
||||
@name = name.to_sym
|
||||
@args = args
|
||||
@locals = []
|
||||
@receiver = receiver
|
||||
@ -21,7 +25,7 @@ module Virtual
|
||||
@start = MethodEnter.new
|
||||
@current = @start
|
||||
end
|
||||
attr_reader :name
|
||||
attr_reader :name , :args
|
||||
|
||||
def add instruction
|
||||
@current.next = instruction
|
||||
|
@ -1,7 +1,3 @@
|
||||
module Boot
|
||||
class BootSoace
|
||||
end
|
||||
end
|
||||
module Virtual
|
||||
# our machine is made up of objects, some of which are code, some data
|
||||
#
|
||||
@ -26,6 +22,10 @@ module Virtual
|
||||
return true
|
||||
end
|
||||
|
||||
def inspect
|
||||
self.class.name + ".new(" + attributes.collect{|a| send(a).inspect }.join(",")+ ")"
|
||||
end
|
||||
|
||||
def self.space
|
||||
if defined? @@space
|
||||
@@space
|
||||
|
Reference in New Issue
Block a user