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