feat: add logical OR operator with short-circuit evaluation and token support

Add TOKEN_PIPEPIPE token for '||' syntax, implement or() parsing function with CODE_OR bytecode, and add VM interpreter logic that short-circuits on truthy left operand. Update .gitignore to exclude *.xccheckout files, extend test coverage for falsy behavior in and.wren and if.wren, and add comprehensive or.wren test suite verifying short-circuit semantics and truthiness rules.
This commit is contained in:
Bob Nystrom
2013-11-20 02:24:58 +00:00
parent 06be5808da
commit 643a7c4f97
7 changed files with 96 additions and 2 deletions
+26
View File
@@ -0,0 +1,26 @@
// Note: These tests implicitly depend on ints being truthy.
// Also rely on io.write() returning its argument.
// Return the first true argument.
io.write(1 || true) // expect: 1
io.write(false || 1) // expect: 1
io.write(false || false || true) // expect: true
// Return the last argument if all are false.
io.write(false || false) // expect: false
io.write(false || false || false) // expect: false
// Short-circuit at the first true argument.
io.write(false) || // expect: false
io.write(true) || // expect: true
io.write(true) // should not print
// Swallow a trailing newline.
io.write(true ||
true) // expect: true
// Only false is falsy.
io.write(0 || true) // expect: 0
io.write(null || true) // expect: null
io.write(("" || true) == "") // expect: true
io.write(false || true) // expect: true