Implemented boolean operators
This commit is contained in:
examples/hello
src/build/core
tests
37
tests/programs/branch-and.q
Normal file
37
tests/programs/branch-and.q
Normal file
@ -0,0 +1,37 @@
|
||||
main() {
|
||||
x := 0
|
||||
|
||||
if x != x && x != x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x == x && x != x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x != x && x == x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x == x && x != x && x != x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x != x && x == x && x != x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x != x && x != x && x == x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x == x && x == x && x == x {
|
||||
exit(0)
|
||||
}
|
||||
|
||||
exit(1)
|
||||
}
|
||||
|
||||
exit(x) {
|
||||
syscall(60, x)
|
||||
}
|
57
tests/programs/branch-combined.q
Normal file
57
tests/programs/branch-combined.q
Normal file
@ -0,0 +1,57 @@
|
||||
main() {
|
||||
x := 0
|
||||
|
||||
if x == x && x != x || x != x && x != x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x != x && x == x || x != x && x != x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x != x && x != x || x == x && x != x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x != x && x != x || x != x && x == x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if (x == x || x != x) && (x != x || x != x) {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if (x != x || x == x) && (x != x || x != x) {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if (x != x || x != x) && (x == x || x != x) {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if (x != x || x != x) && (x != x || x == x) {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x != x || x != x || x != x || x == x || x != x {
|
||||
if x + 1 == inc(x) && x - 1 == dec(x) && x == dec(inc(x)) {
|
||||
if (x == x && x != x || x == x && x == x) && (x == x && x == x || x == x && x != x) {
|
||||
exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit(1)
|
||||
}
|
||||
|
||||
exit(x) {
|
||||
syscall(60, x)
|
||||
}
|
||||
|
||||
inc(x) {
|
||||
return x + 1
|
||||
}
|
||||
|
||||
dec(x) {
|
||||
return x - 1
|
||||
}
|
29
tests/programs/branch-or.q
Normal file
29
tests/programs/branch-or.q
Normal file
@ -0,0 +1,29 @@
|
||||
main() {
|
||||
x := 0
|
||||
|
||||
if x != x || x != x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x != x || x != x || x != x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x == x || x != x {
|
||||
if x != x || x == x {
|
||||
if x == x || x != x || x != x {
|
||||
if x != x || x == x || x != x {
|
||||
if x != x || x != x || x == x {
|
||||
exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit(1)
|
||||
}
|
||||
|
||||
exit(x) {
|
||||
syscall(60, x)
|
||||
}
|
@ -25,15 +25,15 @@ main() {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x >= 1 || 1 <= x {
|
||||
if x >= 1 {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x == inc(x) || x == dec(x) {
|
||||
if 1 <= x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if inc(0) == x || dec(0) == x || inc(x) == dec(x) {
|
||||
if x + 1 != x + 1 {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
@ -41,7 +41,23 @@ main() {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x + 1 != x + 1 {
|
||||
if x - 1 != dec(x) {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if inc(x) != x + 1 {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if dec(x) != x - 1 {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if x != inc(dec(x)) {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if inc(dec(x)) != x {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,10 @@ var programs = []struct {
|
||||
{"nested-calls.q", "", 4},
|
||||
{"return.q", "", 6},
|
||||
{"reassign.q", "", 2},
|
||||
{"branch.q", "", 0},
|
||||
{"branch-and.q", "", 0},
|
||||
{"branch-or.q", "", 0},
|
||||
{"branch-combined.q", "", 0},
|
||||
}
|
||||
|
||||
func TestPrograms(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user