Interested in improving this site? Please check the To Do page.
As an example, let's assume you want to kernelize the html.normalizeName function:
- In CodeWarrior, open the kernvelverbs.r file from the rez group in the project window. Scroll down to the bottom of the file to the 'EFP#' resource named 'html'. Add a new line containing 'normalizeName' to the 'html' bundle.
- In Visual Studio, choose File > Open, select kernvelverbs.rc, switch the Open As popup menu from Auto to Text, and open the file. Scroll down to the bottom of the file to the 'EFP_' resource named 'html'. Add a new line containing 'normalizeName' to the 'html' bundle. Make sure to update the counter at the beginning of that bundle so that it correctly indicates the number of items in the bundle.
- In langhtml.c, add a new identifier to the definition of tyhtmlverbtoken. For our example, the canonical name of the identifier would be 'normalizenamefunc'.
- In langhtml.c, add a new handler to the switch statement in htmlfunctionvalue at the bottom of the file. This handler should usually just call a separate function to be implemented in langhtml.c.
- Create the aforementioned new function. It should return a boolean and take just two parameters: a hdltreenode for the parameter list and a pointer to a tyvaluerecord for the return value of the kernel verb. To extract values from the parameter list, use the get[type]param and get[type]value utility functions in langvalue.c. To set up the return value, use the set[type]value functions in langvalue.c. These functions will also push all tyvaluerecords onto the temp stack as neccessary, so you don't have to worry about memory management for the parameters and return values. There are a lot of examples for how to use all these utility functions in langhtml.c.
- When you are done, recompile the app, launch it, and make sure that the new verb shows up in the system.compiler.kernel table structure. Then adapt the html.normalizeName script to call the kernel routine and test it.
If you want actually want to start a whole new category of kernel verbs, you will first have to complete the following steps before adding individual verbs:
- In kernelverbdefs.h, dd a new preprocessor definition for the resource ID of the new verb category.
- In CodeWarrior, open the kernvelverbs.r file from the rez group in the project window. Scroll down to the bottom of the file and add a new 'EFP#' resource.
- In Visual Studio, choose File > Open, select kernvelverbs.rc, switch the Open As popup menu from Auto to Text, and open the file. Scroll down to the bottom of the file and add a new 'EFP_' resource
- Create a new source code file, perhaps named something like langfoo.c or fooverbs.c, and add it to the project files and the version control database.
- In the source code file, create a function similar to htmlfunctionvalue of langhtml.c. It should set up a default value for the return value and then route the function calls to the appropriate kernel verb implementation based on the token parameter.
- In the source code file, create a function similar to htmlinitverbs of langhtml.c. It should call loadfunctionprocessor with the resource ID from step 1 and a pointer to the function defined in the previous step as the parameter.s Make sure this init function is called from shellinit in shell.c.
- At the top of the source code file, add a typedef for an enum that will contain all the possible tokens for the verbs in this new category, similar to tyhtmlverbtoken at the top of langhtml.c.
- Finally, add the individual verbs for the new category, following the procedure outlined above.