lua: break via guard+raise sentinel; auto-first multi in arith/concat +4 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
This commit is contained in:
@@ -59,28 +59,29 @@
|
||||
(define
|
||||
lua-arith
|
||||
(fn
|
||||
(mm op a b)
|
||||
(cond
|
||||
((and (= (type-of a) "number") (= (type-of b) "number"))
|
||||
(lua-num-op op a b))
|
||||
((and
|
||||
(or (= (type-of a) "number") (= (type-of a) "string"))
|
||||
(or (= (type-of b) "number") (= (type-of b) "string"))
|
||||
(not (= (lua-to-number a) nil))
|
||||
(not (= (lua-to-number b) nil)))
|
||||
(lua-num-op op a b))
|
||||
(else
|
||||
(let
|
||||
((m (lua-get-mm a mm)))
|
||||
(cond
|
||||
((not (= m nil)) (lua-first (m a b)))
|
||||
(else
|
||||
(let
|
||||
((m2 (lua-get-mm b mm)))
|
||||
(if
|
||||
(not (= m2 nil))
|
||||
(lua-first (m2 a b))
|
||||
(error (str "lua: arith on " (type-of a) " " op " " (type-of b))))))))))))
|
||||
(mm op a-in b-in)
|
||||
(let ((a (lua-first a-in)) (b (lua-first b-in)))
|
||||
(cond
|
||||
((and (= (type-of a) "number") (= (type-of b) "number"))
|
||||
(lua-num-op op a b))
|
||||
((and
|
||||
(or (= (type-of a) "number") (= (type-of a) "string"))
|
||||
(or (= (type-of b) "number") (= (type-of b) "string"))
|
||||
(not (= (lua-to-number a) nil))
|
||||
(not (= (lua-to-number b) nil)))
|
||||
(lua-num-op op a b))
|
||||
(else
|
||||
(let
|
||||
((m (lua-get-mm a mm)))
|
||||
(cond
|
||||
((not (= m nil)) (lua-first (m a b)))
|
||||
(else
|
||||
(let
|
||||
((m2 (lua-get-mm b mm)))
|
||||
(if
|
||||
(not (= m2 nil))
|
||||
(lua-first (m2 a b))
|
||||
(error (str "lua: arith on " (type-of a) " " op " " (type-of b)))))))))))))
|
||||
|
||||
(define lua-add (fn (a b) (lua-arith "__add" "+" a b)))
|
||||
|
||||
@@ -116,33 +117,35 @@
|
||||
(define
|
||||
lua-concat-coerce
|
||||
(fn
|
||||
(v)
|
||||
(cond
|
||||
((= (type-of v) "string") v)
|
||||
((= (type-of v) "number") (str v))
|
||||
(else (error (str "lua: cannot concat " v))))))
|
||||
(v-in)
|
||||
(let ((v (lua-first v-in)))
|
||||
(cond
|
||||
((= (type-of v) "string") v)
|
||||
((= (type-of v) "number") (str v))
|
||||
(else (error (str "lua: cannot concat " v)))))))
|
||||
|
||||
(define
|
||||
lua-concat
|
||||
(fn
|
||||
(a b)
|
||||
(cond
|
||||
((and
|
||||
(or (= (type-of a) "string") (= (type-of a) "number"))
|
||||
(or (= (type-of b) "string") (= (type-of b) "number")))
|
||||
(str (lua-concat-coerce a) (lua-concat-coerce b)))
|
||||
(else
|
||||
(let
|
||||
((m (lua-get-mm a "__concat")))
|
||||
(cond
|
||||
((not (= m nil)) (lua-first (m a b)))
|
||||
(else
|
||||
(let
|
||||
((m2 (lua-get-mm b "__concat")))
|
||||
(if
|
||||
(not (= m2 nil))
|
||||
(lua-first (m2 a b))
|
||||
(error (str "lua: concat on " (type-of a) " and " (type-of b))))))))))))
|
||||
(a-in b-in)
|
||||
(let ((a (lua-first a-in)) (b (lua-first b-in)))
|
||||
(cond
|
||||
((and
|
||||
(or (= (type-of a) "string") (= (type-of a) "number"))
|
||||
(or (= (type-of b) "string") (= (type-of b) "number")))
|
||||
(str (lua-concat-coerce a) (lua-concat-coerce b)))
|
||||
(else
|
||||
(let
|
||||
((m (lua-get-mm a "__concat")))
|
||||
(cond
|
||||
((not (= m nil)) (lua-first (m a b)))
|
||||
(else
|
||||
(let
|
||||
((m2 (lua-get-mm b "__concat")))
|
||||
(if
|
||||
(not (= m2 nil))
|
||||
(lua-first (m2 a b))
|
||||
(error (str "lua: concat on " (type-of a) " and " (type-of b)))))))))))))
|
||||
|
||||
(define
|
||||
lua-eq
|
||||
@@ -1646,3 +1649,6 @@
|
||||
(define
|
||||
lua-return-value
|
||||
(fn (e) (if (> (len e) 1) (nth e 1) nil)))
|
||||
|
||||
(define lua-break-sentinel?
|
||||
(fn (e) (and (= (type-of e) "list") (> (len e) 0) (= (first e) (quote lua-brk)))))
|
||||
|
||||
Reference in New Issue
Block a user