Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support structs #30

Open
abhra2020-smart opened this issue Feb 22, 2021 · 11 comments · May be fixed by #55
Open

Support structs #30

abhra2020-smart opened this issue Feb 22, 2021 · 11 comments · May be fixed by #55
Assignees
Labels
enhancement New feature or request

Comments

@abhra2020-smart
Copy link
Contributor

No description provided.

@NeeEoo
Copy link
Contributor

NeeEoo commented Feb 22, 2021

OO is very hard to make in brainfuck. So I don't think that this is feasible yet.

@elikaski
Copy link
Owner

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.

@NeeEoo
Copy link
Contributor

NeeEoo commented Feb 22, 2021

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.

@elikaski elikaski changed the title Add classes (I know C does not support OOP, but why not make it C++?) Support structs Feb 22, 2021
@elikaski elikaski added the enhancement New feature or request label Mar 9, 2021
@NeeEoo NeeEoo mentioned this issue Mar 11, 2021
@NeeEoo
Copy link
Contributor

NeeEoo commented Apr 3, 2021

Could you assign me to this? I want to try to implement this.

@NeeEoo
Copy link
Contributor

NeeEoo commented Apr 3, 2021

What would you recommend to represent ID DOT ID (test.working) in the Node.py?

@elikaski
Copy link
Owner

elikaski commented Apr 3, 2021

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

@NeeEoo
Copy link
Contributor

NeeEoo commented Apr 3, 2021

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.

@NeeEoo
Copy link
Contributor

NeeEoo commented Apr 4, 2021

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?

@NeeEoo
Copy link
Contributor

NeeEoo commented Apr 4, 2021

Nevermind, it would probably be more messy to add new nodes

@elikaski
Copy link
Owner

elikaski commented Apr 4, 2021

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?

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

@NeeEoo
Copy link
Contributor

NeeEoo commented Apr 4, 2021

Ok i got arrays in structs working without adding any extra nodes. I also fixed a small bug that didn't do anything

@NeeEoo NeeEoo linked a pull request Apr 5, 2021 that will close this issue
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants