[Wisp-cvs] wisp/users/dig tran.py,1.93,1.94
Status: Alpha
Brought to you by:
digg
From: <di...@us...> - 2003-05-17 11:27:30
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv1347 Modified Files: tran.py Log Message: extracted make_universal_meaning from Interpreter Index: tran.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v retrieving revision 1.93 retrieving revision 1.94 diff -u -d -r1.93 -r1.94 --- tran.py 17 May 2003 11:05:35 -0000 1.93 +++ tran.py 17 May 2003 11:27:27 -0000 1.94 @@ -219,38 +219,39 @@ Generic_Register = Register() -class Interpreter (object): - __slots__ = 'sections current recordee regpaths hanging regstack state meaning'.split() +MA_PREFIX = 1 - universal_meaning = { +def make_universal_meaning (fn): + um = { 'reg': Generic_Register, '...': Unique('...'), 'tetras': ['dup', '+', 'dup', '+'], # FIXME } - for m in 'any const int lit sum sym'.split(' '): - universal_meaning[m] = Class_Marker(m) + for m in 'any const int lit sum sym'.split(' '): um[m] = Class_Marker(m) # load builtins - _bf = open('tran-builtins', 'r') - _builtins = _bf.read() - _bf.close() + bf = open(fn, 'r') + builtins = bf.read() + bf.close() - MA_PREFIX = 1 + 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 (%s):\n%s\n' % (pa, code) + flags = 0 + if pa: flags |= MA_PREFIX + um[name] = 'builtin', _p, flags + return um - 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 (%s):\n%s\n' % (_pa, _code) - _flags = 0 - if _pa: _flags |= MA_PREFIX - universal_meaning[_name] = 'builtin', _p, _flags +class Interpreter (object): + __slots__ = 'sections current recordee regpaths hanging regstack state meaning'.split() + universal_meaning = make_universal_meaning('tran-builtins') def make_section_switcher (this, name): - def switcher (): - this.current = this.sections[name] + def switcher (): this.current = this.sections[name] return switcher def __init__ (this, byte_order, sections = ['.text']): @@ -284,7 +285,7 @@ elif isinstance(m, tuple): mtype = m[0] if mtype == 'builtin': - if m[2] & Interpreter.MA_PREFIX: + if m[2] & MA_PREFIX: tok = prep.get_token() if not isinstance(tok, str): raise 'word expected', tok m[1](tok) |