git @ Cat's Eye Technologies Tamsin / 81e2923
Have `tamsin` itself support `loadngo`. Cat's Eye Technologies 11 years ago
5 changed file(s) with 35 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
22 from os.path import realpath, dirname, join
33 import sys
44
5 sys.path.insert(0, join(dirname(realpath(sys.argv[0])), '..', 'src'))
5 tamsin_dir = join(dirname(realpath(sys.argv[0])), '..')
6 sys.path.insert(0, join(tamsin_dir, 'src'))
67
78 from tamsin.main import main
89
910
1011 if __name__ == '__main__':
11 main(sys.argv[1:])
12 main(sys.argv[1:], tamsin_dir=tamsin_dir)
11 ----
22
33 * turn system library back into built-in keywords (esp. if ¶ can be used)
4 * better command-line argument parsing
5 * `@include` -- for the scanner, especially
6 * `$.unquote` should take left and right quotes to expect
7 * define a stringify-repr operation on terms
4 * `@include` -- for the scanner, especially -- move metac's to `lib`
5 * figure out why compiled version of tamsin-ast hangs...
6 * arbitrary non-printable characters in terms: `\x99`
7 * `byte` versus `utf_8` scanners ("char" is vague, isn't it?)
88
99 ### 8-bit clean/UTF-8 ###
1010
1111 * 8-bit clean strings, in both Python and C. tests for these as string
1212 literals, ability to scan them on input, and ability to produce them
1313 on output.
14 * arbitrary non-printable characters in terms and such
1514 * decode UTF-8 in compiled C code : character scanner yields one Unicode char
1615 * more tests for UTF-8
1716
18 ### meta-circularity/bootstrapping ###
19
20 * meta-circular implementation of analyzer!
21 * meta-circular implementation of compiler!
22 * meta-circular implementation of interpreter! (not so useful?)
23 * figure out why compiled verstion of tamsin-ast hangs...
24
2517 ### lower-priority/experimental ###
2618
19 * meta-circular implementation of compiler!
20 * `$.unquote` should take left and right quotes to expect
21 * define a stringify-repr operation on terms
2722 * Tamsin scanner: more liberal (every non-alphanum+_ symbol scans as itself,
2823 incl. ones that have no meaning currently like `/` and `?`)
2924 * use `←` instead of `@`, why not?
3025 * `¶foo` means production called `foo`, to disambiguate
3126 (this would mean unaliasing is less necessary -- call your production
32 `¶return` if you like) -- ASCII version? `p^foo`?
27 `¶return` if you like) -- ASCII version? `^^foo`? `:foo`? `||foo`? `//foo`?
3328 * pattern match in send:
3429 * `fields → F@fields(H,T) & H`
3530 * maps, implemented as hash tables.
4136 indeed, this is a fold! something like...
4237 * `fold rule '' +`
4338 * `fold rule nil cons`
39 * maybe `rule/nil/cons`
4440 i.e.
4541 * `"fold" & expr0 & term & ("+" | term)`
4642 that certainly implies that `+` is a constructor though. hmmm...
5046 expr1 = term → E & fold ("*" & term) E mul.
5147 term = "x" | "y" | "z" | "(" & expr0 → E & ")" & E.
5248
49 * on that topic — production values and/or lambda productions...
5350 * auto-generate terms from productions, like Rooibos does
5451 * `;` = `&`?
5552 * pretty-print AST for error messages
00
11 -> Functionality "Intepret Tamsin program" is implemented by
22 -> shell command
3 -> "./loadngo.sh %(test-body-file) < %(test-input-file)"
3 -> "./bin/tamsin loadngo %(test-body-file) < %(test-input-file)"
44
+0
-8
loadngo.sh less more
0 #!/bin/sh
1
2 bin/tamsin compile $1 > foo.c && \
3 gcc -g -Ic_src -Lc_src foo.c -o foo -ltamsin && \
4 ./foo
5 R=$?
6 #rm -f foo.c foo
7 exit $R
33 # Distributed under a BSD-style license; see LICENSE for more information.
44
55 import codecs
6 import os
7 import subprocess
68 import sys
79
810 from tamsin.event import DebugEventListener
4143 print unicode(result).encode('UTF-8')
4244
4345
44 def main(args):
46 def main(args, tamsin_dir='.'):
4547 listeners = []
4648 if args[0] == '--debug':
4749 listeners.append(DebugEventListener())
6668 #print >>sys.stderr, repr(ast)
6769 compiler = Compiler(ast, sys.stdout)
6870 compiler.compile()
71 elif args[0] == 'loadngo':
72 ast = parse_and_check(args[1])
73 c_filename = 'foo.c'
74 exe_filename = './foo'
75 with codecs.open(c_filename, 'w', 'UTF-8') as f:
76 compiler = Compiler(ast, f)
77 compiler.compile()
78 c_src_dir = os.path.join(tamsin_dir, 'c_src')
79 command = ("gcc", "-g", "-I%s" % c_src_dir, "-L%s" % c_src_dir,
80 c_filename, "-o", exe_filename, "-ltamsin")
81 subprocess.check_call(command)
82 try:
83 subprocess.check_call((exe_filename,))
84 exit_code = 0
85 except CalledProcessError:
86 exit_code = 1
87 subprocess.call(('rm', '-f', c_filename, exe_filename))
88 sys.exit(exit_code)
6989 else:
7090 ast = parse_and_check(args[0])
7191 run(ast, listeners=listeners)