wisp-cvs Mailing List for Wisp interpreter (Page 13)
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-04-26 17:43:08
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv30222 Modified Files: linkie.py Log Message: minor cleanup Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- linkie.py 26 Apr 2003 17:42:08 -0000 1.38 +++ linkie.py 26 Apr 2003 17:43:04 -0000 1.39 @@ -43,7 +43,7 @@ delta += this._locals[a] else: # forwards this._unresolved_locals.append((a, s, len(this._contents))) - elif type(a) == StringType: # global reference + elif isinstance(a, str): # global reference if not a[0] in '#&!%': raise 'unprefixed symbol being referred to', a this.notify_linker(this.memsz(), s, a) |
From: <di...@us...> - 2003-04-26 17:42:11
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv29911 Modified Files: linkie.py Log Message: minor cleanup Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- linkie.py 26 Apr 2003 17:40:59 -0000 1.37 +++ linkie.py 26 Apr 2003 17:42:08 -0000 1.38 @@ -109,7 +109,8 @@ starts in '&' or '%'. Does NOT check uniqueness. None signifies the current offset.""" - if type(symbol) <> StringType: raise 'Not a string', symbol + if not isinstance(symbol, str): raise 'Not a string', symbol + symbol = str(symbol) if not symbol[0] in '#&!%': raise 'unprefixed symbol being placed', symbol if value == None: value = len(this._contents) + this._skipped |
From: <di...@us...> - 2003-04-26 17:41:03
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv29427 Modified Files: linkie.py Log Message: minor cleanup Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- linkie.py 26 Apr 2003 17:36:17 -0000 1.36 +++ linkie.py 26 Apr 2003 17:40:59 -0000 1.37 @@ -7,7 +7,7 @@ #### @(#) $Id$ from bits import Bits -from types import IntType, StringType +from types import StringType from array import array class Linkie (Bits): @@ -38,7 +38,7 @@ s = -size; relative -= 1 if type(a) != StringType: raise 'relative non-symbol?', a else: s = size - if type(a) == IntType: # local reference + if isinstance(a, int): # local reference if this._locals[a] <> None: # backwards delta += this._locals[a] else: # forwards |
From: <di...@us...> - 2003-04-26 17:36:21
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv27812 Modified Files: linkie.py Makefile.am Added Files: bits.py Log Message: moved the Bits class from linkie.py to bits.py --- NEW FILE: bits.py --- #### bits.py - a Python module for low-level bit holders # # 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: bits.py,v 1.1 2003/04/26 17:36:17 digg Exp $ from array import array from struct import pack, unpack class Bits (object): __slots__ = ['_contents', '_skipped'] def __init__ (this, byte_order = None): this._contents = array('c') if byte_order == None: pass elif byte_order == '<': this.emit_wyde = this.emit_lewyde this.emit_tetra = this.emit_letetra this.add_wyde = this.add_lewyde this.add_tetra = this.add_letetra elif byte_order == '>': this.emit_wyde = this.emit_bewyde this.emit_tetra = this.emit_betetra this.add_wyde = this.add_bewyde this.add_tetra = this.add_betetra else: raise "Unknown byte order", byte_order def emit_byte (this, b): if this._skipped <> 0: raise "Events out of order", this this._contents.append(chr(b & 0xff)) def emit_bewyde (this, w): if this._skipped <> 0: raise "Events out of order", this this._contents.fromstring(pack('>H', w)) # FIXME? def emit_lewyde (this, w): if this._skipped <> 0: raise "Events out of order", this this._contents.fromstring(pack('<H', w)) # FIXME? def emit_betetra (this, t): if this._skipped <> 0: raise "Events out of order", this this._contents.fromstring(pack('>L', t)) # FIXME? def emit_letetra (this, t): if this._skipped <> 0: raise "Events out of order", this this._contents.fromstring(pack('<L', t)) # FIXME? def emit_string (this, s): if this._skipped <> 0: raise "Events out of order", this this._contents.fromstring(s) def from_array (this, a): this._contents.extend(a) def add_byte (this, ofs, value): this._contents[ofs] = chr((ord(this._contents[ofs]) + value) % 0x100) def _add (this, ofs, value, size, tpl): datum, = unpack(tpl, this._contents[ofs : ofs + size]) datum += value datum %= 1L << (size << 3) this._contents[ofs : ofs + size] = array('c', pack(tpl, datum)) def add_lewyde (this, ofs, value): this._add(ofs, value, 2, '<H') def add_bewyde (this, ofs, value): this._add(ofs, value, 2, '>H') def add_letetra (this, ofs, value): this._add(ofs, value, 4, '<L') def add_betetra (this, ofs, value): this._add(ofs, value, 4, '>L') Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.35 retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- linkie.py 26 Apr 2003 16:52:41 -0000 1.35 +++ linkie.py 26 Apr 2003 17:36:17 -0000 1.36 @@ -6,61 +6,14 @@ # #### @(#) $Id$ -from struct import pack, unpack +from bits import Bits +from types import IntType, StringType from array import array -from types import * - -class Bits (object): - __slots__ = ['_contents'] - def __init__ (this, byte_order = None): - this._contents = array('c') - if byte_order == None: pass - elif byte_order == '<': - this.emit_wyde = this.emit_lewyde - this.emit_tetra = this.emit_letetra - this.add_wyde = this.add_lewyde - this.add_tetra = this.add_letetra - elif byte_order == '>': - this.emit_wyde = this.emit_bewyde - this.emit_tetra = this.emit_betetra - this.add_wyde = this.add_bewyde - this.add_tetra = this.add_betetra - else: raise "Unknown byte order", byte_order - def emit_byte (this, b): - if this._skipped <> 0: raise "Events out of order", this - this._contents.append(chr(b & 0xff)) - def emit_bewyde (this, w): - if this._skipped <> 0: raise "Events out of order", this - this._contents.fromstring(pack('>H', w)) # FIXME? - def emit_lewyde (this, w): - if this._skipped <> 0: raise "Events out of order", this - this._contents.fromstring(pack('<H', w)) # FIXME? - def emit_betetra (this, t): - if this._skipped <> 0: raise "Events out of order", this - this._contents.fromstring(pack('>L', t)) # FIXME? - def emit_letetra (this, t): - if this._skipped <> 0: raise "Events out of order", this - this._contents.fromstring(pack('<L', t)) # FIXME? - def emit_string (this, s): - if this._skipped <> 0: raise "Events out of order", this - this._contents.fromstring(s) - def from_array (this, a): - this._contents.extend(a) - def add_byte (this, ofs, value): - this._contents[ofs] = chr((ord(this._contents[ofs]) + value) % 0x100) - def _add (this, ofs, value, size, tpl): - datum, = unpack(tpl, this._contents[ofs : ofs + size]) - datum += value - datum %= 1L << (size << 3) - this._contents[ofs : ofs + size] = array('c', pack(tpl, datum)) - def add_lewyde (this, ofs, value): this._add(ofs, value, 2, '<H') - def add_bewyde (this, ofs, value): this._add(ofs, value, 2, '>H') - def add_letetra (this, ofs, value): this._add(ofs, value, 4, '<L') - def add_betetra (this, ofs, value): this._add(ofs, value, 4, '>L') class Linkie (Bits): def __init__ (this, byte_order = None): Bits.__init__(this, byte_order) + this._byte_order = byte_order this._symbols = [] # symbol -> address this._alignment = 1 # minimal required alignment constraint this._skipped = 0 # uninitialized space after bits Index: Makefile.am =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Makefile.am 21 Apr 2003 11:28:48 -0000 1.10 +++ Makefile.am 26 Apr 2003 17:36:17 -0000 1.11 @@ -6,8 +6,8 @@ # #### @(#) $Id$ -EXTRA_DIST = .cvsignore .pycheckrc struburn.wisp elf.py linkie.py \ - makehello.py elfdump.py +EXTRA_DIST = .cvsignore .pycheckrc struburn.wisp bits.py elf.py \ + linkie.py makehello.py elfdump.py all: |
From: <di...@us...> - 2003-04-26 16:52:44
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv11450 Modified Files: linkie.py Log Message: extracted Bits from Linkie Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- linkie.py 22 Apr 2003 22:29:29 -0000 1.34 +++ linkie.py 26 Apr 2003 16:52:41 -0000 1.35 @@ -10,73 +10,65 @@ from array import array from types import * -class Linkie (object): - def __init__ (this, byte_order): - this._symbols = [] # symbol -> address - this._alignment = 1 # minimal required alignment constraint - this._binary = array('c') - this._skipped = 0 # uninitialized space after bits - this._locals = [] # label no -> address - this._unresolved_locals = [] # order is irrelevant - this._origin = 0 # the base address of this linkie - this._origin_secondary = 0 # support MS-style RVAs (%foo symbols) - if byte_order == '<': +class Bits (object): + __slots__ = ['_contents'] + def __init__ (this, byte_order = None): + this._contents = array('c') + if byte_order == None: pass + elif byte_order == '<': this.emit_wyde = this.emit_lewyde this.emit_tetra = this.emit_letetra + this.add_wyde = this.add_lewyde + this.add_tetra = this.add_letetra elif byte_order == '>': this.emit_wyde = this.emit_bewyde this.emit_tetra = this.emit_betetra - else: - raise "Unknown byte order", byte_order - this._byte_order = byte_order - this._linker_notes = [] # list of (location, type, data) + this.add_wyde = this.add_bewyde + this.add_tetra = this.add_betetra + else: raise "Unknown byte order", byte_order def emit_byte (this, b): - """emit_byte(b) - Places a byte to the byte collector.""" if this._skipped <> 0: raise "Events out of order", this - this._binary.append(chr(b & 0xff)) + this._contents.append(chr(b & 0xff)) def emit_bewyde (this, w): - """emit_bewyde(w) - Places a BigEndian wyde to the byte collector.""" if this._skipped <> 0: raise "Events out of order", this - this._binary.fromstring(pack('>H', w)) # FIXME? + this._contents.fromstring(pack('>H', w)) # FIXME? def emit_lewyde (this, w): - """emit_bewyde(w) - Places a LittleEndian wyde to the byte collector.""" if this._skipped <> 0: raise "Events out of order", this - this._binary.fromstring(pack('<H', w)) # FIXME? + this._contents.fromstring(pack('<H', w)) # FIXME? def emit_betetra (this, t): - """emit_betetra(t) - Places a BigEndian tetra to the byte collector.""" if this._skipped <> 0: raise "Events out of order", this - this._binary.fromstring(pack('>L', t)) # FIXME? + this._contents.fromstring(pack('>L', t)) # FIXME? def emit_letetra (this, t): - """emit_letetra(t) - Places a LittleEndian tetra to the byte collector.""" if this._skipped <> 0: raise "Events out of order", this - this._binary.fromstring(pack('<L', t)) # FIXME? + this._contents.fromstring(pack('<L', t)) # FIXME? def emit_string (this, s): - """emit_string(s) - Places the specified bytes to the byte collector.""" if this._skipped <> 0: raise "Events out of order", this - this._binary.fromstring(s) + this._contents.fromstring(s) def from_array (this, a): - this._binary.extend(a) - + this._contents.extend(a) def add_byte (this, ofs, value): - this._binary[ofs] = chr((ord(this._binary[ofs]) + value) % 0x100) - def add_wyde (this, ofs, value): - tpl = this._byte_order + 'H' - datum, = unpack(tpl, this._binary[ofs : ofs + 2]) - datum += value - datum %= 0x10000 - this._binary[ofs : ofs + 2] = array('c', pack(tpl, datum)) - def add_tetra (this, ofs, value): - tpl = this._byte_order + 'L' - datum, = unpack(tpl, this._binary[ofs : ofs + 4]) + this._contents[ofs] = chr((ord(this._contents[ofs]) + value) % 0x100) + def _add (this, ofs, value, size, tpl): + datum, = unpack(tpl, this._contents[ofs : ofs + size]) datum += value - datum %= 0x100000000L - this._binary[ofs : ofs + 4] = array('c', pack(tpl, datum)) + datum %= 1L << (size << 3) + this._contents[ofs : ofs + size] = array('c', pack(tpl, datum)) + def add_lewyde (this, ofs, value): this._add(ofs, value, 2, '<H') + def add_bewyde (this, ofs, value): this._add(ofs, value, 2, '>H') + def add_letetra (this, ofs, value): this._add(ofs, value, 4, '<L') + def add_betetra (this, ofs, value): this._add(ofs, value, 4, '>L') + +class Linkie (Bits): + def __init__ (this, byte_order = None): + Bits.__init__(this, byte_order) + this._symbols = [] # symbol -> address + this._alignment = 1 # minimal required alignment constraint + this._skipped = 0 # uninitialized space after bits + this._locals = [] # label no -> address + this._unresolved_locals = [] # order is irrelevant + this._origin = 0 # the base address of this linkie + this._origin_secondary = 0 # support MS-style RVAs (%foo symbols) + this._linker_notes = [] # list of (location, type, data) def notify_linker (this, offset, type, arg): this._linker_notes.append((offset, type, arg)) @@ -97,7 +89,7 @@ if this._locals[a] <> None: # backwards delta += this._locals[a] else: # forwards - this._unresolved_locals.append((a, s, len(this._binary))) + this._unresolved_locals.append((a, s, len(this._contents))) elif type(a) == StringType: # global reference if not a[0] in '#&!%': raise 'unprefixed symbol being referred to', a @@ -119,16 +111,16 @@ def deskip (this): """deskip() Converts all reserved bytes to null bytes.""" - this._binary.fromstring(this._skipped * '\0') + this._contents.fromstring(this._skipped * '\0') this._skipped = 0; def memsz (this): """memsz() -> int Returns the memory image size of the linkie.""" - return len(this._binary) + this._skipped + return len(this._contents) + this._skipped def filesz (this): """filesz() -> int Returns the file image size of the linkie.""" - return len(this._binary) + return len(this._contents) def generate_label (this): """generate_label() -> int Allocates a new local label number. Doesn't place the label. @@ -141,7 +133,7 @@ Places a label previously returned by generate_label.""" if this._locals[label] <> None: raise 'Duplicate label', label - this._locals[label] = len(this._binary) + this._skipped + this._locals[label] = len(this._contents) + this._skipped # Resolve open references to that label, if any i = len(this._unresolved_locals) while i > 0: @@ -167,7 +159,7 @@ if type(symbol) <> StringType: raise 'Not a string', symbol if not symbol[0] in '#&!%': raise 'unprefixed symbol being placed', symbol - if value == None: value = len(this._binary) + this._skipped + if value == None: value = len(this._contents) + this._skipped if symbol[0] in '&%': value += this._origin this._symbols.append((symbol, value)) return value @@ -180,11 +172,11 @@ raise 'Base address violates new alignment', \ (this._origin, boundary) if this._alignment < boundary: this._alignment = boundary - delta = (boundary - 1) & - (len(this._binary) + this._skipped) + delta = (boundary - 1) & - (len(this._contents) + this._skipped) if this._skipped: this._skipped += delta else: - this._binary.fromstring(delta * '\0') + this._contents.fromstring(delta * '\0') def set_origin (this, origin): """set_origin(origin) Sets the base address of the linkie to the specified value. @@ -222,13 +214,13 @@ See also get_memory.""" if this._unresolved_locals: raise 'incomplete linkie', this if this._linker_notes and not force: raise 'unlinked linkie', this - return this._binary[:] + return this._contents[:] def get_memory (this): """get_memory() -> array of chars Returns a copy of the memory image of the linkie. See also get_file and get_alignment.""" if this._unresolved_locals: raise 'Incomplete linkie', this - return this._binary + array('c', '\0') * this._skipped + return this._contents + array('c', '\0') * this._skipped def get_alignment (this): """get_alignment() -> int Returns the alignment constraint of the linkie. @@ -268,7 +260,7 @@ if this._unresolved_locals: raise 'Incomplete linkie', this that = Linkie(this._byte_order) that._alignment = this._alignment - that._binary = this._binary[:] + that._contents = this._contents[:] that._skipped = this._skipped that._symbols = this._symbols[:] that._linker_notes = this._linker_notes[:] @@ -282,7 +274,7 @@ if that.filesz(): this.deskip() this.align(that._alignment) delta = this.memsz() - that._origin - this._binary.extend(that._binary) + this._contents.extend(that._contents) this._skipped = that._skipped for sym, val in that._symbols: this._symbols.append((sym, val)) @@ -311,7 +303,7 @@ thatofs = this.memsz() # carry over all the bits - this._binary.extend(that._binary) + this._contents.extend(that._contents) this._skipped = that._skipped # carry over and process the symbols @@ -348,17 +340,20 @@ elif type == 4: this.add_tetra(offset, symbols[arg]) elif type == -1: - this.add_byte(offset, symbols[arg] - offset) + this.add_byte(offset, symbols[arg] - + (this._origin + offset)) elif type == -2: - this.add_wyde(offset, symbols[arg] - offset) + this.add_wyde(offset, symbols[arg] - + (this._origin + offset)) elif type == -4: - this.add_tetra(offset, symbols[arg] - offset) + this.add_tetra(offset, symbols[arg] - + (this._origin + offset)) else: raise 'Invalid linker note type', (offset, type, arg) del this._linker_notes[i] return len(this._linker_notes) def dump (this): - filesz = len(this._binary) + filesz = len(this._contents) skipsz = this._skipped memsz = filesz + skipsz origin = this._origin @@ -398,7 +393,7 @@ if start <= column < stop: offset = row + column if offset < this.filesz(): - byte = this._binary[offset] + byte = this._contents[offset] hex += '%02x ' % ord(byte) if byte < ' ' or byte > '~': byte = '.' ascii += byte |
From: <pi...@us...> - 2003-04-24 12:31:48
|
Update of /cvsroot/wisp/wisp/users/pisi In directory sc8-pr-cvs1:/tmp/cvs-serv16832 Modified Files: whiptail.wisp dialect.pisi.wim Added Files: whiptail.wim Log Message: created whiptail wrapper for wisp --- NEW FILE: whiptail.wim --- ;;;; whiptail.wim - wisp whiptail wrapper - www it is ;-) ;; ;; Copyright by me. Support new world order and buy microsoft oil shares! ;; ... Praise the Lord! if you find the ring, give it back to frodo. ;; ;; some notes: ;; the exit status gets lost in the capture-output(pipe-*) functions. This means ;; that at the moment pressing cancel is not a good idea - i can't detect it. ;; this should be fixed in unix.wim (like an option `signal-nonzero-exit' ;; or something similar) ;; ;; the screen size calculation is done once per whiptail call. it can ;; happen that the screen gets resized before the real whiptail invocation. ;; this can easily happen when using xterm, but should not matter when used on a ;; fixed size console (like framebuffer and text consoles) ;; also note that whiptail-utf8 doesn't look good on a bare linux text console.. ;; ;; you also need to use the fluids module, as there are some macros that use fluids ;; i guess one could do the same thing without any macros... ;;;; (module whiptail) (export page task whiptail-backtitle whiptail-title) (export message yesno menu checklist password input) (use fluids unix strings files arithmetics dialect.pisi) ;;;; implementation (define whiptail-backtitle (make-fluid "")) (define whiptail-title (make-fluid "")) (define (current-title) (ref whiptail-title)) (define bin-whiptail "/usr/bin/whiptail") (define bin-stty "/bin/stty") ;;; page, title - macros for convinient fluid title mapping (defmacro (page title . thunk) `(begin (with-fluid whiptail-backtitle ,title (lambda #f ,@thunk)))) (defmacro (task title . thunk) `(begin (with-fluid whiptail-title ,title (lambda #f ,@thunk)))) ;;;; whiptail - returns the list with the correct preamble that could be fed to call-process (define (whiptail . parameters) (flatten `(,bin-whiptail "--nocancel" "--separate-output" "--noitem" ,(title-maker "--title" (ref whiptail-title)) ,(title-maker "--backtitle" (ref whiptail-backtitle)) ,parameters))) ;;; the current screen size - needed for some calculations (define (screen-size) (map string->integer (string->word-list (first (capture-output-lines '(bin-stty "size") ))))) ;;; return either empty list or title keywords (define (title-maker str title) (if (string-empty? title) '() `(,str ,title))) ;;; the most stupid part - size calculations (define (longest-string strlist) (apply max (map length strlist))) (define (textlistsize text) (list (length text) (longest-string text))) (define (textboxsize text) (textlistsize (split-by-char #\newline text))) ;;; size needed by ordinary textboxes (define (ynsize title other (extralines 0)) (my txt (textboxsize other) (map integer->string (list (+ extralines 6 (first txt)) (max 17 (+ 4 (second txt)) (+ 6 (length title))))))) ;;; size needed by menu, radiolist and checklist functions (define (mnsize title other args (addon 0)) (my txt (textboxsize other) (map integer->string (list (+ 7 (first txt) (length args)) (max 17 (+ addon 9 (longest-string args)) (+ 4 (second txt)) (+ 6 (length title))))))) ;;; yesno - returns either #t or #f (define (yesno message) (my result (call-process (whiptail "--yesno" message (ynsize (current-title) message))) (if (and (eq? (second result) 'exit) (= (third result) 0)) #t #f))) ;;; message - informative text. (define (message text) (call-process (whiptail "--msgbox" text (ynsize (current-title) text)))) ;;; password - ask a password (define (password text) (my op (capture-output-lines (whiptail "--passwordbox" text (ynsize (current-title) text 1)) *error-stream*) (if (not (zero? (length op))) (first op) ""))) ;;; input - Ask for whatever (define (input text (default "")) (my op (capture-output-lines (whiptail "--inputbox" text (ynsize (current-title) text 1) default) *error-stream*) (if (not (zero? (length op))) (first op) ""))) ;;; menu - given an alist, show cars and return selected cdr (define (menu text args) (let ((khm (mnsize (current-title) text (map car args))) (optionlist (flatten (map (lambda (asi) (list (car asi) "dummy")) args)))) (my result (first (capture-output-lines (whiptail "--menu" text khm (integer->string (length args)) optionlist) *error-stream*)) (cdr (assoc result args))))) ;;; checklist - given an alist, show cars and return selected cdrs (define (checklist text args) (let ((khm (mnsize (current-title) text (map car args) 7)) (optionlist (flatten (map (lambda (asi) (list (car asi) "off" )) args)))) (my result (capture-output-lines (whiptail "--checklist" text khm (integer->string (length args)) optionlist) *error-stream*) (map (lambda (asi) (cdr (assoc asi args))) result)))) Index: whiptail.wisp =================================================================== RCS file: /cvsroot/wisp/wisp/users/pisi/whiptail.wisp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- whiptail.wisp 13 Apr 2003 17:25:58 -0000 1.1 +++ whiptail.wisp 24 Apr 2003 12:31:43 -0000 1.2 @@ -1,45 +1,19 @@ -;;; alternate pipe reader -;;; whiptail prints selected items to stderr -;;; and requires stdout to be a tty (in case i want to see anything, what i do) -;;; solution - make an alternate pipe reader -;;; should this be incorporated to unix.wim someday/somehow ? - -(use unix files syscalls semiraw-files) - -(define (make-pipe-close-hook pid) - (lambda (port read? write?) - (if (and read? write?) - (begin - (sys:close (file-descriptor port)) - ; FIXME: the fd slot should be NULLed too. - (sys:waitpid pid 0))))) - - -(define (pipe-alternate-from proc (num 2)) - (let* ((pipe (sys:pipe)) - (child (sys:fork))) - - (if (zero? child) - ; child - (begin - (sys:close (car pipe)) - (sys:dup2 (cdr pipe) num) - (sys:close (cdr pipe)) - (dedicated proc)) - ; parent - (begin - (sys:close (cdr pipe)) - (my res (make-instance <old-file>) - (init-input-file res (car pipe) (make-pipe-close-hook child)) - res))))) +#!/usr/bin/wisp -(define (capture-alternate-lines proc num) - (my p (pipe-alternate-from proc num) - (hold (read-all-lines p) - (close-input-port p)))) +(use fluids whiptail) -;;; test -(write (capture-alternate-lines "whiptail --noitem --separate-output --title Test --menu Select 20 20 10 tag1 item1 tag2 item2" 2)) -(newline) -(write (capture-alternate-lines "whiptail --noitem --separate-output --title Test --checklist checkbox 20 40 10 tag1 on tag2 on \"long tag1\" on \"long tag2\" on" 2)) -(newline) +(let ((user "John Doe")) +(page "Wisp's Whiptail Wrapper" + (task "Welcome!" + (message "Welcome!\n\nThis is a whiptail(1) wrapper for wisp\nthat allows you to create pseudo-graphical\npseudo-guis for your applications") + (set! user (input "First, please tell me who you are, Stranger?")) + (if (yesno "So, $,[user]... Do you want to know how to use WWW ?") + (message "Okay, $,[user], you seem a smart person, I'll tell you") + (message "Whatever, i see you need some enlightenment, $,[user]")) + (message "You can use the (yesno /text/) function\nto ask questions, and (message /text/) function to\ninform the user about something") + (message "What i can easily crack: your password was `$,(password "You can ask the user for a password")'") + (my stupido (menu "Or you can ask the user to make selections" '(("I'm stupid" . stupid-level-4) ("I'm bill gates" . stupid-level-200) ("I'm very stupid" . stupid-level-2))) + (message "After your evaluation, yor stupid-level seems to be: $,(symbol->string stupido)") + ) + (message "$,(checklist "You can also ask several values at once" '(("Delicious salads" . salad) ("Hot soups" . soup) ("Tasty meat" . meat)))") + ))) Index: dialect.pisi.wim =================================================================== RCS file: /cvsroot/wisp/wisp/users/pisi/dialect.pisi.wim,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- dialect.pisi.wim 25 Feb 2003 08:16:51 -0000 1.9 +++ dialect.pisi.wim 24 Apr 2003 12:31:43 -0000 1.10 @@ -6,52 +6,75 @@ ;; ;;;; @(#) $Id$ -; this file at the moment deals with unix integration so most of the tools -; are for interacting with the unix environment and acting as a shell +;;; NOTE: this module may often overtule some existing modules, so it should be the LAST one +;;; in the (use ...) clause (module dialect.pisi) -(export - forever unix-command unix-search-path reaper talk-to-process) +; we have some macros... +(export forever) -(use lists strings unix syscalls) +; some unix stuff +(export unix-command unix-search-path reaper talk-to-process name2path capture-output-lines *output-stream* *error-stream*) +(export directory-files) + +; some string related things +(export string-empty?) + +(use lists strings unix syscalls files) ;;; this is like $PATH in unix this should be local to callers and threads.. hmm. ;;; if we get called FROM an existing unix environment we adapt to the existing path ;;; this way one can set a new sarch path using (set! (unix-search-path) '(..)) + (define *unix-search-path* (make-box '())) (define (unix-search-path (:= new-path)) (if (not :=?) (map string-copy (box-ref *unix-search-path*)) - (set! (box-ref *unix-search-path*) (map string-copy new-path)))) + (set! (box-ref *unix-search-path*) (map string-copy new-path)))) -;;; (unix-command "command with options" (pathref)) -(define (unix-command commando (pathlist (unix-search-path))) - (if (not (any - (lambda (otsikoht) - (try - (my cmdlist (string->word-list commando) - (my pathplace "$,[otsikoht]/$,(first cmdlist)" - (case (file-type pathplace) - ((regular) (call-process `(,pathplace ,@(cdr cmdlist))) #t) - (else #f)))) - (except () - #f))) - pathlist)) - (raise 'no-good-command-in-path commando)) -) +;;; unix stream numbering +(define *output-stream* 1) +(define *error-stream* 2) + +;;; locate a name using something like $PATH in bash +;;; it returns the first occurance of given type, by appending the name to the elements of +;;; pathlist and stating. +;;; FIXME: SSSS - simple, stypid & slow solution + +(define (name2path name (pathlist (unix-search-path)) (type 'regular) ) + (cond + ((find (lambda (piece) (try (eq? type (file-type "$,[piece]/$,[name]")) (except () #f))) pathlist) + => (lambda (tulem) "$,[tulem]/$,[name]")) + (else (raise 'no-good-path-given name)))) + +;;; (unix-command "command with options") - splits the string +;;; and finds the command from the unix path. this will become something as /do-like-shell/ + +(define (unix-command commando) + (my cmdlist (string->word-list commando) + (call-process `(,(name2path (first cmdlist)) ,@(cdr cmdlist))))) +;;; helper.. should go to strings.wim +(define (string-empty? str) + (zero? (length (string->word-list str)))) + +;;; helper.. should go to unix.wim +(define (capture-output-lines proc (from *output-stream*)) + (my p (pipe-from proc from) + (hold (read-all-lines p) + (close-input-port p)))) + +;;; helper - should be somewhere in the main archive... ;;; (forever ...) - do something forever. (defmacro (forever . body) `(let (loop) (hide loop ,@body) (loop))) - - ;;; reaper - loops and waits (define (reaper) (forever (my exitproc (sys:waitpid -1 0) @@ -60,7 +83,7 @@ -;;;; Talk-to-process +;;;; Talk-to-process you can use nc(1) to do some strange things ;) (define (talk-to-process proc masterproc) (let* ((pipe-child (sys:pipe)) (pipe-parent (sys:pipe)) @@ -81,6 +104,13 @@ )))) +(define (directory-files dir) + (collect (lambda (emit) + (for-dir-entries (lambda (name inode) + (if (not (or (string=? "." name) (string=? ".." name))) (emit name)) + ) dir)) + )) + ;;; module initalization |
From: <di...@us...> - 2003-04-22 22:29:36
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv16179 Modified Files: linkie.py make-pe-exe.py mswhello.tran pedump.py Log Message: preparations for PE-EXE generation Index: linkie.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/linkie.py,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- linkie.py 22 Apr 2003 07:04:20 -0000 1.33 +++ linkie.py 22 Apr 2003 22:29:29 -0000 1.34 @@ -64,15 +64,19 @@ this._binary.extend(a) def add_byte (this, ofs, value): - this._binary[ofs] = chr(ord(this._binary[ofs]) + value) + this._binary[ofs] = chr((ord(this._binary[ofs]) + value) % 0x100) def add_wyde (this, ofs, value): tpl = this._byte_order + 'H' datum, = unpack(tpl, this._binary[ofs : ofs + 2]) - this._binary[ofs : ofs + 2] = array('c', pack(tpl, datum + value)) + datum += value + datum %= 0x10000 + this._binary[ofs : ofs + 2] = array('c', pack(tpl, datum)) def add_tetra (this, ofs, value): tpl = this._byte_order + 'L' datum, = unpack(tpl, this._binary[ofs : ofs + 4]) - this._binary[ofs : ofs + 4] = array('c', pack(tpl, datum + value)) + datum += value + datum %= 0x100000000L + this._binary[ofs : ofs + 4] = array('c', pack(tpl, datum)) def notify_linker (this, offset, type, arg): this._linker_notes.append((offset, type, arg)) @@ -161,7 +165,7 @@ Does NOT check uniqueness. None signifies the current offset.""" if type(symbol) <> StringType: raise 'Not a string', symbol - if not symbol[0] in '#&!': + if not symbol[0] in '#&!%': raise 'unprefixed symbol being placed', symbol if value == None: value = len(this._binary) + this._skipped if symbol[0] in '&%': value += this._origin @@ -337,9 +341,18 @@ i = i - 1 offset, type, arg = this._linker_notes[i] if symbols.has_key(arg): - if type == 1: this.add_byte(offset, symbols[arg]) - elif type == 2: this.add_wyde(offset, symbols[arg]) - elif type == 4: this.add_tetra(offset, symbols[arg]) + if type == 1: + this.add_byte(offset, symbols[arg]) + elif type == 2: + this.add_wyde(offset, symbols[arg]) + elif type == 4: + this.add_tetra(offset, symbols[arg]) + elif type == -1: + this.add_byte(offset, symbols[arg] - offset) + elif type == -2: + this.add_wyde(offset, symbols[arg] - offset) + elif type == -4: + this.add_tetra(offset, symbols[arg] - offset) else: raise 'Invalid linker note type', (offset, type, arg) del this._linker_notes[i] return len(this._linker_notes) Index: make-pe-exe.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/make-pe-exe.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- make-pe-exe.py 16 Apr 2003 09:00:25 -0000 1.6 +++ make-pe-exe.py 22 Apr 2003 22:29:30 -0000 1.7 @@ -13,6 +13,9 @@ # This file is *very* incomplete +def roundup (value, boundary): + return (value + boundary - 1) & ~(boundary - 1) + def make_mz_prefix (message = 'OS too broken'): if message.find('$') != -1: raise 'MZ message may not contain dollar signs', message @@ -109,6 +112,22 @@ # 0x4000 should only be run on uniprocessor machines return h +def make_section_header (name): + t = Linkie('<') + t.align(4) + t.emit_string(name[:8]) + t.emit_string('\0' * max(0, 8 - len(name))) + t.emit_tetra_sum(['#' + name + '/memsz']) + t.emit_tetra_sum(['%' + name]) + t.emit_tetra_sum(['#' + name + '/filesz']) + t.emit_tetra_sum(['!' + name]) + t.emit_tetra_sum(['!' + name + '/reloc']) + t.emit_tetra_sum(['!' + name + '/lineno']) + t.emit_wyde_sum(['#' + name + '/reloc']) + t.emit_wyde_sum(['#' + name + '/lineno']) + t.emit_tetra_sum(['#' + name + '/flags']) + return t + def make_pe_aout_header (): h = Linkie('<') h.align(4) @@ -119,7 +138,7 @@ h.emit_tetra_sum(['#aout/text-size']) h.emit_tetra_sum(['#aout/data-size']) h.emit_tetra_sum(['#aout/bss-size']) - h.emit_tetra_sum(['%_entry']) + h.emit_tetra_sum(['%_start']) h.emit_tetra_sum(['!.text']) h.emit_tetra_sum(['!.data']) # not present in PE32+ (?) # #aout/image-base must be multiple of 64ki @@ -134,9 +153,10 @@ h.emit_wyde_sum(['#aout/subsys-version-major']) h.emit_wyde_sum(['#aout/subsys-version-minor']) h.emit_tetra(0) - # #aout/image-size must be a multiple of #aout/object-align - h.emit_tetra_sum(['#aout/image-size']) - h.emit_tetra_sum(['#aout/header-size']) + # %aout/image-end must be a multiple of #aout/memory-align + h.emit_tetra_sum(['%aout/image-end']) + # !aout/header-end must be a multiple of #aout/file-align + h.emit_tetra_sum(['!aout/header-end']) h.emit_tetra(0) # checksum h.emit_wyde_sum(['#aout/subsys']) # Known values for #aout/subsys @@ -162,8 +182,8 @@ h.emit_tetra_sum(['#aout/dict-entry-count']) h.emit_tetra_sum(['%export-table']) h.emit_tetra_sum(['#export-table/size']) - h.emit_tetra_sum(['%import-table']) - h.emit_tetra_sum(['#import-table/size']) + h.emit_tetra_sum(['%.imports']) + h.emit_tetra_sum(['#.imports/memsz']) h.emit_tetra_sum(['%resource-table']) h.emit_tetra_sum(['#resource-table/size']) h.emit_tetra_sum(['%exception-table']) @@ -193,21 +213,186 @@ h.emit_tetra(0); h.emit_tetra(0) # reserved return h +text = Linkie('<') # ia32 +text.place_symbol('&_start') +text.place_symbol('%_start') +text.emit_byte(0x68); text.emit_tetra(-11 % 0x100000000) # push -11 +text.emit_byte(0xe8); text.emit_tetra_sum(['&GetStdHandle@kernel32'], delta = -4, relative = 1) # call GetStdHandle +text.emit_byte(0x68); text.emit_tetra(0) # push 0 +text.emit_byte(0x68); text.emit_tetra_sum(['&rckeep']) # push &rckeep +text.emit_byte(0x68); text.emit_tetra(15) # push 15 +text.emit_byte(0x68); text.emit_tetra_sum(['&message']) # push &message +text.emit_byte(0x50) # push %eax +text.emit_byte(0xe8); text.emit_tetra_sum(['&WriteFile@kernel32'], delta = -4, relative = 1) # call WriteFile +text.emit_byte(0x68); text.emit_tetra(0) # push 0 +text.emit_byte(0xe8); text.emit_tetra_sum(['&ExitProcess@kernel32'], delta = -4, relative = 1) # call ExitProcess + +istubs = Linkie('<') + +data = Linkie('<') +data.place_symbol('&message') +data.emit_string('Hello, world!\x0D\x0A') + +bss = Linkie('<') +bss.place_symbol('&rckeep') +bss.skip(4) + +imports = Linkie('<') + +sections = {'.text': text, '.istubs': istubs, '.data': data, '.bss': bss, '.imports': imports} +sectnames = ['.text', '.istubs', '.data', '.bss', '.imports'] + e = Linkie('<'); e.paste(0, make_mz_prefix('OS too broken')) e.align(8) # PE header must be aligned to 8 e.place_symbol('!pe') e.emit_string('PE\0\0') e.paste(None, make_coff_header()) +e.paste(None, make_pe_aout_header()) +base_address = 0x00400000 +memory_boundary = base_address +for s in sectnames: + e.paste(None, make_section_header(s)) + e.place_symbol('!' + s + '/reloc', 0) + e.place_symbol('!' + s + '/lineno', 0) + e.place_symbol('#' + s + '/reloc', 0) + e.place_symbol('#' + s + '/lineno', 0) +e.align(512) +e.place_symbol('!aout/header-end') +## generate import structures +# gather names of import functions +imports_by_dlls = {} +for s in sectnames: + for ofs, typ, nam in sections[s].get_notes(): + if nam[0] != '&': continue + at = nam.find('@') + if at == -1: continue + name = nam[1:at] + dll = nam[at + 1:].lower() + if not imports_by_dlls.has_key(dll): + imports_by_dlls[dll] = {} + imports_by_dlls[dll][name] = None +# emit import table root +imports.align(4) +import_table_start = imports.memsz() +for dll in imports_by_dlls.keys(): + imports.emit_tetra_sum(['%.imports/' + dll + '/hint-name']) + imports.emit_tetra(0) # timestamp + imports.emit_tetra_sum(['#.imports/' + dll + '/forwarder-chain']) + imports.emit_tetra_sum(['%.imports/' + dll + '/dll-name']) + imports.emit_tetra_sum(['%.imports/' + dll + '/first-thunk']) + imports.place_symbol('#.imports/' + dll + '/forwarder-chain', 0) + # Apparently, hint-name array may not exist. + # It is rumoured that Symantec's linkers don't emit it. + imports.place_symbol('%.imports/' + dll + '/hint-name', 0) +imports.emit_string('\0' * 20) +# emit thunk lists +for dll in imports_by_dlls.keys(): + imports.align(4) + imports.place_symbol('%.imports/' + dll + '/first-thunk') + for sym in imports_by_dlls[dll].keys(): + imports.place_symbol('&.imports/slot/' + sym + '@' + dll) + imports.emit_tetra_sum(['%.imports/thunk/' + sym + '@' + dll]) + imports.emit_tetra(0) +# emit thunk structures +for dll in imports_by_dlls.keys(): + for sym in imports_by_dlls[dll].keys(): + imports.place_symbol('%.imports/thunk/' + sym + '@' + dll) + imports.align(2) + imports.emit_wyde(0) # ordinal + imports.emit_string(sym) + imports.emit_byte(0) +# emit DLL names +for dll in imports_by_dlls.keys(): + imports.place_symbol('%.imports/' + dll + '/dll-name') + imports.emit_string(dll + '.dll') + imports.emit_byte(0) + +# generate stub procedures +for dll in imports_by_dlls.keys(): + for sym in imports_by_dlls[dll].keys(): + istubs.align(8) + istubs.place_symbol('&' + sym + '@' + dll) + istubs.emit_byte(0xFF) + istubs.emit_byte(0x25) + istubs.emit_tetra_sum(['&.imports/slot/' + sym + '@' + dll]) + +# paste sections together +for s in sectnames: + # file alignment + e.align(512) + # memory alignment + memory_boundary = roundup(memory_boundary, \ + max(0x1000, sections[s].get_alignment())) + # establish origins + sections[s].set_origin(memory_boundary) + sections[s].set_secondary_origin(memory_boundary - base_address) + e.place_symbol('!' + s) + e.place_symbol('&' + s, memory_boundary) + e.place_symbol('%' + s, memory_boundary - base_address) + # process sizes + e.place_symbol('#' + s + '/memsz', sections[s].memsz()) + e.place_symbol('#' + s + '/filesz', roundup(sections[s].filesz(), 0x200)) + # paste bits + e.paste(-1, sections[s]) + # increase memory_boundary + memory_boundary = roundup(memory_boundary + sections[s].memsz(), 4096) +e.place_symbol('%aout/image-end', memory_boundary) + e.place_symbol('#coff/magic', 0x014C) # I386MAGIC +e.place_symbol('#coff/nscns', len(sectnames)) e.place_symbol('#coff/timdat', int(time.time())) e.place_symbol('!coff/symptr', 0) e.place_symbol('#coff/nsyms', 0) e.place_symbol('#coff/opthdr', 0x00E0) e.place_symbol('#coff/flags', 0x0002) +e.place_symbol('#aout/magic', 0x010B) # PE32 +e.place_symbol('#aout/linker-version-major', 0) +e.place_symbol('#aout/linker-version-minor', 1) +e.place_symbol('#aout/text-size', roundup(text.memsz(), 0x200)) +e.place_symbol('#aout/data-size', roundup(data.memsz(), 0x200)) +e.place_symbol('#aout/bss-size', roundup(bss.memsz(), 0x200)) e.place_symbol('#aout/image-base', 0x00400000) e.place_symbol('#aout/memory-align', 4096) e.place_symbol('#aout/file-align', 512) -e.paste(None, make_pe_aout_header()) +# 4.0 = MSW95 +e.place_symbol('#aout/os-version-major', 4) +e.place_symbol('#aout/os-version-minor', 0) +# +e.place_symbol('#aout/image-version-major', 0) +e.place_symbol('#aout/image-version-minor', 1) +# 4.0 = MSW95 +e.place_symbol('#aout/subsys-version-major', 4) +e.place_symbol('#aout/subsys-version-minor', 0) +# 3 = Windows character +e.place_symbol('#aout/subsys', 3) +e.place_symbol('#aout/dll-flags', 0) +e.place_symbol('#aout/stack-reserve-size', 1024 * 1024) # one megabyte +e.place_symbol('#aout/stack-commit-size', 0x1000) # one page +e.place_symbol('#aout/heap-reserve-size', 1024 * 1024) # one megabyte +e.place_symbol('#aout/heap-commit-size', 0x1000) # one page + +e.place_symbol('#aout/dict-entry-count', 16) +e.place_symbol('%export-table', 0) +e.place_symbol('#export-table/size', 0) +e.place_symbol('%resource-table', 0) +e.place_symbol('#resource-table/size', 0) +e.place_symbol('%exception-table', 0) +e.place_symbol('#exception-table/size', 0) +e.place_symbol('!certificate-table', 0) +e.place_symbol('#certificate-table/size', 0) +e.place_symbol('%debug-data', 0) +e.place_symbol('#debug-data/size', 0) +e.place_symbol('%architecture-specific', 0) +e.place_symbol('#architecture-specific/size', 0) +e.place_symbol('%thread-local-storage', 0) +e.place_symbol('#thread-local-storage/size', 0) +e.place_symbol('%load-config-table', 0) +e.place_symbol('#load-config-table/size', 0) +e.place_symbol('%delay-import-descriptor', 0) +e.place_symbol('#delay-import-descriptor/size', 0) +e.place_symbol('%COM+-runtime-header', 0) +e.place_symbol('#COM+-runtime-header/size', 0) + e.link() e.dump() e.get_file(force = 1).tofile(open('pehello.exe', 'w')) Index: mswhello.tran =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/mswhello.tran,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- mswhello.tran 22 Apr 2003 17:34:08 -0000 1.6 +++ mswhello.tran 22 Apr 2003 22:29:30 -0000 1.7 @@ -13,14 +13,14 @@ lit :macro $call #xe8 b, 4 - $-t, ; // :macro GetStdHandle \ (handle-number -- handle) - commit ref GetStdHandle@kernel32 $call %eax ; + commit ref GetStdHandle@kernel32#344 $call %eax ; \ FIXME: reverse arguments // :macro WriteFile \ (file buffer count result* overlapped* -- result) - commit ref WriteFile@kernel32 $call %eax ; + commit ref WriteFile@kernel32#730 $call %eax ; // :macro ExitProcess \ (code --) - commit ref ExitProcess@kernel32 $call ; + commit ref ExitProcess@kernel32#131 $call ; \ main entry point Index: pedump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/pedump.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pedump.py 15 Apr 2003 21:04:02 -0000 1.4 +++ pedump.py 22 Apr 2003 22:29:30 -0000 1.5 @@ -85,6 +85,7 @@ # s - is a system file (?) # d - is a DLL # u - should only be run on uniprocessor systems + print print '=== Optional (a.out) header ===' state_enum('Optional header magic', take('w'), { 0x010B: 'PE32', |
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(' ') |
From: <di...@us...> - 2003-04-22 16:09:51
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv16684 Modified Files: tran.py Added Files: tran-builtins Log Message: extracted tran-builtins from tran.py --- NEW FILE: tran-builtins --- #### tran-builtins - see tran.py for details # # 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: tran-builtins,v 1.1 2003/04/22 16:09:46 digg Exp $ $-t, sym cursect.emit_tetra_sum([str(Regstack.pop())], relative = 1) + int int n = Regstack.pop(); m = Regstack.pop() Regstack.append(m + n) .bss cursect = Bss .data cursect = Data .text cursect = Text // Regstack = [] :macro|name if len(Regstack) > 2: raise 'too long argument pattern', Regstack name = ' '.join([name] + [matchers(i).next() for i in Regstack]) Regstack = [] if Meaning.has_key(name): raise 'duplicate declaration', name current_recordee = Meaning[name] = [] def record_state (tok): global current_recordee, State if tok == Semicolon: State = outer_state current_recordee = None else: current_recordee.append(tok) State = record_state :regs|family if Meaning.has_key(family): raise 'duplicate declaration', tok Register(current_register_family) f = Register(current_register_family) Meaning[family] = f Registers[f] = family current_register_index = 0 def regs_state (tok): global State, current_register_family, current_register_index if tok != Semicolon: if Meaning.has_key(tok): raise 'duplicate declaration', tok r = Register(current_register_family, current_register_index) Meaning[tok] = r Registers[r] = tok current_register_index += 1 else: State = outer_state current_register_family += 1 current_register_index = None State = regs_state align int cursect.align(long(Regstack.pop())) b, int cursect.emit_byte(long(Regstack.pop()) % 0x100) b, sym cursect.emit_byte_sum([str(Regstack.pop())]) drop any Regstack.pop() dup any Regstack.append(Regstack[-1]) label|name cursect.place_symbol('&' + name) minor reg Regstack.append(Integer_Literal(Regstack.pop()[-1])) include|name prep.push_file(str(name) + '.tran') ref|name Regstack.append(Symbol_Literal('&' + name)) reserve int cursect.skip(Regstack.pop()) swap any any y = Regstack.pop(); x = Regstack.pop() Regstack.append(y); Regstack.append(x) t, int cursect.emit_tetra(long(Regstack.pop()) % 0x100000000L) t, sym cursect.emit_tetra_sum([str(Regstack.pop())]) w, int cursect.emit_wyde(long(Regstack.pop()) % 0x10000L) w, sym cursect.emit_wyde_sum([str(Regstack.pop())]) # vim: ft=python Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.64 retrieving revision 1.65 diff -u -d -r1.64 -r1.65 --- tran.py 22 Apr 2003 16:03:02 -0000 1.64 +++ tran.py 22 Apr 2003 16:09:46 -0000 1.65 @@ -212,112 +212,12 @@ for m in 'any const int lit sum sym'.split(' '): Meaning[m] = Class_Marker(m) -BUILTINS = ''' - -$-t, sym - cursect.emit_tetra_sum([str(Regstack.pop())], relative = 1) - -+ int int - n = Regstack.pop(); m = Regstack.pop() - Regstack.append(m + n) - -.bss - cursect = Bss - -.data - cursect = Data - -.text - cursect = Text - -// - Regstack = [] - -:macro|name - if len(Regstack) > 2: raise 'too long argument pattern', Regstack - name = ' '.join([name] + [matchers(i).next() for i in Regstack]) - Regstack = [] - if Meaning.has_key(name): raise 'duplicate declaration', name - current_recordee = Meaning[name] = [] - def record_state (tok): - global current_recordee, State - if tok == Semicolon: - State = outer_state - current_recordee = None - else: - current_recordee.append(tok) - State = record_state - -:regs|family - if Meaning.has_key(family): raise 'duplicate declaration', tok - Register(current_register_family) - f = Register(current_register_family) - Meaning[family] = f - Registers[f] = family - current_register_index = 0 - def regs_state (tok): - global State, current_register_family, current_register_index - if tok != Semicolon: - if Meaning.has_key(tok): raise 'duplicate declaration', tok - r = Register(current_register_family, current_register_index) - Meaning[tok] = r - Registers[r] = tok - current_register_index += 1 - else: - State = outer_state - current_register_family += 1 - current_register_index = None - State = regs_state - -align int - cursect.align(long(Regstack.pop())) - -b, int - cursect.emit_byte(long(Regstack.pop()) % 0x100) - -b, sym - cursect.emit_byte_sum([str(Regstack.pop())]) - -drop any - Regstack.pop() - -dup any - Regstack.append(Regstack[-1]) - -label|name - cursect.place_symbol('&' + name) - -minor reg - Regstack.append(Integer_Literal(Regstack.pop()[-1])) - -include|name - prep.push_file(str(name) + '.tran') - -ref|name - Regstack.append(Symbol_Literal('&' + name)) - -reserve int - cursect.skip(Regstack.pop()) - -swap any any - y = Regstack.pop(); x = Regstack.pop() - Regstack.append(y); Regstack.append(x) - -t, int - cursect.emit_tetra(long(Regstack.pop()) % 0x100000000L) - -t, sym - cursect.emit_tetra_sum([str(Regstack.pop())]) - -w, int - cursect.emit_wyde(long(Regstack.pop()) % 0x10000L) - -w, sym - cursect.emit_wyde_sum([str(Regstack.pop())]) -''' +bf = open('tran-builtins', 'r') +builtins = bf.read() +bf.close() -for b in BUILTINS.split('\n\n'): - if b: +for b in builtins.split('\n\n'): + if b[0] != '#': name, code = b.split('\n', 1) np = (name + '|').split('|') name = np[0] |
From: <di...@us...> - 2003-04-22 16:03:09
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv10964 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.63 retrieving revision 1.64 diff -u -d -r1.63 -r1.64 --- tran.py 22 Apr 2003 15:57:17 -0000 1.63 +++ tran.py 22 Apr 2003 16:03:02 -0000 1.64 @@ -126,7 +126,7 @@ def contained_registers (this): return this, -class Class_Marker (object): +class Class_Marker (object, Stackable): def __init__ (this, id): this.id = id @@ -185,7 +185,8 @@ raise 'meaningless word', root m = Meaning[tok] if isinstance(m, list): prep.push_macro(m) - else: + elif isinstance(m, Stackable): Regstack.append(m) + else: # assume tuple mtype = m[0] if mtype == 'builtin': if m[2] & MA_PREFIX: @@ -194,7 +195,6 @@ m[1](tok) else: m[1]() - elif mtype == 'simple': Regstack.append(m[1]) else: raise 'Unknown meaning type in', `Meaning[tok]` else: raise 'bad token', tok @@ -208,15 +208,9 @@ reggen = Generic_Register.child_generator() MA_PREFIX = 1 -Meaning = { - 'any': ('simple', Class_Marker('any')), - 'const': ('simple', Class_Marker('const')), - 'int': ('simple', Class_Marker('int')), - 'lit': ('simple', Class_Marker('lit')), - 'reg': ('simple', Generic_Register), - 'sum': ('simple', Class_Marker('sum')), - 'sym': ('simple', Class_Marker('sym')), -} +Meaning = {'reg': Generic_Register} +for m in 'any const int lit sum sym'.split(' '): + Meaning[m] = Class_Marker(m) BUILTINS = ''' @@ -258,7 +252,7 @@ if Meaning.has_key(family): raise 'duplicate declaration', tok Register(current_register_family) f = Register(current_register_family) - Meaning[family] = 'simple', f + Meaning[family] = f Registers[f] = family current_register_index = 0 def regs_state (tok): @@ -266,7 +260,7 @@ if tok != Semicolon: if Meaning.has_key(tok): raise 'duplicate declaration', tok r = Register(current_register_family, current_register_index) - Meaning[tok] = 'simple', r + Meaning[tok] = r Registers[r] = tok current_register_index += 1 else: |
From: <di...@us...> - 2003-04-22 15:57:24
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv5942 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.62 retrieving revision 1.63 diff -u -d -r1.62 -r1.63 --- tran.py 22 Apr 2003 15:52:58 -0000 1.62 +++ tran.py 22 Apr 2003 15:57:17 -0000 1.63 @@ -184,17 +184,18 @@ except StopIteration: raise 'meaningless word', root m = Meaning[tok] - mtype = m[0] - if mtype == 'builtin': - if m[2] & MA_PREFIX: - tok = prep.get_token() - if not isinstance(tok, str): raise 'word expected', tok - m[1](tok) - else: - m[1]() - elif mtype == 'macro': prep.push_macro(m[1]) - elif mtype == 'simple': Regstack.append(m[1]) - else: raise 'Unknown meaning type in', `Meaning[tok]` + if isinstance(m, list): prep.push_macro(m) + else: + mtype = m[0] + if mtype == 'builtin': + if m[2] & MA_PREFIX: + tok = prep.get_token() + if not isinstance(tok, str): raise 'word expected', tok + m[1](tok) + else: + m[1]() + elif mtype == 'simple': Regstack.append(m[1]) + else: raise 'Unknown meaning type in', `Meaning[tok]` else: raise 'bad token', tok # Main output sections. @@ -243,9 +244,7 @@ name = ' '.join([name] + [matchers(i).next() for i in Regstack]) Regstack = [] if Meaning.has_key(name): raise 'duplicate declaration', name - newmac = [] - Meaning[name] = ('macro', newmac) - current_recordee = newmac + current_recordee = Meaning[name] = [] def record_state (tok): global current_recordee, State if tok == Semicolon: |
From: <di...@us...> - 2003-04-22 15:53:04
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv2935 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.61 retrieving revision 1.62 diff -u -d -r1.61 -r1.62 --- tran.py 22 Apr 2003 15:47:59 -0000 1.61 +++ tran.py 22 Apr 2003 15:52:58 -0000 1.62 @@ -76,6 +76,8 @@ 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 @@ -171,8 +173,6 @@ global Regstack if isinstance(tok, Integer_Literal): Regstack.append(tok) - elif isinstance(tok, str) and tok[:2] == '#/' and len(tok) == 3: - Regstack.append(Integer_Literal(ord(tok[2]))) elif isinstance(tok, str): root = tok mg = match_generator(root) @@ -192,13 +192,8 @@ m[1](tok) else: m[1]() - elif mtype == 'macro': - prep.push_macro(m[1]) - elif mtype == 'simple': - Regstack.append(m[1]) - elif mtype == 'include': - fn = prep.get_token() + '.tran' - prep.push_file(fn) + elif mtype == 'macro': prep.push_macro(m[1]) + elif mtype == 'simple': Regstack.append(m[1]) else: raise 'Unknown meaning type in', `Meaning[tok]` else: raise 'bad token', tok @@ -215,7 +210,6 @@ Meaning = { 'any': ('simple', Class_Marker('any')), 'const': ('simple', Class_Marker('const')), - 'include': ('include',), 'int': ('simple', Class_Marker('int')), 'lit': ('simple', Class_Marker('lit')), 'reg': ('simple', Generic_Register), @@ -302,6 +296,9 @@ minor reg Regstack.append(Integer_Literal(Regstack.pop()[-1])) + +include|name + prep.push_file(str(name) + '.tran') ref|name Regstack.append(Symbol_Literal('&' + name)) |
From: <di...@us...> - 2003-04-22 15:48:05
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv32536 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.60 retrieving revision 1.61 diff -u -d -r1.60 -r1.61 --- tran.py 22 Apr 2003 15:44:21 -0000 1.60 +++ tran.py 22 Apr 2003 15:47:59 -0000 1.61 @@ -167,7 +167,7 @@ except StopIteration: pass except StopIteration: pass -def state_outer (tok): +def outer_state (tok): global Regstack if isinstance(tok, Integer_Literal): Regstack.append(tok) @@ -252,14 +252,14 @@ newmac = [] Meaning[name] = ('macro', newmac) current_recordee = newmac - def state_record (tok): + def record_state (tok): global current_recordee, State if tok == Semicolon: - State = state_outer + State = outer_state current_recordee = None else: current_recordee.append(tok) - State = state_record + State = record_state :regs|family if Meaning.has_key(family): raise 'duplicate declaration', tok @@ -268,7 +268,7 @@ Meaning[family] = 'simple', f Registers[f] = family current_register_index = 0 - def state_regs (tok): + def regs_state (tok): global State, current_register_family, current_register_index if tok != Semicolon: if Meaning.has_key(tok): raise 'duplicate declaration', tok @@ -277,10 +277,10 @@ Registers[r] = tok current_register_index += 1 else: - State = state_outer + State = outer_state current_register_family += 1 current_register_index = None - State = state_regs + State = regs_state align int cursect.align(long(Regstack.pop())) @@ -340,7 +340,7 @@ current_recordee = None current_register_family = 0 -State = state_outer +State = outer_state Registers = {Generic_Register: 'reg'} # for reverse translation def mainloop (): |
From: <di...@us...> - 2003-04-22 15:44:26
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv30787 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.59 retrieving revision 1.60 diff -u -d -r1.59 -r1.60 --- tran.py 22 Apr 2003 15:40:19 -0000 1.59 +++ tran.py 22 Apr 2003 15:44:21 -0000 1.60 @@ -201,18 +201,6 @@ prep.push_file(fn) else: raise 'Unknown meaning type in', `Meaning[tok]` else: raise 'bad token', tok -def state_regs (tok): - global State, current_register_family, current_register_index - if tok != Semicolon: - if Meaning.has_key(tok): raise 'duplicate declaration', tok - r = Register(current_register_family, current_register_index) - Meaning[tok] = 'simple', r - Registers[r] = tok - current_register_index += 1 - else: - State = state_outer - current_register_family += 1 - current_register_index = None # Main output sections. Text = Linkie('<') @@ -280,6 +268,18 @@ Meaning[family] = 'simple', f Registers[f] = family current_register_index = 0 + def state_regs (tok): + global State, current_register_family, current_register_index + if tok != Semicolon: + if Meaning.has_key(tok): raise 'duplicate declaration', tok + r = Register(current_register_family, current_register_index) + Meaning[tok] = 'simple', r + Registers[r] = tok + current_register_index += 1 + else: + State = state_outer + current_register_family += 1 + current_register_index = None State = state_regs align int |
From: <di...@us...> - 2003-04-22 15:40:24
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv28272 Modified Files: tran.py Log Message: major cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.58 retrieving revision 1.59 diff -u -d -r1.58 -r1.59 --- tran.py 22 Apr 2003 15:34:53 -0000 1.58 +++ tran.py 22 Apr 2003 15:40:19 -0000 1.59 @@ -46,14 +46,6 @@ return str.__new__(cls, s) def __repr__ (this): return 'Symbol_Literal(%r)' % str(this) - def __add__ (this, that): - if not isinstance(this, Constant_Sum): this = Constant_Sum(this) - if not isinstance(that, Constant_Sum): that = Constant_Sum(that) - return this + that - def __sub__ (this, that): - if not isinstance(this, Constant_Sum): this = Constant_Sum(this) - if not isinstance(that, Constant_Sum): that = Constant_Sum(that) - return this - that def get_symbols (this): return this, @@ -73,65 +65,6 @@ Semicolon = Unique_Token(';') Dollar = Dollar_Type() -class Constant_Sum (Stackable): - def __init__ (this, plus = (), minus = (), scalar = 0L): - this.scalar = long(scalar) - if isinstance(plus, Symbol_Literal) or plus == Dollar: - plus = plus, - if isinstance(minus, Symbol_Literal) or minus == Dollar: - minus = minus, - if isinstance(plus, Integer_Literal): - this.scalar += long(plus); plus = () - if isinstance(minus, Integer_Literal): - this.scalar -= long(minus); minus = () - this.plus = []; this.minus = [] - for item in plus: - if isinstance(item, Symbol_Literal) or item == Dollar: - this.plus.append(item) - else: raise 'bad addee', item - for item in minus: - if isinstance(item, Symbol_Literal) or item == Dollar: - try: - i = this.plus.index(item) - this.plus.pop(i) - except ValueError: - this.minus.append(item) - else: raise 'bad subtractee', item - this.plus = tuple(this.plus); this.minus = tuple(this.minus) - def __add__ (this, that): - if isinstance(that, Symbol_Literal) or that == Dollar: - that = Constant_Sum(plus = [that]) - return Constant_Sum(plus = this.plus + that.plus, - minus = this.minus + that.minus, - scalar = this.scalar + that.scalar).simplify() - def __sub__ (this, that): - if isinstance(that, Symbol_Literal) or that == Dollar: - that = Constant_Sum(plus = [that]) - return Constant_Sum(plus = this.plus + that.minus, - minus = this.minus + that.plus, - scalar = this.scalar - that.scalar).simplify() - def __repr__ (this): - arg = [] - if this.plus: arg.append('plus = ' + `this.plus`) - if this.minus: arg.append('minus = ' + `this.minus`) - if this.scalar: arg.append('scalar = ' + `this.scalar`) - return 'Constant_Sum(%s)' % ', '.join(arg) - def __str__ (this): - res = '' - for item in this.plus: res += ' + ' + str(item) - for item in this.minus: res += ' - ' + str(item) - if this.scalar > 0: res += ' + ' + str(this.scalar) - else: res += ' - ' + str(-this.scalar) - if res[0] == ' ': res = res[1:] - if res[:2] == '+ ': res = res[2:] - return '(' + res + ')' - def simplify (this): - if len(this.plus) == 0 and len(this.minus) == 0: - return Integer_Literal(this.scalar) - if len(this.plus) == 1 and len(this.minus) == 0 and this.scalar == 0: - return this.plus[0] - else: return this - class Lexer (shlex): def __init__ (this, filename): shlex.__init__(this, instream = open(filename, 'r'), infile = filename) @@ -195,51 +128,6 @@ def __init__ (this, id): this.id = id -class Sum (list): - def __init__ (this, addends, scalar = 0, dollars = 0): - list.__init__(this, []) - 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 isinstance(a, Integer_Literal) or isinstance(a, IntType): - this.scalar += long(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 plus (a, b): - if not isinstance(a, Constant_Sum): a = Constant_Sum(a) - if not isinstance(b, Constant_Sum): b = Constant_Sum(b) - Regstack.append(a + b) -def minus (a, b): - if not isinstance(a, Constant_Sum): a = Constant_Sum(a) - if not isinstance(b, Constant_Sum): b = Constant_Sum(b) - Regstack.append(a - b) - def matchers (object): if isinstance(object, Class_Marker): yield object.id @@ -251,9 +139,6 @@ yield 'sym' yield 'lit' yield 'const' - elif isinstance(object, Constant_Sum): - yield 'sum' - yield 'const' elif object == Dollar: yield '$' yield 'const' @@ -301,17 +186,12 @@ m = Meaning[tok] mtype = m[0] if mtype == 'builtin': - argc = m[2] & MA_ARGC - if len(Regstack) < argc: raise 'Stack too empty', tok - if argc: - arg = Regstack[-argc:]; Regstack = Regstack[:-argc] - else: - arg = [] if m[2] & MA_PREFIX: tok = prep.get_token() if not isinstance(tok, str): raise 'word expected', tok - arg.append(tok) - apply(m[1], arg) + m[1](tok) + else: + m[1]() elif mtype == 'macro': prep.push_macro(m[1]) elif mtype == 'simple': @@ -343,11 +223,8 @@ Generic_Register = Register() reggen = Generic_Register.child_generator() -MA_ARGC = 007 -MA_PREFIX = 010 +MA_PREFIX = 1 Meaning = { - '+ const const': ('builtin', plus, 2), - '- const const': ('builtin', minus, 2), 'any': ('simple', Class_Marker('any')), 'const': ('simple', Class_Marker('const')), 'include': ('include',), @@ -362,6 +239,10 @@ $-t, sym cursect.emit_tetra_sum([str(Regstack.pop())], relative = 1) + ++ int int + n = Regstack.pop(); m = Regstack.pop() + Regstack.append(m + n) .bss cursect = Bss |
From: <di...@us...> - 2003-04-22 15:34:57
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv24686 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.57 retrieving revision 1.58 diff -u -d -r1.57 -r1.58 --- tran.py 22 Apr 2003 15:33:15 -0000 1.57 +++ tran.py 22 Apr 2003 15:34:53 -0000 1.58 @@ -231,8 +231,6 @@ res += '- ' + `-this.scalar` return res -def minor (reg): - Regstack.append(Integer_Literal(reg[-1])) def plus (a, b): if not isinstance(a, Constant_Sum): a = Constant_Sum(a) if not isinstance(b, Constant_Sum): b = Constant_Sum(b) @@ -355,7 +353,6 @@ 'include': ('include',), 'int': ('simple', Class_Marker('int')), 'lit': ('simple', Class_Marker('lit')), - 'minor reg': ('builtin', minor, 1), 'reg': ('simple', Generic_Register), 'sum': ('simple', Class_Marker('sum')), 'sym': ('simple', Class_Marker('sym')), @@ -421,6 +418,9 @@ label|name cursect.place_symbol('&' + name) + +minor reg + Regstack.append(Integer_Literal(Regstack.pop()[-1])) ref|name Regstack.append(Symbol_Literal('&' + name)) |
From: <di...@us...> - 2003-04-22 15:33:20
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv23690 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.56 retrieving revision 1.57 diff -u -d -r1.56 -r1.57 --- tran.py 22 Apr 2003 15:32:07 -0000 1.56 +++ tran.py 22 Apr 2003 15:33:15 -0000 1.57 @@ -231,7 +231,6 @@ res += '- ' + `-this.scalar` return res -def align (n): cursect.align(n) def minor (reg): Regstack.append(Integer_Literal(reg[-1])) def plus (a, b): @@ -351,7 +350,6 @@ Meaning = { '+ const const': ('builtin', plus, 2), '- const const': ('builtin', minus, 2), - 'align int': ('builtin', align, 1), 'any': ('simple', Class_Marker('any')), 'const': ('simple', Class_Marker('const')), 'include': ('include',), @@ -405,6 +403,9 @@ Registers[f] = family current_register_index = 0 State = state_regs + +align int + cursect.align(long(Regstack.pop())) b, int cursect.emit_byte(long(Regstack.pop()) % 0x100) |
From: <di...@us...> - 2003-04-22 15:32:13
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv22986 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.55 retrieving revision 1.56 diff -u -d -r1.55 -r1.56 --- tran.py 22 Apr 2003 15:30:55 -0000 1.55 +++ tran.py 22 Apr 2003 15:32:07 -0000 1.56 @@ -231,8 +231,6 @@ res += '- ' + `-this.scalar` return res -def label (name): - cursect.place_symbol('&' + name) def align (n): cursect.align(n) def minor (reg): Regstack.append(Integer_Literal(reg[-1])) @@ -358,7 +356,6 @@ 'const': ('simple', Class_Marker('const')), 'include': ('include',), 'int': ('simple', Class_Marker('int')), - 'label': ('builtin', label, 0 | MA_PREFIX), 'lit': ('simple', Class_Marker('lit')), 'minor reg': ('builtin', minor, 1), 'reg': ('simple', Generic_Register), @@ -420,6 +417,9 @@ dup any Regstack.append(Regstack[-1]) + +label|name + cursect.place_symbol('&' + name) ref|name Regstack.append(Symbol_Literal('&' + name)) |
From: <di...@us...> - 2003-04-22 15:31:08
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv22360 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.54 retrieving revision 1.55 diff -u -d -r1.54 -r1.55 --- tran.py 22 Apr 2003 15:27:40 -0000 1.54 +++ tran.py 22 Apr 2003 15:30:55 -0000 1.55 @@ -326,13 +326,6 @@ prep.push_file(fn) else: raise 'Unknown meaning type in', `Meaning[tok]` else: raise 'bad token', tok -def state_record (tok): - global State, current_recordee - if tok == Semicolon: - State = state_outer - current_recordee = None - else: - current_recordee.append(tok) def state_regs (tok): global State, current_register_family, current_register_index if tok != Semicolon: @@ -398,6 +391,13 @@ newmac = [] Meaning[name] = ('macro', newmac) current_recordee = newmac + def state_record (tok): + global current_recordee, State + if tok == Semicolon: + State = state_outer + current_recordee = None + else: + current_recordee.append(tok) State = state_record :regs|family |
From: <di...@us...> - 2003-04-22 15:27:44
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv20319 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.53 retrieving revision 1.54 diff -u -d -r1.53 -r1.54 --- tran.py 22 Apr 2003 15:26:18 -0000 1.53 +++ tran.py 22 Apr 2003 15:27:40 -0000 1.54 @@ -236,8 +236,6 @@ def align (n): cursect.align(n) def minor (reg): Regstack.append(Integer_Literal(reg[-1])) -def dup (x): - Regstack.append(x); Regstack.append(x) def plus (a, b): if not isinstance(a, Constant_Sum): a = Constant_Sum(a) if not isinstance(b, Constant_Sum): b = Constant_Sum(b) @@ -365,7 +363,6 @@ 'align int': ('builtin', align, 1), 'any': ('simple', Class_Marker('any')), 'const': ('simple', Class_Marker('const')), - 'dup any': ('builtin', dup, 1), 'include': ('include',), 'int': ('simple', Class_Marker('int')), 'label': ('builtin', label, 0 | MA_PREFIX), @@ -420,6 +417,9 @@ drop any Regstack.pop() + +dup any + Regstack.append(Regstack[-1]) ref|name Regstack.append(Symbol_Literal('&' + name)) |
From: <di...@us...> - 2003-04-22 15:26:23
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv19424 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.52 retrieving revision 1.53 diff -u -d -r1.52 -r1.53 --- tran.py 22 Apr 2003 15:19:24 -0000 1.52 +++ tran.py 22 Apr 2003 15:26:18 -0000 1.53 @@ -238,25 +238,6 @@ Regstack.append(Integer_Literal(reg[-1])) def dup (x): Regstack.append(x); Regstack.append(x) -def colon_macro (name): - global State, Regstack, current_recordee - if len(Regstack) > 2: raise 'too long argument pattern', Regstack - name = ' '.join([name] + [matchers(i).next() for i in Regstack]) - Regstack = [] - if Meaning.has_key(name): raise 'duplicate declaration', name - newmac = [] - Meaning[name] = ('macro', newmac) - current_recordee = newmac - State = state_record -def colon_regs (family): - global State, current_register_index - if Meaning.has_key(family): raise 'duplicate declaration', tok - Register(current_register_family) - f = Register(current_register_family) - Meaning[family] = 'simple', f - Registers[f] = family - current_register_index = 0 - State = state_regs def plus (a, b): if not isinstance(a, Constant_Sum): a = Constant_Sum(a) if not isinstance(b, Constant_Sum): b = Constant_Sum(b) @@ -381,8 +362,6 @@ Meaning = { '+ const const': ('builtin', plus, 2), '- const const': ('builtin', minus, 2), - ':macro': ('builtin', colon_macro, 0 | MA_PREFIX), - ':regs': ('builtin', colon_regs, 0 | MA_PREFIX), 'align int': ('builtin', align, 1), 'any': ('simple', Class_Marker('any')), 'const': ('simple', Class_Marker('const')), @@ -414,6 +393,25 @@ // Regstack = [] +:macro|name + if len(Regstack) > 2: raise 'too long argument pattern', Regstack + name = ' '.join([name] + [matchers(i).next() for i in Regstack]) + Regstack = [] + if Meaning.has_key(name): raise 'duplicate declaration', name + newmac = [] + Meaning[name] = ('macro', newmac) + current_recordee = newmac + State = state_record + +:regs|family + if Meaning.has_key(family): raise 'duplicate declaration', tok + Register(current_register_family) + f = Register(current_register_family) + Meaning[family] = 'simple', f + Registers[f] = family + current_register_index = 0 + State = state_regs + b, int cursect.emit_byte(long(Regstack.pop()) % 0x100) @@ -452,7 +450,8 @@ np = (name + '|').split('|') name = np[0] pa = np[1] - exec 'def _p (%s):\n global cursect, Regstack\n%s\n' % (pa, code) + g = 'cursect, Regstack, State, current_recordee, current_register_index' + exec 'def _p (%s):\n global %s\n%s\n' % (pa, g, code) flags = 0 if pa: flags |= MA_PREFIX Meaning[name] = 'builtin', _p, flags |
From: <di...@us...> - 2003-04-22 15:19:30
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv15566 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- tran.py 22 Apr 2003 15:14:27 -0000 1.51 +++ tran.py 22 Apr 2003 15:19:24 -0000 1.52 @@ -233,8 +233,6 @@ def label (name): cursect.place_symbol('&' + name) -def ref (name): - Regstack.append(Symbol_Literal('&' + name)) def align (n): cursect.align(n) def minor (reg): Regstack.append(Integer_Literal(reg[-1])) @@ -394,7 +392,6 @@ 'label': ('builtin', label, 0 | MA_PREFIX), 'lit': ('simple', Class_Marker('lit')), 'minor reg': ('builtin', minor, 1), - 'ref': ('builtin', ref, 0 | MA_PREFIX), 'reg': ('simple', Generic_Register), 'sum': ('simple', Class_Marker('sum')), 'sym': ('simple', Class_Marker('sym')), @@ -426,6 +423,9 @@ drop any Regstack.pop() +ref|name + Regstack.append(Symbol_Literal('&' + name)) + reserve int cursect.skip(Regstack.pop()) @@ -449,8 +449,13 @@ for b in BUILTINS.split('\n\n'): if b: name, code = b.split('\n', 1) - exec 'def _primitive ():\n global cursect, Regstack\n' + code + '\n' - Meaning[name] = 'builtin', _primitive, 0 + np = (name + '|').split('|') + name = np[0] + pa = np[1] + exec 'def _p (%s):\n global cursect, Regstack\n%s\n' % (pa, code) + flags = 0 + if pa: flags |= MA_PREFIX + Meaning[name] = 'builtin', _p, flags current_recordee = None current_register_family = 0 |
From: <di...@us...> - 2003-04-22 15:14:31
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv12134 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- tran.py 22 Apr 2003 15:09:09 -0000 1.50 +++ tran.py 22 Apr 2003 15:14:27 -0000 1.51 @@ -400,29 +400,10 @@ 'sym': ('simple', Class_Marker('sym')), } -# Emitters -def byte_comma_int (n): cursect.emit_byte(long(n) % 0x100L) -Meaning['b, int'] = 'builtin', byte_comma_int, 1 -def byte_comma_sym (a): cursect.emit_byte_sum([str(a)]) -Meaning['b, sym'] = 'builtin', byte_comma_sym, 1 - -def wyde_comma_int (n): cursect.emit_wyde(long(n) % 0x10000L) -Meaning['w, int'] = 'builtin', wyde_comma_int, 1 -def wyde_comma_sym (a): cursect.emit_wyde_sum([str(a)]) -Meaning['w, sym'] = 'builtin', wyde_comma_sym, 1 - -def tetra_comma_int (n): cursect.emit_tetra(long(n) % 0x100000000L) -Meaning['t, int'] = 'builtin', tetra_comma_int, 1 -def tetra_comma_sym (a): cursect.emit_tetra_sum([str(a)]) -Meaning['t, sym'] = 'builtin', tetra_comma_sym, 1 - - -# End of builtins BUILTINS = ''' $-t, sym - a = Regstack.pop() - cursect.emit_tetra_sum([str(n)], relative = 1) + cursect.emit_tetra_sum([str(Regstack.pop())], relative = 1) .bss cursect = Bss @@ -436,6 +417,12 @@ // Regstack = [] +b, int + cursect.emit_byte(long(Regstack.pop()) % 0x100) + +b, sym + cursect.emit_byte_sum([str(Regstack.pop())]) + drop any Regstack.pop() @@ -445,6 +432,18 @@ swap any any y = Regstack.pop(); x = Regstack.pop() Regstack.append(y); Regstack.append(x) + +t, int + cursect.emit_tetra(long(Regstack.pop()) % 0x100000000L) + +t, sym + cursect.emit_tetra_sum([str(Regstack.pop())]) + +w, int + cursect.emit_wyde(long(Regstack.pop()) % 0x10000L) + +w, sym + cursect.emit_wyde_sum([str(Regstack.pop())]) ''' for b in BUILTINS.split('\n\n'): |
From: <di...@us...> - 2003-04-22 15:09:13
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv8190 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.49 retrieving revision 1.50 diff -u -d -r1.49 -r1.50 --- tran.py 22 Apr 2003 15:05:35 -0000 1.49 +++ tran.py 22 Apr 2003 15:09:09 -0000 1.50 @@ -416,16 +416,14 @@ def tetra_comma_sym (a): cursect.emit_tetra_sum([str(a)]) Meaning['t, sym'] = 'builtin', tetra_comma_sym, 1 -def dollar_minus_tetra_comma_sym (n): - cursect.emit_tetra_sum([str(n)], relative = 1) -Meaning['$-t, sym'] = 'builtin', dollar_minus_tetra_comma_sym, 1 - -def drop_any (): Regstack.pop() -Meaning['drop any'] = 'builtin', drop_any, 0 # End of builtins BUILTINS = ''' +$-t, sym + a = Regstack.pop() + cursect.emit_tetra_sum([str(n)], relative = 1) + .bss cursect = Bss @@ -500,3 +498,5 @@ f.close() main() + +# vim: nofen |
From: <di...@us...> - 2003-04-22 15:05:39
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv6113 Modified Files: tran.py Log Message: minor cleanup Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.48 retrieving revision 1.49 diff -u -d -r1.48 -r1.49 --- tran.py 22 Apr 2003 15:02:12 -0000 1.48 +++ tran.py 22 Apr 2003 15:05:35 -0000 1.49 @@ -236,7 +236,6 @@ def ref (name): Regstack.append(Symbol_Literal('&' + name)) def align (n): cursect.align(n) -def reserve (n): cursect.skip(n) def minor (reg): Regstack.append(Integer_Literal(reg[-1])) def dup (x): @@ -397,7 +396,6 @@ 'minor reg': ('builtin', minor, 1), 'ref': ('builtin', ref, 0 | MA_PREFIX), 'reg': ('simple', Generic_Register), - 'reserve int': ('builtin', reserve, 1), 'sum': ('simple', Class_Marker('sum')), 'sym': ('simple', Class_Marker('sym')), } @@ -442,6 +440,9 @@ drop any Regstack.pop() + +reserve int + cursect.skip(Regstack.pop()) swap any any y = Regstack.pop(); x = Regstack.pop() |