fix all tests
This commit is contained in:
parent
b59a9da34e
commit
9891da88a4
@ -74,7 +74,7 @@ module Ast
|
||||
|
||||
class VariableExpression < NameExpression
|
||||
def compile frame ,method
|
||||
Virtual::ObjectGet.new(name)
|
||||
method.add Virtual::ObjectGet.new(name)
|
||||
end
|
||||
end
|
||||
end
|
@ -8,8 +8,8 @@ module Ast
|
||||
frame = frame.new_frame
|
||||
return_type = nil
|
||||
body.each do |ex|
|
||||
val = ex.compile(frame , method )
|
||||
return_type = val.type
|
||||
return_type = ex.compile(frame , method )
|
||||
raise return_type.inspect if return_type.is_a? Virtual::Instruction
|
||||
end
|
||||
method.return_type = return_type
|
||||
method
|
||||
|
@ -2,7 +2,11 @@ module Ast
|
||||
class OperatorExpression < Expression
|
||||
# attr_reader :operator, :left, :right
|
||||
def compile frame , method
|
||||
Virtual::Reference.new
|
||||
tmp = method.get_tmp
|
||||
ass = AssignmentExpression.new( tmp , left )
|
||||
l = ass.compile(frame , method)
|
||||
call = CallSiteExpression.new( operator , [right] , l)
|
||||
call.compile(frame , method)
|
||||
end
|
||||
def scratch
|
||||
into = context.function
|
||||
|
@ -21,6 +21,7 @@ module Virtual
|
||||
@name = name.to_sym
|
||||
@args = args
|
||||
@locals = []
|
||||
@tmps = []
|
||||
@receiver = receiver
|
||||
@return_type = return_type
|
||||
@start = start
|
||||
@ -30,8 +31,10 @@ module Virtual
|
||||
attr_accessor :return_type
|
||||
|
||||
def add instruction
|
||||
raise instruction.inspect unless instruction.is_a? Instruction
|
||||
@current.next = instruction
|
||||
@current = instruction
|
||||
instruction.type
|
||||
end
|
||||
|
||||
# determine whether this method has a variable by the given name
|
||||
@ -40,7 +43,14 @@ module Virtual
|
||||
def has_var name
|
||||
var = @args.find {|a| a == name }
|
||||
var = @locals.find {|a| a == name } unless var
|
||||
var = @tmps.find {|a| a == name } unless var
|
||||
var
|
||||
end
|
||||
|
||||
def get_tmp
|
||||
name = "__tmp__#{@tmps.length}"
|
||||
@tmps << name
|
||||
Ast::NameExpression.new(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ class TestBasic < MiniTest::Test
|
||||
|
||||
def test_name
|
||||
@string_input = 'foo '
|
||||
@output = [Virtual::FrameSend.new(:foo)]
|
||||
@output = [Virtual::Reference]
|
||||
check
|
||||
end
|
||||
|
||||
@ -39,7 +39,7 @@ class TestBasic < MiniTest::Test
|
||||
|
||||
def test_instance_variable
|
||||
@string_input = '@foo_bar '
|
||||
@output = [Virtual::ObjectGet.new(:foo_bar)]
|
||||
@output = [Virtual::Reference]
|
||||
check
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
require_relative "virtual_helper"
|
||||
|
||||
class TestFunctionDefinition < MiniTest::Test
|
||||
class TestMethods < MiniTest::Test
|
||||
include VirtualHelper
|
||||
|
||||
def test_simplest_function
|
||||
@ -9,7 +9,7 @@ def foo(x)
|
||||
5
|
||||
end
|
||||
HERE
|
||||
@output = [Virtual::Method.new(:foo,[Ast::NameExpression.new(:x)],Virtual::SelfReference.new(),Virtual::Integer,Virtual::MethodEnter.new(nil))]
|
||||
@output = [Virtual::Method.new(:foo,[Ast::NameExpression.new(:x)],Virtual::SelfReference.new(),Virtual::IntegerConstant.new(5),Virtual::MethodEnter.new(nil))]
|
||||
check
|
||||
end
|
||||
|
||||
@ -19,7 +19,7 @@ def String.length(x)
|
||||
@length
|
||||
end
|
||||
HERE
|
||||
@output = [Virtual::Method.new(:length,[Ast::NameExpression.new(:x)],Boot::BootClass.new(:String,:Object),Virtual::Reference,Virtual::MethodEnter.new(nil))]
|
||||
@output = [Virtual::Method.new(:length,[Ast::NameExpression.new(:x)],Boot::BootClass.new(:String,:Object),Virtual::Reference,Virtual::MethodEnter.new(Virtual::ObjectGet.new(:length)))]
|
||||
check
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user