diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2023-10-11 17:44:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 17:44:14 +0200 |
commit | 816589b6674e3af281766f1279420758dcacedc4 (patch) | |
tree | 3e4f825e29e2068466a35edc69cc27967b743687 /compiler/semobjconstr.nim | |
parent | ecaccafa6c18e0b92cd5f75d3363d61c0866dec9 (diff) | |
download | Nim-816589b6674e3af281766f1279420758dcacedc4.tar.gz |
NIR: Nim intermediate representation (#22777)
Theoretical Benefits / Plans: - Typed assembler-like language. - Allows for a CPS transformation. - Can replace the existing C backend by a new C backend. - Can replace the VM. - Can do more effective "not nil" checking and static array bounds checking. - Can be used instead of the DFA. - Easily translatable to LLVM. - Reasonably easy to produce native code from. - Tiny memory consumption. No pointers, no cry. **In very early stages of development.** Todo: - [x] Map Nim types to IR types. - [ ] Map Nim AST to IR instructions: - [x] Map bitsets to bitops. - [ ] Implement string cases. - [ ] Implement range and index checks. - [x] Implement `default(T)` builtin. - [x] Implement multi string concat. - [ ] Write some analysis passes. - [ ] Write a backend. - [x] Integrate into the compilation pipeline.
Diffstat (limited to 'compiler/semobjconstr.nim')
-rw-r--r-- | compiler/semobjconstr.nim | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim index 2d366d8fc..ebc8be0c3 100644 --- a/compiler/semobjconstr.nim +++ b/compiler/semobjconstr.nim @@ -68,9 +68,7 @@ proc locateFieldInInitExpr(c: PContext, field: PSym, initExpr: PNode): PNode = let assignment = initExpr[i] if assignment.kind != nkExprColonExpr: invalidObjConstr(c, assignment) - continue - - if fieldId == considerQuotedIdent(c, assignment[0]).id: + elif fieldId == considerQuotedIdent(c, assignment[0]).id: return assignment proc semConstrField(c: PContext, flags: TExprFlags, @@ -125,7 +123,7 @@ proc pickCaseBranch(caseExpr, matched: PNode): PNode = return caseExpr[i] if endsWithElse: - return caseExpr[^1] + result = caseExpr[^1] else: result = nil @@ -138,8 +136,8 @@ iterator directFieldsInRecList(recList: PNode): PNode = else: doAssert recList.kind == nkRecList for field in recList: - if field.kind != nkSym: continue - yield field + if field.kind == nkSym: + yield field template quoteStr(s: string): string = "'" & s & "'" @@ -416,8 +414,8 @@ proc semConstructTypeAux(c: PContext, if status in {initPartial, initNone, initUnknown}: discard collectMissingFields(c, t.n, constrCtx, result.defaults) let base = t[0] - if base == nil or base.id == t.id or - base.kind in { tyRef, tyPtr } and base[0].id == t.id: + if base == nil or base.id == t.id or + base.kind in {tyRef, tyPtr} and base[0].id == t.id: break t = skipTypes(base, skipPtrs) if t.kind != tyObject: @@ -463,7 +461,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType if t == nil: return localErrorNode(c, result, "object constructor needs an object type") - + if t.skipTypes({tyGenericInst, tyAlias, tySink, tyOwned, tyRef}).kind != tyObject and expectedType != nil and expectedType.skipTypes({tyGenericInst, |