Skip to content

Commit

Permalink
Add test for _CAST
Browse files Browse the repository at this point in the history
  • Loading branch information
a740g committed Nov 28, 2024
1 parent 0c105be commit 9cc74ee
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/qb64pe.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
141 changes: 141 additions & 0 deletions tests/compile_tests/cast/cast_test.bas
Original file line number Diff line number Diff line change
@@ -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
104 changes: 104 additions & 0 deletions tests/compile_tests/cast/cast_test.output
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9cc74ee

Please sign in to comment.