first method test

This commit is contained in:
Torsten Ruger
2014-07-14 11:29:38 +03:00
parent c1f475070b
commit d531a24930
5 changed files with 143 additions and 9 deletions

View File

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

View File

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