mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 15:44:14 +00:00
Merge branch 'devel' into pr_remove_macros
This commit is contained in:
@@ -611,8 +611,7 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||
n[1] = makeTypeSymNode(c, lhsType, n[1].info)
|
||||
lhsType = n[1].typ
|
||||
else:
|
||||
if lhsType.base.kind == tyNone or
|
||||
(c.inGenericContext > 0 and lhsType.base.containsGenericType):
|
||||
if c.inGenericContext > 0 and lhsType.base.containsGenericType:
|
||||
# BUGFIX: don't evaluate this too early: ``T is void``
|
||||
return
|
||||
|
||||
|
||||
@@ -421,8 +421,9 @@ proc foldConv(n, a: PNode; idgen: IdGenerator; g: ModuleGraph; check = false): P
|
||||
of tyChar, tyUInt..tyUInt64, tyInt..tyInt64:
|
||||
var val = a.getOrdValue
|
||||
if dstTyp.kind in {tyUInt..tyUInt64}:
|
||||
result = newIntNodeT(val, n, idgen, g)
|
||||
result = newIntNodeT(maskBytes(val, getSize(g.config, dstTyp)), n, idgen, g)
|
||||
result.transitionIntKind(nkUIntLit)
|
||||
result.typ = dstTyp
|
||||
else:
|
||||
if check: rangeCheck(n, val, g)
|
||||
result = newIntNodeT(val, n, idgen, g)
|
||||
|
||||
@@ -1785,10 +1785,6 @@ proc typeSectionFinalPass(c: PContext, n: PNode) =
|
||||
checkForMetaFields(c, baseType.n, hasError)
|
||||
if not hasError:
|
||||
checkConstructedType(c.config, s.info, s.typ)
|
||||
|
||||
# fix bug #5170, bug #17162, bug #15526: ensure locally scoped types get a unique name:
|
||||
if s.typ.kind in {tyEnum, tyRef, tyObject} and not isTopLevel(c):
|
||||
incl(s.flags, sfGenSym)
|
||||
#instAllTypeBoundOp(c, n.info)
|
||||
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ proc hashSym(c: var MD5Context, s: PSym) =
|
||||
c &= it.name.s
|
||||
c &= "."
|
||||
it = it.owner
|
||||
c &= "#"
|
||||
c &= s.disamb
|
||||
|
||||
proc hashTypeSym(c: var MD5Context, s: PSym; conf: ConfigRef) =
|
||||
if sfAnon in s.flags or s.kind == skGenericParam:
|
||||
@@ -69,6 +71,8 @@ proc hashTypeSym(c: var MD5Context, s: PSym; conf: ConfigRef) =
|
||||
c &= it.name.s
|
||||
c &= "."
|
||||
it = it.owner
|
||||
c &= "#"
|
||||
c &= s.disamb
|
||||
|
||||
proc hashTree(c: var MD5Context, n: PNode; flags: set[ConsiderFlag]; conf: ConfigRef) =
|
||||
if n == nil:
|
||||
|
||||
@@ -67,7 +67,8 @@ proc inotify_init*(): FileHandle {.cdecl, importc: "inotify_init",
|
||||
|
||||
proc inotify_init1*(flags: cint): FileHandle {.cdecl, importc: "inotify_init1",
|
||||
header: "<sys/inotify.h>".}
|
||||
## Create and initialize inotify instance.
|
||||
## Like `inotify_init<#inotify_init>`_ ,
|
||||
## but has a flags argument that provides access to some extra functionality.
|
||||
|
||||
proc inotify_add_watch*(fd: cint; name: cstring; mask: uint32): cint {.cdecl,
|
||||
importc: "inotify_add_watch", header: "<sys/inotify.h>".}
|
||||
@@ -79,11 +80,18 @@ proc inotify_rm_watch*(fd: cint; wd: cint): cint {.cdecl,
|
||||
|
||||
iterator inotify_events*(evs: pointer, n: int): ptr InotifyEvent =
|
||||
## Abstract the packed buffer interface to yield event object pointers.
|
||||
## ```Nim
|
||||
## var evs = newSeq[byte](8192) # Already did inotify_init+add_watch
|
||||
## while (let n = read(fd, evs[0].addr, 8192); n) > 0: # read forever
|
||||
## for e in inotify_events(evs[0].addr, n): echo e[].len # echo name lens
|
||||
## ```
|
||||
runnableExamples("-r:off"):
|
||||
when defined(linux):
|
||||
import std/posix # needed for FileHandle read procedure
|
||||
const MaxWatches = 8192
|
||||
|
||||
let inotifyFd = inotify_init() # create new inotify instance and get it's FileHandle
|
||||
let wd = inotifyFd.inotify_add_watch("/tmp", IN_CREATE or IN_DELETE) # Add new watch
|
||||
|
||||
var events: array[MaxWatches, byte] # event buffer
|
||||
while (let n = read(inotifyFd, addr events, MaxWatches); n) > 0: # blocks until any events have been read
|
||||
for e in inotify_events(addr events, n):
|
||||
echo (e[].wd, e[].mask, cast[cstring](addr e[].name)) # echo watch id, mask, and name value of each event
|
||||
var ev: ptr InotifyEvent = cast[ptr InotifyEvent](evs)
|
||||
var n = n
|
||||
while n > 0:
|
||||
@@ -94,8 +102,10 @@ iterator inotify_events*(evs: pointer, n: int): ptr InotifyEvent =
|
||||
|
||||
runnableExamples:
|
||||
when defined(linux):
|
||||
let inoty: FileHandle = inotify_init() ## Create 1 Inotify.
|
||||
doAssert inoty >= 0 ## Check for errors (FileHandle is alias to cint).
|
||||
let watchdoge: cint = inotify_add_watch(inoty, ".", IN_ALL_EVENTS) ## Add directory to watchdog.
|
||||
doAssert watchdoge >= 0 ## Check for errors.
|
||||
doAssert inotify_rm_watch(inoty, watchdoge) >= 0 ## Remove directory from the watchdog
|
||||
let inotifyFd = inotify_init() # create and get new inotify FileHandle
|
||||
doAssert inotifyFd >= 0 # check for errors
|
||||
|
||||
let wd = inotifyFd.inotify_add_watch("/tmp", IN_CREATE or IN_DELETE) # Add new watch
|
||||
doAssert wd >= 0 # check for errors
|
||||
|
||||
discard inotifyFd.inotify_rm_watch(wd) # remove watch
|
||||
|
||||
@@ -142,7 +142,7 @@ pkg "pixie"
|
||||
pkg "plotly", "nim c examples/all.nim"
|
||||
pkg "pnm"
|
||||
pkg "polypbren"
|
||||
pkg "presto"
|
||||
pkg "presto", allowFailure = true
|
||||
pkg "prologue", "nimble tcompile"
|
||||
pkg "protobuf", "nim c -o:protobuff -r src/protobuf.nim"
|
||||
pkg "rbtree"
|
||||
|
||||
@@ -109,3 +109,12 @@ block: # make sure `hashType` doesn't recurse infinitely
|
||||
a, b: PFoo
|
||||
c: int
|
||||
var a: PFoo
|
||||
|
||||
block: # issue #22571
|
||||
macro foo(x: typed) =
|
||||
result = x
|
||||
|
||||
block: # or `proc main =`
|
||||
foo:
|
||||
type Foo = object
|
||||
doAssert $Foo() == "()"
|
||||
|
||||
@@ -47,3 +47,8 @@ block:
|
||||
# bug #14522
|
||||
doAssert 0xFF000000_00000000.uint64 == 18374686479671623680'u64
|
||||
|
||||
block: # bug #23954
|
||||
let testRT_u8 : uint8 = 0x107.uint8
|
||||
doAssert testRT_u8 == 7
|
||||
const testCT_u8 : uint8 = 0x107.uint8
|
||||
doAssert testCT_u8 == 7
|
||||
|
||||
@@ -165,3 +165,7 @@ block: # previously tisop.nim
|
||||
doAssert f.y.typeof is float
|
||||
doAssert f.z.typeof is float
|
||||
p(A, f)
|
||||
|
||||
block: # issue #22850
|
||||
doAssert not (type is int)
|
||||
doAssert not (typedesc is int)
|
||||
|
||||
Reference in New Issue
Block a user