wisp-cvs Mailing List for Wisp interpreter (Page 5)
Status: Alpha
Brought to you by:
digg
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(30) |
Sep
(312) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(5) |
Feb
(131) |
Mar
(17) |
Apr
(184) |
May
(252) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
From: <di...@us...> - 2003-05-18 11:40:49
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv3727 Modified Files: i80386.tran i8086.tran Log Message: declared the segreg register group Index: i80386.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/i80386.tran,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- i80386.tran 17 May 2003 09:28:34 -0000 1.3 +++ i80386.tran 18 May 2003 11:40:45 -0000 1.4 @@ -13,4 +13,6 @@ :regs reg32 %eax %ecx %edx %ebx %esp %ebp %esi %edi ; ; +:regs segreg %fs %gs ; + \ vim: ft=tran Index: i8086.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/i8086.tran,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- i8086.tran 18 May 2003 11:25:14 -0000 1.8 +++ i8086.tran 18 May 2003 11:40:46 -0000 1.9 @@ -19,6 +19,8 @@ ... ; +:regs segreg %es %cs %ss %ds ... ; + \ instructions :[ lit ] $int #xCD b, b, ; |
From: <di...@us...> - 2003-05-18 11:25:17
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv24985 Modified Files: i8086.tran Log Message: implemented |$mov reg8 lit| for i8086 Index: i8086.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/i8086.tran,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- i8086.tran 17 May 2003 09:55:40 -0000 1.7 +++ i8086.tran 18 May 2003 11:25:14 -0000 1.8 @@ -22,6 +22,7 @@ \ instructions :[ lit ] $int #xCD b, b, ; +:[ reg8 lit ] $mov swap minor #o260 + b, ; :[ reg16 lit ] $mov $o16 swap minor #o270 + b, w, ; :[ reg32 lit ] $mov $o32 swap minor #o270 + b, t, ; |
From: <di...@us...> - 2003-05-18 11:20:54
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv23485 Modified Files: tran-builtins Log Message: implemented |times int| Index: tran-builtins =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- tran-builtins 17 May 2003 16:26:21 -0000 1.30 +++ tran-builtins 18 May 2003 11:20:51 -0000 1.31 @@ -202,6 +202,10 @@ t, sym interpreter.current[::4] = str(interpreter.regstack.pop()) +times int|word + multiplier = interpreter.regstack.pop() + interpreter.toksrc.push(Macro_Cursor([word] * multiplier)) + w, int interpreter.current[::2] = long(interpreter.regstack.pop()) |
From: <di...@us...> - 2003-05-17 16:49:18
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv22581 Modified Files: pe.py Log Message: simplified populate_pe_directories Index: pe.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/pe.py,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- pe.py 17 May 2003 15:37:14 -0000 1.11 +++ pe.py 17 May 2003 16:49:13 -0000 1.12 @@ -153,9 +153,9 @@ '&delay-import-descr': base, '#delay-import-descr/size': 0, '&COM+-runtime-header': base, '#COM+-runtime-header/size': 0, } - for s in defaults.keys(): + for sym, defval in defaults.items(): if given.has_key(s): linkie.place_symbol(s, given[s]) - else: linkie.place_symbol(s, defaults[s]) + else: linkie.place_symbol(s, defval) def make_pe_executable (text = None, data = None, bss = None, base_address = 0x00400000): |
From: <di...@us...> - 2003-05-17 16:26:25
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv12697 Modified Files: tran-builtins Log Message: implemented |b, sum| and |w, sum| Index: tran-builtins =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- tran-builtins 17 May 2003 16:19:41 -0000 1.29 +++ tran-builtins 17 May 2003 16:26:21 -0000 1.30 @@ -133,6 +133,11 @@ b, int interpreter.current[::1] = long(interpreter.regstack.pop()) +b, sum + sum = interpreter.regstack.pop() + interpreter.current.emit_byte_sum(map(str, sum.get_symbols()), + delta = sum.get_scalar()) + b, sym interpreter.current[::1] = str(interpreter.regstack.pop()) @@ -189,16 +194,21 @@ t, int interpreter.current[::4] = long(interpreter.regstack.pop()) -t, sym - interpreter.current[::4] = str(interpreter.regstack.pop()) - t, sum sum = interpreter.regstack.pop() interpreter.current.emit_tetra_sum(map(str, sum.get_symbols()), delta = sum.get_scalar()) +t, sym + interpreter.current[::4] = str(interpreter.regstack.pop()) + w, int interpreter.current[::2] = long(interpreter.regstack.pop()) + +w, sum + sum = interpreter.regstack.pop() + interpreter.current.emit_wyde_sum(map(str, sum.get_symbols()), + delta = sum.get_scalar()) w, sym interpreter.current[::2] = str(interpreter.regstack.pop()) |
From: <di...@us...> - 2003-05-17 16:19:44
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv10111 Modified Files: tran-builtins tran.py Log Message: implemented |+ sym sym| and |t, sum| Index: tran-builtins =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- tran-builtins 17 May 2003 15:21:25 -0000 1.28 +++ tran-builtins 17 May 2003 16:19:41 -0000 1.29 @@ -28,6 +28,10 @@ n = interpreter.regstack.pop(); m = interpreter.regstack.pop() interpreter.regstack.append(m + n) ++ sym sym + n = interpreter.regstack.pop(); m = interpreter.regstack.pop() + interpreter.regstack.append(Sum([m, n])) + - int int n = interpreter.regstack.pop(); m = interpreter.regstack.pop() interpreter.regstack.append(m - n) @@ -187,6 +191,11 @@ t, sym interpreter.current[::4] = str(interpreter.regstack.pop()) + +t, sum + sum = interpreter.regstack.pop() + interpreter.current.emit_tetra_sum(map(str, sum.get_symbols()), + delta = sum.get_scalar()) w, int interpreter.current[::2] = long(interpreter.regstack.pop()) Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.107 retrieving revision 1.108 diff -u -d -r1.107 -r1.108 --- tran.py 17 May 2003 15:33:36 -0000 1.107 +++ tran.py 17 May 2003 16:19:42 -0000 1.108 @@ -78,6 +78,10 @@ elif isinstance(a, Symbol_Literal): me.append(a) else: raise 'improper addend', a return tuple.__new__(cls, [Integer_Literal(scalar)] + me) + def get_scalar (this): + return this[0] + def get_symbols (this): + return this[1:] def __repr__ (this): return 'Sum(%s)' % repr(tuple(this)) def __str__ (this): |
From: <di...@us...> - 2003-05-17 15:37:18
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv25242 Modified Files: coff.py pe.py Log Message: dropped make_coff_header in favour of make-coff-header Index: coff.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/coff.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- coff.py 17 May 2003 13:50:52 -0000 1.3 +++ coff.py 17 May 2003 15:37:14 -0000 1.4 @@ -9,9 +9,6 @@ from linkie import Linkie from tran import interpret_single -def make_coff_header (target = '<'): - return interpret_single('make-coff-header', target, include = 'coff') - def make_coff_section_header (byte_order, name): h = Linkie(byte_order) h.align(4) Index: pe.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/pe.py,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- pe.py 17 May 2003 15:05:17 -0000 1.10 +++ pe.py 17 May 2003 15:37:14 -0000 1.11 @@ -166,7 +166,7 @@ e.align(8) # PE header must be aligned to 8 e.place_symbol('!pe') e.emit_string('PE\0\0') - e.glue(e.memsz(), make_coff_header(), None) + interpret_single('make-coff-header', e, include = 'coff') e.glue(e.memsz(), make_pe_aout_header(), None) text = text.copy() # so we won't add import stubs to the original linkie imports = Linkie('<') |
From: <di...@us...> - 2003-05-17 15:33:39
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv23966 Modified Files: tran.py Log Message: use long instead of string.atol Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.106 retrieving revision 1.107 diff -u -d -r1.106 -r1.107 --- tran.py 17 May 2003 15:29:50 -0000 1.106 +++ tran.py 17 May 2003 15:33:36 -0000 1.107 @@ -12,7 +12,6 @@ from linkie import Linkie from shlex import shlex -import string def abstract (this, *arg, **narg): raise 'abstract method was called', (this, arg, narg) @@ -110,12 +109,12 @@ def get_token (this): tok = shlex.get_token(this) if tok == '': tok = None - elif tok[:2] == '#o': tok = Integer_Literal(string.atol(tok[2:], 8)) - elif tok[:2] == '#x': tok = Integer_Literal(string.atol(tok[2:], 16)) + elif tok[:2] == '#o': tok = Integer_Literal(long(tok[2:], 8)) + elif tok[:2] == '#x': tok = Integer_Literal(long(tok[2:], 16)) elif tok[:2] == '#/' and len(tok) == 3: tok = Integer_Literal(ord(tok[2])) else: - try: tok = Integer_Literal(string.atol(tok, 10)) + try: tok = Integer_Literal(long(tok, 10)) except: pass if tok == ';': return Semicolon else: return tok @@ -366,7 +365,7 @@ for opt, arg in opts: if opt in ('-v', '--verbose'): verbose = 1 if opt in ('-o', '--output'): output_name = arg - if opt in ('-b', '--base'): base = string.atol(arg, 16) + if opt in ('-b', '--base'): base = long(arg, 16) if opt in ('-f', '--format'): format = arg if output_name == None: output_name = default_output_names[format] if len(args) != 1: |
From: <di...@us...> - 2003-05-17 15:29:53
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv22487 Modified Files: tran.py Log Message: implemented Register.ancestry Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.105 retrieving revision 1.106 diff -u -d -r1.105 -r1.106 --- tran.py 17 May 2003 14:46:34 -0000 1.105 +++ tran.py 17 May 2003 15:29:50 -0000 1.106 @@ -154,6 +154,8 @@ def parent (this): if len(this): return Register(this[:-1], this.names) else: return None + def ancestry (this): + return [this[:i] for i in range(len(this) - 1, -1, -1)] def next (this): l = list(this) l[-1] += 1 @@ -352,7 +354,6 @@ from getopt import getopt import elf import pe - import string import sys default_output_names = {'elf': 'a.out', 'pe': 'untitled.exe'} |
From: <di...@us...> - 2003-05-17 15:21:28
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv19200 Modified Files: tran-builtins Log Message: implemented |2mingle| Index: tran-builtins =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- tran-builtins 17 May 2003 15:05:17 -0000 1.27 +++ tran-builtins 17 May 2003 15:21:25 -0000 1.28 @@ -152,6 +152,15 @@ before, after = tpl interpreter.regstack.append(Symbol_Literal(before + core + after)) +2mingle sym sym|tpl + core2 = str(interpreter.regstack.pop())[1:] + core1 = str(interpreter.regstack.pop())[1:] + tpl = tpl.split('*', 2) + if len(tpl) <> 3: raise 'not exactly two stars', tpl + before, middle, after = tpl + interpreter.regstack.append(Symbol_Literal(before + core1 + \ + middle + core2 + after)) + label|name if not name[0] in '&#!': name = '&' + name interpreter.current.place_symbol(name) |
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv9829 Modified Files: coff.tran elf.py hello.tran mswhello.tran mz.tran pe.py pe.tran tran-builtins winapi.tran Log Message: renamed |ref| to |'| Index: coff.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/coff.tran,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- coff.tran 17 May 2003 13:50:52 -0000 1.1 +++ coff.tran 17 May 2003 15:05:16 -0000 1.2 @@ -8,7 +8,7 @@ :[ ] make-coff-header 4 align - ref #coff/magic w, + '#coff/magic w, \ Known magic values: \ 0x0000 unknown \ 0x014C i80386 @@ -29,12 +29,12 @@ \ 0x0284 Alpha AXP 64-bit \ 0x0366 Mips with FPU \ 0x0466 Mips 16 with FPU - ref #coff/nscns w, - ref #coff/timdat t, - ref !coff/symptr t, - ref #coff/nsyms t, - ref #coff/opthdr w, - ref #coff/flags w, + '#coff/nscns w, + '#coff/timdat t, + '!coff/symptr t, + '#coff/nsyms t, + '#coff/opthdr w, + '#coff/flags w, \ Flags for COFF: \ 0x0001 no relocations -- can only be loaded at the preferred address \ 0x0002 executable Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.59 retrieving revision 1.60 diff -u -d -r1.59 -r1.60 --- elf.py 17 May 2003 14:16:24 -0000 1.59 +++ elf.py 17 May 2003 15:05:17 -0000 1.60 @@ -353,7 +353,7 @@ t.align(4) t |= '!elf/proghdr' for name in names: - interpret_single(['ref', name, 'make-elf32-phentry'], + interpret_single(["'", name, 'make-elf32-phentry'], t, include = 'elf') t.place_symbol('#elf/phnum', len(names)) return t Index: hello.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/hello.tran,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- hello.tran 17 May 2003 09:41:22 -0000 1.4 +++ hello.tran 17 May 2003 15:05:17 -0000 1.5 @@ -15,7 +15,7 @@ label _start %edx 6 $mov - %ecx ref message $mov + %ecx 'message $mov %ebx 1 $mov %eax 4 $mov #x80 $int Index: mswhello.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/mswhello.tran,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- mswhello.tran 17 May 2003 06:08:31 -0000 1.13 +++ mswhello.tran 17 May 2003 15:05:17 -0000 1.14 @@ -16,7 +16,7 @@ label _start -11 GetStdHandle - ref message 7 ref rckeep 0 WriteFile drop + 'message 7 'rckeep 0 WriteFile drop 0 ExitProcess .data Index: mz.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/mz.tran,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- mz.tran 17 May 2003 14:54:41 -0000 1.1 +++ mz.tran 17 May 2003 15:05:17 -0000 1.2 @@ -8,15 +8,15 @@ :[ ] make-mz-header #x4D b, #x5A b, \ magic - ref #mz/bytes-in-last-block w, ref #mz/blocks-in-file w, - ref #mz/reloc-count w, - ref #mz/header-size w, - ref #mz/low-memory-limit w, ref #mz/high-memory-limit w, - ref #mz/ss w, ref #mz/sp w, - ref #mz/checksum w, - ref #mz/ip w, ref #mz/cs w, - ref !mz/reloc w, - ref #mz/overlay w, + '#mz/bytes-in-last-block w, '#mz/blocks-in-file w, + '#mz/reloc-count w, + '#mz/header-size w, + '#mz/low-memory-limit w, '#mz/high-memory-limit w, + '#mz/ss w, '#mz/sp w, + '#mz/checksum w, + '#mz/ip w, '#mz/cs w, + '!mz/reloc w, + '#mz/overlay w, ; \ vim: ft=tran Index: pe.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/pe.py,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- pe.py 17 May 2003 14:54:41 -0000 1.9 +++ pe.py 17 May 2003 15:05:17 -0000 1.10 @@ -6,7 +6,6 @@ # #### @(#) $Id$ -from mz import * from coff import * import time from tran import interpret_single Index: pe.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/pe.tran,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pe.tran 17 May 2003 14:54:41 -0000 1.2 +++ pe.tran 17 May 2003 15:05:17 -0000 1.3 @@ -22,13 +22,13 @@ 0 =: !mz/reloc 0 =: #mz/overlay - #x8C b, #xc8 b, \ mov %ax, %cs - #x8E b, #xD8 b, \ mov %ds, %ax - #xB4 b, 9 b, \ mov %ah, 9 - #xBA b, ref mz/message w, \ mov %dx, message - #xCD b, #x21 b, \ int 0x21 - #xB8 b, #x4CFF w, \ mov %ax, 0x4CFF - #xCD b, #x21 b, \ int 0x21 + #x8C b, #xc8 b, \ mov %ax, %cs + #x8E b, #xD8 b, \ mov %ds, %ax + #xB4 b, 9 b, \ mov %ah, 9 + #xBA b, 'mz/message w, \ mov %dx, message + #xCD b, #x21 b, \ int 0x21 + #xB8 b, #x4CFF w, \ mov %ax, 0x4CFF + #xCD b, #x21 b, \ int 0x21 ; \ vim: ft=tran Index: tran-builtins =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- tran-builtins 17 May 2003 14:46:34 -0000 1.26 +++ tran-builtins 17 May 2003 15:05:17 -0000 1.27 @@ -162,7 +162,7 @@ include|name interpreter.toksrc.push(Lexer(str(name) + '.tran')) -ref|name +'|name if not name[0] in '&#!': name = '&' + name interpreter.regstack.append(Symbol_Literal(name)) Index: winapi.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/winapi.tran,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- winapi.tran 17 May 2003 05:08:45 -0000 1.2 +++ winapi.tran 17 May 2003 15:05:17 -0000 1.3 @@ -7,12 +7,12 @@ \\\\ @(#) $Id$ :[ ] GetStdHandle \ (handle-number -- handle) - commit ref GetStdHandle@kernel32 $call %eax ; + commit 'GetStdHandle@kernel32 $call %eax ; :[ ] WriteFile \ (file buffer count result* overlapped* -- result) - 5rev commit ref WriteFile@kernel32 $call %eax ; + 5rev commit 'WriteFile@kernel32 $call %eax ; :[ ] ExitProcess \ (code --) - commit ref ExitProcess@kernel32 $call ; + commit 'ExitProcess@kernel32 $call ; \ vim: ft=tran |
From: <di...@us...> - 2003-05-17 14:54:44
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv1841 Modified Files: Makefile.am pe.py pe.tran Added Files: mz.tran Removed Files: mz.py Log Message: replaced pe.py by pe.tran --- NEW FILE: mz.tran --- \\\\ mz.tran - MZ-EXE generation \ \ Copyleft © 2003 by Andres Soolo (di...@us...) \ This file is licensed under the GNU GPL v2. If you \ don't know what that means, please do read the GPL. \ \\\\ @(#) $Id: mz.tran,v 1.1 2003/05/17 14:54:41 digg Exp $ :[ ] make-mz-header #x4D b, #x5A b, \ magic ref #mz/bytes-in-last-block w, ref #mz/blocks-in-file w, ref #mz/reloc-count w, ref #mz/header-size w, ref #mz/low-memory-limit w, ref #mz/high-memory-limit w, ref #mz/ss w, ref #mz/sp w, ref #mz/checksum w, ref #mz/ip w, ref #mz/cs w, ref !mz/reloc w, ref #mz/overlay w, ; \ vim: ft=tran Index: Makefile.am =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/Makefile.am,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- Makefile.am 17 May 2003 14:46:34 -0000 1.21 +++ Makefile.am 17 May 2003 14:54:41 -0000 1.22 @@ -9,7 +9,7 @@ EXTRA_DIST = .cvsignore .pycheckrc struburn.wisp bits.py linkie.py \ coff.py elf.py pe.py \ i8086.tran i80386.tran ia16.tran ia32.tran \ - coff.tran elf.tran pe.tran \ + coff.tran elf.tran mz.tran pe.tran \ winapi.tran \ hello.tran mswhello.tran \ makehello.py elfdump.py Index: pe.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/pe.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- pe.py 17 May 2003 14:46:34 -0000 1.8 +++ pe.py 17 May 2003 14:54:41 -0000 1.9 @@ -30,8 +30,7 @@ raise 'MZ message may not contain dollar signs', message if message.find('\r') == -1: # if no CRs, insert them message = '\r\n'.join(message.split('\n')) - b = make_mz_header() - interpret_single('make-pe-mz-stub-structure', b, include = 'pe') + b = interpret_single('make-pe-mz-stub-structure', '<', include = 'pe') message += '$' # Dollar the Terminator # a pointer to the PE signature must appear at the offset 0x003C Index: pe.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/pe.tran,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- pe.tran 17 May 2003 14:46:34 -0000 1.1 +++ pe.tran 17 May 2003 14:54:41 -0000 1.2 @@ -6,7 +6,11 @@ \ \\\\ @(#) $Id$ +include mz + +\ The result's assumed origin address is 0x100. :[ ] make-pe-mz-stub-structure \ no message itself + make-mz-header 0 =: #mz/reloc-count \ no relocation 0 =: #mz/header-size \ empty MZ header--load it all #x40 dup =: #mz/low-memory-limit =: #mz/high-memory-limit @@ -21,9 +25,9 @@ #x8C b, #xc8 b, \ mov %ax, %cs #x8E b, #xD8 b, \ mov %ds, %ax #xB4 b, 9 b, \ mov %ah, 9 - #xBA b, ref mz/message t, \ mov %dx, message + #xBA b, ref mz/message w, \ mov %dx, message #xCD b, #x21 b, \ int 0x21 - #xB8 b, #x4CFF t, \ mov %ax, 0x4CFF + #xB8 b, #x4CFF w, \ mov %ax, 0x4CFF #xCD b, #x21 b, \ int 0x21 ; --- mz.py DELETED --- |
From: <di...@us...> - 2003-05-17 14:46:40
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv28158 Modified Files: Makefile.am pe.py tran-builtins tran.py Added Files: pe.tran Log Message: converted the body of make_pe_mz_stub into the |make-pe-mz-stub-structure| tran macro --- NEW FILE: pe.tran --- \\\\ pe.tran - PE generation routines \ \ Copyleft © 2003 by Andres Soolo (di...@us...) \ This file is licensed under the GNU GPL v2. If you \ don't know what that means, please do read the GPL. \ \\\\ @(#) $Id: pe.tran,v 1.1 2003/05/17 14:46:34 digg Exp $ :[ ] make-pe-mz-stub-structure \ no message itself 0 =: #mz/reloc-count \ no relocation 0 =: #mz/header-size \ empty MZ header--load it all #x40 dup =: #mz/low-memory-limit =: #mz/high-memory-limit #x-10 =: #mz/ss #x100 =: #mz/sp 0 =: #mz/checksum #x100 current-offset + =: #mz/ip #x-10 =: #mz/cs 0 =: !mz/reloc 0 =: #mz/overlay #x8C b, #xc8 b, \ mov %ax, %cs #x8E b, #xD8 b, \ mov %ds, %ax #xB4 b, 9 b, \ mov %ah, 9 #xBA b, ref mz/message t, \ mov %dx, message #xCD b, #x21 b, \ int 0x21 #xB8 b, #x4CFF t, \ mov %ax, 0x4CFF #xCD b, #x21 b, \ int 0x21 ; \ vim: ft=tran Index: Makefile.am =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/Makefile.am,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- Makefile.am 17 May 2003 14:16:23 -0000 1.20 +++ Makefile.am 17 May 2003 14:46:34 -0000 1.21 @@ -9,7 +9,7 @@ EXTRA_DIST = .cvsignore .pycheckrc struburn.wisp bits.py linkie.py \ coff.py elf.py pe.py \ i8086.tran i80386.tran ia16.tran ia32.tran \ - coff.tran elf.tran \ + coff.tran elf.tran pe.tran \ winapi.tran \ hello.tran mswhello.tran \ makehello.py elfdump.py Index: pe.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/pe.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pe.py 17 May 2003 10:16:53 -0000 1.7 +++ pe.py 17 May 2003 14:46:34 -0000 1.8 @@ -9,6 +9,7 @@ from mz import * from coff import * import time +from tran import interpret_single def roundup (value, boundary): return (value + boundary - 1) & ~(boundary - 1) @@ -30,22 +31,7 @@ if message.find('\r') == -1: # if no CRs, insert them message = '\r\n'.join(message.split('\n')) b = make_mz_header() - b.place_symbol('#mz/reloc-count', 0) # no relocation - b.place_symbol('#mz/header-size', 0) # empty MZ header--load it all - b.place_symbol('#mz/low-memory-limit', 0x40) - b.place_symbol('#mz/high-memory-limit', 0x40) - b.place_symbol('#mz/ss', -0x10) - b.place_symbol('#mz/sp', 0x100) - b.place_symbol('#mz/checksum', 0) - b.place_symbol('#mz/ip', 0x100 + b.memsz()) - b.place_symbol('#mz/cs', -0x10) - b.place_symbol('!mz/reloc', 0) - b.place_symbol('#mz/overlay', 0) - b[::1] = 0x8C, 0xC8, 0x8E, 0xD8 # mov %ax, %cs; mov %ds, mov %ax - b[::1] = 0xB4, 0x09 # mov %ah, 0x09 - b[::1] = 0xBA; b[::2] = '&mz/message' # mov %dx, message - b[::1] = 0xCD, 0x21 # int 0x21 - b[::1] = 0xB8, 0xFF, 0x4C, 0xCD, 0x21 # mov %ax, 0x4CFF; int 0x21 + interpret_single('make-pe-mz-stub-structure', b, include = 'pe') message += '$' # Dollar the Terminator # a pointer to the PE signature must appear at the offset 0x003C Index: tran-builtins =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- tran-builtins 17 May 2003 14:16:24 -0000 1.25 +++ tran-builtins 17 May 2003 14:46:34 -0000 1.26 @@ -118,6 +118,11 @@ interpreter.register_names[r] = tok regs_state0(family) +=: int|name + if not name[0] in '&#!': name = '&' + name + value = interpreter.regstack.pop() + interpreter.current.place_symbol(name, value) + align int interpreter.current.align(long(interpreter.regstack.pop())) @@ -131,6 +136,9 @@ interpreter.regstack.reverse() interpreter.toksrc.push(Macro_Cursor(['$push'] * len(interpreter.regstack))) +current-offset + interpreter.regstack.append(Integer_Literal(interpreter.current.memsz())) + drop any interpreter.regstack.pop() @@ -145,7 +153,8 @@ interpreter.regstack.append(Symbol_Literal(before + core + after)) label|name - interpreter.current.place_symbol('&' + name) + if not name[0] in '&#!': name = '&' + name + interpreter.current.place_symbol(name) minor reg interpreter.regstack.append(Integer_Literal(interpreter.regstack.pop()[-1])) Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.104 retrieving revision 1.105 diff -u -d -r1.104 -r1.105 --- tran.py 17 May 2003 14:16:24 -0000 1.104 +++ tran.py 17 May 2003 14:46:34 -0000 1.105 @@ -173,6 +173,10 @@ class Class_Marker (object, Stackable): def __init__ (this, id): this.id = id + def __str__ (this): + return this.id + def __repr__ (this): + return `this.id` def matchers (object): if isinstance(object, Class_Marker): @@ -279,9 +283,9 @@ while not this.meaning.has_key(tok): tok = mg.next() if tok == None: - raise 'stack too empty or meaningless word', root + raise 'stack too empty or meaningless word', (root, ' '.join(map(str, this.regstack))) except StopIteration: - raise 'meaningless word', root + raise 'meaningless word', (root, ' '.join(map(str, this.regstack))) m = this.meaning[tok] if isinstance(m, list): this.toksrc.push(Macro_Cursor(m)) elif isinstance(m, Stackable): this.regstack.append(m) |
From: <di...@us...> - 2003-05-17 14:16:27
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv10809 Modified Files: Makefile.am elf.py tran-builtins tran.py Added Files: elf.tran Log Message: converted the body of make_ELF32_header into the |make-elf32-phentry| tran macro --- NEW FILE: elf.tran --- \\\\ elf.tran - ELF generation routines \ \ Copyleft © 2003 by Andres Soolo (di...@us...) \ This file is licensed under the GNU GPL v2. If you \ don't know what that means, please do read the GPL. \ \\\\ @(#) $Id: elf.tran,v 1.1 2003/05/17 14:16:24 digg Exp $ :[ ] make-elf32-phentry 4 align dup mingle #*/p_type t, dup mingle !* t, \ offset dup mingle &* t, \ p_vaddr dup mingle &* t, \ p_paddr dup mingle #*/filesz t, dup mingle #*/memsz t, dup mingle #*/p_flags t, mingle #*/p_align t, ; \ vim: ft=tran Index: Makefile.am =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/Makefile.am,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- Makefile.am 17 May 2003 13:50:52 -0000 1.19 +++ Makefile.am 17 May 2003 14:16:23 -0000 1.20 @@ -9,7 +9,7 @@ EXTRA_DIST = .cvsignore .pycheckrc struburn.wisp bits.py linkie.py \ coff.py elf.py pe.py \ i8086.tran i80386.tran ia16.tran ia32.tran \ - coff.tran \ + coff.tran elf.tran \ winapi.tran \ hello.tran mswhello.tran \ makehello.py elfdump.py Index: elf.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elf.py,v retrieving revision 1.58 retrieving revision 1.59 diff -u -d -r1.58 -r1.59 --- elf.py 17 May 2003 11:11:30 -0000 1.58 +++ elf.py 17 May 2003 14:16:24 -0000 1.59 @@ -322,6 +322,7 @@ NUM = 11 from linkie import Linkie +from tran import interpret_single def make_ELF32_header (byte_order, reloc = 0): h = Linkie(byte_order) @@ -352,14 +353,8 @@ t.align(4) t |= '!elf/proghdr' for name in names: - t[::4] = '#' + name + '/p_type' - t[::4] = '!' + name # offset - t[::4] = '&' + name # p_vaddr - t[::4] = '&' + name # p_paddr - t[::4] = '#' + name + '/filesz' - t[::4] = '#' + name + '/memsz' - t[::4] = '#' + name + '/p_flags' - t[::4] = '#' + name + '/p_align' + interpret_single(['ref', name, 'make-elf32-phentry'], + t, include = 'elf') t.place_symbol('#elf/phnum', len(names)) return t Index: tran-builtins =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- tran-builtins 17 May 2003 13:50:52 -0000 1.24 +++ tran-builtins 17 May 2003 14:16:24 -0000 1.25 @@ -137,6 +137,13 @@ dup any interpreter.regstack.append(interpreter.regstack[-1]) +mingle sym|tpl + core = str(interpreter.regstack.pop())[1:] + tpl = tpl.split('*', 1) + if len(tpl) <> 2: raise 'not exactly one star', tpl + before, after = tpl + interpreter.regstack.append(Symbol_Literal(before + core + after)) + label|name interpreter.current.place_symbol('&' + name) Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.103 retrieving revision 1.104 diff -u -d -r1.103 -r1.104 --- tran.py 17 May 2003 13:50:52 -0000 1.103 +++ tran.py 17 May 2003 14:16:24 -0000 1.104 @@ -106,7 +106,7 @@ shlex.__init__(this, instream = open(filename, 'r'), infile = filename) this.commenters = '\\' this.quotes = '"' - this.wordchars += '!#$%*+,-./:;<=>?@[]' + this.wordchars += '!#$%&*+,-./:;<=>?@[]' def get_token (this): tok = shlex.get_token(this) if tok == '': tok = None @@ -309,7 +309,7 @@ this.toksrc = None def interpret_single (toksrc, target, include = [], verbose = 0): - if isinstance(toksrc, str): toksrc = [toksrc] + if isinstance(toksrc, str): toksrc = toksrc.split() # FIXME: integers? if isinstance(toksrc, list): toksrc = Macro_Cursor(toksrc) if isinstance(target, str): target = Linkie(target) # byte order @@ -327,7 +327,7 @@ return target def interpret_multi (toksrc, target, include = [], verbose = 0): - if isinstance(toksrc, str): toksrc = [toksrc] + if isinstance(toksrc, str): toksrc = toksrc.split() # FIXME: integers? if isinstance(toksrc, list): toksrc = Macro_Cursor(toksrc) if isinstance(target, str): target = target.split() |
From: <di...@us...> - 2003-05-17 13:51:01
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv556 Modified Files: Makefile.am coff.py tran-builtins tran.py Added Files: coff.tran Log Message: converted the body of make_coff_header into a tran macro --- NEW FILE: coff.tran --- \\\\ coff.tran - COFF generation routines \ \ Copyleft © 2003 by Andres Soolo (di...@us...) \ This file is licensed under the GNU GPL v2. If you \ don't know what that means, please do read the GPL. \ \\\\ @(#) $Id: coff.tran,v 1.1 2003/05/17 13:50:52 digg Exp $ :[ ] make-coff-header 4 align ref #coff/magic w, \ Known magic values: \ 0x0000 unknown \ 0x014C i80386 \ 0x014D i80486 \ 0x014E Pentium \ 0x0162 Mips Mark I (R2000, R3000) \ 0x0163 Mips Mark II (R6000) \ 0x0166 Mips Mark III (R4000) \ 0x0168 R10000 \ 0x0184 Alpha AXP \ 0x01A2 Hitachi SH3 \ 0x01A6 Hitachi SH4 \ 0x01C0 ARM \ 0x01F0 PowerPC LittleEndian \ 0x0200 ia64 \ 0x0266 Mips 16 \ 0x0268 m68k \ 0x0284 Alpha AXP 64-bit \ 0x0366 Mips with FPU \ 0x0466 Mips 16 with FPU ref #coff/nscns w, ref #coff/timdat t, ref !coff/symptr t, ref #coff/nsyms t, ref #coff/opthdr w, ref #coff/flags w, \ Flags for COFF: \ 0x0001 no relocations -- can only be loaded at the preferred address \ 0x0002 executable \ 0x0004 no COFF line number data \ 0x0008 no COFF local symbol entries \ Additional flags for PE: \ 0x0010 aggressively trim working set (?) \ 0x0020 program is aware of addresses larger than 2Gi \ 0x0040 reserved \ 0x0200 debugging information stripped away \ 0x0400 if file on removable media, copy and run from swap (?) \ 0x1000 is a system program (?) \ 0x2000 library \ 0x4000 should only be run on uniprocessor machines ; \ vim: ft=tran Index: Makefile.am =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/Makefile.am,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- Makefile.am 17 May 2003 12:59:13 -0000 1.18 +++ Makefile.am 17 May 2003 13:50:52 -0000 1.19 @@ -9,6 +9,7 @@ EXTRA_DIST = .cvsignore .pycheckrc struburn.wisp bits.py linkie.py \ coff.py elf.py pe.py \ i8086.tran i80386.tran ia16.tran ia32.tran \ + coff.tran \ winapi.tran \ hello.tran mswhello.tran \ makehello.py elfdump.py Index: coff.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/coff.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- coff.py 16 May 2003 16:23:04 -0000 1.2 +++ coff.py 17 May 2003 13:50:52 -0000 1.3 @@ -7,49 +7,10 @@ #### @(#) $Id$ from linkie import Linkie +from tran import interpret_single -def make_coff_header (): - h = Linkie('<') - h.align(4) - h[::2] = '#coff/magic' - # Known magic values: - # 0x0000 unknown - # 0x014C i80386 - # 0x014D i80486 - # 0x014E Pentium - # 0x0162 Mips Mark I (R2000, R3000) - # 0x0163 Mips Mark II (R6000) - # 0x0166 Mips Mark III (R4000) - # 0x0168 R10000 - # 0x0184 Alpha AXP - # 0x01A2 Hitachi SH3 - # 0x01A6 Hitachi SH4 - # 0x01C0 ARM - # 0x01F0 PowerPC LittleEndian - # 0x0200 ia64 - # 0x0266 Mips 16 - # 0x0268 m68k - # 0x0284 Alpha AXP 64-bit - # 0x0366 Mips with FPU - # 0x0466 Mips 16 with FPU - h[::2] = '#coff/nscns' - h[::4] = '#coff/timdat', '!coff/symptr', '#coff/nsyms' - h[::2] = '#coff/opthdr', '#coff/flags' - # Flags for COFF: - # 0x0001 no relocations -- can only be loaded at the preferred address - # 0x0002 executable - # 0x0004 no COFF line number data - # 0x0008 no COFF local symbol entries - # Additional flags for PE: - # 0x0010 aggressively trim working set (?) - # 0x0020 program is aware of addresses larger than 2Gi - # 0x0040 reserved - # 0x0200 debugging information stripped away - # 0x0400 if file on removable media, copy and run from swap (?) - # 0x1000 is a system program (?) - # 0x2000 library - # 0x4000 should only be run on uniprocessor machines - return h +def make_coff_header (target = '<'): + return interpret_single('make-coff-header', target, include = 'coff') def make_coff_section_header (byte_order, name): h = Linkie(byte_order) Index: tran-builtins =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- tran-builtins 17 May 2003 12:50:49 -0000 1.23 +++ tran-builtins 17 May 2003 13:50:52 -0000 1.24 @@ -147,7 +147,8 @@ interpreter.toksrc.push(Lexer(str(name) + '.tran')) ref|name - interpreter.regstack.append(Symbol_Literal('&' + name)) + if not name[0] in '&#!': name = '&' + name + interpreter.regstack.append(Symbol_Literal(name)) reserve int interpreter.current.skip(interpreter.regstack.pop()) Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.102 retrieving revision 1.103 diff -u -d -r1.102 -r1.103 --- tran.py 17 May 2003 13:33:49 -0000 1.102 +++ tran.py 17 May 2003 13:50:52 -0000 1.103 @@ -298,6 +298,7 @@ else: raise 'Unknown meaning format for', tok else: raise 'bad token', tok def run (this, toksrc, verbose = 0): + if isinstance(toksrc, str): toksrc = Lexer(toksrc) this.toksrc = Preprocessor(toksrc) tok = this.toksrc.get_token() while tok <> None: @@ -308,13 +309,15 @@ this.toksrc = None def interpret_single (toksrc, target, include = [], verbose = 0): + if isinstance(toksrc, str): toksrc = [toksrc] if isinstance(toksrc, list): toksrc = Macro_Cursor(toksrc) - if isinstance(toksrc, str): toksrc = Lexer(toksrc) if isinstance(target, str): target = Linkie(target) # byte order elif isinstance(target, Linkie): pass else: raise 'neither a linkie nor a byte order specifier', target + if isinstance(include, str): include = include.split() + interp = Interpreter(target) for i in include: interp.run(i + '.tran') interp.run(toksrc, verbose = verbose) @@ -324,10 +327,13 @@ return target def interpret_multi (toksrc, target, include = [], verbose = 0): + if isinstance(toksrc, str): toksrc = [toksrc] if isinstance(toksrc, list): toksrc = Macro_Cursor(toksrc) - if isinstance(toksrc, str): toksrc = Lexer(toksrc) if isinstance(target, str): target = target.split() + + if isinstance(include, str): include = include.split() + byte_order = target[0] sections = target[1:] interp = Interpreter(byte_order = byte_order, output = sections) |
From: <di...@us...> - 2003-05-17 13:33:52
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv26651 Modified Files: tran.py Log Message: split interpret into interpret_single and interpret_multi Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.101 retrieving revision 1.102 diff -u -d -r1.101 -r1.102 --- tran.py 17 May 2003 13:26:32 -0000 1.101 +++ tran.py 17 May 2003 13:33:49 -0000 1.102 @@ -307,34 +307,36 @@ tok = this.toksrc.get_token() this.toksrc = None -def interpret (toksrc, target, include = [], verbose = 0): +def interpret_single (toksrc, target, include = [], verbose = 0): if isinstance(toksrc, list): toksrc = Macro_Cursor(toksrc) if isinstance(toksrc, str): toksrc = Lexer(toksrc) - if isinstance(target, str): target = target.split() + if isinstance(target, str): target = Linkie(target) # byte order + elif isinstance(target, Linkie): pass + else: raise 'neither a linkie nor a byte order specifier', target - if isinstance(target, Linkie): - interp = Interpreter(target) - for i in include: interp.run(i) - interp.run(toksrc, verbose = verbose) - if interp.regstack: - raise 'regstack not empty after finishing interpretation', \ - interp.regstack - return target - elif isinstance(target, list): - byte_order = target[0] - sections = target[1:] - if sections: - interp = Interpreter(byte_order = byte_order, output = sections) - for i in include: interp.run(i) - interp.run(toksrc, verbose = verbose) - if interp.regstack: - raise 'regstack not empty after finishing interpretation', \ - interp.regstack - return map((lambda n: interp.sections[n]), target[1:]) - else: - return interpret(toksrc, Linkie(byte_order), - include = include, verbose = verbose) + interp = Interpreter(target) + for i in include: interp.run(i + '.tran') + interp.run(toksrc, verbose = verbose) + if interp.regstack: + raise 'regstack not empty after finishing interpretation', \ + interp.regstack + return target + +def interpret_multi (toksrc, target, include = [], verbose = 0): + if isinstance(toksrc, list): toksrc = Macro_Cursor(toksrc) + if isinstance(toksrc, str): toksrc = Lexer(toksrc) + + if isinstance(target, str): target = target.split() + byte_order = target[0] + sections = target[1:] + interp = Interpreter(byte_order = byte_order, output = sections) + for i in include: interp.run(i + '.tran') + interp.run(toksrc, verbose = verbose) + if interp.regstack: + raise 'regstack not empty after finishing interpretation', \ + interp.regstack + return map((lambda n: interp.sections[n]), target[1:]) def main (): from getopt import getopt @@ -343,8 +345,6 @@ import string import sys - interpreter = Interpreter('<', ['.text', '.data', '.bss']) - default_output_names = {'elf': 'a.out', 'pe': 'untitled.exe'} verbose = 0 format = 'elf' @@ -360,8 +360,8 @@ if output_name == None: output_name = default_output_names[format] if len(args) != 1: raise 'Invalid argument count -- must be 1', args - text, data, bss = interpret(Lexer(args[0]), '< .text .data .bss', - verbose = verbose) + text, data, bss = interpret_multi(Lexer(args[0]), '< .text .data .bss', + verbose = verbose) text.dump(title = 'TEXT') data.dump(title = 'DATA') bss.dump(title = 'BSS') |
From: <di...@us...> - 2003-05-17 13:26:34
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv24001 Modified Files: tran.py Log Message: added the include argument to interpret Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.100 retrieving revision 1.101 diff -u -d -r1.100 -r1.101 --- tran.py 17 May 2003 13:20:59 -0000 1.100 +++ tran.py 17 May 2003 13:26:32 -0000 1.101 @@ -307,7 +307,7 @@ tok = this.toksrc.get_token() this.toksrc = None -def interpret (toksrc, target, verbose = 0): +def interpret (toksrc, target, include = [], verbose = 0): if isinstance(toksrc, list): toksrc = Macro_Cursor(toksrc) if isinstance(toksrc, str): toksrc = Lexer(toksrc) @@ -315,6 +315,7 @@ if isinstance(target, Linkie): interp = Interpreter(target) + for i in include: interp.run(i) interp.run(toksrc, verbose = verbose) if interp.regstack: raise 'regstack not empty after finishing interpretation', \ @@ -325,13 +326,15 @@ sections = target[1:] if sections: interp = Interpreter(byte_order = byte_order, output = sections) + for i in include: interp.run(i) interp.run(toksrc, verbose = verbose) if interp.regstack: raise 'regstack not empty after finishing interpretation', \ interp.regstack return map((lambda n: interp.sections[n]), target[1:]) else: - return interpret(toksrc, Linkie(byte_order)) + return interpret(toksrc, Linkie(byte_order), + include = include, verbose = verbose) def main (): from getopt import getopt |
From: <di...@us...> - 2003-05-17 13:21:03
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv21777 Modified Files: tran.py Log Message: introduced the interpret procedure Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.99 retrieving revision 1.100 diff -u -d -r1.99 -r1.100 --- tran.py 17 May 2003 12:59:14 -0000 1.99 +++ tran.py 17 May 2003 13:20:59 -0000 1.100 @@ -229,17 +229,22 @@ interpreter.current = interpreter.sections[name] return switcher - def __init__ (this, byte_order, sections = ['.text']): - this.sections = {} + def __init__ (this, byte_order, output = ['.text']): this.meaning = Interpreter.universal_meaning.copy() - for s in sections: - this.sections[s] = Linkie(byte_order) - this.meaning[s] = 'builtin', this.make_section_switcher(s), 0 + # if first argument is a linkie, all output goes to that linkie + if isinstance(byte_order, Linkie): + this.sections = None + this.current = byte_order + else: + this.sections = {} + for s in output: + this.sections[s] = Linkie(byte_order) + this.meaning[s] = 'builtin', this.make_section_switcher(s), 0 + this.current = this.sections[output[0]] this.register_names = {} reg = Register([], names = this.register_names) this.meaning['reg'] = reg this.register_names[reg] = 'reg' - this.current = this.sections[sections[0]] this.recordee = None this.regpaths = [reg.child()] # for generating new registers this.hanging = {} @@ -302,6 +307,32 @@ tok = this.toksrc.get_token() this.toksrc = None +def interpret (toksrc, target, verbose = 0): + if isinstance(toksrc, list): toksrc = Macro_Cursor(toksrc) + if isinstance(toksrc, str): toksrc = Lexer(toksrc) + + if isinstance(target, str): target = target.split() + + if isinstance(target, Linkie): + interp = Interpreter(target) + interp.run(toksrc, verbose = verbose) + if interp.regstack: + raise 'regstack not empty after finishing interpretation', \ + interp.regstack + return target + elif isinstance(target, list): + byte_order = target[0] + sections = target[1:] + if sections: + interp = Interpreter(byte_order = byte_order, output = sections) + interp.run(toksrc, verbose = verbose) + if interp.regstack: + raise 'regstack not empty after finishing interpretation', \ + interp.regstack + return map((lambda n: interp.sections[n]), target[1:]) + else: + return interpret(toksrc, Linkie(byte_order)) + def main (): from getopt import getopt import elf @@ -315,40 +346,23 @@ verbose = 0 format = 'elf' opts, args = getopt(sys.argv[1:], 'vo:b:f:', - ['verbose', 'output=', 'base=', 'format=', 'list-words']) + ['verbose', 'output=', 'base=', 'format=']) output_name = None - list_words = 0 base = None for opt, arg in opts: if opt in ('-v', '--verbose'): verbose = 1 if opt in ('-o', '--output'): output_name = arg if opt in ('-b', '--base'): base = string.atol(arg, 16) if opt in ('-f', '--format'): format = arg - if opt == '--list-words': list_words = 1 if output_name == None: output_name = default_output_names[format] - if list_words: - wd = {} - for w in interpreter.meaning.keys(): - s = w.find(' ') - if s != -1: w = w[:s] - wd[w] = 1 - w = wd.keys() - w.sort() - print 'Internally known words:' - print ' ', ' '.join(w) if len(args) != 1: raise 'Invalid argument count -- must be 1', args - interpreter.run(Lexer(args[0]), verbose = verbose) - interpreter.sections['.text'].dump(title = 'TEXT') - interpreter.sections['.data'].dump(title = 'DATA') - interpreter.sections['.bss'].dump(title = 'BSS') - if interpreter.regstack: - raise 'Regstack not empty after parsing ended', interpreter.regstack - argum = { - 'text': interpreter.sections['.text'], - 'data': interpreter.sections['.data'], - 'bss': interpreter.sections['.bss'], - } + text, data, bss = interpret(Lexer(args[0]), '< .text .data .bss', + verbose = verbose) + text.dump(title = 'TEXT') + data.dump(title = 'DATA') + bss.dump(title = 'BSS') + argum = {'text': text, 'data': data, 'bss': bss} if base <> None: argum['base_address'] = base if format == 'elf': argum['flags'] = 's' |
From: <di...@us...> - 2003-05-17 12:59:18
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv14343 Modified Files: Makefile.am tran.py Removed Files: interpreter.py Log Message: folded interpreter.py back into tran.py Index: Makefile.am =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/Makefile.am,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- Makefile.am 17 May 2003 11:35:28 -0000 1.17 +++ Makefile.am 17 May 2003 12:59:13 -0000 1.18 @@ -8,7 +8,6 @@ EXTRA_DIST = .cvsignore .pycheckrc struburn.wisp bits.py linkie.py \ coff.py elf.py pe.py \ - interpreter.py \ i8086.tran i80386.tran ia16.tran ia32.tran \ winapi.tran \ hello.tran mswhello.tran \ Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.98 retrieving revision 1.99 diff -u -d -r1.98 -r1.99 --- tran.py 17 May 2003 12:52:34 -0000 1.98 +++ tran.py 17 May 2003 12:59:14 -0000 1.99 @@ -8,17 +8,307 @@ # #### @(#) $Id$ -from __future__ import generators -from __future__ import nested_scopes +from __future__ import generators, nested_scopes -from getopt import getopt -from interpreter import Lexer, Interpreter, Preprocessor -import elf -import pe +from linkie import Linkie +from shlex import shlex import string -import sys + +def abstract (this, *arg, **narg): + raise 'abstract method was called', (this, arg, narg) + +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_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) + 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) + def get_scalar (this): + return long(this) + +class Symbol_Literal (str, Stackable, Summable): + def __new__ (cls, s): + return str.__new__(cls, s) + def __repr__ (this): + return 'Symbol_Literal(%r)' % str(this) + 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 + def __repr__ (this): + return 'Unique(%r)' % this.name + def __str__ (this): + return this.name +class Unique_Token (Unique, Token): pass + +Semicolon = Unique_Token(';') + +class Token_Source (object): + """After creation, a Token_Source instance will deliver one token +each time its get_token method is called, until the token stream ends. +After that, it will return None.""" + get_token = abstract + +class Lexer (shlex, Token_Source): + def __init__ (this, filename): + shlex.__init__(this, instream = open(filename, 'r'), infile = filename) + this.commenters = '\\' + this.quotes = '"' + this.wordchars += '!#$%*+,-./:;<=>?@[]' + def get_token (this): + tok = shlex.get_token(this) + if tok == '': tok = None + elif tok[:2] == '#o': tok = Integer_Literal(string.atol(tok[2:], 8)) + elif tok[:2] == '#x': tok = Integer_Literal(string.atol(tok[2:], 16)) + elif tok[:2] == '#/' and len(tok) == 3: + tok = Integer_Literal(ord(tok[2])) + else: + try: tok = Integer_Literal(string.atol(tok, 10)) + except: pass + if tok == ';': return Semicolon + else: return tok + def push_file (this, filename): + this.push_source(open(filename, 'r'), filename) + +class Macro_Cursor (Token_Source): + def __init__ (this, sequence): + this.sequence = sequence + this.current = 0 + def get_token (this): + if this.current >= len(this.sequence): return None + datum = this.sequence[this.current] + this.current += 1 + return datum + +class Preprocessor (Token_Source): + __slots__ = ['tss'] + def __init__ (this, toksrc): + object.__init__(this) + this.tss = [toksrc] + def push (this, toksrc): + this.tss.append(toksrc) + def get_token (this): + tok = None + while this.tss and tok == None: + tok = this.tss[-1].get_token() + if tok == None: this.tss.pop() + return tok + +class Register (tuple, Stackable): + def __new__ (cls, items, names = None): + this = tuple.__new__(cls, items) + this.names = names + return this + def parent (this): + if len(this): return Register(this[:-1], this.names) + else: return None + def next (this): + l = list(this) + l[-1] += 1 + return Register(l, this.names) + def child (this, index = 0): + return Register(this + (index,), this.names) + def __repr__ (this): + return 'Register' + tuple.__repr__(this) + def __str__ (this): + if this.names != None and this.names.has_key(this): + return this.names[this] + else: + return '%' + '.'.join(map(str, this)) + def contained_registers (this): + return this, + +class Class_Marker (object, Stackable): + def __init__ (this, id): + this.id = id + +def matchers (object): + if isinstance(object, Class_Marker): + yield object.id + elif isinstance(object, Integer_Literal): + yield 'int' + yield 'lit' + yield 'const' + elif isinstance(object, Symbol_Literal): + yield 'sym' + yield 'lit' + yield 'const' + elif isinstance(object, Sum): + yield 'sum' + yield 'const' + elif isinstance(object, Register): + while object <> None: + yield str(object) # involves appropriate lookup + object = object.parent() + yield 'any' + +MA_PREFIX = 1 + +def make_universal_meaning (fn): + um = { + '...': Unique('...'), + 'tetras': ['dup', '+', 'dup', '+'], # FIXME + } + for m in 'any const int lit sum sym'.split(' '): um[m] = Class_Marker(m) + + # load builtins + bf = open(fn, 'r') + builtins = bf.read() + bf.close() + + for b in builtins.split('\n\n'): + if b[0] != '#': + name, code = b.split('\n', 1) + np = (name + '|').split('|') + name = np[0] + pa = np[1] + exec 'def _p (interpreter, %s):\n%s\n' % (pa, code) + flags = 0 + if pa: flags |= MA_PREFIX + um[name] = 'builtin', _p, flags + return um + +class Interpreter (object): + __slots__ = 'sections current recordee regpaths hanging regstack state meaning register_names toksrc'.split() + universal_meaning = make_universal_meaning('tran-builtins') + + def make_section_switcher (this, name): + def switcher (interpreter): + interpreter.current = interpreter.sections[name] + return switcher + + def __init__ (this, byte_order, sections = ['.text']): + this.sections = {} + this.meaning = Interpreter.universal_meaning.copy() + for s in sections: + this.sections[s] = Linkie(byte_order) + this.meaning[s] = 'builtin', this.make_section_switcher(s), 0 + this.register_names = {} + reg = Register([], names = this.register_names) + this.meaning['reg'] = reg + this.register_names[reg] = 'reg' + this.current = this.sections[sections[0]] + this.recordee = None + this.regpaths = [reg.child()] # for generating new registers + this.hanging = {} + this.regstack = [] + this.state = this.outer_state + this.toksrc = None # only used during interpretation + def match_generator (this, root): + yield root + if len(this.regstack) < 1: yield None # want more registers + m = matchers(this.regstack[-1]) + try: + while 1: + yield root + ' ' + m.next() + except StopIteration: pass + if len(this.regstack) < 2: yield None + m1 = matchers(this.regstack[-2]) + try: + while 1: + n1 = m1.next() + m2 = matchers(this.regstack[-1]) + try: + while 1: yield root + ' ' + n1 + ' ' + m2.next() + except StopIteration: pass + except StopIteration: pass + def outer_state (this, tok): + if isinstance(tok, Integer_Literal): + this.regstack.append(tok) + elif isinstance(tok, str): + root = tok + mg = this.match_generator(root) + try: + while not this.meaning.has_key(tok): + tok = mg.next() + if tok == None: + raise 'stack too empty or meaningless word', root + except StopIteration: + raise 'meaningless word', root + m = this.meaning[tok] + if isinstance(m, list): this.toksrc.push(Macro_Cursor(m)) + elif isinstance(m, Stackable): this.regstack.append(m) + elif isinstance(m, tuple): + mtype = m[0] + if mtype == 'builtin': + if m[2] & MA_PREFIX: + tok = this.toksrc.get_token() + if not isinstance(tok, str): raise 'word expected', tok + m[1](this, tok) + else: + m[1](this) + else: raise 'Unknown meaning type in', `this.meaning[tok]` + else: raise 'Unknown meaning format for', tok + else: raise 'bad token', tok + def run (this, toksrc, verbose = 0): + this.toksrc = Preprocessor(toksrc) + tok = this.toksrc.get_token() + while tok <> None: + if verbose: + print '(%s) %s' % (' '.join(map(str, this.regstack)), tok) + this.state(tok) + tok = this.toksrc.get_token() + this.toksrc = None def main (): + from getopt import getopt + import elf + import pe + import string + import sys + interpreter = Interpreter('<', ['.text', '.data', '.bss']) default_output_names = {'elf': 'a.out', 'pe': 'untitled.exe'} @@ -69,6 +359,6 @@ binary.get_file().tofile(f) f.close() -main() +if __name__ == '__main__': main() # vim: nofen --- interpreter.py DELETED --- |
From: <di...@us...> - 2003-05-17 12:52:37
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv11889 Modified Files: tran.py Log Message: cleaner main Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.97 retrieving revision 1.98 diff -u -d -r1.97 -r1.98 --- tran.py 17 May 2003 12:50:49 -0000 1.97 +++ tran.py 17 May 2003 12:52:34 -0000 1.98 @@ -18,14 +18,12 @@ import string import sys -interpreter = Interpreter('<', ['.text', '.data', '.bss']) - -default_output_names = {'elf': 'a.out', 'pe': 'untitled.exe'} -verbose = 0 -format = 'elf' - def main (): - global verbose, format + interpreter = Interpreter('<', ['.text', '.data', '.bss']) + + default_output_names = {'elf': 'a.out', 'pe': 'untitled.exe'} + verbose = 0 + format = 'elf' opts, args = getopt(sys.argv[1:], 'vo:b:f:', ['verbose', 'output=', 'base=', 'format=', 'list-words']) output_name = None |
From: <di...@us...> - 2003-05-17 12:50:52
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv11083 Modified Files: interpreter.py tran-builtins tran.py Log Message: made interpreter.py importable Index: interpreter.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/interpreter.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- interpreter.py 17 May 2003 12:29:16 -0000 1.7 +++ interpreter.py 17 May 2003 12:50:49 -0000 1.8 @@ -6,7 +6,14 @@ # #### @(#) $Id$ -# Not yet importable! +from __future__ import generators, nested_scopes + +from linkie import Linkie +from shlex import shlex +import string + +def abstract (this, *arg, **narg): + raise 'abstract method was called', (this, arg, narg) def simplest_summable (scalar, symbols, registers): if len(symbols) == len(registers) == 0: @@ -123,11 +130,11 @@ this.current += 1 return datum -class Preprocessor (Lexer): +class Preprocessor (Token_Source): __slots__ = ['tss'] - def __init__ (this, filename): - Lexer.__init__(this, filename) - this.tss = [] + def __init__ (this, toksrc): + object.__init__(this) + this.tss = [toksrc] def push (this, toksrc): this.tss.append(toksrc) def get_token (this): @@ -135,8 +142,7 @@ while this.tss and tok == None: tok = this.tss[-1].get_token() if tok == None: this.tss.pop() - if tok <> None: return tok - else: return Lexer.get_token(this) + return tok class Register (tuple, Stackable): def __new__ (cls, items, names = None): @@ -213,7 +219,7 @@ return um class Interpreter (object): - __slots__ = 'sections current recordee regpaths hanging regstack state meaning register_names'.split() + __slots__ = 'sections current recordee regpaths hanging regstack state meaning register_names toksrc'.split() universal_meaning = make_universal_meaning('tran-builtins') def make_section_switcher (this, name): @@ -237,6 +243,7 @@ this.hanging = {} this.regstack = [] this.state = this.outer_state + this.toksrc = None # only used during interpretation def match_generator (this, root): yield root if len(this.regstack) < 1: yield None # want more registers @@ -269,13 +276,13 @@ except StopIteration: raise 'meaningless word', root m = this.meaning[tok] - if isinstance(m, list): prep.push(Macro_Cursor(m)) + if isinstance(m, list): this.toksrc.push(Macro_Cursor(m)) elif isinstance(m, Stackable): this.regstack.append(m) elif isinstance(m, tuple): mtype = m[0] if mtype == 'builtin': if m[2] & MA_PREFIX: - tok = prep.get_token() + tok = this.toksrc.get_token() if not isinstance(tok, str): raise 'word expected', tok m[1](this, tok) else: @@ -283,4 +290,12 @@ else: raise 'Unknown meaning type in', `this.meaning[tok]` else: raise 'Unknown meaning format for', tok else: raise 'bad token', tok - + def run (this, toksrc, verbose = 0): + this.toksrc = Preprocessor(toksrc) + tok = this.toksrc.get_token() + while tok <> None: + if verbose: + print '(%s) %s' % (' '.join(map(str, this.regstack)), tok) + this.state(tok) + tok = this.toksrc.get_token() + this.toksrc = None Index: tran-builtins =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- tran-builtins 17 May 2003 12:12:53 -0000 1.22 +++ tran-builtins 17 May 2003 12:50:49 -0000 1.23 @@ -129,7 +129,7 @@ commit interpreter.regstack.reverse() - prep.push(Macro_Cursor(['$push'] * len(interpreter.regstack))) + interpreter.toksrc.push(Macro_Cursor(['$push'] * len(interpreter.regstack))) drop any interpreter.regstack.pop() @@ -144,7 +144,7 @@ interpreter.regstack.append(Integer_Literal(interpreter.regstack.pop()[-1])) include|name - prep.push_file(str(name) + '.tran') + interpreter.toksrc.push(Lexer(str(name) + '.tran')) ref|name interpreter.regstack.append(Symbol_Literal('&' + name)) Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.96 retrieving revision 1.97 diff -u -d -r1.96 -r1.97 --- tran.py 17 May 2003 12:12:53 -0000 1.96 +++ tran.py 17 May 2003 12:50:49 -0000 1.97 @@ -12,18 +12,12 @@ from __future__ import nested_scopes from getopt import getopt -from linkie import Linkie -from shlex import shlex +from interpreter import Lexer, Interpreter, Preprocessor import elf import pe import string import sys -def abstract (this, *arg, **narg): - raise 'abstract method was called', this - -exec open('interpreter.py') - interpreter = Interpreter('<', ['.text', '.data', '.bss']) default_output_names = {'elf': 'a.out', 'pe': 'untitled.exe'} @@ -31,7 +25,7 @@ format = 'elf' def main (): - global prep, verbose, format + global verbose, format opts, args = getopt(sys.argv[1:], 'vo:b:f:', ['verbose', 'output=', 'base=', 'format=', 'list-words']) output_name = None @@ -56,12 +50,7 @@ print ' ', ' '.join(w) if len(args) != 1: raise 'Invalid argument count -- must be 1', args - prep = Preprocessor(args[0]) - tok = prep.get_token() - while tok <> None: - if verbose: print '(%s) %s' % (' '.join(map(str, interpreter.regstack)), tok) - interpreter.state(tok) - tok = prep.get_token() + interpreter.run(Lexer(args[0]), verbose = verbose) interpreter.sections['.text'].dump(title = 'TEXT') interpreter.sections['.data'].dump(title = 'DATA') interpreter.sections['.bss'].dump(title = 'BSS') |
From: <di...@us...> - 2003-05-17 12:29:20
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv3666 Modified Files: interpreter.py Log Message: converted match_generator into an Interpreter method Index: interpreter.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/interpreter.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- interpreter.py 17 May 2003 12:25:39 -0000 1.6 +++ interpreter.py 17 May 2003 12:29:16 -0000 1.7 @@ -186,25 +186,6 @@ object = object.parent() yield 'any' -def match_generator (root): - yield root - if len(interpreter.regstack) < 1: yield None # want more registers - m = matchers(interpreter.regstack[-1]) - try: - while 1: - yield root + ' ' + m.next() - except StopIteration: pass - if len(interpreter.regstack) < 2: yield None - m1 = matchers(interpreter.regstack[-2]) - try: - while 1: - n1 = m1.next() - m2 = matchers(interpreter.regstack[-1]) - try: - while 1: yield root + ' ' + n1 + ' ' + m2.next() - except StopIteration: pass - except StopIteration: pass - MA_PREFIX = 1 def make_universal_meaning (fn): @@ -256,12 +237,30 @@ this.hanging = {} this.regstack = [] this.state = this.outer_state + def match_generator (this, root): + yield root + if len(this.regstack) < 1: yield None # want more registers + m = matchers(this.regstack[-1]) + try: + while 1: + yield root + ' ' + m.next() + except StopIteration: pass + if len(this.regstack) < 2: yield None + m1 = matchers(this.regstack[-2]) + try: + while 1: + n1 = m1.next() + m2 = matchers(this.regstack[-1]) + try: + while 1: yield root + ' ' + n1 + ' ' + m2.next() + except StopIteration: pass + except StopIteration: pass def outer_state (this, tok): if isinstance(tok, Integer_Literal): this.regstack.append(tok) elif isinstance(tok, str): root = tok - mg = match_generator(root) + mg = this.match_generator(root) try: while not this.meaning.has_key(tok): tok = mg.next() |
From: <di...@us...> - 2003-05-17 12:25:42
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv2369 Modified Files: interpreter.py Log Message: added the interpreter argument to builtins Index: interpreter.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/interpreter.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- interpreter.py 17 May 2003 12:17:09 -0000 1.5 +++ interpreter.py 17 May 2003 12:25:39 -0000 1.6 @@ -225,7 +225,7 @@ np = (name + '|').split('|') name = np[0] pa = np[1] - exec 'def _p (%s):\n%s\n' % (pa, code) + exec 'def _p (interpreter, %s):\n%s\n' % (pa, code) flags = 0 if pa: flags |= MA_PREFIX um[name] = 'builtin', _p, flags @@ -236,7 +236,8 @@ universal_meaning = make_universal_meaning('tran-builtins') def make_section_switcher (this, name): - def switcher (): this.current = this.sections[name] + def switcher (interpreter): + interpreter.current = interpreter.sections[name] return switcher def __init__ (this, byte_order, sections = ['.text']): @@ -277,9 +278,9 @@ if m[2] & MA_PREFIX: tok = prep.get_token() if not isinstance(tok, str): raise 'word expected', tok - m[1](tok) + m[1](this, tok) else: - m[1]() + m[1](this) else: raise 'Unknown meaning type in', `this.meaning[tok]` else: raise 'Unknown meaning format for', tok else: raise 'bad token', tok |
From: <di...@us...> - 2003-05-17 12:17:12
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv32010 Modified Files: interpreter.py Log Message: deglobalized interpreter's methods Index: interpreter.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/interpreter.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- interpreter.py 17 May 2003 12:12:53 -0000 1.4 +++ interpreter.py 17 May 2003 12:17:09 -0000 1.5 @@ -262,13 +262,13 @@ root = tok mg = match_generator(root) try: - while not interpreter.meaning.has_key(tok): + while not this.meaning.has_key(tok): tok = mg.next() if tok == None: raise 'stack too empty or meaningless word', root except StopIteration: raise 'meaningless word', root - m = interpreter.meaning[tok] + m = this.meaning[tok] if isinstance(m, list): prep.push(Macro_Cursor(m)) elif isinstance(m, Stackable): this.regstack.append(m) elif isinstance(m, tuple): @@ -280,7 +280,7 @@ m[1](tok) else: m[1]() - else: raise 'Unknown meaning type in', `interpreter.meaning[tok]` + else: raise 'Unknown meaning type in', `this.meaning[tok]` else: raise 'Unknown meaning format for', tok else: raise 'bad token', tok |
From: <di...@us...> - 2003-05-17 12:12:56
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv30078 Modified Files: interpreter.py tran-builtins tran.py Log Message: deglobalized register handling Index: interpreter.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/interpreter.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- interpreter.py 17 May 2003 12:01:58 -0000 1.3 +++ interpreter.py 17 May 2003 12:12:53 -0000 1.4 @@ -182,7 +182,7 @@ yield 'const' elif isinstance(object, Register): while object <> None: - yield Registers[object] + yield str(object) # involves appropriate lookup object = object.parent() yield 'any' @@ -205,13 +205,10 @@ except StopIteration: pass except StopIteration: pass -Generic_Register = Register([]) - MA_PREFIX = 1 def make_universal_meaning (fn): um = { - 'reg': Generic_Register, '...': Unique('...'), 'tetras': ['dup', '+', 'dup', '+'], # FIXME } @@ -235,7 +232,7 @@ return um class Interpreter (object): - __slots__ = 'sections current recordee regpaths hanging regstack state meaning'.split() + __slots__ = 'sections current recordee regpaths hanging regstack state meaning register_names'.split() universal_meaning = make_universal_meaning('tran-builtins') def make_section_switcher (this, name): @@ -248,9 +245,13 @@ for s in sections: this.sections[s] = Linkie(byte_order) this.meaning[s] = 'builtin', this.make_section_switcher(s), 0 + this.register_names = {} + reg = Register([], names = this.register_names) + this.meaning['reg'] = reg + this.register_names[reg] = 'reg' this.current = this.sections[sections[0]] this.recordee = None - this.regpaths = [Register([0])] # for generating new registers + this.regpaths = [reg.child()] # for generating new registers this.hanging = {} this.regstack = [] this.state = this.outer_state Index: tran-builtins =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran-builtins,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- tran-builtins 17 May 2003 11:05:34 -0000 1.21 +++ tran-builtins 17 May 2003 12:12:53 -0000 1.22 @@ -95,7 +95,7 @@ interpreter.regpaths[-1] = f.next() interpreter.regpaths.append(f.child()) interpreter.meaning[family] = f - Registers[f] = family + interpreter.register_names[f] = family interpreter.state = regs_state def regs_state (tok): if tok == Semicolon: @@ -115,7 +115,7 @@ else: interpreter.regpaths[-1] = r.next() interpreter.meaning[tok] = r - Registers[r] = tok + interpreter.register_names[r] = tok regs_state0(family) align int Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.95 retrieving revision 1.96 diff -u -d -r1.95 -r1.96 --- tran.py 17 May 2003 11:35:29 -0000 1.95 +++ tran.py 17 May 2003 12:12:53 -0000 1.96 @@ -26,8 +26,6 @@ interpreter = Interpreter('<', ['.text', '.data', '.bss']) -Registers = {Generic_Register: 'reg'} # for reverse translation - default_output_names = {'elf': 'a.out', 'pe': 'untitled.exe'} verbose = 0 format = 'elf' |