1. The stack of values, used for evaluation, local variables and arguments. Note that arguments are treated as local variables. Every element on the value stack will have the format "struct svalue", as defined in interpret.h. The value stack is stored in an array, with limited size. The first push operation will store a value into element 0. Access of arguments and local variables are supposed to be fast, by simply indexing in the value stack using the frame pointer as offset.
Start of stack ----- | Frame pointer-> | Argument number 0 | Argument number 1 | etc. | Local variable number 0 | Local variable number 1 | etc. | Temporary stack values | etc v2. The control stack that contains return addresses, frame pointer etc.
Instruction format:
b0 b1 b2 b3 b0 = F_FUNCTION. b1, b2 = The number of the function to be called. b3 = Number of arguments sent.The F_FUNCTION instruction will also initiate the frame pointer to point to the first argument.
The number of arguments are stored in the 'struct function' which is found using the number of the function and indexing in ob->prog->functions[]; The number of arguments will be adjusted to fit the called function. This is done by either pushing zeroes, or poping excessive arguments. F_FUNCTION will also initiate local variables, by pusing a 0 for each of them.
The called function must ensure that exactly one value remains on the stack when returning. The caller is responsible of deallocating the returned value.
When a function returns, it will use the instruction F_RETURN, which will deallocate all arguments and local variables, and only let the top of stack entry remain. The number of arguments and local variables are stored in the control stack, so that the evaluator knows hoh much to deallocate.
If flag 'extern_call' is set, then the evaluator should return. Otherwise, the evaluator will continue to execute the instruction at the returned address.
Format:
b0 b0 = F_RETURN.
Instruction format:
b1 b1 = The F_ code of the called function.If a variable number of arguments are allowed, then an extra byte will follow the instruction, that states number of actual arguments.
The execution unit will parse number of arguments immediately, regardless of which instruction it is when it is stated that a variable number of arguments are allowed. It will also check soem of the types of the arguments immediately, if it is possible. But never more than the types of the first two arguments.
b1, b2 b1 = F_CALL_OTHER, b2 = number of arguments.
b1, b2, b3 b1 = F_AGGREGATE, (b2,b3) = Size of the array (max 0xffff).
F_CATCH will when executed do setjmp() and call eval_instruction() recursively. That means that a new frame has to be set up.
F_THROW will do a longjmp().
format:
F_THROW, b1, b2, (instructions...), F_RETURNWhere b1,b2 is the address of the instruction after the return instruction.