make some system modules compile again
This commit is contained in:
parent
29c075299d
commit
c0433b0b6c
2 changed files with 19 additions and 19 deletions
|
|
@ -127,7 +127,7 @@ proc fileMatches(c, bp: cstring): bool =
|
||||||
|
|
||||||
proc canonFilename*(filename: cstring): cstring =
|
proc canonFilename*(filename: cstring): cstring =
|
||||||
## returns 'nil' if the filename cannot be found.
|
## returns 'nil' if the filename cannot be found.
|
||||||
for i in 0 ..< dbgFilenameLen:
|
for i in 0 .. dbgFilenameLen-1:
|
||||||
result = dbgFilenames[i]
|
result = dbgFilenames[i]
|
||||||
if fileMatches(result, filename): return result
|
if fileMatches(result, filename): return result
|
||||||
result = nil
|
result = nil
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,13 @@
|
||||||
# The generic ``repr`` procedure for the javascript backend.
|
# The generic ``repr`` procedure for the javascript backend.
|
||||||
|
|
||||||
proc reprInt(x: int64): string {.compilerproc.} = return $x
|
proc reprInt(x: int64): string {.compilerproc.} = return $x
|
||||||
proc reprFloat(x: float): string {.compilerproc.} =
|
proc reprFloat(x: float): string {.compilerproc.} =
|
||||||
# Js toString doesn't differentiate between 1.0 and 1,
|
# Js toString doesn't differentiate between 1.0 and 1,
|
||||||
# but we do.
|
# but we do.
|
||||||
if $x == $(x.int): $x & ".0"
|
if $x == $(x.int): $x & ".0"
|
||||||
else: $x
|
else: $x
|
||||||
|
|
||||||
proc reprPointer(p: pointer): string {.compilerproc.} =
|
proc reprPointer(p: pointer): string {.compilerproc.} =
|
||||||
# Do we need to generate the full 8bytes ? In js a pointer is an int anyway
|
# Do we need to generate the full 8bytes ? In js a pointer is an int anyway
|
||||||
var tmp: int
|
var tmp: int
|
||||||
{. emit: """
|
{. emit: """
|
||||||
|
|
@ -38,7 +38,7 @@ proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} =
|
||||||
result = $typ.node.sons[e].name
|
result = $typ.node.sons[e].name
|
||||||
else:
|
else:
|
||||||
result = $e & " (invalid data!)"
|
result = $e & " (invalid data!)"
|
||||||
|
|
||||||
proc reprChar(x: char): string {.compilerRtl.} =
|
proc reprChar(x: char): string {.compilerRtl.} =
|
||||||
result = "\'"
|
result = "\'"
|
||||||
case x
|
case x
|
||||||
|
|
@ -50,7 +50,7 @@ proc reprChar(x: char): string {.compilerRtl.} =
|
||||||
|
|
||||||
proc reprStrAux(result: var string, s: cstring, len: int) =
|
proc reprStrAux(result: var string, s: cstring, len: int) =
|
||||||
add(result, "\"")
|
add(result, "\"")
|
||||||
for i in 0 ..< len:
|
for i in 0 .. len-1:
|
||||||
let c = s[i]
|
let c = s[i]
|
||||||
case c
|
case c
|
||||||
of '"': add(result, "\\\"")
|
of '"': add(result, "\\\"")
|
||||||
|
|
@ -67,7 +67,7 @@ proc reprStr(s: string): string {.compilerRtl.} =
|
||||||
if cast[pointer](s).isNil:
|
if cast[pointer](s).isNil:
|
||||||
# Handle nil strings here because they don't have a length field in js
|
# Handle nil strings here because they don't have a length field in js
|
||||||
# TODO: check for null/undefined before generating call to length in js?
|
# TODO: check for null/undefined before generating call to length in js?
|
||||||
# Also: c backend repr of a nil string is <pointer>"", but repr of an
|
# Also: c backend repr of a nil string is <pointer>"", but repr of an
|
||||||
# array of string that is not initialized is [nil, nil, ...] ??
|
# array of string that is not initialized is [nil, nil, ...] ??
|
||||||
add(result, "nil")
|
add(result, "nil")
|
||||||
else:
|
else:
|
||||||
|
|
@ -86,7 +86,7 @@ proc addSetElem(result: var string, elem: int, typ: PNimType) =
|
||||||
|
|
||||||
iterator setKeys(s: int): int {.inline.} =
|
iterator setKeys(s: int): int {.inline.} =
|
||||||
# The type of s is a lie, but it's expected to be a set.
|
# The type of s is a lie, but it's expected to be a set.
|
||||||
# Iterate over the JS object representing a set
|
# Iterate over the JS object representing a set
|
||||||
# and returns the keys as int.
|
# and returns the keys as int.
|
||||||
var len: int
|
var len: int
|
||||||
var yieldRes: int
|
var yieldRes: int
|
||||||
|
|
@ -124,16 +124,16 @@ proc initReprClosure(cl: var ReprClosure) =
|
||||||
cl.recDepth = -1 # default is to display everything!
|
cl.recDepth = -1 # default is to display everything!
|
||||||
cl.indent = 0
|
cl.indent = 0
|
||||||
|
|
||||||
proc reprAux(result: var string, p: pointer, typ: PNimType, cl: var ReprClosure)
|
proc reprAux(result: var string, p: pointer, typ: PNimType, cl: var ReprClosure)
|
||||||
|
|
||||||
proc reprArray(a: pointer, typ: PNimType,
|
proc reprArray(a: pointer, typ: PNimType,
|
||||||
cl: var ReprClosure): string {.compilerRtl.} =
|
cl: var ReprClosure): string {.compilerRtl.} =
|
||||||
var isNilArrayOrSeq: bool
|
var isNilArrayOrSeq: bool
|
||||||
# isnil is not enough here as it would try to deref `a` without knowing what's inside
|
# isnil is not enough here as it would try to deref `a` without knowing what's inside
|
||||||
{. emit: """
|
{. emit: """
|
||||||
if (`a` == null) {
|
if (`a` == null) {
|
||||||
`isNilArrayOrSeq` = true;
|
`isNilArrayOrSeq` = true;
|
||||||
} else if (`a`[0] == null) {
|
} else if (`a`[0] == null) {
|
||||||
`isNilArrayOrSeq` = true;
|
`isNilArrayOrSeq` = true;
|
||||||
} else {
|
} else {
|
||||||
`isNilArrayOrSeq` = false;
|
`isNilArrayOrSeq` = false;
|
||||||
|
|
@ -146,19 +146,19 @@ proc reprArray(a: pointer, typ: PNimType,
|
||||||
result = if typ.kind == tySequence: "@[" else: "["
|
result = if typ.kind == tySequence: "@[" else: "["
|
||||||
var len: int = 0
|
var len: int = 0
|
||||||
var i: int = 0
|
var i: int = 0
|
||||||
|
|
||||||
{. emit: "`len` = `a`.length;\n" .}
|
{. emit: "`len` = `a`.length;\n" .}
|
||||||
var dereffed: pointer = a
|
var dereffed: pointer = a
|
||||||
for i in 0 ..< len:
|
for i in 0 .. len-1:
|
||||||
if i > 0 :
|
if i > 0 :
|
||||||
add(result, ", ")
|
add(result, ", ")
|
||||||
# advance pointer and point to element at index
|
# advance pointer and point to element at index
|
||||||
{. emit: """
|
{. emit: """
|
||||||
`dereffed`_Idx = `i`;
|
`dereffed`_Idx = `i`;
|
||||||
`dereffed` = `a`[`dereffed`_Idx];
|
`dereffed` = `a`[`dereffed`_Idx];
|
||||||
""" .}
|
""" .}
|
||||||
reprAux(result, dereffed, typ.base, cl)
|
reprAux(result, dereffed, typ.base, cl)
|
||||||
|
|
||||||
add(result, "]")
|
add(result, "]")
|
||||||
|
|
||||||
proc isPointedToNil(p: pointer): bool {.inline.}=
|
proc isPointedToNil(p: pointer): bool {.inline.}=
|
||||||
|
|
@ -181,7 +181,7 @@ proc reprRef(result: var string, p: pointer, typ: PNimType,
|
||||||
|
|
||||||
proc reprRecordAux(result: var string, o: pointer, typ: PNimType, cl: var ReprClosure) =
|
proc reprRecordAux(result: var string, o: pointer, typ: PNimType, cl: var ReprClosure) =
|
||||||
add(result, "[")
|
add(result, "[")
|
||||||
|
|
||||||
var first: bool = true
|
var first: bool = true
|
||||||
var val: pointer = o
|
var val: pointer = o
|
||||||
if typ.node.len == 0:
|
if typ.node.len == 0:
|
||||||
|
|
@ -192,7 +192,7 @@ proc reprRecordAux(result: var string, o: pointer, typ: PNimType, cl: var ReprCl
|
||||||
reprAux(result, val, typ.node.typ, cl)
|
reprAux(result, val, typ.node.typ, cl)
|
||||||
else:
|
else:
|
||||||
# if the object has more than one field, sons is not nil and contains the fields.
|
# if the object has more than one field, sons is not nil and contains the fields.
|
||||||
for i in 0 ..< typ.node.len:
|
for i in 0 .. typ.node.len-1:
|
||||||
if first: first = false
|
if first: first = false
|
||||||
else: add(result, ",\n")
|
else: add(result, ",\n")
|
||||||
|
|
||||||
|
|
@ -214,11 +214,11 @@ proc reprJSONStringify(p: int): string {.compilerRtl.} =
|
||||||
{. emit: "`tmp` = JSON.stringify(`p`);\n" .}
|
{. emit: "`tmp` = JSON.stringify(`p`);\n" .}
|
||||||
result = $tmp
|
result = $tmp
|
||||||
|
|
||||||
proc reprAux(result: var string, p: pointer, typ: PNimType,
|
proc reprAux(result: var string, p: pointer, typ: PNimType,
|
||||||
cl: var ReprClosure) =
|
cl: var ReprClosure) =
|
||||||
if cl.recDepth == 0:
|
if cl.recDepth == 0:
|
||||||
add(result, "...")
|
add(result, "...")
|
||||||
return
|
return
|
||||||
dec(cl.recDepth)
|
dec(cl.recDepth)
|
||||||
case typ.kind
|
case typ.kind
|
||||||
of tyInt..tyInt64, tyUInt..tyUInt64:
|
of tyInt..tyInt64, tyUInt..tyUInt64:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue