support iteration on lists and tuples #43

Closed
opened 2021-10-03 16:49:42 +08:00 by sb10q · 4 comments
Owner
@extern
def output_int(x: int32):
    ...

def run() -> int32:
    a = [1, 2, 3, 4]
    for x in a:
        output_int(x)
    return 0

currently fails with:

thread '<unnamed>' panicked at 'not implemented: Located { location: Location { row: 7, column: 5 }, custom: None, node: For { target: Located { location: Location { row: 7, column: 9 }, custom: Some(UnificationKey(112)), node: Name { id: "x", ctx: Load } }, iter: Located { location: Location { row: 7, column: 14 }, custom: Some(UnificationKey(111)), node: Name { id: "a", ctx: Load } }, body: [Located { location: Location { row: 8, column: 9 }, custom: None, node: Expr { value: Located { location: Location { row: 8, column: 19 }, custom: Some(UnificationKey(4)), node: Call { func: Located { location: Location { row: 8, column: 9 }, custom: Some(UnificationKey(106)), node: Name { id: "output_int", ctx: Load } }, args: [Located { location: Location { row: 8, column: 20 }, custom: Some(UnificationKey(112)), node: Name { id: "x", ctx: Load } }], keywords: [] } } } }], orelse: [], type_comment: None } }', nac3core/src/codegen/stmt.rs:217:18
```python @extern def output_int(x: int32): ... def run() -> int32: a = [1, 2, 3, 4] for x in a: output_int(x) return 0 ``` currently fails with: ``` thread '<unnamed>' panicked at 'not implemented: Located { location: Location { row: 7, column: 5 }, custom: None, node: For { target: Located { location: Location { row: 7, column: 9 }, custom: Some(UnificationKey(112)), node: Name { id: "x", ctx: Load } }, iter: Located { location: Location { row: 7, column: 14 }, custom: Some(UnificationKey(111)), node: Name { id: "a", ctx: Load } }, body: [Located { location: Location { row: 8, column: 9 }, custom: None, node: Expr { value: Located { location: Location { row: 8, column: 19 }, custom: Some(UnificationKey(4)), node: Call { func: Located { location: Location { row: 8, column: 9 }, custom: Some(UnificationKey(106)), node: Name { id: "output_int", ctx: Load } }, args: [Located { location: Location { row: 8, column: 20 }, custom: Some(UnificationKey(112)), node: Name { id: "x", ctx: Load } }], keywords: [] } } } }], orelse: [], type_comment: None } }', nac3core/src/codegen/stmt.rs:217:18 ```
sb10q changed title from support iteration on lists to support iteration on lists and tuples 2021-10-03 16:50:47 +08:00
Author
Owner

With a tuple, the error is

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "Cannot unify tuple[int32, int32, int32, int32] with list[int32] at line 7 column 14"', nac3standalone/src/main.rs:65:35

We need to decide whether to support it or not on tuples, which can be heterogenous so assigning a type to x isn't always possible.

With a tuple, the error is ``` thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "Cannot unify tuple[int32, int32, int32, int32] with list[int32] at line 7 column 14"', nac3standalone/src/main.rs:65:35 ``` We need to decide whether to support it or not on tuples, which can be heterogenous so assigning a type to ``x`` isn't always possible.
Contributor

tuple requires the loop unfolding feature, which requires the pseudo comment support.

tuple requires the loop unfolding feature, which requires the pseudo comment support.
Contributor

Implemented for list.

Implemented for list.
Contributor

see #63 for iteration over tuples.

see #63 for iteration over tuples.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#43
No description provided.