php-codegen fixes

This commit is contained in:
Andreas Rumpf
2016-02-06 19:58:28 +01:00
parent db4b9b1bdd
commit 8ec7c0af20
2 changed files with 12 additions and 4 deletions

View File

@@ -180,12 +180,15 @@ proc mangleName(s: PSym; target: TTarget): Rope =
var i = 0
while i < s.name.s.len:
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'}:
x.add '_'
x.add(chr(c.ord - 'A'.ord + 'a'.ord))
else:
of 'a'..'z', '_', '0'..'9':
x.add c
else:
x.add("HEX" & toHex(ord(c), 2))
inc i
result = rope(x)
add(result, "_")
@@ -1571,7 +1574,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
"(strlen($1)-1)")
else:
unaryExpr(p, n, r, "", "($1 != null ? ($1.length-1) : -1)" |
"(count($1.length)-1)")
"(count($1)-1)")
of mInc:
if n[1].typ.skipTypes(abstractRange).kind in tyUInt .. tyUInt64:
binaryUintExpr(p, n, r, "+", true)
@@ -1614,7 +1617,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
if p.target == targetJS:
unaryExpr(p, n, r, "mnewString", "mnewString(0)")
else:
unaryExpr(p, n, r, "", "$# = ''")
unaryExpr(p, n, r, "", "''")
of mDotDot:
genProcForSymIfNeeded(p, n.sons[0].sym)
genCall(p, n, r)

View File

@@ -275,6 +275,11 @@ proc mnewString(len: int): string {.asmNoStackFrame, compilerproc.} =
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.} =
# argument type is a fake
when defined(nimphp):