Skip to content

Commit

Permalink
* lib/unholy/pyasm.rb: jump opcode and empty arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
_why committed May 15, 2008
1 parent 12d52c4 commit ea44e7a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/unholy/pyasm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def build_tuple(n)
bc(0x66, n, 0x0)
end
def build_list(n)
@stack.slice! -(n-1), (n-1)
@stack.slice! -(n-1), (n-1) if n > 0
bc(0x67, n, 0x0)
end
def load_attr(name)
Expand All @@ -96,6 +96,9 @@ def import_name(name)
def import_from(name)
bc 0x6c, add_sym(name), 0x0
end
def jump(n)
mark_jump n, bc(0x6e, n, 0x0)
end
def jump_if_false(n)
mark_jump n, bc(0x6f, n, 0x0)
end
Expand Down
27 changes: 27 additions & 0 deletions tests/07if.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 123
# 123
# 456
# 123
a = []
if true
a << 123
end
puts a[0]

a = []
if true
a << 123
else
a << 456
end
puts a[0]

a = []
if false
a << 123
else
a << 456
end
puts a[0]

puts 123 if true

0 comments on commit ea44e7a

Please sign in to comment.