From e1716e83846c916ad177662dfcaf2ee40f49f9a5 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:42:53 +0800 Subject: [PATCH] gear3: adds a type for arrayConstr (#337) * nimony: adds a type for arrayConstr * use `getType` * Apply suggestions from code review Co-authored-by: Andreas Rumpf --------- Co-authored-by: Andreas Rumpf --- src/gear3/expander.nim | 6 ++++++ src/nimony/sem.nim | 1 + tests/nimony/sysbasics/tbasics.nif | 24 ++++++++++++++++++++++++ tests/nimony/sysbasics/tbasics.nim | 6 ++++++ 4 files changed, 37 insertions(+) create mode 100644 tests/nimony/sysbasics/tbasics.nif create mode 100644 tests/nimony/sysbasics/tbasics.nim diff --git a/src/gear3/expander.nim b/src/gear3/expander.nim index 8980adbb..cd944796 100644 --- a/src/gear3/expander.nim +++ b/src/gear3/expander.nim @@ -871,6 +871,12 @@ proc traverseExpr(e: var EContext; c: var Cursor) = e.dest.shrink beforeType traverseExpr(e, c) skipParRi(e, c) + of AconstrX: + e.dest.add tagToken("aconstr", c.info) + var arrayType = e.typeCache.getType(c) + inc c + e.traverseType(arrayType, {}) + inc nested of OconstrX: e.dest.add tagToken("oconstr", c.info) inc c diff --git a/src/nimony/sem.nim b/src/nimony/sem.nim index 4dd2f879..4b059ca0 100644 --- a/src/nimony/sem.nim +++ b/src/nimony/sem.nim @@ -3362,6 +3362,7 @@ proc semArrayConstr(c: var SemContext, it: var Item) = buildErr c, it.n.info, "empty array needs a specified type" wantParRi c, it.n return + var elem = Item(n: it.n, typ: c.types.autoType) case it.typ.typeKind of ArrayT: # , SeqT, OpenArrayT diff --git a/tests/nimony/sysbasics/tbasics.nif b/tests/nimony/sysbasics/tbasics.nif new file mode 100644 index 00000000..c1c2619c --- /dev/null +++ b/tests/nimony/sysbasics/tbasics.nif @@ -0,0 +1,24 @@ +(.nif24) +,1,tests/nimony/sysbasics/tbasics.nim(stmts 8,1 + (type ~6 :Array.0.tbawx6nu81 . . . 7 + (array ~11,5,lib/std/system.nim + (i -1) + (rangetype + (i -1) +0 +4))) 4,3 + (var :s.0.tbawx6nu81 . . + (array + (i -1) + (rangetype + (i -1) +0 +2)) 4 + (arr 1 +1 4 +2 7 +3)) 4,4 + (var :s2.0.tbawx6nu81 . . 11,~3 + (array ~11,5,lib/std/system.nim + (i -1) + (rangetype + (i -1) +0 +4)) .) 4,5 + (var :s3.0.tbawx6nu81 . . 11,~4 + (array ~11,5,lib/std/system.nim + (i -1) + (rangetype + (i -1) +0 +4)) 12 + (arr 1 +1 4 +2 7 +3 10 +4 13 +5))) \ No newline at end of file diff --git a/tests/nimony/sysbasics/tbasics.nim b/tests/nimony/sysbasics/tbasics.nim new file mode 100644 index 00000000..56544280 --- /dev/null +++ b/tests/nimony/sysbasics/tbasics.nim @@ -0,0 +1,6 @@ +type + Array = array[5, int] + +var s = [1, 2, 3] +var s2: Array +var s3: Array = [1, 2, 3, 4, 5] \ No newline at end of file