Open abhra2020-smart opened 3 years ago
In this implementation there are no pointers (including function pointers), so making it OO is not feasible I'm afraid. But I do think that adding structs is a decent idea.
The structs must have the size known. So when copying it to a variable or parameter, it would make enough space for the struct. Then when copying the struct, it copies every cell of the struct.
The best way to start implementing structs is to make the function/variable compiler have a cell size value. So it can adjust the space between every variable's location on the tape.
When accessing/writing a value from a struct it would point directly to that cell, since the name can't change.
struct Example {
char message[5];
bool working;
};
struct Example test;
test.working = true;
Would just write the value 1 to the 6th cell of the variable.
Could you assign me to this? I want to try to implement this.
What would you recommend to represent ID DOT ID (test.working) in the Node.py?
I think it should be similar to NodeArrayGetElement and NodeArraySetElement (Maybe names should be NodeStructSet and NodeStructGet or something similar) The class should hold the token ID of the struct (e.g. token of "test"), and token ID of the field name (e.g. token of "working") There should be a function (maybe in General.py?) that has input of these two tokens, and an output of index of the cell in which the field value should be Then use get_copy_to_offset_code to do the reading/writing, or something similar
We should also consider whether or not we allow arrays of structs. E.g. arr[i].working=1;
, as this might be tricky
Arrays with structs is planned. Structs in structs is also planned.
I also came up with an idea that the pointer () could make it inherit the same id from that id map. So `int test(struct Example aaaa)` would make aaaa point to the same variable as that was passed in the parameters. The pointers wouldn't have all the functionality but it would have some.
I might need to add more Node types such as NodeStructSetArrayElement
and NodeStructGetArrayElement
. Would this be okay, or should i try to find a way to integrate it into the pre existing nodes?
Nevermind, it would probably be more messy to add new nodes
I might need to add more Node types such as
NodeStructSetArrayElement
andNodeStructGetArrayElement
. Would this be okay, or should i try to find a way to integrate it into the pre existing nodes?
It's your decision :) In my opinion it would be best to use existing code as much as possible, so I would say defining Struct Nodes that will use the Array Nodes If it's too difficult or theres a good reason to define new Nodes then that would be OK too
Ok i got arrays in structs working without adding any extra nodes. I also fixed a small bug that didn't do anything
OO is very hard to make in brainfuck. So I don't think that this is feasible yet.