Skip to content

Commit 85ba2cc

Browse files
committed
supports nil literal and ref/ptr types
1 parent feb2b72 commit 85ba2cc

File tree

6 files changed

+32
-18
lines changed

6 files changed

+32
-18
lines changed

compiler/icnif/enum2nif.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by enumgen.nim. DO NOT EDIT!
1+
# Generated by gear2/generator/enumgen.nim in Nimony repo. DO NOT EDIT!
22

33
import ".." / [ast, options]
44

@@ -27,7 +27,7 @@ proc toNifTag*(s: TNodeKind): string =
2727
of nkStrLit: "strlit"
2828
of nkRStrLit: "rstrlit"
2929
of nkTripleStrLit: "triplestrlit"
30-
of nkNilLit: "nillit"
30+
of nkNilLit: "nil"
3131
of nkComesFrom: "comesfrom"
3232
of nkDotCall: "dotcall"
3333
of nkCommand: "cmd"
@@ -197,7 +197,7 @@ proc parseNodeKind*(s: string): TNodeKind =
197197
of "strlit": nkStrLit
198198
of "rstrlit": nkRStrLit
199199
of "triplestrlit": nkTripleStrLit
200-
of "nillit": nkNilLit
200+
of "nil": nkNilLit
201201
of "comesfrom": nkComesFrom
202202
of "dotcall": nkDotCall
203203
of "cmd": nkCommand
@@ -800,7 +800,7 @@ proc toNifTag*(s: TMagic): string =
800800
of mString: "string"
801801
of mCstring: "cstring"
802802
of mPointer: "pointer"
803-
of mNil: "nil"
803+
of mNil: "nilm"
804804
of mExpr: "exprm"
805805
of mStmt: "stmtm"
806806
of mTypeDesc: "typedesc"
@@ -1082,7 +1082,7 @@ proc parseMagic*(s: string): TMagic =
10821082
of "string": mString
10831083
of "cstring": mCstring
10841084
of "pointer": mPointer
1085-
of "nil": mNil
1085+
of "nilm": mNil
10861086
of "exprm": mExpr
10871087
of "stmtm": mStmt
10881088
of "typedesc": mTypeDesc

compiler/icnif/nifdecoder.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ proc fromNif(c: var DecodeContext; n: var Cursor): PNode =
274274
of ParLe:
275275
let kind = n.nodeKind
276276
case kind:
277+
of nkNilLit:
278+
result = newNode(nkNilLit)
279+
inc n
280+
skipParRi n
277281
of nkPostfix, nkTypeSection, nkStmtList:
278282
result = newNode(kind)
279283
inc n

compiler/icnif/nifencoder.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ proc toNif(c: var EncodeContext; n: PNode) =
202202
c.b.addStrLit n.strVal, "R"
203203
of nkTripleStrLit:
204204
c.b.addStrLit n.strVal, "T"
205+
of nkNilLit:
206+
c.b.addKeyw toNifTag(nkNilLit)
205207
of nkIdentDefs:
206208
c.b.withNode n:
207209
assert n.len == 3

compiler/icnif/nifencodertypes.nim

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
proc writeTypeFlags(c: var EncodeContext; t: PType) =
44
writeFlags c.b, t.flags, "tf"
55

6-
proc isNominalRef(t: PType): bool {.inline.} =
7-
let e = t.elementType
8-
t.sym != nil and e.kind == tyObject and (e.sym == nil or sfAnon in e.sym.flags)
9-
106
template singleElement(keyw: string) {.dirty.} =
117
c.b.withTree keyw:
128
writeTypeFlags(c, t)
@@ -97,18 +93,12 @@ proc toNif(c: var EncodeContext; t: PType; isTypeSection = false) =
9793
toNif c, son
9894
else:
9995
symToNif c, t.sym
100-
of tyPtr:
101-
if isNominalRef(t):
102-
symToNif c, t.sym
103-
else:
104-
c.typeHead t:
105-
toNif c, t.elementType
106-
of tyRef:
107-
if isNominalRef(t):
96+
of tyRef, tyPtr:
97+
if tfRefsAnonObj in t.flags and not isTypeSection:
10898
symToNif c, t.sym
10999
else:
110100
c.typeHead t:
111-
toNif c, t.elementType
101+
toNif c, t.elementType, isTypeSection
112102
of tyVar:
113103
c.b.withTree(if isOutParam(t): "out" else: "mut"):
114104
toNif c, t.elementType

tests/icnif/testcode/modtestliterals.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ var uint64litH = 18446744073709551615'u64
2525
var floatlit = 1.25
2626
var float32lit = 1.25'f32
2727
var float64lit = 1.25'f64
28+
29+
var nillit: ptr int = nil

tests/icnif/testcode/modtesttypesections.nim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,25 @@ type
1212
TestObject2* = object
1313
x: TestObject
1414

15+
TestRefInt = ref int
16+
TestPtrInt = ptr int
17+
18+
TestRefObj = ref object
19+
x: int
20+
21+
TestPtrObj = ptr object
22+
x: int
23+
1524
var x: TestInt
1625
var testEnum: TestEnum
1726
var testEnum1 = X
1827
var testDistinct: TestDistinct
1928
var testObject: TestObject
2029
var testObject2*: TestObject2
30+
31+
var testRefInt: TestRefInt = nil
32+
var testRefInt2: ref int = nil
33+
var testPtrInt: TestPtrInt = nil
34+
var testPtrInt2: ptr int = nil
35+
var testRefObj: TestRefObj = nil
36+
var testPtrObj: TestPtrObj = nil

0 commit comments

Comments
 (0)