duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit c27d3405d6f540afb3aa34da4fac86ee4fcb6469
parent 47b24e972bc0e538ffc8f859666dafc180c78da6
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Fri, 31 Mar 2023 20:31:45 -0400

halcc: callfuncidx()

Diffstat:
Mfs/comp/c/egen.fs | 10+++++++---
Mfs/comp/c/expr.fs | 1-
Mfs/tests/comp/c/cc.fs | 2+-
Mfs/tests/comp/c/test2.c | 13+++++++++++++
4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/fs/comp/c/egen.fs b/fs/comp/c/egen.fs @@ -114,11 +114,11 @@ BOPSCNT wordtbl boptbl ( left right -- res ) \ because it's the callee's responsibility to free its arguments. code _callA branchA, : _funcall ( res -- res ) psoff dup >r >r \ V1=psinitlvl V2=pslvl - dup Result :iscdecl? _assert ')' readChar? not if begin ( funcres tok ) + ')' readChar? not if begin ( funcres tok ) parseExpression Result :?>W psoff V2 - ?dup if dup ps+, neg to+ psoff then CELLSZ to+ V2 ',' readChar? while nextt repeat ')' expectChar then ( funcres ) - dup Result :cdecl# dup CDecl :funcsig? if ( funcres cdecl ) + dup Result cdecl dup CDecl :funcsig? if ( funcres cdecl ) nip dup CDecl offset execute, else swap Result :hal$ A>) @, ['] _callA execute, then ( cdecl ) rdrop r> ( psinitlvl ) to psoff @@ -156,7 +156,11 @@ code _callA branchA, MAXLITSZ Stack :new structbind Stack _list : parseList ( -- res ) _list :empty begin ( ) - nextt parseFactor Result :const# _list :push + nextt parseFactor dup Result type case ( res ) + Result CONST of = Result :const# endof + Result CDECL of = + Result cdecl dup CDecl :isglobal? _assert CDecl offset endof + _err endcase ( n ) _list :push ',' readChar? not until ( tok ) '}' expectChar _list :self Result ARRAY Result :new ; diff --git a/fs/comp/c/expr.fs b/fs/comp/c/expr.fs @@ -66,7 +66,6 @@ struct[ Result : :basesz cdecl CDecl type typesize ; : :unsigned? cdecl typeunsigned? ; - : :cdecl# dup :iscdecl? _assert cdecl ; : :nb) ( halop self -- halop ) dup lvl if drop else :basesz nb) then ; \ Never changes W, never pushes to PS : :hal# ( self -- halop ) dup type case ( self ) diff --git a/fs/tests/comp/c/cc.fs b/fs/tests/comp/c/cc.fs @@ -69,9 +69,9 @@ mydata structget $35 #eq mydata $42 structset mydata 4 + @ $42345678 #eq 42 globstructset globstructget 42 #eq globdata 4 + 16b @ 42 #eq -testend \s 0 callfuncidx 42 #eq 2 callfuncidx 82 #eq +testend \s 33 switchstmt 0 #eq 42 switchstmt 12 #eq 1234 switchstmt 3 #eq diff --git a/fs/tests/comp/c/test2.c b/fs/tests/comp/c/test2.c @@ -277,3 +277,16 @@ void globstructset(short val) { globdata.bar = val; } +// support funcsig ident in global arrays and don't mess up thing when the +// function's return type isn't 4b +typedef short (*ShortRet)(); +static ShortRet globfuncs[3] = {retconst, NULL, variables}; + +int callfuncidx(int idx) { + if (idx != 1) { + return globfuncs[idx](); + } else { + return 0; + } +} +