Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NOT, _NEGATE, and macOS startup script bugs #484

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions source/qb64pe.bas
Original file line number Diff line number Diff line change
Expand Up @@ -13030,7 +13030,7 @@ IF os$ = "LNX" THEN
OPEN path.exe$ + file$ + extension$ + "_start.command" FOR OUTPUT AS #ff
PRINT #ff, "cd " + CHR$(34) + "$(dirname " + CHR$(34) + "$0" + CHR$(34) + ")" + CHR$(34);
PRINT #ff, CHR$(10);
PRINT #ff, "./" + file$ + extension$ + " &";
PRINT #ff, "./" + CHR$(34) + file$ + extension$ + CHR$(34) + " &";
PRINT #ff, CHR$(10);
PRINT #ff, "osascript -e 'tell application " + CHR$(34) + "Terminal" + CHR$(34) + " to close (every window whose name contains " + CHR$(34) + file$ + extension$ + "_start.command" + CHR$(34) + ")' &";
PRINT #ff, CHR$(10);
Expand Down Expand Up @@ -16181,7 +16181,7 @@ FUNCTION evaluate$ (a2$, typ AS LONG)
o$ = block(i)
u = operatorusage(o$, typ, i$, lhstyp, rhstyp, result)

IF u <> 5 THEN 'not unary
IF u <> 5 AND u <> 6 THEN 'not unary
nonop = 1
IF i = 1 OR evaledblock(i - 1) = 0 THEN
IF i = 1 AND blockn = 1 AND o$ = "-" THEN Give_Error "Expected variable/value after '" + UCASE$(o$) + "'": EXIT FUNCTION 'guess - is neg in this case
Expand Down Expand Up @@ -16298,7 +16298,7 @@ FUNCTION evaluate$ (a2$, typ AS LONG)
END IF

'Reduce floating point values to common base for comparison?
IF isop = 7 THEN 'comparative operator
IF isop = 10 THEN 'comparative (=) operator (check the value if isoperator() is changed!)
'Corrects problems encountered such as:
' S = 2.1
' IF S = 2.1 THEN PRINT "OK" ELSE PRINT "ERROR S PRINTS AS"; S; "BUT IS SEEN BY QB64 AS..."
Expand Down Expand Up @@ -16401,6 +16401,11 @@ FUNCTION evaluate$ (a2$, typ AS LONG)

'STEP 3: apply operator appropriately

IF u = 6 THEN
block(i + 1) = "-(" + i$ + "(" + block(i + 1) + ")" + ")"
block(i) = "": i = i + 1: GOTO operatorapplied
END IF

IF u = 5 THEN
block(i + 1) = i$ + "(" + block(i + 1) + ")"
block(i) = "": i = i + 1: GOTO operatorapplied
Expand Down Expand Up @@ -19055,7 +19060,7 @@ FUNCTION fixoperationorder$ (savea$)
IF lco <> hco THEN
'brackets needed

