1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-31 07:33:01 +00:00

Fix bug in compiler with if form under certain conditions.

Begin bundled 'cook' tool for managing janet projects.
This commit is contained in:
Calvin Rose
2018-12-25 15:32:42 -05:00
parent 2c94aa1a6a
commit 17283241ab
8 changed files with 136 additions and 72 deletions

View File

@@ -233,6 +233,22 @@
(array/concat accum body)
(tuple/slice accum 0))
(defmacro try
"Try something and catch errors. Body is any expression,
and catch should be a form with the first element a tuple. This tuple
should contain a binding for errors and an optional binding for
the fiber wrapping the body. Returns the result of body if no error,
or the result of catch if an error."
[body catch]
(let [[[err fib]] catch
f (gensym)
r (gensym)]
~(let [,f (,fiber/new (fn [] ,body) :e)
,r (resume ,f)]
(if (= (,fiber/status ,f) :error)
(do (def ,err ,r) ,(if fib ~(def ,fib ,f)) ,;(tuple/slice catch 1))
,r))))
(defmacro and
"Evaluates to the last argument if all preceding elements are true, otherwise
evaluates to false."