Feature: Aliases support #176

Open
opened 2024-05-07 18:21:02 +01:00 by deavmi · 24 comments
Owner

Purpose ✍️

To add support for declaring aliases and then using them. An alias should be declared and have a right-hand-side expression associated with it. Then the MetaProcessor should do the following:

  1. Discover all declared aliases in a given Module
  2. Perform the replacement of all AliasExpressions with the alias's value

Todo :note

  • Implement
    • Ensure everything is working with it (more MCloneable)
    • Basic
    • Nearest replacement
    • Position-order
      • Don't allow the replacement if the alias is declared AFTER you.
  • Add unittests to actually test it out, cloneability etc.
# Purpose ✍️ To add support for declaring aliases and then using them. An _alias_ should be declared and have a right-hand-side expression associated with it. Then the `MetaProcessor` should do the following: 1. Discover all _declared_ aliases in a given `Module` 2. Perform the replacement of all `AliasExpression`s with the alias's value ## Todo :note - [ ] Implement - [ ] Ensure everything is working with it (more `MCloneable`) - [x] Basic - [x] Nearest replacement - [ ] Position-order * Don't allow the replacement if the alias is declared AFTER you. - [x] Add unittests to actually test it out, cloneability etc.
deavmi started working 2024-05-07 18:21:07 +01:00
Author
Owner

Working on this now to see what I can get done.

Working on this now to see what I can get done.
deavmi added reference feature/aliases 2024-05-07 18:27:57 +01:00
deavmi added the
parser
meta
labels 2024-05-07 18:28:03 +01:00
deavmi self-assigned this 2024-05-07 18:28:05 +01:00
deavmi added this to the Parser project 2024-05-07 18:28:12 +01:00
deavmi added this to the Performance and Clarity milestone 2024-05-07 18:28:20 +01:00
Author
Owner

I now have alias declarations. I now need to work on the MetaProcessor to now firstly look up all VariableExpression(s) and then find those with alias names and replace them with the AliasDeclaration's getExpression() result.

I now have alias _declarations_. I now need to work on the `MetaProcessor` to now firstly look up all `VariableExpression`(s) and then find those with alias names and replace them with the `AliasDeclaration`'s `getExpression()` result.
Author
Owner

Okay, alias searching is working. Now for the replacement stratergy.

Okay, alias searching is working. Now for the replacement stratergy.
Author
Owner

It works! 🥓

It works! 🥓
deavmi stopped working 2024-05-07 19:57:50 +01:00
1 hour 36 minutes
deavmi added the due date 2024-05-11 2024-05-07 19:57:56 +01:00
deavmi added spent time 2024-05-07 20:37:11 +01:00
5 minutes
deavmi started working 2024-05-07 20:37:13 +01:00
Author
Owner

This need to sort out places where MCloneable is not implemented etc.

This need to sort out places where `MCloneable` is not implemented etc.
deavmi stopped working 2024-05-07 20:37:30 +01:00
17 seconds
deavmi added spent time 2024-05-07 20:45:30 +01:00
4 minutes
deavmi started working 2024-05-07 20:45:33 +01:00
Author
Owner

This need to sort out places where MCloneable is not implemented etc.

Busy with this now...

> This need to sort out places where `MCloneable` is not implemented etc. Busy with this now...
Author
Owner

This need to sort out places where MCloneable is not implemented etc.

Busy with this now...

Fixed

> > This need to sort out places where `MCloneable` is not implemented etc. > > Busy with this now... Fixed ✅
Author
Owner

Will push code later tonight

Will push code later tonight
deavmi stopped working 2024-05-07 20:48:10 +01:00
2 minutes 37 seconds
deavmi started working 2024-05-08 08:23:29 +01:00
Author
Owner

