Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv27826
Modified Files:
tran.py
Log Message:
added the Sum class
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- tran.py 15 Apr 2003 21:27:32 -0000 1.10
+++ tran.py 15 Apr 2003 22:01:19 -0000 1.11
@@ -52,12 +52,52 @@
def __init__ (this, id):
this.id = id
+class Sum (list):
+ def __init__ (this, addends, scalar = 0, dollars = 0):
+ list.__init__(this, [])
+ this.scalar = scalar
+ this.dollars = 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
+ else: this.append(a)
+ def __add__ (this, that):
+ return Sum(this, that)
+ def __repr__ (this):
+ res = `list(this)`
+ if this.scalar: res += ', scalar = ' + `this.scalar`
+ if this.dollars: res += ', dollars = ' + `this.dollars`
+ return 'Sum(' + res + ')'
+ def __str__ (this):
+ res = ' + '.join(map(str, this))
+ if this.dollars:
+ if res <> '': res += ' '
+ res += '- '
+ if this.dollars <> 1: res += `this.dollars`
+ res += '$'
+ if this.scalar:
+ if this.scalar > 0:
+ if res <> '': res += ' + '
+ res += `this.scalar`
+ else:
+ if res <> '': res += ' '
+ res += '- ' + `-this.scalar`
+ return res
+
def b_comma (n):
- if type(n) == LongType: cursect.emit_byte(n)
+ if type(n) == LongType: cursect.emit_byte(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)
+ 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)
+ if type(n) == LongType: cursect.emit_tetra(n % 0x100000000L)
elif type(n) == StringType: cursect.emit_tetra_sum([n])
else: raise 'Literal expected', n
def label (name):
@@ -215,20 +255,21 @@
':macro': ('builtin', colon_macro, 0 | MA_PREFIX),
':regs': ('builtin', colon_regs, 0 | MA_PREFIX),
'align int': ('builtin', align, 1),
- 'reserve int': ('builtin', reserve, 1),
'any': ('simple', ClassMarker('any')),
'b, lit': ('builtin', b_comma, 1),
'drop any': ('builtin', drop, 1),
+ 'dup any': ('builtin', dup, 1),
'int': ('simple', ClassMarker('int')),
'label': ('builtin', label, 0 | MA_PREFIX),
'lit': ('simple', ClassMarker('lit')),
'minor reg': ('builtin', minor, 1),
'ref': ('builtin', ref, 0 | MA_PREFIX),
'reg': ('simple', Generic_Register),
+ 'reserve int': ('builtin', reserve, 1),
'sum': ('simple', ClassMarker('sum')),
'swap any any': ('builtin', swap, 2),
- 'dup any': ('builtin', dup, 1),
't, lit': ('builtin', t_comma, 1),
+ 'w, lit': ('builtin', w_comma, 1),
}
current_recordee = None
current_register_family = 0
|