Reputation: 68436
I have just stumbled across picoc and I am very impressed with what it can do - especially the fact that it can be extended by adding new functions etc. It saves me from going down the route of trying to "roll my own" interpreter.
However, I am wondering if there is anyway I can extend picoc by:
Does anyone have any experience of doing this, or can someone provide pointers on how to go about adding new data types and their operator functions to picoc?
[[Edit]]
On further inspection of the code, I believe I have found how to add new data types (by modifying type.c). However, it is still not clear to me how to add arithmetic operators for new data types in picoc. Any help appreciated,
Upvotes: 2
Views: 157
Reputation: 39807
Adding new types can be done in the same manner that you can add new functions. A simple example of this can be had by examining picoc's source stdbool.c
, where you'll find a typedef int bool;
in the StdboolDefs
element. You have to look elsewhere, include.c
, to find the element in use; you'll find it as the "SetupCSource" parameter to an IncludeRegister()
call.
Regarding adding new operators -- of course it's possible but only with a rather invasive change to the picoc library. As @yeputons said, the C language doesn't allow you to change or add operators, so there's no reason for picoc to directly support that.
Upvotes: 1
Reputation: 9238
In general, C does not have operators overloading (while C++ does). Picoc is positioned as very tiny and having only the essentials, so I don't think it provides any extensions for it.
Upvotes: 1