It may interest you to know I'm working on a "Memory Manager" (yes, that's a terrible name, but what else could I call it?).
Using my library (libraries, actually), you'll be able to:
[Please insert "pseudo-" in front of all the list items.]
Create variables (bools, [unsigned] chars, [unsigned] ints, [unsigned] longs, floats, doubles, strings, and arrays of those types, too)
Set their values (working on it; support for different ops is being added)
Use "hash tables" (working on it)
Parsers of [obfuscated] expressions (... guess; yeah, you're right: I need to finish the hash stuff first)
"Dynamic" memory management
Dynamic typing (if you're insane enough to want this), and duck typing (I just wrote this down for kicks, actually; quack quack)
Function overloading
Possibly operator overloading
And definitely use super advanced kung-fu fighting robot functions
Eventually, I hope to add "pseudo-structs" and "pseudo-classes", but I'm not sure about the implementation. I don't feel like creating an interpreter [do any of us?], but I may have to, if I want such complicated stuff...
If I can get structs down, and function pointers (I figured out part of the implementation for that, but it'll require the user of my library to implement part of it themselves), I may be able to get pseudo-pseudo-recursion, though that's probably the last thing I'll do. (I haven't really thought about this, though, so feel free to criticize me for being an idiot and not seeing that structs and function pointers have nothing to do with pseudo-pseudo-recursion.)
Did I mention you could potentially have some of the most wanted NXC features:
pseudo pointers
pseudo function pointers (actually, no one really wants this but me)
pseudo doubles (64-bit IEEE-754) -- I may need some help with this
It's untested, but when I'm done, I'll need someone to test it. (Unless you want to wait a few more months or a year, since I don't have a NXT to test it with me all the time. )
Stay tuned for possible updates on my blog. Or the forums, since someone needs to test it...If anyone wants the not even 25% done code, feel free to PM me with your email so I can give it to some spammers/advertisers.
Last edited by muntoo on 27 Apr 2011, 00:21, edited 6 times in total.
Commit to LEGO Mindstorms Robotics Stack Exchange: bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Hmmm... Cool...
The pseudo-doubles may be very useful for a project I'm working on, a way to approximate pi on the NXT
Good luck..
-Tim.
ps. even though I don't know what half these things are, I'd be happy to try to test it for you
Can you tell me what the output of the attached program .rxe is? Maybe a screenshot? If it doesn't work, can you try it with the optimization level set to 1, and then 0?
/* A memory manager, in case you lose your brain. But this is NOT a replacement for brain data backup! Be sure to get RipOff's Brain Backup System for only 100 easy payments of $999.99, with a free bottle of RipOff's Really Expensive Ketchup! */
When I run the rxe it says "Deleting memory." after a few seconds and the quits
-Tim\
EDIT: It does this under your rxe, and when I compile it, with optimization levels 0,1,2 (EFW 1.31 compiler 1.2.1r3)
/* A memory manager, in case you lose your brain. But this is NOT a replacement for brain data backup! Be sure to get RipOff's Brain Backup System for only 100 easy payments of $999.99, with a free bottle of RipOff's Really Expensive Ketchup! */
When I run the rxe it says "Deleting memory." after a few seconds and the quits
-Tim\
EDIT: It does this under your rxe, and when I compile it, with optimization levels 0,1,2 (EFW 1.31 compiler 1.2.1r3)
I'm assuming the "deleting memory" bit comes after 2 seconds of program start? Are you sure nothing else comes up?
/* Program Name: "MM_v0_3.nxc"
** This program was created by "muntoo" on March 4, 2011
** Created using BricxCC (by John Hansen) and written in NXC (by John Hansen)
** ( http://bricxcc.sourceforge.net/ )
Description:
A demo program for a memory manager, in case you lose your brain. But this is NOT a replacement for brain data backup! Be sure to get RipOff's Brain Backup System for only 100 easy payments of $999.99, with a free bottle of RipOff's Really Expensive Ketchup!
*/
#include "MM.nxc"
/*
*/
// <ATTENTION> <UNTESTED>
byte MM_get_BYTE(MM_ID /* & is not necessary; pointers! */ id)
{
// <ATTENTION> Possible bug. Do you think using returns like this is *safe*?
return(MM_mem[id.idx]);
}
/*
*/
// <ATTENTION> <UNTESTED>
MM_ID MM_set_BYTE(MM_ID /* & is not necessary; pointers! */ id, byte val)
{
MM_mem[id.idx] = val;
return(id); // return id for no reason
}
MM_ID MM_ID_CPY(MM_ID id)
{
MM_ID retVal;
retVal.type = id.type;
retVal.len = id.len;
retVal.idx = id.idx;
return(retVal);
}
task main()
{
MM_init(); // Initialize Memory Manager; Always call at beginning of program
MM_ID myvar = MM_new(MM_ID_TYPE_BYTE, 5); // Create pointer to an array of 5 elements
MM_ID ptr;
ptr = MM_ID_CPY(myvar);
// <ATTENTION> Possible bug! Does ptr.idx++ really work?
// <ATTENTION> Possible bug! MM_ID ptr = MM_ID_CPY(myvar);
// Set values to random numbers
// Report NXC Bug. Can't use "MM_ID ptr = myvar;"
for(; ptr.idx < (myvar.idx + MM_sizeOf(myvar.type)); ptr.idx++)
{
// MM_set_BYTE(ptr, Random(pow(0x100, MM_sizeOf(myvar.type)) - 1));
MM_set_BYTE(ptr, (ptr.idx - myvar.idx));
}
// <ATTENTION> Possible bug! Does ptr.idx++ really work?
// Display values
for(; ptr.idx < (myvar.idx + MM_sizeOf(myvar.type)); ptr.idx++)
{
NumOut(0, 8 * (myvar.idx + MM_sizeOf(myvar.type) - 1 - ptr.idx), MM_get_BYTE(ptr));
}
Wait(2000);
ClearScreen();
TextOut(0, 0, "Deleting memory...", 0);
MM_delete(myvar); // Mark memory free for this variable
MM_init(); // Reset Memory Manager. Frees all Memory Manager memory.
Wait(5000);
}
Commit to LEGO Mindstorms Robotics Stack Exchange: bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
OT, but how do you get those tabs? I always just cascade my windows when I have multiple programs open in BCC. I would like to have tabs instead (like you).
mattallen37 wrote:OT, but how do you get those tabs? I always just cascade my windows when I have multiple programs open in BCC. I would like to have tabs instead (like you).
Go to Edit->Prefrences->General->Uncheck "Use MDI mode" and restart BricxCC.
-----
@nxtboyiii Thanks for that bug fix.
The fixed code is attached.