This is the JavaScript code generator.Type info generation for the JS backend.
Imports
-
../ast/ast_idgen, ../ast/ast_query, ../ast/ast_types, ../ast/idents, ../ast/types, ../ast/renderer, ../ast/lineinfos, ../modules/magicsys, ../modules/modulegraphs, ../mir/mirenv, ../mir/mirtrees, ../front/options, ../front/msgs, ../utils/containers, ../utils/idioms, ../utils/int128, ../utils/nversion, ../utils/ropes, cgir, compat, jsflow, ../ast/reports_sem, ../ast/reports_backend, ../ast/report_enums
Types
PGlobals = ref object typeInfo, constants*, code*: Rope typeInfoGenerated: IntSet dataGenerated: IntSet unique: int requestArrayConstr: bool ## used for deferring registration of the ``arrayConstr`` proc names: Table[int, string] ## maps a symbol IDs to the symbol's JavaScript name procs: SeqMap[ProcedureId, string] ## the JavaScript name for each procedure consts: SeqMap[ConstId, Loc] globals: SeqMap[GlobalId, Loc] env*: MirEnv ## the project-wide MIR environment
- Source Edit
TProc = object prc: PSym fullBody*: Body ## the procedure's full body defs, body: Rope options: TOptions module: BModule g: PGlobals lastErrorBackupNeeded: bool ## signals whether the value of ``lastJSError`` needs to be captured ## on procedure entry unique: int blocks: seq[BlockInfo] ## enclosing exception handlers, finallys, and labeled blocks. Used ## for correcting wrong control-flow paths and tracking where the ## current exception needs to be restored numHandlers: int ## number of enclosing 'catch' clauses. The name of the ## exception local is derived from this counter extraIndent: int locals: OrdinalSeq[LocalId, Loc] ## stores all relevant code generator state for the procedure's ## locals addrTaken: PackedSet[LocalId] ## locals that have their address taken at some point
- Source Edit
Procs
proc defineGlobal(globals: PGlobals; m: BModule; id: GlobalId) {. ...raises: [KeyError, Exception, ERecoverableError], tags: [ReadDirEffect, RootEffect].}
- Emits the definition for the single global v into the top-level section, with m being the module the global belongs to. Also sets up the symbol's JavaScript name. Source Edit
proc finishProc(p: PProc): string {....raises: [KeyError, Exception, ERecoverableError], tags: [ReadDirEffect, RootEffect].}
- Source Edit
proc genConstant(g: PGlobals; m: BModule; id: ConstId) {. ...raises: [KeyError, Exception, ERecoverableError], tags: [ReadDirEffect, RootEffect].}
- Source Edit
proc genPartial(p: PProc; n: CgNode) {....raises: [KeyError, Exception, ERecoverableError], tags: [ReadDirEffect, RootEffect].}
- Generates the JavaScript code for n and appends the result to p. This is intended for CG IR that wasn't already available when calling startProc. Source Edit
proc genProc(g: PGlobals; module: BModule; id: ProcedureId; body: sink Body): Rope {. ...raises: [KeyError, Exception, ERecoverableError], tags: [ReadDirEffect, RootEffect].}
- Source Edit
proc genTopLevelStmt(globals: PGlobals; m: BModule; body: sink Body) {. ...raises: [Exception, ERecoverableError, KeyError], tags: [RootEffect, ReadDirEffect].}
- Source Edit
proc newGlobals(g: ModuleGraph): PGlobals {. ...raises: [KeyError, Exception, ERecoverableError], tags: [ReadDirEffect, RootEffect].}
- Source Edit