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

Definitions #11

Open
BraedonWooding opened this issue Jul 4, 2018 · 0 comments
Open

Definitions #11

BraedonWooding opened this issue Jul 4, 2018 · 0 comments

Comments

@BraedonWooding
Copy link
Member

I've played around with a way to 'define' objects, defined objects are copied each place they are used. This means that they are extremely similar to #define in C/C++ (that's why I'm calling the definitions).

My current syntax is;

a : T = b
// Or to infer
a := b
// No support for this however since I don't see a need
a : T
// And function calls are fine however see the bottom note
a := B.x()

Where b can be any value such as an array, map, or integral type same as if you were passing an argument into a function. The type is a 'unique' thing since so far no types have really been used except in IR, I would propose either follow the IR type names (int, flt, str, bool, obj, dec) with support for arrays/maps like how you define 'object' maps/arrays i.e. x : [int : []flt] = { 3 : [1.0, 2.5], 5 : [5.3, 3.9] }

We could also expand the names to be like int, float, string, bool, object, decimal

NOTE: function calls

Function calls are a small problem because of the following reason;

  • Should we cache the value of the call at the site of definition and copy that to each call
    Now we may want to do this because of something like this;
A : B
A.x = 2
val := A.x
A.z = val // clearly 2
A.x = 5
// is val 2 or 5?
A.y = val // should this be 2 or 5?

Now originally I would say it would be '2', however by the idea of definitions it would become A.y = A.x which would be 5.

Maybe we support this but also support 'references' which would emulate the second behaviour i.e. 5. This could be done through defining the reference like val := &A.x. This is actually easier to implement as it would just make each x = val into x = A.x instead, where as if you go the value without the & then we would need to make a 'copy' somewhere to use later on, perhaps we could implement this by placing the 'val' as a register (which typically just holds objects but I don't see how it can't hold a non object), which can be indexed as usual by a pushobj (which would push an object from a register onto the stack), this IR probably needs to be implemented anyways but this would require it.

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

No branches or pull requests

1 participant