next up previous contents
Next: Error Handling Up: Write the Functions Previous: Without CMOD   Contents

With CMOD

If we are using CMOD, then we have our skeleton to start writing the code. That is because CMOD generates some code that accesses the stack for us, so we can simply go ahead and write the implementation of the methods in plain C. In the end of each method (or should we call it function, since that is what it actually is) a RETURN statement should be placed. That RETURN removes the arguments from the stack and pushes the return value to it.

There are however two special cases where some extra code has to be written. The first one is when we have a method with optional arguments. Then CMOD does not manage the stack for us, instead we will have to check the args parameter and if the arguments exist, fetch them from the stack, just the same way as it is done when writing modules without CMOD.

The other special case is when we implement a method of type void. At the end of that method we can not use RETURN since there is nothing to return. Instead a pop_n_elems(args) needs to be done in order to keep the stack up to date.


next up previous contents
Next: Error Handling Up: Write the Functions Previous: Without CMOD   Contents
2003-03-04