diff options
| author | Joel Martin <github@martintribe.org> | 2015-01-08 23:25:40 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-08 23:25:40 -0600 |
| commit | 9d42904e47c50c5ff2306da04993b2a32bc9cd16 (patch) | |
| tree | e1b2d46a232e6573dc2c185967ebe988be3db973 /lua/step1_read_print.lua | |
| parent | fd888612ca589d7e1a46c36fc3fe12aed126f6a8 (diff) | |
| download | mal-9d42904e47c50c5ff2306da04993b2a32bc9cd16.tar.gz mal-9d42904e47c50c5ff2306da04993b2a32bc9cd16.zip | |
Lua: all steps and self-hosting.
Also some misc docs/TODO updates.
Diffstat (limited to 'lua/step1_read_print.lua')
| -rwxr-xr-x | lua/step1_read_print.lua | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lua/step1_read_print.lua b/lua/step1_read_print.lua new file mode 100755 index 0000000..abd555d --- /dev/null +++ b/lua/step1_read_print.lua @@ -0,0 +1,42 @@ +#!/usr/bin/env lua + +local readline = require('readline') +local utils = require('utils') +local reader = require('reader') +local printer = require('printer') + +-- read +function READ(str) + return reader.read_str(str) +end + +-- eval +function EVAL(ast, env) + return ast +end + +-- print +function PRINT(exp) + return printer._pr_str(exp, true) +end + +-- repl +function rep(str) + return PRINT(EVAL(READ(str),"")) +end + +while true do + line = readline.readline("user> ") + if not line then break end + xpcall(function() + print(rep(line)) + end, function(exc) + if exc then + if types._malexception_Q(exc) then + exc = printer._pr_str(exc.val, true) + end + print("Error: " .. exc) + print(debug.traceback()) + end + end) +end |
