Skip to content

Commit

Permalink
use fork for combparser, test refactoring semexprs
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Aug 31, 2024
1 parent c9086f3 commit 4407e5e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
54 changes: 30 additions & 24 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1123,20 +1123,6 @@ proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags; expectedTy
# don't fold calls in concepts and typeof
result = evalAtCompileTime(c, result)

proc shouldBeBracketExpr(n: PNode): bool =
result = false
assert n.kind in nkCallKinds
let a = n[0]
if a.kind in nkCallKinds:
let b = a[0]
if b.kind in nkSymChoices:
for i in 0..<b.len:
if b[i].kind == nkSym and b[i].sym.magic == mArrGet:
let be = newNodeI(nkBracketExpr, n.info)
for i in 1..<a.len: be.add(a[i])
n[0] = be
return true

proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType = nil): PNode =
result = nil
checkMinSonsLen(n, 1, c.config)
Expand All @@ -1159,11 +1145,6 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType
else:
n[0] = n0
else:
if n[0].kind == nkBracketExpr or shouldBeBracketExpr(n):
var s = qualifiedLookUp(c, n[0][0], {})
if s != nil and s.kind in routineKinds:
n[0][0] = semSymGenericInstantiation(c, n[0][0], s)
return semDirectOp(c, n, flags, expectedType)
n[0] = semExpr(c, n[0], {efInCall, efAllowSymChoice})
let t = n[0].typ
if t != nil and t.kind in {tyVar, tyLent}:
Expand Down Expand Up @@ -3005,6 +2986,35 @@ proc semTupleConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PTyp
else:
result = tupexp

proc isExplicitGenericCall(c: PContext, n: PNode): bool =
template checkCallee(n: PNode) =
if isSymChoice(n):
result = true
else:
let s = qualifiedLookUp(c, n, {})
if s != nil and s.kind in routineKinds:
result = true
n = semSymGenericInstantiation(c, n, s)
assert n.kind in nkCallKinds
result = false
let a = n[0]
case a.kind
of nkBracketExpr:
checkCallee(a[0])
of nkCallKinds:
let b = a[0]
if b.kind in nkSymChoices:
let name = b.getPIdent
if name != nil and name.s == "[]":
checkCallee(a[1])
if result:
# transform callee into normal bracket expr
let be = newNodeI(nkBracketExpr, a.info)
for i in 1..<a.len: be.add(a[i])
n[0] = be
else:
result = false

proc asBracketExpr(c: PContext; n: PNode): PNode =
proc isGeneric(c: PContext; n: PNode): bool =
if n.kind in {nkIdent, nkAccQuoted}:
Expand Down Expand Up @@ -3346,11 +3356,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType
else:
#liMessage(n.info, warnUser, renderTree(n));
result = semIndirectOp(c, n, flags, expectedType)
elif (n[0].kind == nkBracketExpr or shouldBeBracketExpr(n)) and
isSymChoice(n[0][0]):
# indirectOp can deal with explicit instantiations; the fixes
# the 'newSeq[T](x)' bug
setGenericParams(c, n[0], nil)
elif isExplicitGenericCall(c, n): # this modifies `n` if true
result = semDirectOp(c, n, flags, expectedType)
elif nfDotField in n.flags:
result = semDirectOp(c, n, flags, expectedType)
Expand Down
3 changes: 2 additions & 1 deletion testament/important_packages.nim
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ pkg "pnm"
pkg "polypbren"
pkg "presto"
pkg "prologue", "nimble tcompile"
pkg "protobuf", "nim c -o:protobuff -r src/protobuf.nim"
# remove fork after https://github.com/PMunch/combparser/pull/6 is merged:
pkg "protobuf", "nimble install https://github.com/metagn/combparser@#HEAD; nim c -o:protobuff -r src/protobuf.nim"
pkg "rbtree"
pkg "react", "nimble example"
pkg "regex", "nim c src/regex"
Expand Down

0 comments on commit 4407e5e

Please sign in to comment.