Omnimaga

General Discussion => Technology and Development => Computer Projects and Ideas => Topic started by: yrinfish on July 16, 2011, 05:25:10 am

Title: Designing Happy - OOP
Post by: yrinfish on July 16, 2011, 05:25:10 am
Ok, I'm trying to add OOP to Happy.
I only have a small problem:

Where do I place te objects, and how big?

It is simple with objects like this:

Code: [Select]
type point[2] {
    ubyte x;
    ubyte y;
}

// And in the program or global declarations:

point lol;


I can place this with the other vars after the code, and I know I need 2 bytes of space

But even this approach gives problems:
For example, how do I give it initial values? 

Amd when using the stack, How do I know the amount of space left?

And this gives even more problems:

Code: [Select]
type string[] { // Yup, no native support
    ubyte[] value;
    
    empty create(ubyte[] in) { // empty is a subroutine type
        // Loop and copy the string
    }
}

This one doesn't make sense, because we have the same data twice in RAM.

Code: [Select]
type enemy[10] {
    ubyte x;
    ubyte y;
    ubyte[8] sprite; // The monochtome sprite data

    empty move(sbyte dx, sbyte dy) {
        x = x + dx;
        y = y + dy; // update the pos
    }
}

To make it short:
1. Happy doesn't always know how big it is
2. How can initial values be set?
3. How do I stop the program from corrupting things in RAM, with a ever-growing stack?
Title: Re: Designing Happy - OOP
Post by: Munchor on July 24, 2011, 10:01:24 am
I think you need to create classes for each object you want to be possible to be made. Also, this should be posted in "Computer Programming Help".
Title: Re: Designing Happy - OOP
Post by: Ashbad on July 27, 2011, 06:57:45 pm
1. That's actually a problem, the language should be able to find out how big both base classes and instances should be.
2. You could just make it either strict for abstraction and not allow values defined in class declarations, but only methods and attribute sizes, or have class flags that tell which values need to be copied over to instances and which are just undefined in value at initialization.
3. You could always allocate a chunk of memory (perhaps an application variable?) of a large size like 2048 or 4096 bytes where all primitives and simple objects can go, and set the SP to the last byte of that stack.  Then you don't even need to worry about the built-in way for handling the stack with TI-OS ;)
Title: Re: Designing Happy - OOP
Post by: yrinfish on July 27, 2011, 07:33:40 pm
@Ephan, that would be an awful amount of classes...

@Ashbad, you are great!!! (now please use your old avatar again)