Skip to content
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

modernize jsgen; clean up some leftovers #22423

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,15 @@ template nested(p, body) =
dec p.extraIndent

proc newGlobals(): PGlobals =
new(result)
result.forwarded = @[]
result.generatedSyms = initIntSet()
result.typeInfoGenerated = initIntSet()
result = PGlobals(forwarded: @[],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good example of where result only introduces noise, ie extra alignment etc

proc newGlobals(): PGlobals =
  PGlobals(
     forwarded: @[],
     generatedSyms: initIntSet(),
     typeInfoGenerated: initIntSet()
  )

generatedSyms: initIntSet(),
typeInfoGenerated: initIntSet()
)

proc initCompRes(r: var TCompRes) =
r.address = ""
r.res = ""
r.tmpLoc = ""
r.typ = etyNone
r.kind = resNone
proc initCompRes(): TCompRes =
result = TCompRes(address: "", res: "",
tmpLoc: "", typ: etyNone, kind: resNone
)

proc rdLoc(a: TCompRes): Rope {.inline.} =
if a.typ != etyBaseIndex:
Expand Down Expand Up @@ -350,9 +348,10 @@ proc isSimpleExpr(p: PProc; n: PNode): bool =
if n[i].kind notin {nkCommentStmt, nkEmpty}: return false
result = isSimpleExpr(p, n.lastSon)
else:
result = false
if n.isAtom:
result = true
else:
result = false

proc getTemp(p: PProc, defineInLocals: bool = true): Rope =
inc(p.unique)
Expand Down Expand Up @@ -3006,13 +3005,11 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =

proc newModule(g: ModuleGraph; module: PSym): BModule =
## Create a new JS backend module node.
new(result)
result.module = module
result.sigConflicts = initCountTable[SigHash]()
if g.backend == nil:
g.backend = newGlobals()
result.graph = g
result.config = g.config
result = BModule(module: module, sigConflicts: initCountTable[SigHash](),
graph: g, config: g.config
)
if sfSystemModule in module.flags:
PGlobals(g.backend).inSystem = true

Expand Down