more fixes for new integer promotion rules; fixes #152; fixes #157; fixes #156; fixes #155

This commit is contained in:
Araq 2012-07-09 21:11:11 +02:00
commit 4966212141
8 changed files with 27 additions and 20 deletions

View file

@ -391,6 +391,7 @@ proc symToYaml(n: PSym, indent: int = 0, maxRecDepth: int = - 1): PRope =
var marker = InitIntSet() var marker = InitIntSet()
result = symToYamlAux(n, marker, indent, maxRecDepth) result = symToYamlAux(n, marker, indent, maxRecDepth)
proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope
proc debugType(n: PType): PRope = proc debugType(n: PType): PRope =
if n == nil: if n == nil:
result = toRope("null") result = toRope("null")
@ -407,6 +408,9 @@ proc debugType(n: PType): PRope =
app(result, "null") app(result, "null")
else: else:
app(result, debugType(n.sons[i])) app(result, debugType(n.sons[i]))
if n.kind == tyObject and n.n != nil:
app(result, ", node: ")
app(result, debugTree(n.n, 2, 100))
app(result, ")") app(result, ")")
proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope = proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope =

View file

@ -601,6 +601,9 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
else: else:
result = magicCall(m, n) result = magicCall(m, n)
of mIs: of mIs:
# BUGFIX: don't evaluate this too early: ``T is void``
if not containsGenericType(n[1].typ) and
not containsGenericType(n[2].typ):
result = newIntNodeT(ord(sameType(n[1].typ, n[2].typ)), n) result = newIntNodeT(ord(sameType(n[1].typ, n[2].typ)), n)
of mAstToStr: of mAstToStr:
result = newStrNodeT(renderTree(n[1], {renderNoComments}), n) result = newStrNodeT(renderTree(n[1], {renderNoComments}), n)

View file

@ -31,12 +31,6 @@ proc checkConstructedType*(info: TLineInfo, typ: PType) =
if t.sons[0].kind != tyObject or tfFinal in t.sons[0].flags: if t.sons[0].kind != tyObject or tfFinal in t.sons[0].flags:
localError(info, errInheritanceOnlyWithNonFinalObjects) localError(info, errInheritanceOnlyWithNonFinalObjects)
proc containsGenericTypeIter(t: PType, closure: PObject): bool =
result = t.kind in GenericTypes
proc containsGenericType*(t: PType): bool =
result = iterOverType(t, containsGenericTypeIter, nil)
proc searchInstTypes(tab: TIdTable, key: PType): PType = proc searchInstTypes(tab: TIdTable, key: PType): PType =
# returns nil if we need to declare this type # returns nil if we need to declare this type
result = PType(IdTableGet(tab, key)) result = PType(IdTableGet(tab, key))

View file

@ -1094,3 +1094,9 @@ proc getSize(typ: PType): biggestInt =
result = computeSize(typ) result = computeSize(typ)
if result < 0: InternalError("getSize(" & $typ.kind & ')') if result < 0: InternalError("getSize(" & $typ.kind & ')')
proc containsGenericTypeIter(t: PType, closure: PObject): bool =
result = t.kind in GenericTypes
proc containsGenericType*(t: PType): bool =
result = iterOverType(t, containsGenericTypeIter, nil)

View file

@ -297,6 +297,6 @@ when isMainModule:
for w in r.items: for w in r.items:
echo w echo w
for w in r.allPrefixed("de"): for w in r.itemsWithPrefix("de"):
echo w echo w

View file

