Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -l argument; evaluate -e arguments immediately #191

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions bin/lumen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1218,17 +1218,18 @@ var eval_print = function (form) {
}
}
};
var rep = function (s) {
return eval_print(reader["read-string"](s));
var read_eval = function (s) {
var __form = reader["read-string"](s);
return compiler["eval"](__form);
};
var repl = function () {
var __buf = "";
var rep1 = function (s) {
__buf = __buf + s;
var __more = [];
var __form = reader["read-string"](__buf, __more);
if (!( __form === __more)) {
eval_print(__form);
var __form1 = reader["read-string"](__buf, __more);
if (!( __form1 === __more)) {
eval_print(__form1);
__buf = "";
return system.write("> ");
}
Expand All @@ -1241,8 +1242,8 @@ var repl = function () {
compile_file = function (path) {
var __s = reader.stream(system["read-file"](path));
var __body = reader["read-all"](__s);
var __form1 = compiler.expand(join(["do"], __body));
return compiler.compile(__form1, {_stash: true, stmt: true});
var __form2 = compiler.expand(join(["do"], __body));
return compiler.compile(__form2, {_stash: true, stmt: true});
};
_load = function (path) {
var __previous = target;
Expand All @@ -1267,6 +1268,7 @@ var usage = function () {
print(" <arguments>\tPassed to program in system.argv");
print(" <object files>\tLoaded before compiling <input>");
print("options:");
print(" -l <input>\tLoad input file");
print(" -c <input>\tCompile input file");
print(" -o <output>\tOutput file");
print(" -t <target>\tTarget language (default: lua)");
Expand All @@ -1289,23 +1291,28 @@ var main = function () {
var __i = 0;
while (__i < _35(__argv)) {
var __a = __argv[__i];
if (__a === "-c" || __a === "-o" || __a === "-t" || __a === "-e") {
if (__a === "-l" || __a === "-c" || __a === "-o" || __a === "-t" || __a === "-e") {
if (__i === edge(__argv)) {
print("missing argument for " + __a);
} else {
__i = __i + 1;
var __val = __argv[__i];
if (__a === "-c") {
__input = __val;
if (__a === "-l") {
_load(__val);
} else {
if (__a === "-o") {
__output = __val;
if (__a === "-c") {
__input = __val;
} else {
if (__a === "-t") {
__target1 = __val;
if (__a === "-o") {
__output = __val;
} else {
if (__a === "-e") {
__expr = __val;
if (__a === "-t") {
__target1 = __val;
} else {
if (__a === "-e") {
__expr = __val;
read_eval(__expr);
}
}
}
}
Expand All @@ -1327,7 +1334,9 @@ var main = function () {
}
if (nil63(__input)) {
if (__expr) {
return rep(__expr);
if (is63(_37result)) {
return print(str(_37result));
}
} else {
return repl();
}
Expand Down
43 changes: 26 additions & 17 deletions bin/lumen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1105,17 +1105,18 @@ local function eval_print(form)
end
end
end
local function rep(s)
return eval_print(reader["read-string"](s))
local function read_eval(s)
local __form = reader["read-string"](s)
return compiler["eval"](__form)
end
local function repl()
local __buf = ""
local function rep1(s)
__buf = __buf .. s
local __more = {}
local __form = reader["read-string"](__buf, __more)
if not( __form == __more) then
eval_print(__form)
local __form1 = reader["read-string"](__buf, __more)
if not( __form1 == __more) then
eval_print(__form1)
__buf = ""
return system.write("> ")
end
Expand All @@ -1133,8 +1134,8 @@ end
function compile_file(path)
local __s1 = reader.stream(system["read-file"](path))
local __body = reader["read-all"](__s1)
local __form1 = compiler.expand(join({"do"}, __body))
return compiler.compile(__form1, {_stash = true, stmt = true})
local __form2 = compiler.expand(join({"do"}, __body))
return compiler.compile(__form2, {_stash = true, stmt = true})
end
function _load(path)
local __previous = target
Expand All @@ -1159,6 +1160,7 @@ local function usage()
print(" <arguments>\tPassed to program in system.argv")
print(" <object files>\tLoaded before compiling <input>")
print("options:")
print(" -l <input>\tLoad input file")
print(" -c <input>\tCompile input file")
print(" -o <output>\tOutput file")
print(" -t <target>\tTarget language (default: lua)")
Expand All @@ -1181,23 +1183,28 @@ local function main()
local __i = 0
while __i < _35(__argv) do
local __a = __argv[__i + 1]
if __a == "-c" or __a == "-o" or __a == "-t" or __a == "-e" then
if __a == "-l" or __a == "-c" or __a == "-o" or __a == "-t" or __a == "-e" then
if __i == edge(__argv) then
print("missing argument for " .. __a)
else
__i = __i + 1
local __val = __argv[__i + 1]
if __a == "-c" then
__input = __val
if __a == "-l" then
_load(__val)
else
if __a == "-o" then
__output = __val
if __a == "-c" then
__input = __val
else
if __a == "-t" then
__target1 = __val
if __a == "-o" then
__output = __val
else
if __a == "-e" then
__expr = __val
if __a == "-t" then
__target1 = __val
else
if __a == "-e" then
__expr = __val
read_eval(__expr)
end
end
end
end
Expand All @@ -1219,7 +1226,9 @@ local function main()
end
if nil63(__input) then
if __expr then
return rep(__expr)
if is63(_37result) then
return print(str(_37result))
end
else
return repl()
end
Expand Down
15 changes: 9 additions & 6 deletions main.l
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
lua: (print (cat "error: " (get v 'message) "\n" (get v 'stack))))
(is? v) (print (str v)))))

(define rep (s)
(eval-print ((get reader 'read-string) s)))
(define read-eval (s)
(let form ((get reader 'read-string) s)
((get compiler 'eval) form)))

(define repl ()
(let buf ""
Expand Down Expand Up @@ -61,6 +62,7 @@
(print " <arguments>\tPassed to program in system.argv")
(print " <object files>\tLoaded before compiling <input>")
(print "options:")
(print " -l <input>\tLoad input file")
(print " -c <input>\tCompile input file")
(print " -o <output>\tOutput file")
(print " -t <target>\tTarget language (default: lua)")
Expand All @@ -81,19 +83,20 @@
argv (get system 'argv))
(for i (# argv)
(let a (at argv i)
(if (or (= a "-c") (= a "-o") (= a "-t") (= a "-e"))
(if (or (= a "-l") (= a "-c") (= a "-o") (= a "-t") (= a "-e"))
(if (= i (edge argv))
(print (cat "missing argument for " a))
(do (inc i)
(let val (at argv i)
(if (= a "-c") (set input val)
(if (= a "-l") (load val)
(= a "-c") (set input val)
(= a "-o") (set output val)
(= a "-t") (set target1 val)
(= a "-e") (set expr val)))))
(= a "-e") (read-eval (set expr val))))))
(not (= "-" (char a 0))) (add pre a))))
(step file pre
(run-file file))
(if (nil? input) (if expr (rep expr) (repl))
(if (nil? input) (if expr (if (is? %result) (print (str %result))) (repl))
(do (if target1 (set target target1))
(let code (compile-file input)
(if (or (nil? output) (= output "-"))
Expand Down