Skip to content

Commit

Permalink
gear3: adds a type for arrayConstr (#337)
Browse files Browse the repository at this point in the history
* nimony: adds a type for arrayConstr

* use `getType`

* Apply suggestions from code review

Co-authored-by: Andreas Rumpf <[email protected]>

---------

Co-authored-by: Andreas Rumpf <[email protected]>
  • Loading branch information
ringabout and Araq authored Jan 7, 2025
1 parent 4ad773b commit e1716e8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/gear3/expander.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/nimony/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/nimony/sysbasics/tbasics.nif
Original file line number Diff line number Diff line change
@@ -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)))
6 changes: 6 additions & 0 deletions tests/nimony/sysbasics/tbasics.nim
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit e1716e8

Please sign in to comment.