Permalink
Browse files

omg

  • Loading branch information...
1 parent 1bd63df commit b719015f1f323b02885154755dfe6b37881b4a15 @txus committed Dec 27, 2012
@@ -22,17 +22,17 @@ def disassemble
def encode(name)
ret
+ instrs = instructions.map(&:encode).flatten
+
output = "_#{name}\n"
- output << ":%i:%i\n" % [
- @literals.size,
- @ip
- ]
+ output << ":%i:%i\n" % [@literals.size, instrs.size]
+
output << @literals.join("\n")
output << "\n"
# instructions.each do |i|
# p i
# end
- output << instructions.map(&:encode).flatten.join("\n")
+ output << instrs.join("\n")
output
end
@@ -16,7 +16,7 @@ module Terror
value = inst.class.value
inst.operands.must_equal [2, 3]
- inst.encode.must_equal [value, 2, 3]
+ inst.encode.must_equal ["#{value} #{instruction.upcase}", 2, 3]
end
end
end
@@ -30,21 +30,21 @@ module Terror
value = inst.class.value
inst.operands.must_equal [2]
- inst.encode.must_equal [value, 2]
+ inst.encode.must_equal ["#{value} #{instruction.upcase}", 2]
end
end
end
end
describe 'instructions with no operands' do
- %w(noop pushself pushtrue pushfalse pushnil add pop ret dump).each do |instruction|
+ %w(noop pushself pushtrue pushfalse pushnil pop ret dump).each do |instruction|
describe instruction do
it "#{instruction} is encoded correctly" do
inst = @g.__send__ :"_#{instruction}"
value = inst.class.value
inst.operands.must_equal []
- inst.encode.must_equal [value]
+ inst.encode.must_equal ["#{value} #{instruction.upcase}"]
end
end
end
View
@@ -1,14 +1,14 @@
_main
-:1:3
+:1:4
"block_472
-67
+67 DEFN
0
-20
-144
+20 PUSHNIL
+144 RET
_block_472
-:1:2
+:1:3
3
-17
+17 PUSH
0
-144
+144 RET
View
@@ -1,5 +1,5 @@
_main
-:8:13
+:8:28
3
1
"-
@@ -8,32 +8,32 @@ _main
"*
"+
"puts
-16
-17
+16 PUSHSELF
+17 PUSH
0
-17
+17 PUSH
1
-128
+128 SEND
2
1
-17
+17 PUSH
0
-17
+17 PUSH
3
-17
+17 PUSH
0
-128
+128 SEND
4
1
-128
+128 SEND
5
1
-128
+128 SEND
6
1
-128
+128 SEND
7
1
-20
-144
+20 PUSHNIL
+144 RET
View
@@ -1,108 +1,109 @@
_main
-:13:46
+:14:92
"Object
-"clone
+"new
50
"age
1000
"money
+"clone
25
"Parent age:
"print
"puts
"Parent money:
"Child age:
"Child money:
-16
-64
+16 PUSHSELF
+64 GETSLOT
0
-128
+128 SEND
1
0
-33
+33 SETLOCAL
0
-32
+32 PUSHLOCAL
0
-17
+17 PUSH
2
-65
+65 SETSLOT
3
-32
+32 PUSHLOCAL
0
-17
+17 PUSH
4
-65
+65 SETSLOT
5
-32
+32 PUSHLOCAL
0
-128
-1
+128 SEND
+6
0
-33
+33 SETLOCAL
1
-32
+32 PUSHLOCAL
1
-17
-6
-65
-3
-16
-17
+17 PUSH
7
-128
+65 SETSLOT
+3
+16 PUSHSELF
+17 PUSH
8
+128 SEND
+9
1
-16
-32
+16 PUSHSELF
+32 PUSHLOCAL
0
-64
+64 GETSLOT
3
-128
-9
-1
-16
-17
+128 SEND
10
-128
-8
1
-16
-32
+16 PUSHSELF
+17 PUSH
+11
+128 SEND
+9
+1
+16 PUSHSELF
+32 PUSHLOCAL
0
-64
+64 GETSLOT
5
-128
-9
+128 SEND
+10
1
-16
-17
-11
-128
-8
+16 PUSHSELF
+17 PUSH
+12
+128 SEND
+9
1
-16
-32
+16 PUSHSELF
+32 PUSHLOCAL
1
-64
+64 GETSLOT
3
-128
-9
+128 SEND
+10
1
-16
-17
-12
-128
-8
+16 PUSHSELF
+17 PUSH
+13
+128 SEND
+9
1
-16
-32
+16 PUSHSELF
+32 PUSHLOCAL
1
-128
+128 SEND
5
0
-128
-9
+128 SEND
+10
1
-20
-144
+20 PUSHNIL
+144 RET
Oops, something went wrong.

0 comments on commit b719015

Please sign in to comment.