I need a dynamic sized multidimensional array to hold commands read in and help deal with logic flow and command jumps / calls.
I've done things like this myself in the past, and seen many other people and companies do it as well.
It feels powerful, and it's fun to work on, but it's not actually a useful tool for any other people.
If your project is intended to ship to other people, rather than just being for your own enjoyment, I highly recommend against a "custom assembly language."
If you need to support users writing custom code, just use a language that already exists, such as C or C++.
Write a library that contains whatever extra support your specific hardware needs, and make it well documented and easy to call.
The reason this is a much better is that the existing compilers have the bugs worked out, there are tons of references available for the existing languages, and the existing debugging support for existing languages is much better than a single person can build for their own language or "assembly code."
Now, if the reason you need the custom code is because of some pre-existing protocol that already exists, you have to do what you do.
But saying "I can't do this in C" doesn't make sense -- you can do anything that a computer is capable of doing in C. C++ used to compile to C which was then compiled to assembly, and although the language these days compiles straight to assembly, it's very much designed and specified in terms that a C program can implement -- the compiler just helps you by automatically generating a bunch of code that you'd have to write manually in C.
Then again, when you need the smallest code possible, that automatic code may get in the way, and you may be better off with plain C.
So, when you say "I can't do this in C" perhaps what you should do is study the basics of C programming, rather than trying to apply bigger, heavier tools (like C++ or Objective C) to solve the problem.
Parsing a serial protocol, and emulating an instruction stream, should be fairly straightforward for any C programmer. Depending on the specifics of the bytecode you are reading, you can parse straight out of a byte array, or you can store the program as some array of structs that contain pre-parsed instructions.
Similarly, if you have strings literals, binary literals, float values, and so forth, those can go in a big byte array, or they can go into some arrays (tables) of values and be referenced by index or by pointer.
There are tons of ways of doing this, so it sounds to me like the problem really isn't what language you're using.
The particular "G-code-like" code that you show in the last post, should be quite simple to parse in C using either pain pointer arithmetic, or the strtok() function.
If you need a table of line numbers, you can either just scan the program (doing so will be fast!) or you can use a separate table of "line number to array pointer" and binary search through it.
I'd recommend trying two separate implementations:
Store the program as a big char array, and pre-parse where lines live:
Code:
struct Line {
int line;
char const *instr;
};
struct Line lineNumbers[MAX_LINE_NUMBERS];
char program[MAX_PROGRAM_SIZE];
To execute a line of code, simply follow the char pointer, and parse each instruction in the line.
When moving to another line, look up the line number in the table, and start executing that line.
Pre-parse each line into an array of instructions:
Code:
struct Instruction {
uint16_t kind;
uint16_t argument; /* do you need 32-bit values? */
};
struct Instruction program[MAX_INSTRUCTIONS];
To execute, keep an instruction pointer which points to the "next instruction to run."
One of the instructions would be "start of line X"
Each opcode has a value for "kind" and to run an opcode, you switch() on all the kind values (or look up a function pointer in a table of function pointers indexed by kind) and do what's needed.
After executing an opcode, increment the instruction pointer.
To go to another line, simply scan the entire program from the start until you find the opcode "start of line" with the value of the line number you're looking for.