Skip to content

Commit a3302be

Browse files
committed
Allow PNut v51 on method pointers
1 parent 012080a commit a3302be

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

frontends/common.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,22 +1029,26 @@ ERROR_UNKNOWN_SYMBOL(AST *ast)
10291029
}
10301030

10311031
AST *
1032-
GenericFunctionPtr(int numresults)
1032+
GenericFunctionPtr(AST *result_type)
10331033
{
10341034
AST *fptr = NULL;
1035-
AST *exprlist = NULL;
10361035

1037-
if (numresults == 0) {
1038-
exprlist = ast_type_void;
1039-
} else if (numresults == 1) {
1040-
exprlist = NULL;
1041-
} else {
1042-
while (numresults > 0) {
1043-
exprlist = NewAST(AST_TUPLE_TYPE, NULL, exprlist);
1044-
--numresults;
1036+
if (result_type && result_type->kind == AST_INTEGER) {
1037+
int numresults = result_type->d.ival;
1038+
AST *exprlist;
1039+
if (numresults == 0) {
1040+
exprlist = ast_type_void;
1041+
} else if (numresults == 1) {
1042+
exprlist = NULL;
1043+
} else {
1044+
while (numresults > 0) {
1045+
exprlist = NewAST(AST_TUPLE_TYPE, NULL, exprlist);
1046+
--numresults;
1047+
}
10451048
}
1049+
result_type = exprlist;
10461050
}
1047-
fptr = NewAST(AST_FUNCTYPE, exprlist, NULL);
1051+
fptr = NewAST(AST_FUNCTYPE, result_type, NULL);
10481052
fptr = NewAST(AST_PTRTYPE, fptr, NULL);
10491053
return fptr;
10501054
}
@@ -1086,7 +1090,7 @@ Init()
10861090
ast_type_string = NewAST(AST_PTRTYPE, NewAST(AST_MODIFIER_CONST, ast_type_byte, NULL), NULL);
10871091

10881092
// a generic function returning a single (unknown) value
1089-
ast_type_generic_funcptr = GenericFunctionPtr(1);
1093+
ast_type_generic_funcptr = GenericFunctionPtr(AstInteger(1));
10901094

10911095
// a generic function for Spin2 SEND type functionality
10921096
ast_type_sendptr = NewAST(AST_MODIFIER_SEND_ARGS,
@@ -1097,7 +1101,7 @@ Init()
10971101
ast_type_long, NULL)),
10981102
NULL),
10991103
NULL);
1100-
ast_type_recvptr = GenericFunctionPtr(1);
1104+
ast_type_recvptr = GenericFunctionPtr(AstInteger(1));
11011105

11021106
initSpinLexer(gl_p2);
11031107

frontends/spin/spin.y

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,11 @@ AST *ExpandCEscapes(AST *str) {
197197
return elist;
198198
}
199199

200-
// in common.c
201-
extern AST *GenericFunctionPtr(int numresults);
202-
203200
static AST *
204201
MakeFunccall(AST *func, AST *params, AST *numresults)
205202
{
206-
if (numresults && numresults->kind == AST_INTEGER) {
207-
int paramcount;
208-
paramcount = numresults->d.ival;
209-
func = NewAST(AST_CAST, GenericFunctionPtr(paramcount), func);
203+
if (numresults) {
204+
func = NewAST(AST_CAST, GenericFunctionPtr(numresults), func);
210205
}
211206
return NewAST(AST_FUNCCALL, func, params);
212207
}
@@ -2310,6 +2305,11 @@ opt_numrets:
23102305
{ $$ = NULL; }
23112306
| ':' SP_NUM
23122307
{ $$ = $2; }
2308+
| ':' SP_TYPENAME
2309+
{
2310+
AST *typ = $2;
2311+
$$ = typ;
2312+
}
23132313
;
23142314

23152315
funccall:

spinc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Spin to C/C++ converter
3-
* Copyright 2011-2024 Total Spectrum Software Inc.
3+
* Copyright 2011-2025 Total Spectrum Software Inc.
44
* main header file
55
*/
66

@@ -72,4 +72,7 @@ AST *BuildDebugList(AST *exprlist, AST *dbgmask);
7272
// convert AST debug list into printf
7373
AST *CreatePrintfDebug(AST *exprlist, AST *dbgmask);
7474

75+
// in common.c
76+
AST *GenericFunctionPtr(AST *result_type);
77+
7578
#endif

0 commit comments

Comments
 (0)