Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 80 lines (67 sloc) 1.734 kB
#!/usr/bin/env python2.5
import sys
from getopt import getopt
from pair import cons, nil
import reader
import lx
from util import report_compile_error, print_context
def basename(name):
return name[:name.find('.')]
def read_file(n):
return reader.read(open(n).read(), n)
opts, args = getopt(sys.argv[1:], 'btcho:', [
'bare',
'thunk',
'generate-c',
'generate-h',
'output=',
])
infile = args[0]
outfile = None
gen_c = False
gen_h = False
use_thunk = True
for opt, val in opts:
if opt in ('--generate-c', '-c'):
gen_c = True
if opt in ('--generate-h', '-h'):
gen_h = True
elif opt in ('--thunk', '-t'):
use_thunk = True
elif opt in ('--bare', '-b'):
use_thunk = False
elif opt in ('--output', '-o'):
outfile = val
if outfile is None:
if gen_c:
outfile = infile + '.c'
elif gen_h:
outfile = infile + '.h'
else:
outfile = infile + 'c'
if len(sys.argv) < 2:
print 'please give me a flie'
sys.exit()
exps = read_file(infile)
if use_thunk:
# ((fn () ...))
exp = cons(cons(lx.fn_s, cons(nil, exps)), nil)
else:
# (do ...)
exp = cons(lx.do_s, exps)
try:
code = lx.compile(exp, lx.S('val'), lx.S('next'), nil, lx.S('pop-all-top'))
code = lx.end_with_linkage(lx.S('return'), code, lx.S('fake-pop-all'))
outfd = open(outfile, 'w')
if gen_c:
if not outfile.endswith('.c'): raise 'bad output file name', outfile
code.gen_c(basename(infile), outfd)
elif gen_h:
code.gen_h(basename(infile), outfd)
else:
code.assemble(outfd)
except lx.CompileError, err:
report_compile_error(err, file=infile)
except Exception, err:
print_context(err)
raise
Jump to Line
Something went wrong with that request. Please try again.