From 9d42904e47c50c5ff2306da04993b2a32bc9cd16 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Thu, 8 Jan 2015 23:25:40 -0600 Subject: Lua: all steps and self-hosting. Also some misc docs/TODO updates. --- lua/step1_read_print.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 lua/step1_read_print.lua (limited to 'lua/step1_read_print.lua') 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 -- cgit v1.2.3