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

Can't store pointers #1

Open
graypegg opened this issue Feb 12, 2017 · 9 comments
Open

Can't store pointers #1

graypegg opened this issue Feb 12, 2017 · 9 comments

Comments

@graypegg
Copy link

graypegg commented Feb 12, 2017

Would be useful for higher-level programming if Poco was able to reference registers from memory. Currently, reference data types like arrays or hash-maps couldn't be compiled to Poco bytecode because theres no way to call 4x set commands using data from a register.

You might not even have to make a pointer type, maybe use the second argument of 4x as a flag to make the source register act as a pointer, like so:

Init:

Register Value
a d
b 4
c 0
d 0

Byte Code

4xa1b     # Set register at value of ~a to value of ~b

After:

Register Value
a d
b 4
c 0
d 4
@gmisail
Copy link
Owner

gmisail commented Feb 12, 2017

This could be achieved by using 4xa2b, setting the value of the a register to the b register.

@graypegg
Copy link
Author

That only sets the value of ~a to the value of ~b

Would need to be able to set ~a to 'd', then using 4x, set ~d to a value from another cell, BUT if ~a where set to 'c' initally, 4x would set ~c instead. Imagine ~a as a variable that stores the location of the register to change.

Thus you kinda have pointers, which are basically a necessity for doing anything of substance

@gmisail
Copy link
Owner

gmisail commented Feb 12, 2017

You can replace the a and b values to the buffers you want to use.

4xa2d

@graypegg
Copy link
Author

graypegg commented Feb 12, 2017

What if the buffer identifier has to be dynamic? Like it may be 1,2,3,4... etc as the result of a loop

@graypegg
Copy link
Author

graypegg commented Feb 12, 2017

Asking btw because I'm building a Brainf*ck-to-PocoBytecode compiler to test out a generic Brainf*ck compiler I'm making, will need to access a pointer for the current cell in Brainf*ck

@gmisail
Copy link
Owner

gmisail commented Feb 12, 2017

Im not familiar with brainf*ck really, its not really a language you use for what I typically do. The buffer identifier (a, b, c, 1, 4, ...) can be any single character, if thats what you are asking.

@graypegg
Copy link
Author

No one uses brainf*ck for anything :P Just a stupid side-project to get comfortable working on compilers.

I'll make a pull request in a bit, but all I'll be adding is: if the second argument in a 4x command is 1 instead of 2, it does this:

storage[storage[line[1].substring(0, 1)]] = storage[line[1].substring(2, 3)];

(Which uses the value of the first buffer as the buffer identifier for the ACTUAL buffer your setting too. This is similar to a pointer, which is a common part of most close-to-metal languages like C)

instead of this:

storage[line[1].substring(0, 1)] = storage[line[1].substring(2, 3)];

@gmisail
Copy link
Owner

gmisail commented Feb 12, 2017

Okay, I wrote some basic API docs in the wiki if you want to add it.

@gmisail
Copy link
Owner

gmisail commented Feb 13, 2017

For the docs, could you give a quick description of the function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants