Skip to content
Open
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
26 changes: 13 additions & 13 deletions compiler/jstypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ proc genObjectFields(p: PProc, typ: PType, n: PNode): Rope =
for i in 0..<n.len:
if i > 0: s.add(", \L")
s.add(genObjectFields(p, typ, n[i]))
result = ("{kind: 2, len: $1, offset: 0, " &
"typ: null, name: null, sons: [$2]}") % [rope(n.len), s]
result = ("{kind: 2, offset: 0, " &
"typ: null, name: null, sons: [$1]}") % [s]
of nkSym:
field = n.sym
s = genTypeInfo(p, field.typ)
result = ("{kind: 1, offset: \"$1\", len: 0, " &
result = ("{kind: 1, offset: \"$1\", " &
"typ: $2, name: $3, sons: null}") %
[mangleName(p.module, field), s,
makeJSString(field.name.s)]
Expand Down Expand Up @@ -73,8 +73,8 @@ proc objHasTypeField(t: PType): bool {.inline.} =

proc genObjectInfo(p: PProc, typ: PType, name: Rope) =
let kind = if objHasTypeField(typ): tyObject else: tyTuple
var s = ("var $1 = {size: 0, kind: $2, base: null, node: null, " &
"finalizer: null};$n") % [name, rope(ord(kind))]
var s = "var $1 = {size: 0, kind: $2, base: null, node: null};$n" %
[name, rope(ord(kind))]
prepend(p.g.typeInfo, s)
p.g.typeInfo.addf("var NNI$1 = $2;$n",
[rope(typ.id), genObjectFields(p, typ, typ.n)])
Expand All @@ -94,8 +94,8 @@ proc genTupleFields(p: PProc, typ: PType): Rope =
"typ: null, name: null, sons: [$2]}") % [rope(typ.len), s]

proc genTupleInfo(p: PProc, typ: PType, name: Rope) =
var s = ("var $1 = {size: 0, kind: $2, base: null, node: null, " &
"finalizer: null};$n") % [name, rope(ord(typ.kind))]
var s = "var $1 = {size: 0, kind: $2, base: null, node: null};$n" %
[name, rope(ord(typ.kind))]
prepend(p.g.typeInfo, s)
p.g.typeInfo.addf("var NNI$1 = $2;$n",
[rope(typ.id), genTupleFields(p, typ)])
Expand All @@ -108,12 +108,12 @@ proc genEnumInfo(p: PProc, typ: PType, name: Rope) =
let field = typ.n[i].sym
if i > 0: s.add(", \L")
let extName = if field.ast == nil: field.name.s else: field.ast.strVal
s.addf("\"$1\": {kind: 1, offset: $1, typ: $2, name: $3, len: 0, sons: null}",
s.addf("\"$1\": {kind: 1, offset: $1, typ: $2, name: $3, sons: null}",
[rope(field.position), name, makeJSString(extName)])
var n = ("var NNI$1 = {kind: 2, offset: 0, typ: null, " &
"name: null, len: $2, sons: {$3}};$n") % [rope(typ.id), rope(typ.n.len), s]
s = ("var $1 = {size: 0, kind: $2, base: null, node: null, " &
"finalizer: null};$n") % [name, rope(ord(typ.kind))]
s = "var $1 = {size: 0, kind: $2, base: null, node: null};$n" %
[name, rope(ord(typ.kind))]
prepend(p.g.typeInfo, s)
p.g.typeInfo.add(n)
p.g.typeInfo.addf("$1.node = NNI$2;$n", [name, rope(typ.id)])
Expand All @@ -130,19 +130,19 @@ proc genTypeInfo(p: PProc, typ: PType): Rope =
result = genTypeInfo(p, t.skipModifier)
of tyPointer, tyProc, tyBool, tyChar, tyCstring, tyString, tyInt..tyUInt64:
var s =
"var $1 = {size: 0,kind: $2,base: null,node: null,finalizer: null};$n" %
"var $1 = {size: 0,kind: $2,base: null,node: null};$n" %
[result, rope(ord(t.kind))]
prepend(p.g.typeInfo, s)
of tyVar, tyLent, tyRef, tyPtr, tySequence, tyRange, tySet, tyOpenArray:
var s =
"var $1 = {size: 0, kind: $2, base: null, node: null, finalizer: null};$n" %
"var $1 = {size: 0, kind: $2, base: null, node: null};$n" %
[result, rope(ord(t.kind))]
prepend(p.g.typeInfo, s)
p.g.typeInfo.addf("$1.base = $2;$n",
[result, genTypeInfo(p, t.elementType)])
of tyArray:
var s =
"var $1 = {size: 0, kind: $2, base: null, node: null, finalizer: null};$n" %
"var $1 = {size: 0, kind: $2, base: null, node: null};$n" %
[result, rope(ord(t.kind))]
prepend(p.g.typeInfo, s)
p.g.typeInfo.addf("$1.base = $2;$n",
Expand Down
Loading