php-codegen fixes
This commit is contained in:
parent
db4b9b1bdd
commit
8ec7c0af20
2 changed files with 12 additions and 4 deletions
|
|
@ -180,12 +180,15 @@ proc mangleName(s: PSym; target: TTarget): Rope =
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < s.name.s.len:
|
while i < s.name.s.len:
|
||||||
let c = s.name.s[i]
|
let c = s.name.s[i]
|
||||||
if c in {'A'..'Z'}:
|
case c
|
||||||
|
of 'A'..'Z':
|
||||||
if i > 0 and s.name.s[i-1] in {'a'..'z'}:
|
if i > 0 and s.name.s[i-1] in {'a'..'z'}:
|
||||||
x.add '_'
|
x.add '_'
|
||||||
x.add(chr(c.ord - 'A'.ord + 'a'.ord))
|
x.add(chr(c.ord - 'A'.ord + 'a'.ord))
|
||||||
else:
|
of 'a'..'z', '_', '0'..'9':
|
||||||
x.add c
|
x.add c
|
||||||
|
else:
|
||||||
|
x.add("HEX" & toHex(ord(c), 2))
|
||||||
inc i
|
inc i
|
||||||
result = rope(x)
|
result = rope(x)
|
||||||
add(result, "_")
|
add(result, "_")
|
||||||
|
|
@ -1571,7 +1574,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
"(strlen($1)-1)")
|
"(strlen($1)-1)")
|
||||||
else:
|
else:
|
||||||
unaryExpr(p, n, r, "", "($1 != null ? ($1.length-1) : -1)" |
|
unaryExpr(p, n, r, "", "($1 != null ? ($1.length-1) : -1)" |
|
||||||
"(count($1.length)-1)")
|
"(count($1)-1)")
|
||||||
of mInc:
|
of mInc:
|
||||||
if n[1].typ.skipTypes(abstractRange).kind in tyUInt .. tyUInt64:
|
if n[1].typ.skipTypes(abstractRange).kind in tyUInt .. tyUInt64:
|
||||||
binaryUintExpr(p, n, r, "+", true)
|
binaryUintExpr(p, n, r, "+", true)
|
||||||
|
|
@ -1614,7 +1617,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
if p.target == targetJS:
|
if p.target == targetJS:
|
||||||
unaryExpr(p, n, r, "mnewString", "mnewString(0)")
|
unaryExpr(p, n, r, "mnewString", "mnewString(0)")
|
||||||
else:
|
else:
|
||||||
unaryExpr(p, n, r, "", "$# = ''")
|
unaryExpr(p, n, r, "", "''")
|
||||||
of mDotDot:
|
of mDotDot:
|
||||||
genProcForSymIfNeeded(p, n.sons[0].sym)
|
genProcForSymIfNeeded(p, n.sons[0].sym)
|
||||||
genCall(p, n, r)
|
genCall(p, n, r)
|
||||||
|
|
|
||||||
|
|
@ -275,6 +275,11 @@ proc mnewString(len: int): string {.asmNoStackFrame, compilerproc.} =
|
||||||
return result;
|
return result;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
when defined(nimphp):
|
||||||
|
proc nimSubstr(s: string; a, b: int): string {.
|
||||||
|
asmNoStackFrame, compilerproc.} =
|
||||||
|
asm """return substr(`s`,`a`,`b`-`a`+1);"""
|
||||||
|
|
||||||
proc SetCard(a: int): int {.compilerproc, asmNoStackFrame.} =
|
proc SetCard(a: int): int {.compilerproc, asmNoStackFrame.} =
|
||||||
# argument type is a fake
|
# argument type is a fake
|
||||||
when defined(nimphp):
|
when defined(nimphp):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue