Turned everything upside down, and fixed a couple bugs.

Bugs fixed:
- %= and the new assignment operators were not emitting error on invalid types.
- List globals referenced in another global were duplicated entirely.
- Properly recognize -option in the command line.

Rest:
- Complete overhaul of the internal data structure.
  - Got rid of the symbol table plus mini-trees, and made everything one big tree plus an auxiliary symbol table.
  - No more special case hacks like using tuples instead of lists...
  - Got rid of the EXPR hack.
  - Dict-based, rather than list-based. Allows adding arbitrary data to any node or symbol entry.
- Added a few coverage tests for the new code.
- Return values can now be chained; the functions parameter requirement is gone. Still not fully convinced, though. My guess is that a parser object should be passed between functions instead. Will do for now.
This commit is contained in:
Sei Lisa 2014-07-30 04:54:16 +02:00
parent 5d4abf967d
commit fb68273eed
5 changed files with 691 additions and 734 deletions

14
main.py
View file

@ -64,7 +64,7 @@ means that e.g. a + 3 + 5 is not optimized to a + 8; however a + (3 + 5) is.
return 1
optchanges = sys.argv[2].split(',')
for chg in optchanges:
if chg[0:1] != '+':
if chg[0:1] not in ('+', '-'):
chg = '+' + chg
if chg[0] == '-':
options.discard(chg[1:])
@ -78,24 +78,22 @@ means that e.g. a + 3 + 5 is not optimized to a + 8; however a + (3 + 5) is.
try:
if fname == '-':
script = sys.stdin.read()
p.parse(script, options)
ts = p.parse(script, options)
else:
p.parsefile(fname, options)
funcs = p.functions
symtab = p.symtab
ts = p.parsefile(fname, options)
except EParse as e:
print e.message
return 1
del p
opt = optimizer()
opt.optimize(symtab, funcs, options)
ts = opt.optimize(ts, options)
del opt
outs = outscript()
script = outs.output(symtab, options)
script = outs.output(ts, options)
del outs
del symtab
del ts
sys.stdout.write(script)
return 0