IF lco = 6 THEN 'NOT exception
IF lco = 9 THEN 'NOT exception (check the value if isoperator() is changed!)
'Step 1: Add brackets as follows ~~~ ( NOT ( ~~~ NOT ~~~ NOT ~~~ NOT ~~~ ))
'Step 2: Recheck line from beginning
IF n = 1 THEN Give_Error "Expected NOT ...": EXIT FUNCTION
Expand Down Expand Up @@ -20837,6 +20842,7 @@ FUNCTION operatorusage (operator$, typ AS LONG, info$, lhs AS LONG, rhs AS LONG,
'3= bracket left and right side with negation and change operator to info$
'4= BINARY NOT l.h.s, then apply operator in info$
'5= UNARY, bracket up rhs, apply operator info$ to left, rebracket again
'6= UNARY, bracket up rhs, apply operator info$ to left, rebracket, negate, rebracket again

'lhs & rhs bit-field values
'1=integeral
Expand Down Expand Up @@ -20905,7 +20911,7 @@ FUNCTION operatorusage (operator$, typ AS LONG, info$, lhs AS LONG, rhs AS LONG,

lhs = 7
IF operator$ = "NOT" THEN info$ = "~": operatorusage = 5: EXIT FUNCTION
IF operator$ = "_NEGATE" OR (qb64prefix_set AND operator$ = "NEGATE") THEN info$ = "!": operatorusage = 5: EXIT FUNCTION
IF operator$ = "_NEGATE" OR (qb64prefix_set AND operator$ = "NEGATE") THEN info$ = "!": operatorusage = 6: EXIT FUNCTION

IF Debug THEN PRINT #9, "INVALID NUMBERIC OPERATOR!": END

Expand Down
65 changes: 0 additions & 65 deletions tests/compile_tests/bool_test/bool_test.bas

This file was deleted.

141 changes: 141 additions & 0 deletions tests/compile_tests/operators_test/op_exp.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
$CONSOLE:ONLY
_DEFINE A-Z AS LONG
OPTION _EXPLICIT

DIM AS LONG x

PRINT 1 OR 2
PRINT 3 AND 1
PRINT NOT 2
PRINT 2 XOR 3
PRINT 10 EQV 5
PRINT 20 IMP 50

PRINT 20 MOD 3
PRINT 2 + 3
PRINT 2 - 3
PRINT 6 / 3
PRINT 7 \ 3
PRINT 7 * 20
PRINT 3 ^ 10

x = 20
PRINT -x

PRINT 2 = 2
PRINT 2 <> 3
PRINT 2 <> 3
PRINT 2 <= 3
PRINT 2 <= 3
PRINT 2 >= 3
PRINT 2 >= 3
PRINT 2 > 3
PRINT 2 < 3

' The left side which has no parens to indicate order should still equal the
' right side which has parens to enforce order.
PRINT (2 ^ 2 * 2) = ((2 ^ 2) * 2)
PRINT (2 ^ 2 + 2) = ((2 ^ 2) + 2)
PRINT (NOT 2 + 3) = (NOT (2 + 3))
PRINT (-2 ^ 2) = (-(2 ^ 2))
PRINT (NOT 2 ^ 3) = (NOT (2 ^ 3))
PRINT (3 * 6 / 2) = ((3 * 6) / 2)
PRINT (3 * 10 \ 3) = ((3 * 10) \ 3)

' Many levels of parens
PRINT (2 ^ (3 * (4 - (2 - (10 / (20 / 2))))))

CONST foo = "foo"
CONST bar = "bar"
PRINT foo + bar

' Combos
x = 1
PRINT NOT (x = 0) AND (x <> -1)
PRINT NOT (x = 0) _ANDALSO (x <> -1)
PRINT _NEGATE (x = 0) AND (x <> -1)
PRINT _NEGATE (x = 0) _ANDALSO (x <> -1)

x = 0
PRINT (3 * 2) + (4 - 2) / (5 ^ 2) < 5 AND NOT (x = 0)
PRINT (3 * 2) + (4 - 2) / (5 ^ 2) < 5 AND _NEGATE (x = 0)

CONST A = -100
CONST B = -10
CONST D = 10
CONST E = 100

' More NOT & _NEGATE tests
x = -1
PRINT NOT A
PRINT NOT D
PRINT NOT x
x = 0
PRINT NOT x
x = 1
PRINT NOT x

x = -1
PRINT _NEGATE A
PRINT _NEGATE D
PRINT _NEGATE x
x = 0
PRINT _NEGATE x
x = 1
PRINT _NEGATE x

x = 1000
PRINT NOT x > 2000 OR E = GetValue(123456)
PRINT NOT x > 2000 AND E <> GetValue(123456)

PRINT NOT x > 2000 _ORELSE E = GetValue(123456)
PRINT NOT x > 2000 _ANDALSO E <> GetValue(123456)

x = 0
x = _NEGATE (_NEGATE (_NEGATE (_NEGATE x)))

IF _NEGATE GetValue(x) THEN
PRINT "_NEGATE: Test passed."
ELSE
PRINT "_NEGATE: Test failed."
END IF

IF GetValue(D) < 0 _ANDALSO GetValue(E) < 0 THEN
PRINT "_ANDALSO: Test failed."
ELSE
PRINT "_ANDALSO: Test passed."
END IF

IF GetValue(A) < 0 _ORELSE GetValue(B) < 0 THEN
PRINT "_ORELSE: Test passed."
ELSE
PRINT "_ORELSE: Test failed."
END IF

x = 0
x = NOT (NOT (NOT (NOT x)))

IF NOT GetValue(x) THEN
PRINT "NOT: Test passed."
ELSE
PRINT "NOT: Test failed."
END IF

IF GetValue(D) < 0 AND GetValue(E) < 0 THEN
PRINT "AND: Test failed."
ELSE
PRINT "AND: Test passed."
END IF

IF GetValue(A) < 0 OR GetValue(B) < 0 THEN
PRINT "OR: Test passed."
ELSE
PRINT "OR: Test failed."
END IF

SYSTEM

FUNCTION GetValue& (x AS LONG)
PRINT "Function called for value:"; x
GetValue = x
END FUNCTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,64 @@
Logical op test:

3
1
-3
1
-16
-5
2
5
-1
2
2
140
59049
-20
-1
-1
-1
-1
-1
0
0
0
-1
-1
-1
-1
-1
-1
-1
-1
512
foobar
-1
-1
-1
-1
0
0
99
-11
0
-1
-2
0
0
0
-1
0
Function called for value: 123456
-1
Function called for value: 123456
-1
-1
Function called for value: 123456
-1
Function called for value: 0
_NEGATE: Test passed.
Function called for value: 10
_ANDALSO: Test passed.
Function called for value:-100
_ORELSE: Test passed.

Bitwise op test:

Function called for value: 0
NOT: Test passed.
Function called for value: 10
Expand Down