Well, so far I’ve got a few of the basic types for Memory Manager tested and working. (BYTE, CHAR, INT, UINT
.) A few more should be implemented soon. (LONG, ULONG, FLOAT
.)
(You can download the latest revision here.)
After that, I’ll need [someone] to test MM_convert()
; this will allow you to convert between different types:
MM_ID idf = MM_new(MM_ID_TYPE_FLOAT);
MM_ID idl = MM_convert(idf, MM_ID_TYPE_LONG, false);
(The last false
parameter specifies that you don’t want idf
‘s memory to be automatically deleted.)
Another thing I’m working on is MM_op()
. It will allow you to execute operations:
// int a, b;
MM_ID a = MM_new(MM_ID_TYPE_INT);
MM_ID b = MM_new(MM_ID_TYPE_INT);
// a = 4; b = 2;
MM_set_INT(a, 4);
MM_set_INT(b, 2);
// answer = a + b;
MM_ID answer = MM_op2(a, MM_OP_ADD, b);
Sure, you can always MM_get()
them, and manually execute the operations, but that’s no fun! 🙂
Actually, all of this should be hidden behind a “parser” (it’s more like an interpreter), so you won’t have to worry about it at all; you’ll simply call MM_parse()
to do all the work for you. You’ll just need to input a string with the code into the function. This is what I’m going for:
MM_parse(" \
long a = 2; \
double pi = 3.14; \
double d = a * pi;");
float diameter = MM_parse_get_FLOAT("d");
NumOut(0, 0, diameter, 0);
As you can see, all the type conversions like long
to double
are handled “implicitly” (although I’ll add explicit functionality too, of course). All the memory allocation/operations/etc are handled for you, as if you were programming in NXC… inside NXC. You’ll be able to integrate your code into itself (does that make any sense?). I may also add support for a compiler directive (MM_PARSE_SYSTEM
) which will allow you to execute “system commands” like NumOut()
inside the parser.
If you’re worried about all that typing, you can always use #define
s to make the function names shorter:
#define p(str) MM_parse(str)
#define pgfloat(str) MM_parse_get_float(str)
p(" \
long a = 2; \
double pi = 3.14; \
double d = a * pi;");
float diameter = pgfloat("d");
NumOut(0, 0, diameter, 0);
I could use some help in testing. (I don’t have access to a NXT most of the time.) I’ll post the files to test on this Mindboards thread.
Like this:
Like Loading...
Posted in LEGO Mindstorms NXT
Tags: LEGO, Memory Manager, Mindstorms, NXC, NXT