55
55
* rgerhards, 2008-02-19
58
/* forward definiton - thanks to recursive ABNF, we can not avoid at least one ;) */
58
/* forward definition - thanks to recursive ABNF, we can not avoid at least one ;) */
59
59
static rsRetVal expr(expr_t *pThis, ctok_t *tok);
63
function(expr_t *pThis, ctok_t *tok)
66
ctok_token_t *pToken = NULL;
70
ISOBJ_TYPE_assert(pThis, expr);
71
ISOBJ_TYPE_assert(tok, ctok);
73
CHKiRet(ctok.GetToken(tok, &pToken));
74
/* note: pToken is destructed in finalize_it */
76
if(pToken->tok == ctok_LPAREN) {
77
CHKiRet(ctok_token.Destruct(&pToken)); /* token processed, "eat" it */
78
CHKiRet(ctok.GetToken(tok, &pToken)); /* get next one */
80
ABORT_FINALIZE(RS_RET_FUNC_NO_LPAREN);
82
/* we first push all the params on the stack. Then we call the function */
83
while(pToken->tok != ctok_RPAREN) {
85
CHKiRet(ctok.UngetToken(tok, pToken)); /* not for us, so let others process it */
86
CHKiRet(expr(pThis, tok));
87
CHKiRet(ctok.GetToken(tok, &pToken)); /* get next one, needed for while() check */
88
if(pToken->tok == ctok_COMMA) {
89
CHKiRet(ctok_token.Destruct(&pToken)); /* token processed, "eat" it */
90
CHKiRet(ctok.GetToken(tok, &pToken)); /* get next one */
91
if(pToken->tok == ctok_RPAREN) {
92
ABORT_FINALIZE(RS_RET_FUNC_MISSING_EXPR);
98
/* now push number of arguments - this must be on top of the stack */
99
CHKiRet(var.Construct(&pVar));
100
CHKiRet(var.ConstructFinalize(pVar));
101
CHKiRet(var.SetNumber(pVar, iNumArgs));
102
CHKiRet(vmprg.AddVarOperation(pThis->pVmprg, opcode_PUSHCONSTANT, pVar)); /* add to program */
107
ctok_token.Destruct(&pToken); /* "eat" processed token */
63
115
terminal(expr_t *pThis, ctok_t *tok)
86
138
case ctok_FUNCTION:
87
139
dbgoprint((obj_t*) pThis, "function\n");
88
/* TODO: vm: call - well, need to implement that first */
89
ABORT_FINALIZE(RS_RET_NOT_IMPLEMENTED);
140
CHKiRet(function(pThis, tok)); /* this creates the stack call frame */
141
/* ... but we place the call instruction onto the stack ourselfs (because
142
* we have all relevant information)
144
CHKiRet(ctok_token.UnlinkVar(pToken, &pVar));
145
CHKiRet(vmprg.AddVarOperation(pThis->pVmprg, opcode_FUNC_CALL, pVar)); /* add to program */
92
148
dbgoprint((obj_t*) pThis, "MSGVAR\n");
407
463
BEGINObjClassInit(expr, 1, OBJ_IS_CORE_MODULE) /* class, version */
408
464
/* request objects we use */
465
CHKiRet(objUse(var, CORE_COMPONENT));
409
466
CHKiRet(objUse(vmprg, CORE_COMPONENT));
410
467
CHKiRet(objUse(var, CORE_COMPONENT));
411
468
CHKiRet(objUse(ctok_token, CORE_COMPONENT));