PScript Interpreter – part 3 – Build In Content

PScript would only be able to perform math unless we integrate it to the target platform. In the drawing above I illustrate (1) the build in function “print” and (2) a variable “a”.

Both are declared as a C/C++ struct in a table that point to a function with a specific format that accept a PSCript stack as input. Thes structs are declared on a separate Flash table in C/C++ so that we don’t use SRAM.

Print is a function so we simply parse the call by executing expressions and putting them on the stack. As print accept an endless number of parameters. Each stack entry have a datatype so in the c function we iterate and convert each parameter to text while printing them out.

The variable a is similar – I call a setget function to either set or get the variable. How this is done is up to C code as it might not be an actual variable at all.

The usage of Flash here is important because I usually have limited SRAM, but plenty of Flash. And as function calls create a stack that is released afterwards I only need to account for max stack deptht in SRAM.

To declare names I use static strings which also are on Flash.

To declare parameters I also use a string. ‘.’ means endless list of parameters. ‘*’ means a parameter of any type while ‘A’ to ‘Z’ are specific data types. This makes it easy to define the functions.

Leave a Reply