Seems legit, build the AST once the program begins, only update it when the script is changed, each frame traverse the tree.
Debugging without stopping the game loop might be a "fun ( sarcasm )" task, but I'm sure just logging and skipping over further traversal would do the trick.
binbinhfr wrote:Ha ha, you're clever : that's exactly what I'm doing !!!
Well, not clever, just had a similar idea. I had an idea of making a shader language similar to HLSL for SIMD instructions for the CPU. In my scenario, I wouldn't need to change the shader on the fly, so I would just compile it once at the beginning of the program's launch. My ideas was to use a stack with pseudo registers emulating a CPU. It's quite the undertaking and I got confused a lot when trying to implement the emulator and just like all my other projects, it got placed on the back burner until I'm ready to make another attempt.
While I know emulation isn't going to be as fast as just writing straight SIMD code, I find it cumbersome to not only write, but take into account all the facets involved. Since a SIMD register can be 128 to 512 bits wide, for efficiency you need to take into account how many elements you are working with, if working with AVX or higher, you need to clear the upper part of the registers before doing anything that involves using the XMM part of the register, you need to handle alignment during loading and storing ( not a huge deal on modern CPUs, but every little bit helps I'm sure ).
I tried making a template version of this idea, it would be mostly a header only C++ library that developers could piece together. There would be no interpreting nor me having to come up with an AST nor compiling on my part, the C++ compiler would handling it all. The developer would be responsible for assigning registers for input and output, which is kind of where things started falling apart for me.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com