Make preLoopStatement a part of the for-loops body #78

Closed
opened 2023-01-08 12:09:42 +00:00 by deavmi · 2 comments
Owner

We need to be able to lookup any definitions made in it, such that if we have a for loop such as:

for(int idx; idx < 10; idx++)
{
	... idx=...
}

We can properly resolve idx. I guess it is fine if we effectively make it the first statement of the body. We will, of course need to manage that such that we don't place it in the body when doing code-emit for example. Because then we will generate C code which repeatedly pushes and pops from stack when it should only push once, loop and then pop when the for loop goes out of scope (i.e. we finish all iterations of the for loop). This can be accomplished by assuming there is always one body instruction and then in codegen we always tailPop() it, reverse and take the first and embed it correctly.

Todo

  • The above
  • Marking whether there even is a preloop statement
  • Marking whether there even is a post-iteration statement
We need to be able to lookup any definitions made in it, such that if we have a for loop such as: ```d for(int idx; idx < 10; idx++) { ... idx=... } ``` We can properly resolve `idx`. I guess it is fine if we effectively make it the first statement of the body. We will, of course need to manage that such that we don't place it in the body when doing code-emit for example. Because then we will generate C code which repeatedly pushes and pops from stack when it should only push once, loop and then pop when the for loop goes out of scope (i.e. we finish all iterations of the for loop). This can be accomplished by assuming there is always one body instruction and then in codegen we always `tailPop()` it, reverse and take the first and embed it correctly. ## Todo - [x] The above - [x] Marking whether there even _is_ a **preloop statement** - [x] Marking whether there even _is_ a **post-iteration statement**
deavmi added this to the Basics milestone 2023-01-08 12:09:42 +00:00
deavmi added the
parser
label 2023-01-08 12:09:42 +00:00
deavmi self-assigned this 2023-01-08 12:09:42 +00:00
deavmi added this to the Parser project 2023-01-08 12:09:44 +00:00
deavmi added the
dependency
emit
labels 2023-01-08 12:12:19 +00:00
deavmi added a new dependency 2023-01-08 13:07:44 +00:00
Author
Owner

Solution

  1. We have gone about this by making the pre-loop statement apart of the body of the ForLoop parser node.
  2. The post-loop statement is made a part of the Branch's body (which (the Branch) is in turn a part of the ody of the ForLoop).
## Solution ✅ 1. We have gone about this by making the pre-loop statement apart of the body of the `ForLoop` parser node. 2. The post-loop statement is made a part of the `Branch`'s body (which (the `Branch`) is in turn a part of the ody of the `ForLoop`).
deavmi added the due date 2023-01-11 2023-01-10 19:26:37 +00:00
Author
Owner

We have sorted this out with the above solution!

We have sorted this out with the above solution!
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2023-01-11

Blocks
#74 for loops
tlang/tlang
Reference: tlang/tlang#78
No description provided.