From 6db75fed919c6a4ec377f394b9617f9c1dc77996 Mon Sep 17 00:00:00 2001 From: Samuel Gomes Date: Wed, 27 Nov 2024 08:39:34 +0530 Subject: [PATCH 1/4] Implement _CLngPtr --- source/subs_functions/subs_functions.bas | 10 +++++- .../syntax_highlighter_list.bas | 2 +- tests/compile_tests/clngptr/clngptr_test.bas | 33 +++++++++++++++++++ .../compile_tests/clngptr/clngptr_test.output | 2 ++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/compile_tests/clngptr/clngptr_test.bas create mode 100644 tests/compile_tests/clngptr/clngptr_test.output diff --git a/source/subs_functions/subs_functions.bas b/source/subs_functions/subs_functions.bas index 2cc8cd2aa..9df877f12 100644 --- a/source/subs_functions/subs_functions.bas +++ b/source/subs_functions/subs_functions.bas @@ -87,12 +87,20 @@ SUB reginternal clearid id.n = "_Continue": id.subfunc = 2: id.callname = "sub_stub": regid + clearid + id.n = "_CLngPtr" + id.subfunc = 1 + id.args = 1 + id.arg = MKL$(UOFFSETTYPE - ISPOINTER) + id.ret = UINTEGER64TYPE - ISPOINTER + id.hr_syntax = "_CLngPtr(offsetValue)" + regid + clearid id.n = "_IIf" id.subfunc = 1 id.args = 3 id.arg = MKL$(OFFSETTYPE - ISPOINTER) + MKL$(STRINGTYPE - ISPOINTER) + MKL$(STRINGTYPE - ISPOINTER) ' overridden in qb64pe.bas - id.specialformat = "?,?,?" id.ret = STRINGTYPE - ISPOINTER ' overridden in qb64pe.bas id.hr_syntax = "_IIF(expression, truePart, falsePart)" regid diff --git a/source/subs_functions/syntax_highlighter_list.bas b/source/subs_functions/syntax_highlighter_list.bas index 180fc1650..fe2b27e8e 100644 --- a/source/subs_functions/syntax_highlighter_list.bas +++ b/source/subs_functions/syntax_highlighter_list.bas @@ -20,7 +20,7 @@ listOfKeywords$ = listOfKeywords$ +_ ' [C] - Keywords alphabetical (1st line = QB64, 2nd line = QB4.5, 3rd line = OpenGL) listOfKeywords$ = listOfKeywords$ +_ -"_CAPSLOCK@_CEIL@_CINP@_CLEAR@_CLEARCOLOR@_CLIP@_CLIPBOARD$@_CLIPBOARDIMAGE@_CLOCKWISE@_COLORCHOOSERDIALOG@_COMMANDCOUNT@_CONNECTED@_CONNECTIONADDRESS@_CONNECTIONADDRESS$@_CONSOLE@_CONSOLECURSOR@_CONSOLEFONT@_CONSOLEINPUT@_CONSOLETITLE@_CONTINUE@_CONTROLCHR@_COPYIMAGE@_COPYPALETTE@_COSH@_COT@_COTH@_CRC32@_CSC@_CSCH@_CV@_CWD$@" +_ +"_CAPSLOCK@_CEIL@_CINP@_CLEAR@_CLEARCOLOR@_CLIP@_CLIPBOARD$@_CLIPBOARDIMAGE@_CLNGPTR@_CLOCKWISE@_COLORCHOOSERDIALOG@_COMMANDCOUNT@_CONNECTED@_CONNECTIONADDRESS@_CONNECTIONADDRESS$@_CONSOLE@_CONSOLECURSOR@_CONSOLEFONT@_CONSOLEINPUT@_CONSOLETITLE@_CONTINUE@_CONTROLCHR@_COPYIMAGE@_COPYPALETTE@_COSH@_COT@_COTH@_CRC32@_CSC@_CSCH@_CV@_CWD$@" +_ "CALL@CALLS@CASE@CDBL@CDECL@CHAIN@CHDIR@CHR$@CINT@CIRCLE@CLEAR@CLNG@CLOSE@CLS@COLOR@COM@COMMAND$@COMMON@CONSOLE@CONST@COS@CSNG@CSRLIN@CUSTOMTYPE@CVD@CVDMBF@CVI@CVL@CVS@CVSMBF@" +_ "_GLCALLLIST@_GLCALLLISTS@_GLCLEAR@_GLCLEARACCUM@_GLCLEARCOLOR@_GLCLEARDEPTH@_GLCLEARINDEX@_GLCLEARSTENCIL@_GLCLIPPLANE@_GLCOLOR3B@_GLCOLOR3BV@_GLCOLOR3D@_GLCOLOR3DV@_GLCOLOR3F@_GLCOLOR3FV@_GLCOLOR3I@_GLCOLOR3IV@_GLCOLOR3S@_GLCOLOR3SV@_GLCOLOR3UB@_GLCOLOR3UBV@_GLCOLOR3UI@_GLCOLOR3UIV@_GLCOLOR3US@_GLCOLOR3USV@_GLCOLOR4B@_GLCOLOR4BV@_GLCOLOR4D@_GLCOLOR4DV@_GLCOLOR4F@_GLCOLOR4FV@_GLCOLOR4I@_GLCOLOR4IV@_GLCOLOR4S@_GLCOLOR4SV@_GLCOLOR4UB@_GLCOLOR4UBV@_GLCOLOR4UI@_GLCOLOR4UIV@_GLCOLOR4US@_GLCOLOR4USV@_GLCOLORMASK@_GLCOLORMATERIAL@_GLCOLORPOINTER@_GLCOPYPIXELS@_GLCOPYTEXIMAGE1D@_GLCOPYTEXIMAGE2D@_GLCOPYTEXSUBIMAGE1D@_GLCOPYTEXSUBIMAGE2D@_GLCULLFACE@" diff --git a/tests/compile_tests/clngptr/clngptr_test.bas b/tests/compile_tests/clngptr/clngptr_test.bas new file mode 100644 index 000000000..8b39a884b --- /dev/null +++ b/tests/compile_tests/clngptr/clngptr_test.bas @@ -0,0 +1,33 @@ +$CONSOLE:ONLY +OPTION _EXPLICIT + +DIM myArray(1 TO 10) AS LONG +DIM i AS LONG + +FOR i = LBOUND(myArray) TO UBOUND(myArray) + myArray(i) = 2 ^ i +NEXT i + +PrintArray myArray() + +DIM arrMem AS _MEM: arrMem = _MEM(myArray()) + +FOR i = 0 TO (_CLNGPTR(arrMem.SIZE) \ _SIZE_OF_LONG) - 1 + _MEMPUT arrMem, arrMem.OFFSET + (i * _SIZE_OF_LONG), i + 1 AS LONG +NEXT i + +_MEMFREE arrMem + +PrintArray myArray() + +SYSTEM + +SUB PrintArray (arr() AS LONG) + DIM i AS LONG + + PRINT "Array("; LBOUND(arr); "To"; UBOUND(arr); ") = {"; + FOR i = LBOUND(arr) TO UBOUND(arr) + PRINT arr(i); _IIF(i < UBOUND(arr), ",", ""); + NEXT i + PRINT "}" +END SUB diff --git a/tests/compile_tests/clngptr/clngptr_test.output b/tests/compile_tests/clngptr/clngptr_test.output new file mode 100644 index 000000000..039f15a71 --- /dev/null +++ b/tests/compile_tests/clngptr/clngptr_test.output @@ -0,0 +1,2 @@ +Array( 1 To 10 ) = { 2 , 4 , 8 , 16 , 32 , 64 , 128 , 256 , 512 , 1024 } +Array( 1 To 10 ) = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } From f2fe842a420dce42bb658740edca0b366a5c00fa Mon Sep 17 00:00:00 2001 From: Samuel Gomes Date: Thu, 28 Nov 2024 14:05:38 +0530 Subject: [PATCH 2/4] Remove _OFFSET restrictions --- source/qb64pe.bas | 29 ------------------- source/subs_functions/subs_functions.bas | 9 ------ .../syntax_highlighter_list.bas | 2 +- .../offset_test.bas} | 2 +- .../offset_test.output} | 0 5 files changed, 2 insertions(+), 40 deletions(-) rename tests/compile_tests/{clngptr/clngptr_test.bas => offset/offset_test.bas} (91%) rename tests/compile_tests/{clngptr/clngptr_test.output => offset/offset_test.output} (100%) diff --git a/source/qb64pe.bas b/source/qb64pe.bas index 1d352b824..d013f53de 100644 --- a/source/qb64pe.bas +++ b/source/qb64pe.bas @@ -10769,12 +10769,6 @@ DO e$ = evaluate(e2$, sourcetyp) IF Error_Happened THEN GOTO errmes - IF sourcetyp AND ISOFFSET THEN - IF (targettyp AND ISOFFSET) = 0 THEN - IF id2.internal_subfunc = 0 THEN a$ = "Cannot convert _OFFSET type to other types": GOTO errmes - END IF - END IF - IF RTRIM$(id2.callname) = "sub_paint" THEN IF i = 3 THEN IF (sourcetyp AND ISSTRING) THEN @@ -16806,11 +16800,6 @@ FUNCTION evaluatefunc$ (a2$, args AS LONG, typ AS LONG) GOTO evalfuncspecial END IF '_OFFSET - '*_OFFSET exceptions* - IF sourcetyp AND ISOFFSET THEN - IF n$ = "MKSMBF" AND RTRIM$(id2.musthave) = "$" THEN Give_Error "Cannot convert _OFFSET type to other types": EXIT FUNCTION - IF n$ = "MKDMBF" AND RTRIM$(id2.musthave) = "$" THEN Give_Error "Cannot convert _OFFSET type to other types": EXIT FUNCTION - END IF '*special case* IF n$ = "ENVIRON" THEN @@ -16999,7 +16988,6 @@ FUNCTION evaluatefunc$ (a2$, args AS LONG, typ AS LONG) '*special case* IF n$ = "CDBL" THEN - IF (sourcetyp AND ISOFFSET) THEN Give_Error "Cannot convert _OFFSET type to other types": EXIT FUNCTION IF (sourcetyp AND ISSTRING) THEN Give_Error "Expected numeric value": EXIT FUNCTION IF (sourcetyp AND ISREFERENCE) THEN e$ = refer(e$, sourcetyp, 0) IF Error_Happened THEN EXIT FUNCTION @@ -17017,7 +17005,6 @@ FUNCTION evaluatefunc$ (a2$, args AS LONG, typ AS LONG) '*special case* IF n$ = "CSNG" THEN - IF (sourcetyp AND ISOFFSET) THEN Give_Error "Cannot convert _OFFSET type to other types": EXIT FUNCTION IF (sourcetyp AND ISSTRING) THEN Give_Error "Expected numeric value": EXIT FUNCTION IF (sourcetyp AND ISREFERENCE) THEN e$ = refer(e$, sourcetyp, 0) IF Error_Happened THEN EXIT FUNCTION @@ -17037,7 +17024,6 @@ FUNCTION evaluatefunc$ (a2$, args AS LONG, typ AS LONG) '*special case* IF n$ = "CLNG" THEN - IF (sourcetyp AND ISOFFSET) THEN Give_Error "Cannot convert _OFFSET type to other types": EXIT FUNCTION IF (sourcetyp AND ISSTRING) THEN Give_Error "Expected numeric value": EXIT FUNCTION IF (sourcetyp AND ISREFERENCE) THEN e$ = refer(e$, sourcetyp, 0) IF Error_Happened THEN EXIT FUNCTION @@ -17060,7 +17046,6 @@ FUNCTION evaluatefunc$ (a2$, args AS LONG, typ AS LONG) '*special case* IF n$ = "CINT" THEN - IF (sourcetyp AND ISOFFSET) THEN Give_Error "Cannot convert _OFFSET type to other types": EXIT FUNCTION IF (sourcetyp AND ISSTRING) THEN Give_Error "Expected numeric value": EXIT FUNCTION IF (sourcetyp AND ISREFERENCE) THEN e$ = refer(e$, sourcetyp, 0) IF Error_Happened THEN EXIT FUNCTION @@ -17092,7 +17077,6 @@ FUNCTION evaluatefunc$ (a2$, args AS LONG, typ AS LONG) IF n$ = "_MK" THEN mktype = -1 IF mktype THEN IF mktype <> -1 OR curarg = 2 THEN - 'IF (sourcetyp AND ISOFFSET) THEN Give_Error "Cannot convert " + "_OFFSET type to other types": EXIT FUNCTION 'both _MK and trad. process the following qtyp& = 0 IF mktype$ = "%%" THEN ctype$ = "b": qtyp& = BYTETYPE - ISPOINTER @@ -17469,12 +17453,6 @@ FUNCTION evaluatefunc$ (a2$, args AS LONG, typ AS LONG) GOTO dontevaluate END IF '-8 - IF sourcetyp AND ISOFFSET THEN - IF (targettyp AND ISOFFSET) = 0 THEN - IF id2.internal_subfunc = 0 THEN Give_Error "Cannot convert _OFFSET type to other types": EXIT FUNCTION - END IF - END IF - 'note: this is used for functions like STR(...) which accept all types... explicitreference = 0 IF targettyp = -1 THEN @@ -17962,13 +17940,6 @@ FUNCTION evaluatetotyp$ (a2$, targettyp AS LONG) e$ = evaluate(a$, sourcetyp) IF Error_Happened THEN EXIT FUNCTION - 'Offset protection: - IF sourcetyp AND ISOFFSET THEN - IF (targettyp AND ISOFFSET) = 0 AND targettyp >= 0 THEN - Give_Error "Cannot convert _OFFSET type to other types": EXIT FUNCTION - END IF - END IF - '-5 size '-6 offset IF targettyp = -4 OR targettyp = -5 OR targettyp = -6 THEN '? -> byte_element(offset,element size in bytes) diff --git a/source/subs_functions/subs_functions.bas b/source/subs_functions/subs_functions.bas index 9df877f12..f6d071436 100644 --- a/source/subs_functions/subs_functions.bas +++ b/source/subs_functions/subs_functions.bas @@ -87,15 +87,6 @@ SUB reginternal clearid id.n = "_Continue": id.subfunc = 2: id.callname = "sub_stub": regid - clearid - id.n = "_CLngPtr" - id.subfunc = 1 - id.args = 1 - id.arg = MKL$(UOFFSETTYPE - ISPOINTER) - id.ret = UINTEGER64TYPE - ISPOINTER - id.hr_syntax = "_CLngPtr(offsetValue)" - regid - clearid id.n = "_IIf" id.subfunc = 1 diff --git a/source/subs_functions/syntax_highlighter_list.bas b/source/subs_functions/syntax_highlighter_list.bas index fe2b27e8e..180fc1650 100644 --- a/source/subs_functions/syntax_highlighter_list.bas +++ b/source/subs_functions/syntax_highlighter_list.bas @@ -20,7 +20,7 @@ listOfKeywords$ = listOfKeywords$ +_ ' [C] - Keywords alphabetical (1st line = QB64, 2nd line = QB4.5, 3rd line = OpenGL) listOfKeywords$ = listOfKeywords$ +_ -"_CAPSLOCK@_CEIL@_CINP@_CLEAR@_CLEARCOLOR@_CLIP@_CLIPBOARD$@_CLIPBOARDIMAGE@_CLNGPTR@_CLOCKWISE@_COLORCHOOSERDIALOG@_COMMANDCOUNT@_CONNECTED@_CONNECTIONADDRESS@_CONNECTIONADDRESS$@_CONSOLE@_CONSOLECURSOR@_CONSOLEFONT@_CONSOLEINPUT@_CONSOLETITLE@_CONTINUE@_CONTROLCHR@_COPYIMAGE@_COPYPALETTE@_COSH@_COT@_COTH@_CRC32@_CSC@_CSCH@_CV@_CWD$@" +_ +"_CAPSLOCK@_CEIL@_CINP@_CLEAR@_CLEARCOLOR@_CLIP@_CLIPBOARD$@_CLIPBOARDIMAGE@_CLOCKWISE@_COLORCHOOSERDIALOG@_COMMANDCOUNT@_CONNECTED@_CONNECTIONADDRESS@_CONNECTIONADDRESS$@_CONSOLE@_CONSOLECURSOR@_CONSOLEFONT@_CONSOLEINPUT@_CONSOLETITLE@_CONTINUE@_CONTROLCHR@_COPYIMAGE@_COPYPALETTE@_COSH@_COT@_COTH@_CRC32@_CSC@_CSCH@_CV@_CWD$@" +_ "CALL@CALLS@CASE@CDBL@CDECL@CHAIN@CHDIR@CHR$@CINT@CIRCLE@CLEAR@CLNG@CLOSE@CLS@COLOR@COM@COMMAND$@COMMON@CONSOLE@CONST@COS@CSNG@CSRLIN@CUSTOMTYPE@CVD@CVDMBF@CVI@CVL@CVS@CVSMBF@" +_ "_GLCALLLIST@_GLCALLLISTS@_GLCLEAR@_GLCLEARACCUM@_GLCLEARCOLOR@_GLCLEARDEPTH@_GLCLEARINDEX@_GLCLEARSTENCIL@_GLCLIPPLANE@_GLCOLOR3B@_GLCOLOR3BV@_GLCOLOR3D@_GLCOLOR3DV@_GLCOLOR3F@_GLCOLOR3FV@_GLCOLOR3I@_GLCOLOR3IV@_GLCOLOR3S@_GLCOLOR3SV@_GLCOLOR3UB@_GLCOLOR3UBV@_GLCOLOR3UI@_GLCOLOR3UIV@_GLCOLOR3US@_GLCOLOR3USV@_GLCOLOR4B@_GLCOLOR4BV@_GLCOLOR4D@_GLCOLOR4DV@_GLCOLOR4F@_GLCOLOR4FV@_GLCOLOR4I@_GLCOLOR4IV@_GLCOLOR4S@_GLCOLOR4SV@_GLCOLOR4UB@_GLCOLOR4UBV@_GLCOLOR4UI@_GLCOLOR4UIV@_GLCOLOR4US@_GLCOLOR4USV@_GLCOLORMASK@_GLCOLORMATERIAL@_GLCOLORPOINTER@_GLCOPYPIXELS@_GLCOPYTEXIMAGE1D@_GLCOPYTEXIMAGE2D@_GLCOPYTEXSUBIMAGE1D@_GLCOPYTEXSUBIMAGE2D@_GLCULLFACE@" diff --git a/tests/compile_tests/clngptr/clngptr_test.bas b/tests/compile_tests/offset/offset_test.bas similarity index 91% rename from tests/compile_tests/clngptr/clngptr_test.bas rename to tests/compile_tests/offset/offset_test.bas index 8b39a884b..09d2b9510 100644 --- a/tests/compile_tests/clngptr/clngptr_test.bas +++ b/tests/compile_tests/offset/offset_test.bas @@ -12,7 +12,7 @@ PrintArray myArray() DIM arrMem AS _MEM: arrMem = _MEM(myArray()) -FOR i = 0 TO (_CLNGPTR(arrMem.SIZE) \ _SIZE_OF_LONG) - 1 +FOR i = 0 TO (arrMem.SIZE \ _SIZE_OF_LONG) - 1 _MEMPUT arrMem, arrMem.OFFSET + (i * _SIZE_OF_LONG), i + 1 AS LONG NEXT i diff --git a/tests/compile_tests/clngptr/clngptr_test.output b/tests/compile_tests/offset/offset_test.output similarity index 100% rename from tests/compile_tests/clngptr/clngptr_test.output rename to tests/compile_tests/offset/offset_test.output From 0c105bef287625932632cd8c90a6af655d401963 Mon Sep 17 00:00:00 2001 From: Samuel Gomes Date: Thu, 28 Nov 2024 19:49:01 +0000 Subject: [PATCH 3/4] Initial _CAST support --- source/qb64pe.bas | 45 +++++++++++++++++++ source/subs_functions/subs_functions.bas | 22 ++++++++- .../syntax_highlighter_list.bas | 2 +- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/source/qb64pe.bas b/source/qb64pe.bas index d013f53de..09a83e430 100644 --- a/source/qb64pe.bas +++ b/source/qb64pe.bas @@ -16485,6 +16485,32 @@ FUNCTION evaluatefunc$ (a2$, args AS LONG, typ AS LONG) + ' CAST support + IF n$ = "_CAST" THEN + IF curarg = 1 THEN ' data type + castType$ = type2symbol$(e$) + IF Error_Happened THEN EXIT FUNCTION + + SELECT CASE castType$ + CASE "%%", "~%%", "%", "~%", "&", "~&", "&&", "~&&", "%&", "~%&", "!", "#", "##" + typ& = typname2typ(castType$) + IF Error_Happened THEN EXIT FUNCTION + + r$ = r$ + "(" + typ2ctyp(typ&, castType$) + ")" ' both args are not really needed. Oh well! + IF Error_Happened THEN EXIT FUNCTION + + CASE ELSE + Give_Error "_CAST TYPE unsupported" + EXIT FUNCTION + END SELECT + + e$ = "" + nocomma = 1 + + GOTO dontevaluate + END IF + END IF + '*special case CVI,CVL,CVS,CVD,_CV (part #1) IF n$ = "_CV" THEN IF curarg = 1 THEN @@ -16670,6 +16696,25 @@ FUNCTION evaluatefunc$ (a2$, args AS LONG, typ AS LONG) IF Error_Happened THEN EXIT FUNCTION '------------------------------------------------------------------------------------------------------------ + ' CAST support + IF n$ = "_CAST" THEN + IF curarg = 2 THEN ' numeric value + nocomma = 0 + + IF sourcetyp AND ISSTRING THEN + Give_Error "Expected numeric value" + EXIT FUNCTION + END IF + + IF sourcetyp AND ISREFERENCE THEN e$ = refer(e$, sourcetyp, 0) + IF Error_Happened THEN EXIT FUNCTION + + r$ = r$ + "(" + e$ + "))" + + GOTO evalfuncspecial + END IF + END IF + ' IIF support IF n$ = "_IIF" THEN IF curarg = 1 THEN ' expression diff --git a/source/subs_functions/subs_functions.bas b/source/subs_functions/subs_functions.bas index f6d071436..7baee98c5 100644 --- a/source/subs_functions/subs_functions.bas +++ b/source/subs_functions/subs_functions.bas @@ -87,6 +87,15 @@ SUB reginternal clearid id.n = "_Continue": id.subfunc = 2: id.callname = "sub_stub": regid + clearid + id.n = "_Cast" + id.subfunc = 1 + id.args = 2 + id.arg = MKL$(-1) + MKL$(-1) ' overridden in qb64pe.bas + id.ret = -1 ' overridden in qb64pe.bas + id.hr_syntax = "_CAST(numericalType, numericalValue)" + regid + clearid id.n = "_IIf" id.subfunc = 1 @@ -2628,6 +2637,7 @@ SUB reginternal id.secondargmustbe = "Step" id.hr_syntax = "PUT [STEP](column, row), Array([index])[,] [_CLIP] [{PSET|PRESET|AND|OR|XOR}]][, omitcolor]" regid + clearid id.n = "Put" id.subfunc = 2 @@ -2703,6 +2713,7 @@ SUB reginternal id.ret = STRINGTYPE - ISPOINTER id.hr_syntax = "MKSMBF$(value!)" regid + clearid id.n = "MKDMBF" id.musthave = "$" @@ -2724,6 +2735,7 @@ SUB reginternal id.ret = STRINGTYPE - ISPOINTER id.hr_syntax = "MKI$(integerVariableOrLiteral%)" regid + clearid id.n = "MKL" id.musthave = "$" @@ -2734,6 +2746,7 @@ SUB reginternal id.ret = STRINGTYPE - ISPOINTER id.hr_syntax = "MKL$(longVariableOrLiteral&)" regid + clearid id.n = "MKS" id.musthave = "$" @@ -2744,6 +2757,7 @@ SUB reginternal id.ret = STRINGTYPE - ISPOINTER id.hr_syntax = "MKS$(singlePrecisionVariableOrLiteral!)" regid + clearid id.n = "MKD" id.musthave = "$" @@ -2754,6 +2768,7 @@ SUB reginternal id.ret = STRINGTYPE - ISPOINTER id.hr_syntax = "MKD$(doublePrecisionVariableOrLiteral#)" regid + clearid id.n = "_MK" id.musthave = "$" @@ -2774,6 +2789,7 @@ SUB reginternal id.ret = SINGLETYPE - ISPOINTER id.hr_syntax = "CVSMBF(stringData$)" regid + clearid id.n = "CVDMBF" id.subfunc = 1 @@ -2793,6 +2809,7 @@ SUB reginternal id.ret = INTEGERTYPE - ISPOINTER id.hr_syntax = "CVI(stringData$)" regid + clearid id.n = "CVL" id.subfunc = 1 @@ -2802,6 +2819,7 @@ SUB reginternal id.ret = LONGTYPE - ISPOINTER id.hr_syntax = "CVL(stringData$)" regid + clearid id.n = "CVS" id.subfunc = 1 @@ -2811,6 +2829,7 @@ SUB reginternal id.ret = SINGLETYPE - ISPOINTER id.hr_syntax = "CVS(stringData$)" regid + clearid id.n = "CVD" id.subfunc = 1 @@ -2820,6 +2839,7 @@ SUB reginternal id.ret = DOUBLETYPE - ISPOINTER id.hr_syntax = "CVD(stringData$)" regid + clearid id.n = "_CV" id.subfunc = 1 @@ -4052,8 +4072,8 @@ SUB reginternal id.arg = MKL$(STRINGTYPE - ISPOINTER) + MKL$(STRINGTYPE - ISPOINTER) + MKL$(STRINGTYPE - ISPOINTER) id.specialformat = "[?][,[?][,?]]" id.hr_syntax = "_NOTIFYPOPUP [title$][, message$][, iconType$]" - regid + clearid id.n = "_MessageBox" id.subfunc = 2 ' 1 = function, 2 = sub diff --git a/source/subs_functions/syntax_highlighter_list.bas b/source/subs_functions/syntax_highlighter_list.bas index 180fc1650..c8b5576f7 100644 --- a/source/subs_functions/syntax_highlighter_list.bas +++ b/source/subs_functions/syntax_highlighter_list.bas @@ -20,7 +20,7 @@ listOfKeywords$ = listOfKeywords$ +_ ' [C] - Keywords alphabetical (1st line = QB64, 2nd line = QB4.5, 3rd line = OpenGL) listOfKeywords$ = listOfKeywords$ +_ -"_CAPSLOCK@_CEIL@_CINP@_CLEAR@_CLEARCOLOR@_CLIP@_CLIPBOARD$@_CLIPBOARDIMAGE@_CLOCKWISE@_COLORCHOOSERDIALOG@_COMMANDCOUNT@_CONNECTED@_CONNECTIONADDRESS@_CONNECTIONADDRESS$@_CONSOLE@_CONSOLECURSOR@_CONSOLEFONT@_CONSOLEINPUT@_CONSOLETITLE@_CONTINUE@_CONTROLCHR@_COPYIMAGE@_COPYPALETTE@_COSH@_COT@_COTH@_CRC32@_CSC@_CSCH@_CV@_CWD$@" +_ +"_CAPSLOCK@_CAST@_CEIL@_CINP@_CLEAR@_CLEARCOLOR@_CLIP@_CLIPBOARD$@_CLIPBOARDIMAGE@_CLOCKWISE@_COLORCHOOSERDIALOG@_COMMANDCOUNT@_CONNECTED@_CONNECTIONADDRESS@_CONNECTIONADDRESS$@_CONSOLE@_CONSOLECURSOR@_CONSOLEFONT@_CONSOLEINPUT@_CONSOLETITLE@_CONTINUE@_CONTROLCHR@_COPYIMAGE@_COPYPALETTE@_COSH@_COT@_COTH@_CRC32@_CSC@_CSCH@_CV@_CWD$@" +_ "CALL@CALLS@CASE@CDBL@CDECL@CHAIN@CHDIR@CHR$@CINT@CIRCLE@CLEAR@CLNG@CLOSE@CLS@COLOR@COM@COMMAND$@COMMON@CONSOLE@CONST@COS@CSNG@CSRLIN@CUSTOMTYPE@CVD@CVDMBF@CVI@CVL@CVS@CVSMBF@" +_ "_GLCALLLIST@_GLCALLLISTS@_GLCLEAR@_GLCLEARACCUM@_GLCLEARCOLOR@_GLCLEARDEPTH@_GLCLEARINDEX@_GLCLEARSTENCIL@_GLCLIPPLANE@_GLCOLOR3B@_GLCOLOR3BV@_GLCOLOR3D@_GLCOLOR3DV@_GLCOLOR3F@_GLCOLOR3FV@_GLCOLOR3I@_GLCOLOR3IV@_GLCOLOR3S@_GLCOLOR3SV@_GLCOLOR3UB@_GLCOLOR3UBV@_GLCOLOR3UI@_GLCOLOR3UIV@_GLCOLOR3US@_GLCOLOR3USV@_GLCOLOR4B@_GLCOLOR4BV@_GLCOLOR4D@_GLCOLOR4DV@_GLCOLOR4F@_GLCOLOR4FV@_GLCOLOR4I@_GLCOLOR4IV@_GLCOLOR4S@_GLCOLOR4SV@_GLCOLOR4UB@_GLCOLOR4UBV@_GLCOLOR4UI@_GLCOLOR4UIV@_GLCOLOR4US@_GLCOLOR4USV@_GLCOLORMASK@_GLCOLORMATERIAL@_GLCOLORPOINTER@_GLCOPYPIXELS@_GLCOPYTEXIMAGE1D@_GLCOPYTEXIMAGE2D@_GLCOPYTEXSUBIMAGE1D@_GLCOPYTEXSUBIMAGE2D@_GLCULLFACE@" From 9cc74ee867f9f32e1c012706b4fec08e3f34a4fc Mon Sep 17 00:00:00 2001 From: Samuel Gomes Date: Fri, 29 Nov 2024 02:32:01 +0530 Subject: [PATCH 4/4] Add test for _CAST --- source/qb64pe.bas | 2 +- tests/compile_tests/cast/cast_test.bas | 141 ++++++++++++++++++++++ tests/compile_tests/cast/cast_test.output | 104 ++++++++++++++++ 3 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 tests/compile_tests/cast/cast_test.bas create mode 100644 tests/compile_tests/cast/cast_test.output diff --git a/source/qb64pe.bas b/source/qb64pe.bas index 09a83e430..02565726d 100644 --- a/source/qb64pe.bas +++ b/source/qb64pe.bas @@ -16493,7 +16493,7 @@ FUNCTION evaluatefunc$ (a2$, args AS LONG, typ AS LONG) SELECT CASE castType$ CASE "%%", "~%%", "%", "~%", "&", "~&", "&&", "~&&", "%&", "~%&", "!", "#", "##" - typ& = typname2typ(castType$) + typ& = typname2typ(castType$) - ISPOINTER IF Error_Happened THEN EXIT FUNCTION r$ = r$ + "(" + typ2ctyp(typ&, castType$) + ")" ' both args are not really needed. Oh well! diff --git a/tests/compile_tests/cast/cast_test.bas b/tests/compile_tests/cast/cast_test.bas new file mode 100644 index 000000000..15fc261a4 --- /dev/null +++ b/tests/compile_tests/cast/cast_test.bas @@ -0,0 +1,141 @@ +$CONSOLE:ONLY + +OPTION _EXPLICIT + +CONST CF! = 3.141592653589793239 +CONST CI%& = 255 + +TYPE t + f AS SINGLE + i AS _OFFSET +END TYPE + +DIM f AS SINGLE: f = CF +DIM i AS _OFFSET: i = CI + +DIM t AS t +t.f = f +t.i = i + +DIM a(1) AS SINGLE +a(0) = f +a(1) = _CAST(SINGLE, i) + +PRINT _CAST(_BYTE, CF) +PRINT _CAST(_BYTE, CI) +PRINT _CAST(_BYTE, f * 2) +PRINT _CAST(_BYTE, i * 2) +PRINT _CAST(_BYTE, t.f) +PRINT _CAST(_BYTE, t.i) +PRINT _CAST(_BYTE, a(0) * 2) +PRINT _CAST(_BYTE, a(1) * 2) + +PRINT _CAST(_UNSIGNED _BYTE, CF) +PRINT _CAST(_UNSIGNED _BYTE, CI) +PRINT _CAST(_UNSIGNED _BYTE, f * 2) +PRINT _CAST(_UNSIGNED _BYTE, i * 2) +PRINT _CAST(_UNSIGNED _BYTE, t.f) +PRINT _CAST(_UNSIGNED _BYTE, t.i) +PRINT _CAST(_UNSIGNED _BYTE, a(0) * 2) +PRINT _CAST(_UNSIGNED _BYTE, a(1) * 2) + +PRINT _CAST(INTEGER, CF) +PRINT _CAST(INTEGER, CI) +PRINT _CAST(INTEGER, f * 2) +PRINT _CAST(INTEGER, i * 2) +PRINT _CAST(INTEGER, t.f) +PRINT _CAST(INTEGER, t.i) +PRINT _CAST(INTEGER, a(0) * 2) +PRINT _CAST(INTEGER, a(1) * 2) + +PRINT _CAST(_UNSIGNED INTEGER, CF) +PRINT _CAST(_UNSIGNED INTEGER, CI) +PRINT _CAST(_UNSIGNED INTEGER, f * 2) +PRINT _CAST(_UNSIGNED INTEGER, i * 2) +PRINT _CAST(_UNSIGNED INTEGER, t.f) +PRINT _CAST(_UNSIGNED INTEGER, t.i) +PRINT _CAST(_UNSIGNED INTEGER, a(0) * 2) +PRINT _CAST(_UNSIGNED INTEGER, a(1) * 2) + +PRINT _CAST(LONG, CF) +PRINT _CAST(LONG, CI) +PRINT _CAST(LONG, f * 2) +PRINT _CAST(LONG, i * 2) +PRINT _CAST(LONG, t.f) +PRINT _CAST(LONG, t.i) +PRINT _CAST(LONG, a(0) * 2) +PRINT _CAST(LONG, a(1) * 2) + +PRINT _CAST(_UNSIGNED LONG, CF) +PRINT _CAST(_UNSIGNED LONG, CI) +PRINT _CAST(_UNSIGNED LONG, f * 2) +PRINT _CAST(_UNSIGNED LONG, i * 2) +PRINT _CAST(_UNSIGNED LONG, t.f) +PRINT _CAST(_UNSIGNED LONG, t.i) +PRINT _CAST(_UNSIGNED LONG, a(0) * 2) +PRINT _CAST(_UNSIGNED LONG, a(1) * 2) + +PRINT _CAST(_INTEGER64, CF) +PRINT _CAST(_INTEGER64, CI) +PRINT _CAST(_INTEGER64, f * 2) +PRINT _CAST(_INTEGER64, i * 2) +PRINT _CAST(_INTEGER64, t.f) +PRINT _CAST(_INTEGER64, t.i) +PRINT _CAST(_INTEGER64, a(0) * 2) +PRINT _CAST(_INTEGER64, a(1) * 2) + +PRINT _CAST(_UNSIGNED _INTEGER64, CF) +PRINT _CAST(_UNSIGNED _INTEGER64, CI) +PRINT _CAST(_UNSIGNED _INTEGER64, f * 2) +PRINT _CAST(_UNSIGNED _INTEGER64, i * 2) +PRINT _CAST(_UNSIGNED _INTEGER64, t.f) +PRINT _CAST(_UNSIGNED _INTEGER64, t.i) +PRINT _CAST(_UNSIGNED _INTEGER64, a(0) * 2) +PRINT _CAST(_UNSIGNED _INTEGER64, a(1) * 2) + +PRINT _CAST(_OFFSET, CF) +PRINT _CAST(_OFFSET, CI) +PRINT _CAST(_OFFSET, f * 2) +PRINT _CAST(_OFFSET, i * 2) +PRINT _CAST(_OFFSET, t.f) +PRINT _CAST(_OFFSET, t.i) +PRINT _CAST(_OFFSET, a(0) * 2) +PRINT _CAST(_OFFSET, a(1) * 2) + +PRINT _CAST(_UNSIGNED _OFFSET, CF) +PRINT _CAST(_UNSIGNED _OFFSET, CI) +PRINT _CAST(_UNSIGNED _OFFSET, f * 2) +PRINT _CAST(_UNSIGNED _OFFSET, i * 2) +PRINT _CAST(_UNSIGNED _OFFSET, t.f) +PRINT _CAST(_UNSIGNED _OFFSET, t.i) +PRINT _CAST(_UNSIGNED _OFFSET, a(0) * 2) +PRINT _CAST(_UNSIGNED _OFFSET, a(1) * 2) + +PRINT USING "#####.###"; _CAST(SINGLE, CF) +PRINT USING "#####.###"; _CAST(SINGLE, CI) +PRINT USING "#####.###"; _CAST(SINGLE, f * 2) +PRINT USING "#####.###"; _CAST(SINGLE, i * 2) +PRINT USING "#####.###"; _CAST(SINGLE, t.f) +PRINT USING "#####.###"; _CAST(SINGLE, t.i) +PRINT USING "#####.###"; _CAST(SINGLE, a(0) * 2) +PRINT USING "#####.###"; _CAST(SINGLE, a(1) * 2) + +PRINT USING "#####.###"; _CAST(DOUBLE, CF) +PRINT USING "#####.###"; _CAST(DOUBLE, CI) +PRINT USING "#####.###"; _CAST(DOUBLE, f * 2) +PRINT USING "#####.###"; _CAST(DOUBLE, i * 2) +PRINT USING "#####.###"; _CAST(DOUBLE, t.f) +PRINT USING "#####.###"; _CAST(DOUBLE, t.i) +PRINT USING "#####.###"; _CAST(DOUBLE, a(0) * 2) +PRINT USING "#####.###"; _CAST(DOUBLE, a(1) * 2) + +PRINT USING "#####.###"; _CAST(_FLOAT, CF) +PRINT USING "#####.###"; _CAST(_FLOAT, CI) +PRINT USING "#####.###"; _CAST(_FLOAT, f * 2) +PRINT USING "#####.###"; _CAST(_FLOAT, i * 2) +PRINT USING "#####.###"; _CAST(_FLOAT, t.f) +PRINT USING "#####.###"; _CAST(_FLOAT, t.i) +PRINT USING "#####.###"; _CAST(_FLOAT, a(0) * 2) +PRINT USING "#####.###"; _CAST(_FLOAT, a(1) * 2) + +SYSTEM diff --git a/tests/compile_tests/cast/cast_test.output b/tests/compile_tests/cast/cast_test.output new file mode 100644 index 000000000..3e532dfd3 --- /dev/null +++ b/tests/compile_tests/cast/cast_test.output @@ -0,0 +1,104 @@ + 3 +-1 + 6 +-2 + 3 +-1 + 6 +-2 + 3 + 255 + 6 + 254 + 3 + 255 + 6 + 254 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3 + 255 + 6 + 510 + 3.142 + 255.000 + 6.283 + 510.000 + 3.142 + 255.000 + 6.283 + 510.000 + 3.142 + 255.000 + 6.283 + 510.000 + 3.142 + 255.000 + 6.283 + 510.000 + 3.142 + 255.000 + 6.283 + 510.000 + 3.142 + 255.000 + 6.283 + 510.000