diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2009-03-10 17:37:13 +0100 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2009-03-10 17:37:13 +0100 |
commit | e8499c6d33d09f6d8b42df72da1661be0ef0f088 (patch) | |
tree | 577caaba6912f8f88f8bc29b4105eafe44fd4024 /runtime/vmop.h | |
parent | f67cf99ee5cd88bda499aa52d6008bb7d4afe483 (diff) | |
download | rsyslog-e8499c6d33d09f6d8b42df72da1661be0ef0f088.tar.gz rsyslog-e8499c6d33d09f6d8b42df72da1661be0ef0f088.tar.xz rsyslog-e8499c6d33d09f6d8b42df72da1661be0ef0f088.zip |
initial implementation of RainerScript functions & strlen()
- implemented function support in RainerScript. That means the engine
parses and compile functions, as well as executes a few build-in
ones. Dynamic loading and registration of functions is not yet
supported - but we now have a good foundation to do that later on.
NOTE: nested function calls are not yet supported due to a design
issue with the function call VM instruction set design.
- implemented the strlen() RainerScript function
Diffstat (limited to 'runtime/vmop.h')
-rw-r--r-- | runtime/vmop.h | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/runtime/vmop.h b/runtime/vmop.h index c3d5d5f4..938b08fd 100644 --- a/runtime/vmop.h +++ b/runtime/vmop.h @@ -59,17 +59,44 @@ typedef enum { /* do NOT start at 0 to detect uninitialized types after calloc( opcode_PUSHMSGVAR = 1002, /* requires var operand */ opcode_PUSHCONSTANT = 1003, /* requires var operand */ opcode_UNARY_MINUS = 1010, - opcode_END_PROG = 1011 + opcode_FUNC_CALL = 1012, + opcode_END_PROG = 2000 } opcode_t; +/* Additional doc, operation specific + + FUNC_CALL + All parameter passing is via the stack. Parameters are placed onto the stack in reverse order, + that means the last parameter is on top of the stack, the first at the bottom location. + At the actual top of the stack is the number of parameters. This permits functions to be + called with variable number of arguments. The function itself is responsible for poping + the right number of parameters of the stack and complaining if the number is incorrect. + On exit, a single return value must be pushed onto the stack. The FUNC_CALL operation + is generic. Its pVar argument contains the function name string (TODO: very slow, make + faster in later releases). + + Sample Function call: sampleFunc(p1, p2, p3) ; returns number 4711 (sample) + Stacklayout on entry (order is top to bottom): + 3 + p3 + p2 + p1 + ... other vars ... + + Stack on exit + 4711 + ... other vars ... + + */ + + /* the vmop object */ typedef struct vmop_s { BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */ opcode_t opcode; union { - var_t *pVar; - /* TODO: add function pointer */ + var_t *pVar; /* for function call, this is the name (string) of function to be called */ } operand; struct vmop_s *pNext; /* next operation or NULL, if end of program (logically this belongs to vmprg) */ } vmop_t; |