Oh no it brokey actually, with this cnt() example :(

Oh no it brokey actually, with this `cnt()` example :(
deavmi stopped working 2024-05-08 09:02:47 +01:00
39 minutes 18 seconds
deavmi started working 2024-05-08 09:06:05 +01:00
deavmi stopped working 2024-05-08 09:06:19 +01:00
14 seconds
Author
Owner

It's not replacing for some reason, I feel as though this is some obvious error in the loop but I can't pinpoint it.

It's not replacing for some reason, I feel as though this is some obvious error in the loop but I can't pinpoint it.
deavmi added spent time 2024-05-08 09:28:24 +01:00
30 minutes
Author
Owner

Looks like not being replaced after all 🤔

Looks like not being replaced after all 🤔
Author
Owner

image

![image](/attachments/092496d2-5652-465a-abe0-03b8e92fe49a)
346 KiB
deavmi started working 2024-05-08 11:29:57 +01:00
deavmi added a new dependency 2024-05-08 12:16:53 +01:00
Author
Owner

it is falling through and hitting an MStatementReplaceable of the Expression in VarAss, need to see why that keeps returning true

it is falling through and hitting an `MStatementReplaceable` of the `Expression` in VarAss, need to see why **that** keeps returning `true`
Author
Owner

Ah it is falling into FunctionCall which is not finished yet, and keeps returning true

Ah it is falling into `FunctionCall` which is not finished yet, and keeps returning `true`
Author
Owner

GREAT!

GREAT!
Author
Owner

FunctionCall

  • Made replacement return false for now (ass it is not implemented)
  • Addec MCloneable support
FunctionCall - Made replacement return `false` for now (ass it is not implemented) - Addec `MCloneable` support
Author
Owner

MetaProcessor

  • Re-worked the alias replacement code
MetaProcessor - Re-worked the alias replacement code
deavmi stopped working 2024-05-08 12:48:40 +01:00
1 hour 18 minutes
deavmi started working 2024-05-08 12:49:21 +01:00
deavmi stopped working 2024-05-08 12:49:42 +01:00
21 seconds
deavmi started working 2024-05-08 12:51:52 +01:00
deavmi stopped working 2024-05-08 12:56:12 +01:00
4 minutes 20 seconds
deavmi started working 2024-05-08 12:56:14 +01:00
Author
Owner

Added CI/CD tests and also added it to unittests (for code coverage)

Added CI/CD tests and also added it to unittests (for code coverage)
deavmi stopped working 2024-05-08 12:58:21 +01:00
2 minutes 7 seconds
deavmi started working 2024-05-08 16:48:04 +01:00
Author
Owner

For ordering like this:

alias inner = 1;

int main()
{
	alias inner = 0;
	int i = expr;
	int p = expr;
	int o = inner;
	return i+p+o;
}

We may need to do a first pass to discover all aliases and then sort them. BUT then the context is sort of lacking? Unless we get all parentOf()'s and then distance between containers. Eish!

For ordering like this: ```d alias inner = 1; int main() { alias inner = 0; int i = expr; int p = expr; int o = inner; return i+p+o; } ``` We may need to do a first pass to discover all aliases and then sort them. BUT then the context is sort of lacking? Unless we get all `parentOf()`'s and then distance between containers. Eish!
Author
Owner

For ordering like this:

alias inner = 1;

int main()
{
	alias inner = 0;
	int i = expr;
	int p = expr;
	int o = inner;
	return i+p+o;
}

We may need to do a first pass to discover all aliases and then sort them. BUT then the context is sort of lacking? Unless we get all parentOf()'s and then distance between containers. Eish!

Maybe, I have an idea. We are actually just doing the search not from the right place. Perhaps, on the place of the VarExp, we should call parentOf() and maybe search from there. So anchor it at the reference point of the alias name, not at the call to doAliasProcess(...)

> For ordering like this: > > ```d > alias inner = 1; > > int main() > { > alias inner = 0; > int i = expr; > int p = expr; > int o = inner; > return i+p+o; > } > ``` > > We may need to do a first pass to discover all aliases and then sort them. BUT then the context is sort of lacking? Unless we get all `parentOf()`'s and then distance between containers. Eish! Maybe, I have an idea. We are actually just doing the search not from the right place. Perhaps, on the place of the `VarExp`, we should call `parentOf()` and maybe search from there. So anchor it at the reference point of the alias name, **not** at the call to `doAliasProcess(...)`
Author
Owner

For ordering like this:

alias inner = 1;

int main()
{
	alias inner = 0;
	int i = expr;
	int p = expr;
	int o = inner;
	return i+p+o;
}

We may need to do a first pass to discover all aliases and then sort them. BUT then the context is sort of lacking? Unless we get all parentOf()'s and then distance between containers. Eish!

Maybe, I have an idea. We are actually just doing the search not from the right place. Perhaps, on the place of the VarExp, we should call parentOf() and maybe search from there. So anchor it at the reference point of the alias name, not at the call to doAliasProcess(...)

This looks right at least:

[DEBUG] DeclAlis:  [Alias [name: inner, expr: [integerLiteral: 0 (SIGNED_INTEGER)]], Alias [name: expr, expr: 3 cnt()], Alias [name: inner, expr: [integerLiteral: 1 (SIGNED_INTEGER)]]]
> > For ordering like this: > > > > ```d > > alias inner = 1; > > > > int main() > > { > > alias inner = 0; > > int i = expr; > > int p = expr; > > int o = inner; > > return i+p+o; > > } > > ``` > > > > We may need to do a first pass to discover all aliases and then sort them. BUT then the context is sort of lacking? Unless we get all `parentOf()`'s and then distance between containers. Eish! > > Maybe, I have an idea. We are actually just doing the search not from the right place. Perhaps, on the place of the `VarExp`, we should call `parentOf()` and maybe search from there. So anchor it at the reference point of the alias name, **not** at the call to `doAliasProcess(...)` This looks right at least: ``` [DEBUG] DeclAlis: [Alias [name: inner, expr: [integerLiteral: 0 (SIGNED_INTEGER)]], Alias [name: expr, expr: 3 cnt()], Alias [name: inner, expr: [integerLiteral: 1 (SIGNED_INTEGER)]]] ```
Author
Owner

For ordering like this:

alias inner = 1;

int main()
{
	alias inner = 0;
	int i = expr;
	int p = expr;
	int o = inner;
	return i+p+o;
}

We may need to do a first pass to discover all aliases and then sort them. BUT then the context is sort of lacking? Unless we get all parentOf()'s and then distance between containers. Eish!

Maybe, I have an idea. We are actually just doing the search not from the right place. Perhaps, on the place of the VarExp, we should call parentOf() and maybe search from there. So anchor it at the reference point of the alias name, not at the call to doAliasProcess(...)

This looks right at least:

[DEBUG] DeclAlis:  [Alias [name: inner, expr: [integerLiteral: 0 (SIGNED_INTEGER)]], Alias [name: expr, expr: 3 cnt()], Alias [name: inner, expr: [integerLiteral: 1 (SIGNED_INTEGER)]]]

Found bug, needing to make Program replaceable, did now and looks good

> > > For ordering like this: > > > > > > ```d > > > alias inner = 1; > > > > > > int main() > > > { > > > alias inner = 0; > > > int i = expr; > > > int p = expr; > > > int o = inner; > > > return i+p+o; > > > } > > > ``` > > > > > > We may need to do a first pass to discover all aliases and then sort them. BUT then the context is sort of lacking? Unless we get all `parentOf()`'s and then distance between containers. Eish! > > > > Maybe, I have an idea. We are actually just doing the search not from the right place. Perhaps, on the place of the `VarExp`, we should call `parentOf()` and maybe search from there. So anchor it at the reference point of the alias name, **not** at the call to `doAliasProcess(...)` > > This looks right at least: > > ``` > [DEBUG] DeclAlis: [Alias [name: inner, expr: [integerLiteral: 0 (SIGNED_INTEGER)]], Alias [name: expr, expr: 3 cnt()], Alias [name: inner, expr: [integerLiteral: 1 (SIGNED_INTEGER)]]] > ``` Found bug, needing to make `Program` replaceable, did now and looks good
Author
Owner

Ey! Stuff is coming together. Just really putting a lot of MCloneables in different places.

Ey! Stuff is coming together. Just really putting a lot of `MCloneable`s in different places.
deavmi stopped working 2024-05-08 18:15:11 +01:00
1 hour 27 minutes
Author
Owner

Time for a break now

Time for a break now
deavmi started working 2024-05-10 09:16:49 +01:00
deavmi stopped working 2024-05-10 09:21:28 +01:00
4 minutes 39 seconds
Sign in to join this conversation.
No project
No Assignees
1 Participants
Notifications
Total Time Spent: 5 hours 55 minutes
deavmi
5 hours 55 minutes
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2024-05-11

Reference: tlang/tlang#176
No description provided.