Skip to content

Instantly share code, notes, and snippets.

@radgeRayden
Last active October 5, 2020 00:32
Show Gist options
  • Save radgeRayden/d3e704e11d760a7f689ede1a0a4041a4 to your computer and use it in GitHub Desktop.
Save radgeRayden/d3e704e11d760a7f689ede1a0a4041a4 to your computer and use it in GitHub Desktop.
reverse polish notation lisp (from scopes)
(('(1 2 3) 'reverse) print)
("hello world" print)
(((4 5 +) 2 >) print)
(module-name print)
((5 87 +) print)
((true false and) print)
inline arity-check (n ...)
va-lfold 0
inline (__ arg count)
static-if (none? arg)
hide-traceback;
static-error
.. "expected " (tostring n) " arguments, got " (tostring count)
count + 1
...
inline forward-args (head args...)
hide-traceback;
head args...
run-stage;
let forward-args-symbol = (Symbol "#forward-args")
fn list-handler (lst scope)
raising Error
let at next = (decons lst)
at as:= list
let head rest = (decons at)
if ((('typeof head) == Symbol) and ((head as Symbol) == forward-args-symbol))
return lst scope
else
let head rrest = (decons ('reverse at))
let rest = ('reverse rrest)
let expr = (cons head rest)
return
(cons ('tag (spice-quote [(cons forward-args-symbol expr)]) ('anchor head)) next)
scope
let list-handler =
box-pointer (static-typify list-handler list Scope)
run-stage;
let rpl-env =
do
let + - / // * ** < > <= >= == !=
let print
let sugar-quote spice-quote
let true false
inline and (a b)
arity-check 2 a b
and a b
inline or (a b)
arity-check 2 a b
or a b
inline not (v)
arity-check 1 v
not v
indirect-let forward-args-symbol = forward-args
locals;
let argc argv = (launch-args)
if (argc < 3)
error "expected source file"
fn parse-module-name (filename)
let match? start end = ('match? "(^.+\\/?).+?(?=\\..+$)" filename)
if match?
slice filename start end
else
filename
let filename = (string (argv @ 2))
hide-traceback;
load-module (parse-module-name filename) filename
scope =
'bind rpl-env list-handler-symbol list-handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment