1 /* @(#) pf_cglue.c 98/02/11 1.4 */
2 /***************************************************************
3 ** 'C' Glue support for Forth based on 'C'
6 ** Copyright 1994 3DO, Phil Burk, Larry Polansky, Devid Rosenboom
8 ** The pForth software code is dedicated to the public domain,
9 ** and any third party may reproduce, distribute and modify
10 ** the pForth software code or any derivative works thereof
11 ** without any compensation or license. The pForth software
12 ** code is provided on an "as is" basis without any warranty
13 ** of any kind, including, without limitation, the implied
14 ** warranties of merchantability and fitness for a particular
15 ** purpose and their equivalents under the laws of any jurisdiction.
17 ***************************************************************/
21 typedef cell (*CFunc0)( void );
22 typedef cell (*CFunc1)( cell P1 );
23 typedef cell (*CFunc2)( cell P1, cell P2 );
24 typedef cell (*CFunc3)( cell P1, cell P2, cell P3 );
25 typedef cell (*CFunc4)( cell P1, cell P2, cell P3, cell P4 );
26 typedef cell (*CFunc5)( cell P1, cell P2, cell P3, cell P4, cell P5 );
29 extern void *CustomFunctionTable[];
31 /***************************************************************/
32 int32 CallUserFunction( int32 Index, int32 ReturnMode, int32 NumParams )
34 cell P1, P2, P3, P4, P5;
38 DBUG(("CallUserFunction: Index = %d, ReturnMode = %d, NumParams = %d\n",
39 Index, ReturnMode, NumParams ));
41 CF = CustomFunctionTable[Index];
46 Result = ((CFunc0) CF) ( );
50 Result = ((CFunc1) CF) ( P1 );
55 Result = ((CFunc2) CF) ( P1, P2 );
61 Result = ((CFunc3) CF) ( P1, P2, P3 );
68 Result = ((CFunc4) CF) ( P1, P2, P3, P4 );
76 Result = ((CFunc5) CF) ( P1, P2, P3, P4, P5 );
79 pfReportError("CallUserFunction", PF_ERR_NUM_PARAMS);
83 /* Push result on Forth stack if requested. */
84 if(ReturnMode == C_RETURNS_VALUE) PUSH_DATA_STACK( Result );
89 #if (!defined(PF_NO_INIT)) && (!defined(PF_NO_SHELL))
90 /***************************************************************/
91 Err CreateGlueToC( const char *CName, uint32 Index, int32 ReturnMode, int32 NumParams )
96 CStringToForth( FName, CName );
97 Packed = (Index & 0xFFFF) | 0 | (NumParams << 24) |
99 DBUG(("Packed = 0x%8x\n", Packed));
101 ffCreateSecondaryHeader( FName );
102 CODE_COMMA( ID_CALL_C );