02-25-2021, 12:43 AM
(This post was last modified: 02-25-2021, 12:45 AM by SamuraiCrow.)
(01-14-2021, 10:05 AM)bbjimmy Wrote: Any progress? this would be great!Sorry about the late response. I'm trying to stick to one project at a time. I'm certain it is possible to do. I just recently got a day job but with some help, I'm certain it's possible. The hard part is finding the time to figure it out.
The central aspect of the runtime consists of an intrusive singly linked list stack as a base class. The activation records of each function extend that base class by creating a record of all the local variables. Because function definitions can't be nested inside each other in Yab, the definitions will be written one after another in the call_stack.h file.
The global definitions extend a class containing the stack pointer and any other static runtime states. This gets written to the heap.h file.
The actual executable code gets written to the main.cpp file. However, since some BASIC commands are not strictly structured ordering we can't use structured C++ as a representation of them and therefore are implemented as labels and branches. The way to do that in C++ is to use a simple state machine. The runtime errors are defined as a list of consecutive constants and every additional state is an extension of that list. The error constants along with all nonvariants of compilation are in a fixed header called yabcompile.h and the additional states are written to states.h as we go.
This only leaves the state machine itself. It will be formatted as a while loop containing a switch statement. The case commands within the switch statement will signify the destination labels. A jump statement is represented by assigning a label constant to the state variable and issuing a break statement. This loops back through the while loop reentering the switch statement. An example main.cpp file might look something like this:
Quote:while (state>endWithoutError) {That should give you an idea how this can work.
switch (state) {
case start:
var1=0;
case do1:
printf("var1=%d\n", var1);
var1=var1+1;
if(var1<10) {
state=do1;
break;
}
state=endWithoutErrors;
break;
}
}