I'm currently working on an object-oriented language extension based around dictionaries.
I'm trying to find a way to make it possible to write:
eval(Ball("bounce"), arg1, arg2, ...)or
Ball("bounce", arg1, arg2, ...)I currently store functions as strings, and those references can be called with CALL <reference>. I can pass arguments directly to functions this way, and this works. Now enters THE STACK. To evaluate Ball.bounce, I store some variables to the stack. In a first-class language, I would then execute that function and restore the previous state of the stack. However, in smileBasic, I have not found a way to pass in an unknown number of arguments. This means I have to return a raw string that the user can then call with CALL. Now I have no way to intercept when the call actually takes place to restore the stack state. I'm currently thinking about two ways to fix this and neither is optimal:
- * Generate a range of eval functions, each taking a specific number of parameters - e.g. eval1() to eval22()
I could also make EVAL take a string argument that can be tokenized and passed to the appropriate evalN()
* Add syntactic sugar that replaces the END command of any exported DEF with a call to restore the stack, first.