How to add new kernel verbs

How To Add New Verbs 

As an example, let's assume you want to kernelize the html.normalizeName function:

  1. 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.

  2. 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.

  3. In langhtml.c, add a new identifier to the definition of tyhtmlverbtoken. For our example, the canonical name of the identifier would be 'normalizenamefunc'.

  4. 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.

  5. 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.

  6. 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.


How To Add New Verb Categories 

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:

  1. In kernelverbdefs.h, dd a new preprocessor definition for the resource ID of the new verb category.

  2. 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.

  3. 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

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. Finally, add the individual verbs for the new category, following the procedure outlined above.


Discuss