-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nimony: subscripts sans generic instantiations #194
base: master
Are you sure you want to change the base?
Conversation
I would have done it this way: proc buildReadAccessor(c: var CheckContext; dest: var Tree; tree: Tree, n: NodePos, acc: string) =
copyIntoKind(dest, Call, n.info):
let accessor = c.m.strings.getOrIncl(acc)
buildSymChoice(c, dest, accessor, n.info)
for ch0 in sonsReadonly(tree, n):
copyTree(dest, tree, ch0)
proc semBracketExpr(c: var SemContext; dest: var Tree; tree: Tree; n: NodePos;
preferredType: FullTypeId): FullTypeId =
var tmp = createTempTree(c.thisModule)
discard sem(c, tmp, tree, n.firstSon, autoType)
var routines: seq[FullSymId] = @[]
if isTypeExpr(c, tmp, StartPos):
rollbackTo c.p, tmp, StartPos
result = borrowPosition(c, dest)
semDeclType(c, dest, tree, n, inLocalDecl)
elif isGenericRoutine(c, tmp, StartPos, routines):
rollbackTo c.p, tmp, StartPos
result = semExplicitGenericRoutineInst(c, dest, tree, n, routines)
else:
rollbackTo c.p, tmp, StartPos
buildReadAccessor(c, tmp, tree, n, "[]")
result = sem(c, dest, tmp, StartPos, preferredType)
proc buildWriteAccessor(c: var CheckContext; dest: var Tree; tree: Tree; n: NodePos, acc: string) =
copyIntoKind(dest, Call, n.info):
let accessor = c.m.strings.getOrIncl(acc)
buildSymChoice(c, dest, accessor, n.info)
let (le, ri) = sons2(tree, n)
# flatten the 'BracketExpr' away:
for ch1 in sonsReadonly(tree, le):
copyTree(dest, tree, ch1)
# but not the 'value' of 'a[i] = value':
copyTree(dest, tree, ri)
of AsgnS:
case n.firstSon.kind
of BracketExpr:
var tmp = createTempTree(c.thisModule)
buildWriteAccessor(c, tmp, tree, n, "[]=")
result = sem(c, dest, tmp, StartPos, preferredType)
of CurlyExpr:
var tmp = createTempTree(c.thisModule)
buildWriteAccessor(c, tmp, tree, n, "{}=")
result = sem(c, dest, tmp, StartPos, preferredType)
else:
semAsgn(c, dest, tree, n)
|
And then the system.nim adds [] and []= etc for arrays which are mapped to the magic: mArrPut etc. This is slightly simpler and avoids further problems if [] is used with .borrow and distinct. |
This is ported from the old compiler, I looked into moving So |
Alright, your approach wins then. |
I wasn't disagreeing with your approach, the incompatibilities are fine imo (namely arbitrary pointer dereference & lax index int type) and it's cleaner. The backends will probably still need the different magics (except maybe the assign ones), NIFC wouldn't correctly handle |
Sure but it's not its job anyway. The lowerer translates it to
Well we need more than just |
It would be sad to lose this so we should move it to a |
Code is messy for now, will move out the bugfix
addParLe
s and do theArrayT
reorder as mentioned in #192 first. Also a bug thatlet arrIndex1: int = x[0]
givesgot: (i -1) but wanted: (u -1)