Make codegen for 1 and similar valid
This commit is contained in:
parent
bdb2d21f27
commit
a568c6102f
3 changed files with 25 additions and 55 deletions
|
|
@ -11,49 +11,10 @@
|
||||||
|
|
||||||
# ------------------------- Name Mangling --------------------------------
|
# ------------------------- Name Mangling --------------------------------
|
||||||
|
|
||||||
proc mangleField(name: string): string =
|
proc mangleField(name: string): string =
|
||||||
case name[0]
|
result = mangle(name)
|
||||||
of 'a'..'z':
|
if name[0] in 'a'..'z':
|
||||||
result = ""
|
result[0] = name[0].toUpper
|
||||||
add(result, chr(ord(name[0]) - ord('a') + ord('A')))
|
|
||||||
of '0'..'9', 'A'..'Z':
|
|
||||||
result = ""
|
|
||||||
add(result, name[0])
|
|
||||||
else: result = "HEX" & toHex(ord(name[0]), 2)
|
|
||||||
for i in countup(1, len(name) - 1):
|
|
||||||
case name[i]
|
|
||||||
of 'A'..'Z':
|
|
||||||
add(result, chr(ord(name[i]) - ord('A') + ord('a')))
|
|
||||||
of '_':
|
|
||||||
discard
|
|
||||||
of 'a'..'z', '0'..'9':
|
|
||||||
add(result, name[i])
|
|
||||||
else:
|
|
||||||
add(result, "HEX")
|
|
||||||
add(result, toHex(ord(name[i]), 2))
|
|
||||||
|
|
||||||
proc mangle(name: string): string =
|
|
||||||
when false:
|
|
||||||
case name[0]
|
|
||||||
of 'a'..'z':
|
|
||||||
result = ""
|
|
||||||
add(result, chr(ord(name[0]) - ord('a') + ord('A')))
|
|
||||||
of '0'..'9', 'A'..'Z':
|
|
||||||
result = ""
|
|
||||||
add(result, name[0])
|
|
||||||
else: result = "HEX" & toHex(ord(name[0]), 2)
|
|
||||||
result = ""
|
|
||||||
for i in countup(0, len(name) - 1):
|
|
||||||
case name[i]
|
|
||||||
of 'A'..'Z':
|
|
||||||
add(result, chr(ord(name[i]) - ord('A') + ord('a')))
|
|
||||||
of '_':
|
|
||||||
discard
|
|
||||||
of 'a'..'z', '0'..'9':
|
|
||||||
add(result, name[i])
|
|
||||||
else:
|
|
||||||
add(result, "HEX")
|
|
||||||
add(result, toHex(ord(name[i]), 2))
|
|
||||||
|
|
||||||
proc isKeyword(w: PIdent): bool =
|
proc isKeyword(w: PIdent): bool =
|
||||||
# nimrod and C++ share some keywords
|
# nimrod and C++ share some keywords
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,27 @@ proc makeSingleLineCString*(s: string): string =
|
||||||
result.add(c.toCChar)
|
result.add(c.toCChar)
|
||||||
result.add('\"')
|
result.add('\"')
|
||||||
|
|
||||||
|
proc mangle*(name: string): string =
|
||||||
|
result = ""
|
||||||
|
case name[0]
|
||||||
|
of Letters:
|
||||||
|
result.add(name[0].toLower)
|
||||||
|
of Digits:
|
||||||
|
result.add("N" & name[0])
|
||||||
|
else:
|
||||||
|
result = "HEX" & toHex(ord(name[0]), 2)
|
||||||
|
for i in 1..(name.len-1):
|
||||||
|
let c = name[i]
|
||||||
|
case c
|
||||||
|
of 'A'..'Z':
|
||||||
|
add(result, c.toLower)
|
||||||
|
of '_':
|
||||||
|
discard
|
||||||
|
of 'a'..'z', '0'..'9':
|
||||||
|
add(result, c)
|
||||||
|
else:
|
||||||
|
add(result, "HEX" & toHex(ord(c), 2))
|
||||||
|
|
||||||
proc makeLLVMString*(s: string): PRope =
|
proc makeLLVMString*(s: string): PRope =
|
||||||
const MaxLineLength = 64
|
const MaxLineLength = 64
|
||||||
result = nil
|
result = nil
|
||||||
|
|
|
||||||
|
|
@ -136,18 +136,6 @@ proc mapType(typ: PType): TJSTypeKind =
|
||||||
of tyProc: result = etyProc
|
of tyProc: result = etyProc
|
||||||
of tyCString: result = etyString
|
of tyCString: result = etyString
|
||||||
|
|
||||||
proc mangle(name: string): string =
|
|
||||||
result = ""
|
|
||||||
for i in countup(0, len(name) - 1):
|
|
||||||
case name[i]
|
|
||||||
of 'A'..'Z':
|
|
||||||
add(result, chr(ord(name[i]) - ord('A') + ord('a')))
|
|
||||||
of '_':
|
|
||||||
discard
|
|
||||||
of 'a'..'z', '0'..'9':
|
|
||||||
add(result, name[i])
|
|
||||||
else: add(result, 'X' & toHex(ord(name[i]), 2))
|
|
||||||
|
|
||||||
proc mangleName(s: PSym): PRope =
|
proc mangleName(s: PSym): PRope =
|
||||||
result = s.loc.r
|
result = s.loc.r
|
||||||
if result == nil:
|
if result == nil:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue