Skip to content

Commit

Permalink
Fix handling of leading +s in assembler (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
Storyyeller committed Dec 31, 2016
1 parent 2793645 commit e0999e0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Krakatau/assembler/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def eol(a): a.asserttype('NEWLINES'), a.consume()

def _rawint(a):
a.asserttype('INT_LITERAL')
return a.tok, ast.literal_eval(a.consume().val)
return a.tok, ast.literal_eval(a.consume().val.lstrip('+'))

def boundedint(a, lower, upper):
tok, x = a._rawint()
Expand Down Expand Up @@ -170,15 +170,15 @@ def identifier(a):
def intl(a):
a.asserttype('INT_LITERAL')
tok = a.consume()
x = ast.literal_eval(tok.val)
x = ast.literal_eval(tok.val.lstrip('+'))
if not -1<<31 <= x < 1<<31:
a.error('Value does not fit into int type.', tok)
return x % (1 << 32)

def longl(a):
a.asserttype('LONG_LITERAL')
tok = a.consume()
x = ast.literal_eval(tok.val)
x = ast.literal_eval(tok.val.lstrip('+'))
if not -1 << 63 <= x < 1 << 63:
a.error('Value does not fit into long type.', tok)
return x % (1 << 64)
Expand Down
39 changes: 39 additions & 0 deletions tests/assembler/good/ldcs_plus.j
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.version +50 0x0
.class public LdcTest
.super java/lang/Object

.method public static print : (F)V
.code stack 910 locals 10
ldc 0
ldc -0
ldc +0
ldc +1
ldc +0x1
ldc -0x1
ldc -10e1f
ldc +10e1f
ldc +0.0f
ldc -0.0f
ldc -0x80000000
ldc -0x7FFFFFFF
ldc +0x7FFFFFFF

ldc2_w 0L
ldc2_w -0L
ldc2_w +0L
ldc2_w +1L
ldc2_w +0x1L
ldc2_w -0x1L
ldc2_w -10e1
ldc2_w +10e1
ldc2_w +0.0
ldc2_w -0.0
ldc2_w -0x8000000000000000L
ldc2_w -0x7FFFFFFFffffffffL
ldc2_w +0x7FFFFFFFffffffffL


return
.end code
.end method
.end class

0 comments on commit e0999e0

Please sign in to comment.