[Wisp-cvs] wisp/users/dig ia32.tran,1.3,1.4 mswhello.tran,1.5,1.6 tran-builtins,1.1,1.2 tran.py,1.65
Status: Alpha
Brought to you by:
digg
From: <di...@us...> - 2003-04-22 17:34:14
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv22054 Modified Files: ia32.tran mswhello.tran tran-builtins tran.py Log Message: preparations for PE-EXE generation Index: ia32.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/ia32.tran,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ia32.tran 22 Apr 2003 12:46:57 -0000 1.3 +++ ia32.tran 22 Apr 2003 17:34:08 -0000 1.4 @@ -14,3 +14,4 @@ // lit :macro $int #xCD b, b, ; // reg32 lit :macro $mov swap minor #o270 + b, t, ; // lit :macro $push #x68 b, t, ; +// reg32 :macro $push minor #o120 + b, ; Index: mswhello.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/mswhello.tran,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- mswhello.tran 22 Apr 2003 13:22:21 -0000 1.5 +++ mswhello.tran 22 Apr 2003 17:34:08 -0000 1.6 @@ -12,14 +12,22 @@ lit :macro $call #xe8 b, 4 - $-t, ; +// :macro GetStdHandle \ (handle-number -- handle) + commit ref GetStdHandle@kernel32 $call %eax ; + +\ FIXME: reverse arguments +// :macro WriteFile \ (file buffer count result* overlapped* -- result) + commit ref WriteFile@kernel32 $call %eax ; + +// :macro ExitProcess \ (code --) + commit ref ExitProcess@kernel32 $call ; + \ main entry point label _start - -11 $push - ref GetStdHandle@kernel32 $call - 0 $push ref rckeep $push 7 $push ref message $push %eax $push - ref WriteFile@kernel32 $call - 0 $push ref ExitProcess@kernel32 $call + -11 GetStdHandle + ref message 7 ref rckeep 0 WriteFile drop + 0 ExitProcess .data label message Index: tran-builtins =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- tran-builtins 22 Apr 2003 16:09:46 -0000 1.1 +++ tran-builtins 22 Apr 2003 17:34:09 -0000 1.2 @@ -6,6 +6,12 @@ # #### @(#) $Id$ +$-t, sum + s = Regstack.pop() + scalar = long(s[0]) + symbols = map(str, s[1:]) + cursect.emit_tetra_sum(symbols, delta = scalar % 0x100000000L, relative = 1) + $-t, sym cursect.emit_tetra_sum([str(Regstack.pop())], relative = 1) @@ -13,6 +19,18 @@ n = Regstack.pop(); m = Regstack.pop() Regstack.append(m + n) +- int int + n = Regstack.pop(); m = Regstack.pop() + Regstack.append(m - n) + +- sum int + n = Regstack.pop(); m = Regstack.pop() + Regstack.append(m - n) + +- sym int + n = Regstack.pop(); m = Regstack.pop() + Regstack.append(m - n) + .bss cursect = Bss @@ -69,6 +87,10 @@ b, sym cursect.emit_byte_sum([str(Regstack.pop())]) + +commit + Regstack.reverse() + prep.push_macro(['$push'] * len(Regstack)) drop any Regstack.pop() Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.65 retrieving revision 1.66 diff -u -d -r1.65 -r1.66 --- tran.py 22 Apr 2003 16:09:46 -0000 1.65 +++ tran.py 22 Apr 2003 17:34:09 -0000 1.66 @@ -21,15 +21,39 @@ def abstract (this, *arg, **narg): raise 'abstract method was called', this +def simplest_summable (scalar, symbols, registers): + if len(symbols) == len(registers) == 0: + return Integer_Literal(scalar) + elif scalar == len(registers) == 0 and len(symbols) == 1: + return symbols[0] + elif len(registers) == 0: + return Sum((Integer_Literal(scalar),) + tuple(symbols)) + else: + return NotImplemented + class Summable (object): def get_scalar (this): return 0 - def get_dollars (this): return 0 def get_symbols (this): return () def get_registers (this): return () + def __add__ (this, that): + scalar = this.get_scalar() + that.get_scalar() + symbols = this.get_symbols() + that.get_symbols() + registers = this.get_registers() + that.get_registers() + return simplest_summable(scalar, symbols, registers) + def __sub__ (this, that): + if len(that.get_symbols()) <> 0 or len(that.get_registers()) <> 0: + return NotImplemented + scalar = this.get_scalar() - that.get_scalar() + symbols = this.get_symbols() + registers = this.get_registers() + return simplest_summable(scalar, symbols, registers) + class Token (object): pass + class Stackable (object): def contained_registers (this): return () + class Integer_Literal (long, Stackable, Token, Summable): def __new__ (cls, i): return long.__new__(cls, i) @@ -41,6 +65,7 @@ return 'Integer_Literal(%i)' % long(this) def get_scalar (this): return long(this) + class Symbol_Literal (str, Stackable, Summable): def __new__ (cls, s): return str.__new__(cls, s) @@ -49,6 +74,20 @@ def get_symbols (this): return this, +class Sum (tuple, Summable): + def __new__ (cls, addends): + scalar = 0 + me = [] + for a in addends: + if isinstance(a, Integer_Literal): scalar += long(a) + elif isinstance(a, Symbol_Literal): me.append(a) + else: raise 'improper addend', a + return tuple.__new__(cls, [Integer_Literal(scalar)] + me) + def __repr__ (this): + return 'Sum(%s)' % repr(tuple(this)) + def __str__ (this): + return '+'.join(map(str, this)) + class Unique (object): def __init__ (this, name): this.name = name @@ -57,13 +96,8 @@ def __str__ (this): return this.name class Unique_Token (Unique, Token): pass -class Dollar_Type (Unique, Stackable, Summable): - def __init__ (this): - Unique.__init__(this, '$') - def get_dollars (this): return 1 Semicolon = Unique_Token(';') -Dollar = Dollar_Type() class Lexer (shlex): def __init__ (this, filename): @@ -123,6 +157,11 @@ i += 1 def __repr__ (this): return 'Register' + tuple.__repr__(this) + def __str__ (this): + if Registers.has_key(this): + return Registers[this] + else: + return '%' + '.'.join(map(str, this)) def contained_registers (this): return this, @@ -141,8 +180,8 @@ yield 'sym' yield 'lit' yield 'const' - elif object == Dollar: - yield '$' + elif isinstance(object, Sum): + yield 'sum' yield 'const' elif isinstance(object, Register): while object <> None: @@ -208,7 +247,9 @@ reggen = Generic_Register.child_generator() MA_PREFIX = 1 -Meaning = {'reg': Generic_Register} +Meaning = {'reg': Generic_Register, + 'tetras': ['dup', '+', 'dup', '+'], # FIXME +} for m in 'any const int lit sum sym'.split(' '): Meaning[m] = Class_Marker(m) @@ -236,18 +277,22 @@ def mainloop (): tok = prep.get_token() while tok <> None: + if verbose: print '(%s) %s' % (' '.join(map(str, Regstack)), tok) State(tok) tok = prep.get_token() +verbose = 0 + def main (): - global prep - opts, args = getopt(sys.argv[1:], 'o:', ['output=', 'show-words']) + global prep, verbose + opts, args = getopt(sys.argv[1:], 'vo:', ['verbose', 'output=', 'list-words']) output_name = 'a.out' - show_words = 0 + list_words = 0 for opt, arg in opts: if opt in ('-o', '--output'): output_name = arg - if opt == '--show-words': show_words = 1 - if show_words: + if opt in ('-v', '--verbose'): verbose = 1 + if opt == '--list-words': list_words = 1 + if list_words: wd = {} for w in Meaning.keys(): s = w.find(' ') |