From 2e0e356584559b1a45bce430f9a92485b5763eac Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 20 Feb 2008 17:08:27 +0000 Subject: used new classes in expr.c --- vmprg.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'vmprg.c') diff --git a/vmprg.c b/vmprg.c index 44b403f8..d8795b3b 100644 --- a/vmprg.c +++ b/vmprg.c @@ -65,13 +65,53 @@ CODESTARTobjDestruct(vmprg) ENDobjDestruct(vmprg) +/* destructor for the vmop object */ +BEGINobjDebugPrint(vmprg) /* be sure to specify the object type also in END and CODESTART macros! */ + vmop_t *pOp; +CODESTARTobjDebugPrint(vmprg) + dbgoprint((obj_t*) pThis, "program contents:\n"); + for(pOp = pThis->vmopRoot ; pOp != NULL ; pOp = pOp->pNext) { + vmopDebugPrint(pOp); + } +ENDobjDebugPrint(vmprg) + + +/* this is a shortcut for high-level callers. It creates a new vmop, sets its + * parameters and adds it to the program - all in one big step. If there is no + * var associated with this operation, the caller can simply supply NULL as + * pVar. + */ +rsRetVal +vmprgAddVarOperation(vmprg_t *pThis, opcode_t opcode, var_t *pVar) +{ + DEFiRet; + vmop_t *pOp; + + ISOBJ_TYPE_assert(pThis, vmprg); + + /* construct and fill vmop */ + CHKiRet(vmopConstruct(&pOp)); + CHKiRet(vmopConstructFinalize(pOp)); + CHKiRet(vmopConstructFinalize(pOp)); + CHKiRet(vmopSetOpcode(pOp, opcode)); + if(pVar != NULL) + CHKiRet(vmopSetVar(pOp, pVar)); + + /* and add it to the program */ + CHKiRet(vmprgAddOperation(pThis, pOp)); + +finalize_it: + RETiRet; +} + + /* add an operation (instruction) to the end of the current program. This * function is expected to be called while creating the program, but never * again after this is done and it is being executed. Results are undefined if * it is called after execution. */ rsRetVal -addOperation(vmprg_t *pThis, vmop_t *pOp) +vmprgAddOperation(vmprg_t *pThis, vmop_t *pOp) { DEFiRet; @@ -94,6 +134,7 @@ addOperation(vmprg_t *pThis, vmop_t *pOp) * rgerhards, 2008-02-19 */ BEGINObjClassInit(vmprg, 1) /* class, version */ + OBJSetMethodHandler(objMethod_DEBUGPRINT, vmprgDebugPrint); OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, vmprgConstructFinalize); ENDObjClassInit(vmprg) -- cgit