Permalink
Browse files

Package modules in a thunk so they don't pollute the global environment.

  • Loading branch information...
1 parent e197783 commit 464a4eb9c5dbe3cf57320cd1e579d1867c37023e @kr committed Jan 3, 2007
Showing with 17 additions and 5 deletions.
  1. +2 −0 app.lx
  2. +2 −0 d.lx
  3. +13 −4 lx1c
  4. +0 −1 run
View
2 app.lx
@@ -6,3 +6,5 @@ compile "a.lx"
def c (import c)
c
+
+pr private
View
2 d.lx
@@ -1,3 +1,5 @@
+def private 42
+
def y (import c)
y .run
View
17 lx1c
@@ -3,25 +3,29 @@
import sys
from getopt import getopt
-import pair
+from pair import cons, nil
import reader
import lx
def read_file(n):
return reader.read(open(n).read())
-opts, args = getopt(sys.argv[1:], 'co:', [
+opts, args = getopt(sys.argv[1:], 'mco:', [
+ 'module',
'generate-c',
'output=',
])
infile = args[0]
outfile = infile + 'c'
gen_c = False
+module = False
for opt, val in opts:
if opt in ('--generate-c', '-c'):
gen_c = True
+ elif opt in ('--module', '-m'):
+ module = True
elif opt in ('--output', '-o'):
outfile = val
@@ -30,9 +34,14 @@ if len(sys.argv) < 2:
sys.exit()
exps = read_file(infile)
-exp = pair.cons(lx.begin_s, exps)
+if module:
+ # ((fn () ...))
+ exp = cons(cons(lx.fn_s, cons(nil, exps)), nil)
+else:
+ # (begin ...)
+ exp = cons(lx.begin_s, exps)
-code = lx.compile(exp, lx.S('val'), lx.S('next'), pair.nil)
+code = lx.compile(exp, lx.S('val'), lx.S('next'), nil)
outfd = open(outfile, 'w')
if gen_c:
if not outfile.endswith('.c'): raise 'bad output file name', outfile
View
1 run
@@ -1,5 +1,4 @@
#!/bin/sh -e
-./lx1c prelude.lx
./lx1c "$1"
./vm "$1"c

0 comments on commit 464a4eb

Please sign in to comment.