diff --git a/source/qb64pe.bas b/source/qb64pe.bas index 1d352b824..02565726d 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 @@ -16491,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$) - ISPOINTER + 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 @@ -16676,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 @@ -16806,11 +16845,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 +17033,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 +17050,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 +17069,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 +17091,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 +17122,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 +17498,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 +17985,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 2cc8cd2aa..7baee98c5 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 = "_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 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 @@ -2629,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 @@ -2704,6 +2713,7 @@ SUB reginternal id.ret = STRINGTYPE - ISPOINTER id.hr_syntax = "MKSMBF$(value!)" regid + clearid id.n = "MKDMBF" id.musthave = "$" @@ -2725,6 +2735,7 @@ SUB reginternal id.ret = STRINGTYPE - ISPOINTER id.hr_syntax = "MKI$(integerVariableOrLiteral%)" regid + clearid id.n = "MKL" id.musthave = "$" @@ -2735,6 +2746,7 @@ SUB reginternal id.ret = STRINGTYPE - ISPOINTER id.hr_syntax = "MKL$(longVariableOrLiteral&)" regid + clearid id.n = "MKS" id.musthave = "$" @@ -2745,6 +2757,7 @@ SUB reginternal id.ret = STRINGTYPE - ISPOINTER id.hr_syntax = "MKS$(singlePrecisionVariableOrLiteral!)" regid + clearid id.n = "MKD" id.musthave = "$" @@ -2755,6 +2768,7 @@ SUB reginternal id.ret = STRINGTYPE - ISPOINTER id.hr_syntax = "MKD$(doublePrecisionVariableOrLiteral#)" regid + clearid id.n = "_MK" id.musthave = "$" @@ -2775,6 +2789,7 @@ SUB reginternal id.ret = SINGLETYPE - ISPOINTER id.hr_syntax = "CVSMBF(stringData$)" regid + clearid id.n = "CVDMBF" id.subfunc = 1 @@ -2794,6 +2809,7 @@ SUB reginternal id.ret = INTEGERTYPE - ISPOINTER id.hr_syntax = "CVI(stringData$)" regid + clearid id.n = "CVL" id.subfunc = 1 @@ -2803,6 +2819,7 @@ SUB reginternal id.ret = LONGTYPE - ISPOINTER id.hr_syntax = "CVL(stringData$)" regid + clearid id.n = "CVS" id.subfunc = 1 @@ -2812,6 +2829,7 @@ SUB reginternal id.ret = SINGLETYPE - ISPOINTER id.hr_syntax = "CVS(stringData$)" regid + clearid id.n = "CVD" id.subfunc = 1 @@ -2821,6 +2839,7 @@ SUB reginternal id.ret = DOUBLETYPE - ISPOINTER id.hr_syntax = "CVD(stringData$)" regid + clearid id.n = "_CV" id.subfunc = 1 @@ -4053,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@" 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 diff --git a/tests/compile_tests/offset/offset_test.bas b/tests/compile_tests/offset/offset_test.bas new file mode 100644 index 000000000..09d2b9510 --- /dev/null +++ b/tests/compile_tests/offset/offset_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 (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/offset/offset_test.output b/tests/compile_tests/offset/offset_test.output new file mode 100644 index 000000000..039f15a71 --- /dev/null +++ b/tests/compile_tests/offset/offset_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 }