[Compiler] Implement and/or in the compiler instead of a macro (#231)

* fix sc

* doc update

* another doc update
This commit is contained in:
water111
2021-02-03 16:12:51 -05:00
committed by GitHub
parent 425cc6794c
commit 45f74f078a
10 changed files with 133 additions and 60 deletions
@@ -0,0 +1,33 @@
(start-test "short-circuit")
(defun dont-call-me ()
(segfault)
)
(expect-true (= 1 (and 1)))
(expect-true (= #f (and #f)))
(expect-true (= 1 (and 2 1)))
(expect-true (= #f (and 2 #f 1)))
(expect-true (= #f (and #f 1 1)))
(expect-true (= #f (and 2 1 #f)))
(expect-true (= 1 (or 1)))
(expect-true (= #f (or #f)))
(expect-true (= 2 (or 2 1)))
(expect-true (= 2 (or 2 #f 1)))
(expect-true (= 3 (or #f 3 1)))
(expect-true (= 2 (or 2 1 #f)))
(expect-true (= 2 (or #f #f #f 2 3 #f)))
(or #f #f 1 (segfault) 2)
(and 1 #f 1 (segfault) 2)
(let ((x (the symbol #f)))
;; type system should allow this because and will return a symbol
(set! x (and #t #f))
(set! x (or #t #f))
;; (set! x (or 1 #f)) ;; not allowed.
)
(finish-test)
+5
View File
@@ -370,6 +370,11 @@ TEST_F(WithGameTests, LocalVars) {
{"y is \"test\", x is 12, z is 3.2000\n0\n"});
}
TEST_F(WithGameTests, ShortCircuit) {
runner.run_static_test(env, testCategory, "test-short-circuit.gc",
get_test_pass_string("short-circuit", 13));
}
TEST(TypeConsistency, TypeConsistency) {
Compiler compiler;
compiler.enable_throw_on_redefines();