Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv13567
Modified Files:
tran.py
Log Message:
added the Integer_Literal class
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- tran.py 16 Apr 2003 20:06:36 -0000 1.20
+++ tran.py 16 Apr 2003 20:22:22 -0000 1.21
@@ -22,6 +22,15 @@
class Stackable:
def contained_registers (this):
return ()
+class Integer_Literal (long, Stackable, Token):
+ def __new__ (cls, i):
+ return long.__new__(cls, i)
+ def __add__ (this, that):
+ return Integer_Literal(long(this) + long(that))
+ def __sub__ (this, that):
+ return Integer_Literal(long(this) - long(that))
+ def __repr__ (this):
+ return 'Integer_Literal(%i)' % long(this)
class Unique:
def __init__ (this, name):
@@ -43,10 +52,10 @@
def get_token (this):
tok = shlex.get_token(this)
if tok == '': tok = None
- elif tok[:2] == '#o': tok = string.atol(tok[2:], 8)
- elif tok[:2] == '#x': tok = string.atol(tok[2:], 16)
+ elif tok[:2] == '#o': tok = Integer_Literal(string.atol(tok[2:], 8))
+ elif tok[:2] == '#x': tok = Integer_Literal(string.atol(tok[2:], 16))
else:
- try: tok = string.atol(tok, 10)
+ try: tok = Integer_Literal(string.atol(tok, 10))
except: pass
if tok == ';': return Semicolon
else: return tok
@@ -98,15 +107,15 @@
class Sum (list):
def __init__ (this, addends, scalar = 0, dollars = 0):
list.__init__(this, [])
- this.scalar = scalar
- this.dollars = dollars
+ this.scalar = long(scalar)
+ this.dollars = long(dollars)
for a in addends:
if isinstance(a, Sum):
this.extend(a)
this.scalar += a.scalar
this.dollars += a.dollars
- elif type(a) == LongType or type(a) == IntType:
- this.scalar += a
+ elif isinstance(a, Integer_Literal) or isinstance(a, IntType):
+ this.scalar += long(a)
else: this.append(a)
def __add__ (this, that):
return Sum(this, that)
@@ -132,15 +141,15 @@
return res
def b_comma (n):
- if type(n) == LongType: cursect.emit_byte(n % 0x100)
+ if isinstance(n, Integer_Literal): cursect.emit_byte(long(n) % 0x100)
elif type(n) == StringType: cursect.emit_byte_sum([n])
else: raise 'Literal expected', n
def w_comma (n):
- if type(n) == LongType: cursect.emit_wyde(n % 0x10000)
+ if isinstance(n, Integer_Literal): cursect.emit_wyde(long(n) % 0x10000)
elif type(n) == StringType: cursect.emit_wyde_sum([n])
else: raise 'Literal expected', n
def t_comma (n):
- if type(n) == LongType: cursect.emit_tetra(n % 0x100000000L)
+ if isinstance(n, Integer_Literal): cursect.emit_tetra(long(n) % 0x100000000L)
elif type(n) == StringType: cursect.emit_tetra_sum([n])
else: raise 'Literal expected', n
def label (name):
@@ -160,7 +169,7 @@
def align (n): cursect.align(n)
def reserve (n): cursect.skip(n)
def minor (reg):
- Regstack.append(long(reg[-1]))
+ Regstack.append(Integer_Literal(reg[-1]))
def swap (x, y):
Regstack.append(y); Regstack.append(x)
def dup (x):
@@ -192,7 +201,7 @@
def matchers (object):
if isinstance(object, ClassMarker):
yield object.id
- elif type(object) == LongType:
+ elif isinstance(object, Integer_Literal):
yield 'int'
yield 'lit'
elif type(object) == StringType:
@@ -225,10 +234,10 @@
def state_outer (tok):
global Regstack
- if type(tok) == LongType:
+ if isinstance(tok, Integer_Literal):
Regstack.append(tok)
elif type(tok) == StringType and tok[:2] == '#/' and len(tok) == 3:
- Regstack.append(long(ord(tok[2])))
+ Regstack.append(Integer_Literal(ord(tok[2])))
else:
root = tok
mg = match_generator(root)
|