Permalink
Browse files

Slot assignment works

  • Loading branch information...
1 parent 4c66c90 commit 6f9baae3dbba4d2c09cf664704197f6795a9fdcf @txus committed Jan 7, 2012
View
@@ -96,23 +96,23 @@ def initialize(line, name, value)
@value = value
end
end
-#
-#
-# class SlotAssignNode < Node
-# attr_reader :receiver, :slot, :value
-# def initialize(receiver, slot, value)
-# @receiver = receiver
-# @slot = slot
-# @value = value
-# end
-# end
-#
+
+ class SlotAssign < Node
+ attr_reader :receiver, :name, :value
+ def initialize(line, receiver, name, value)
+ super(line)
+ @receiver = receiver
+ @name = name.name.to_sym
+ @value = value
+ end
+ end
+
class SlotGet < Node
attr_reader :receiver, :name
def initialize(line, receiver, name)
super(line)
@receiver = receiver
- @name = name.to_sym
+ @name = name.name.to_sym
end
end
#
@@ -32,7 +32,7 @@ class ObjectType < Rubinius::LookupTable
attr_accessor :prototype
def initialize
- @prototype = Object
+ @prototype = Runtime::Object
end
noscript_def("clone") do |*args|
View
@@ -157,6 +157,14 @@ def visit_SlotGet(o)
g.send :get, 1
end
+ def visit_SlotAssign(o)
+ set_line(o)
+ o.receiver.accept(self)
+ g.push_literal o.name
+ o.value.accept(self)
+ g.send :put, 2
+ end
+
def finalize
g.local_names = s.variables
g.local_count = s.variables.size
@@ -153,13 +153,13 @@ rule
SlotAssign:
# receiver.slot = 123
- Expression '.' Identifier '=' Expression { result = SlotAssignNode.new(val[0], val[2], val[4]); result.pos(filename, lineno) }
+ Expression '.' Identifier '=' Expression { result = SlotAssign.new(lineno, val[0], val[2], val[4]) }
;
# Get a slot from an object
SlotGet:
# receiver.slot
- | Expression '.' Identifier { result = SlotGet.new(lineno, val[0], val[2].name) }
+ | Expression '.' Identifier { result = SlotGet.new(lineno, val[0], val[2]) }
;
# Function call

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -82,9 +82,10 @@ def test_compile_slot_get
assert_equal 1, @compiler.compile("obj = Object.clone({a: 1}); obj.a").call
end
- # def test_compile_slot_assign
- # assert_equal [:assign_slot], @compiler.compile("foo.a = 3")
- # end
+ def test_compile_slot_assign
+ obj = @compiler.compile("foo = Object.clone(); foo.a = 3; foo").call
+ assert_equal 3, obj.get(:a)
+ end
# def test_compile_slot_get
# assert_equal [:get_slot], @compiler.compile("foo.a")

0 comments on commit 6f9baae

Please sign in to comment.