parent
363d0ada50
commit
162d74db91
2 changed files with 103 additions and 1 deletions
|
|
@ -1363,6 +1363,9 @@ proc unneededIndirection(n: PNode): bool =
|
||||||
n.typ.skipTypes(abstractInstOwned-{tyTypeDesc}).kind == tyRef
|
n.typ.skipTypes(abstractInstOwned-{tyTypeDesc}).kind == tyRef
|
||||||
|
|
||||||
proc canElimAddr(n: PNode): PNode =
|
proc canElimAddr(n: PNode): PNode =
|
||||||
|
if n.sons[0].typ.skipTypes(abstractInst).kind in {tyObject, tyTuple, tyArray}:
|
||||||
|
# objects are reference types in the VM
|
||||||
|
return n[0]
|
||||||
case n.sons[0].kind
|
case n.sons[0].kind
|
||||||
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
|
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
|
||||||
var m = n.sons[0].sons[0]
|
var m = n.sons[0].sons[0]
|
||||||
|
|
@ -2234,7 +2237,7 @@ proc genProc(c: PCtx; s: PSym): int =
|
||||||
c.gABC(body, opcEof, eofInstr.regA)
|
c.gABC(body, opcEof, eofInstr.regA)
|
||||||
c.optimizeJumps(result)
|
c.optimizeJumps(result)
|
||||||
s.offset = c.prc.maxSlots
|
s.offset = c.prc.maxSlots
|
||||||
#if s.name.s == "main":
|
#if s.name.s == "main" or s.name.s == "[]":
|
||||||
# echo renderTree(body)
|
# echo renderTree(body)
|
||||||
# c.echoCode(result)
|
# c.echoCode(result)
|
||||||
c.prc = oldPrc
|
c.prc = oldPrc
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,10 @@ discard """
|
||||||
nimout: '''caught Exception
|
nimout: '''caught Exception
|
||||||
main:begin
|
main:begin
|
||||||
main:end
|
main:end
|
||||||
|
@[{0}]
|
||||||
|
(width: 0, height: 0, path: "")
|
||||||
|
@[(width: 0, height: 0, path: ""), (width: 0, height: 0, path: "")]
|
||||||
|
Done!
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -81,3 +85,98 @@ proc simpleTryFinally()=
|
||||||
echo "main:end"
|
echo "main:end"
|
||||||
|
|
||||||
static: simpleTryFinally()
|
static: simpleTryFinally()
|
||||||
|
|
||||||
|
# bug #10981
|
||||||
|
|
||||||
|
import sets
|
||||||
|
|
||||||
|
proc main =
|
||||||
|
for i in 0..<15:
|
||||||
|
var someSets = @[initHashSet[int]()]
|
||||||
|
someSets[^1].incl(0) # <-- segfaults
|
||||||
|
if i == 0:
|
||||||
|
echo someSets
|
||||||
|
|
||||||
|
static:
|
||||||
|
main()
|
||||||
|
|
||||||
|
# bug #7261
|
||||||
|
const file = """
|
||||||
|
sprites.png
|
||||||
|
size: 1024,1024
|
||||||
|
format: RGBA8888
|
||||||
|
filter: Linear,Linear
|
||||||
|
repeat: none
|
||||||
|
char/slide_down
|
||||||
|
rotate: false
|
||||||
|
xy: 730, 810
|
||||||
|
size: 204, 116
|
||||||
|
orig: 204, 116
|
||||||
|
offset: 0, 0
|
||||||
|
index: -1
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
AtlasPage = object
|
||||||
|
width, height: int
|
||||||
|
path: string
|
||||||
|
|
||||||
|
CtsStream = object
|
||||||
|
data: string
|
||||||
|
pos: int
|
||||||
|
|
||||||
|
proc atEnd(stream: CtsStream): bool =
|
||||||
|
stream.pos >= stream.data.len
|
||||||
|
|
||||||
|
proc readChar(stream: var CtsStream): char =
|
||||||
|
if stream.atEnd:
|
||||||
|
result = '\0'
|
||||||
|
else:
|
||||||
|
result = stream.data[stream.pos]
|
||||||
|
inc stream.pos
|
||||||
|
|
||||||
|
proc readLine(s: var CtsStream, line: var string): bool =
|
||||||
|
# This is pretty much copied from the standard library:
|
||||||
|
line.setLen(0)
|
||||||
|
while true:
|
||||||
|
var c = readChar(s)
|
||||||
|
if c == '\c':
|
||||||
|
c = readChar(s)
|
||||||
|
break
|
||||||
|
elif c == '\L': break
|
||||||
|
elif c == '\0':
|
||||||
|
if line.len > 0: break
|
||||||
|
else: return false
|
||||||
|
line.add(c)
|
||||||
|
result = true
|
||||||
|
|
||||||
|
proc peekLine(s: var CtsStream, line: var string): bool =
|
||||||
|
let oldPos = s.pos
|
||||||
|
result = s.readLine(line)
|
||||||
|
s.pos = oldPos
|
||||||
|
|
||||||
|
proc initCtsStream(data: string): CtsStream =
|
||||||
|
CtsStream(
|
||||||
|
pos: 0,
|
||||||
|
data: data
|
||||||
|
)
|
||||||
|
|
||||||
|
# ********************
|
||||||
|
# Interesting stuff happens here:
|
||||||
|
# ********************
|
||||||
|
|
||||||
|
proc parseAtlas(stream: var CtsStream) =
|
||||||
|
var pages = @[AtlasPage(), AtlasPage()]
|
||||||
|
var line = ""
|
||||||
|
|
||||||
|
block:
|
||||||
|
let page = addr pages[^1]
|
||||||
|
discard stream.peekLine(line)
|
||||||
|
discard stream.peekLine(line)
|
||||||
|
echo page[]
|
||||||
|
echo pages
|
||||||
|
|
||||||
|
static:
|
||||||
|
var stream = initCtsStream(file)
|
||||||
|
parseAtlas(stream)
|
||||||
|
echo "Done!"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue