Skip to content

Commit

Permalink
Merge pull request #581 from a740g/clngptr
Browse files Browse the repository at this point in the history
Remove _OFFSET restrictions and implement _CAST
  • Loading branch information
a740g authored Nov 29, 2024
2 parents bb82976 + 9cc74ee commit c58af66
Show file tree
Hide file tree
Showing 7 changed files with 347 additions and 32 deletions.
74 changes: 45 additions & 29 deletions source/qb64pe.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 21 additions & 2 deletions source/subs_functions/subs_functions.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2704,6 +2713,7 @@ SUB reginternal
id.ret = STRINGTYPE - ISPOINTER
id.hr_syntax = "MKSMBF$(value!)"
regid
clearid
id.n = "MKDMBF"
id.musthave = "$"
Expand All @@ -2725,6 +2735,7 @@ SUB reginternal
id.ret = STRINGTYPE - ISPOINTER
id.hr_syntax = "MKI$(integerVariableOrLiteral%)"
regid
clearid
id.n = "MKL"
id.musthave = "$"
Expand All @@ -2735,6 +2746,7 @@ SUB reginternal
id.ret = STRINGTYPE - ISPOINTER
id.hr_syntax = "MKL$(longVariableOrLiteral&)"
regid
clearid
id.n = "MKS"
id.musthave = "$"
Expand All @@ -2745,6 +2757,7 @@ SUB reginternal
id.ret = STRINGTYPE - ISPOINTER
id.hr_syntax = "MKS$(singlePrecisionVariableOrLiteral!)"
regid
clearid
id.n = "MKD"
id.musthave = "$"
Expand All @@ -2755,6 +2768,7 @@ SUB reginternal
id.ret = STRINGTYPE - ISPOINTER
id.hr_syntax = "MKD$(doublePrecisionVariableOrLiteral#)"
regid
clearid
id.n = "_MK"
id.musthave = "$"
Expand All @@ -2775,6 +2789,7 @@ SUB reginternal
id.ret = SINGLETYPE - ISPOINTER
id.hr_syntax = "CVSMBF(stringData$)"
regid
clearid
id.n = "CVDMBF"
id.subfunc = 1
Expand All @@ -2794,6 +2809,7 @@ SUB reginternal
id.ret = INTEGERTYPE - ISPOINTER
id.hr_syntax = "CVI(stringData$)"
regid
clearid
id.n = "CVL"
id.subfunc = 1
Expand All @@ -2803,6 +2819,7 @@ SUB reginternal
id.ret = LONGTYPE - ISPOINTER
id.hr_syntax = "CVL(stringData$)"
regid
clearid
id.n = "CVS"
id.subfunc = 1
Expand All @@ -2812,6 +2829,7 @@ SUB reginternal
id.ret = SINGLETYPE - ISPOINTER
id.hr_syntax = "CVS(stringData$)"
regid
clearid
id.n = "CVD"
id.subfunc = 1
Expand All @@ -2821,6 +2839,7 @@ SUB reginternal
id.ret = DOUBLETYPE - ISPOINTER
id.hr_syntax = "CVD(stringData$)"
regid
clearid
id.n = "_CV"
id.subfunc = 1
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/subs_functions/syntax_highlighter_list.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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@"
Expand Down
Loading

0 comments on commit c58af66

Please sign in to comment.