@ -455,7 +455,7 @@ when defined(Windows) and not defined(useNimRtl):
rfds[i] = readfds[i].FProcessHandle rfds[i] = readfds[i].FProcessHandle
var ret = waitForMultipleObjects(readfds.len.int32, var ret = waitForMultipleObjects(readfds.len.int32,
addr(rfds), 0'i32, timeout) addr(rfds), 0'i32, timeout.int32)
case ret case ret
of WAIT_TIMEOUT: of WAIT_TIMEOUT:
return 0 return 0

View file

@ -352,7 +352,7 @@ proc bindAddr*(socket: TSocket, port = TPort(0), address = "") =
hints.ai_socktype = toInt(SOCK_STREAM) hints.ai_socktype = toInt(SOCK_STREAM)
hints.ai_protocol = toInt(IPPROTO_TCP) hints.ai_protocol = toInt(IPPROTO_TCP)
gaiNim(address, port, hints, aiList) gaiNim(address, port, hints, aiList)
if bindSocket(socket.fd, aiList.ai_addr, aiList.ai_addrLen) < 0'i32: if bindSocket(socket.fd, aiList.ai_addr, aiList.ai_addrLen.cint) < 0'i32:
OSError() OSError()
when false: when false:
@ -570,7 +570,7 @@ proc connect*(socket: TSocket, name: string, port = TPort(0),
var success = false var success = false
var it = aiList var it = aiList
while it != nil: while it != nil:
if connect(socket.fd, it.ai_addr, it.ai_addrlen) == 0'i32: if connect(socket.fd, it.ai_addr, it.ai_addrlen.cint) == 0'i32:
success = true success = true
break break
it = it.ai_next it = it.ai_next
@ -624,7 +624,7 @@ proc connectAsync*(socket: TSocket, name: string, port = TPort(0),
var success = false var success = false
var it = aiList var it = aiList
while it != nil: while it != nil:
var ret = connect(socket.fd, it.ai_addr, it.ai_addrlen) var ret = connect(socket.fd, it.ai_addr, it.ai_addrlen.cint)
if ret == 0'i32: if ret == 0'i32:
success = true success = true
break break
@ -669,8 +669,8 @@ proc connectAsync*(socket: TSocket, name: string, port = TPort(0),
proc timeValFromMilliseconds(timeout = 500): TTimeVal = proc timeValFromMilliseconds(timeout = 500): TTimeVal =
if timeout != -1: if timeout != -1:
var seconds = timeout div 1000 var seconds = timeout div 1000
result.tv_sec = seconds result.tv_sec = seconds.int32
result.tv_usec = (timeout - seconds * 1000) * 1000 result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
#proc recvfrom*(s: TWinSocket, buf: cstring, len, flags: cint, #proc recvfrom*(s: TWinSocket, buf: cstring, len, flags: cint,
# fromm: ptr TSockAddr, fromlen: ptr cint): cint # fromm: ptr TSockAddr, fromlen: ptr cint): cint
@ -772,9 +772,9 @@ proc readIntoBuf(socket: TSocket, flags: int32): int =
if socket.isSSL: if socket.isSSL:
result = SSLRead(socket.sslHandle, addr(socket.buffer), int(socket.buffer.high)) result = SSLRead(socket.sslHandle, addr(socket.buffer), int(socket.buffer.high))
else: else:
result = recv(socket.fd, addr(socket.buffer), int(socket.buffer.high), flags) result = recv(socket.fd, addr(socket.buffer), cint(socket.buffer.high), flags)
else: else:
result = recv(socket.fd, addr(socket.buffer), int(socket.buffer.high), flags) result = recv(socket.fd, addr(socket.buffer), cint(socket.buffer.high), flags)
if result <= 0: if result <= 0:
socket.buflen = 0 socket.buflen = 0
socket.currPos = 0 socket.currPos = 0
@ -824,9 +824,9 @@ proc recv*(socket: TSocket, data: pointer, size: int): int =
if socket.isSSL: if socket.isSSL:
result = SSLRead(socket.sslHandle, data, size) result = SSLRead(socket.sslHandle, data, size)
else: else:
result = recv(socket.fd, data, size, 0'i32) result = recv(socket.fd, data, size.cint, 0'i32)
else: else:
result = recv(socket.fd, data, size, 0'i32) result = recv(socket.fd, data, size.cint, 0'i32)
proc waitFor(socket: TSocket, waited: var float, timeout: int): int = proc waitFor(socket: TSocket, waited: var float, timeout: int): int =
## returns the number of characters available to be read. In unbuffered ## returns the number of characters available to be read. In unbuffered
@ -1068,7 +1068,7 @@ proc send*(socket: TSocket, data: pointer, size: int): int =
return SSLWrite(socket.sslHandle, cast[cstring](data), size) return SSLWrite(socket.sslHandle, cast[cstring](data), size)
when defined(windows) or defined(macosx): when defined(windows) or defined(macosx):
result = send(socket.fd, data, size, 0'i32) result = send(socket.fd, data, size.cint, 0'i32)
else: else:
result = send(socket.fd, data, size, int32(MSG_NOSIGNAL)) result = send(socket.fd, data, size, int32(MSG_NOSIGNAL))

View file

@ -10,7 +10,7 @@ import
osproc, osproc,
cairowin32, cairoxlib, cairowin32, cairoxlib,
gl, glut, glu, glx, glext, wingl, gl, glut, glu, glx, glext, wingl,
lua, lualib, lauxlib, mysql, sqlite3, db_mongo lua, lualib, lauxlib, mysql, sqlite3, db_mongo, osproc
writeln(stdout, "test compilation of binding modules") writeln(stdout, "test compilation of binding modules")