Nim 2.0.8 Manualcode that will be executed at compile time cannot use the following language features: methods closure iterators the cast operator reference (pointer) types FFI The use of wrappers that use FFI and/or convention closure . Nim supports these calling conventions: nimcall is the default convention used for a Nim proc. It is the same as fastcall , but only for C compilers that support fastcall . closure is procedure has a hidden implicit parameter (an environment). Proc vars that have the calling convention closure take up two machine words: One for the proc pointer and another one for the pointer to implicitly0 码力 | 132 页 | 5.73 MB | 1 年前3
Nim 2.0.2 中文手册{nextFib()}") result static: echo displayFib 对编译期执⾏的限制 编译期执⾏的 Nim 代码不能使⽤以下语⾔特性: methods ⽅法 closure iterators 闭包迭代器 cast 运算符 引⽤ (指针) 类型 FFI 不允许使⽤ FFI 和/或 cast 的包装器。请注意,这也包括标准库中的包装器。 随着时间的推移,可能会取消部分或所有限制。 的特例,调⽤约定为 nimcall 的过程可以被传递给期望调⽤约定为 closure 的过程参数。 Nim ⽀持下列 calling conventions "调⽤约定": nimcall 是Nim proc 使⽤的默认约定。它与 fastcall 相同,但只适⽤于⽀持 fastcall 的 C 编译器。 closure 是 程序类型 没有任意编译指示注解的默认调⽤约定,该过程有⼀个隐藏参数( 藏参数( environment "环境")。 具有 closure 调⽤约定的过程变体占⽤两个机器字。⼀个是过程的指针,另⼀个是指向隐藏参数环境的指针。 type Data = tuple[x, y: int, s: string] # 在堆上为 Data 分配内存: var d = cast[ptr Data](alloc0(sizeof(Data))) # 在垃圾回收(GC)堆上创建⼀个新的字符串:0 码力 | 127 页 | 7.05 MB | 1 年前3
Nim - the first high performance language with full support for hot codereloading at runtimerespects the type system levels of complexity: normal procs and inline iterators generic procs and closure iterators templates macros 11 Templates Templates template withFile(f: untyped, filename: string closures to C/C++ (resumable funcs) iterator closure_iter*(): int {.closure.} = # a resumable function var x = 1 while x < 10: yield x inc x for i in closure_iter(): echo i 1 2 3 4 5 6 struct state_type int x1; // the state }; struct closure_type { N_NIMCALL_PTR(int, c_ptr) (void* e_ptr); // function ptr void* e_ptr; // environment ptr }; N_LIB_PRIVATE N_CLOSURE(int, func)(void* e_ptr) { // def0 码力 | 63 页 | 2.91 MB | 1 年前3
Computer Programming with the Nim Programming Language
currently provides two types of iterators — inline iterators, which are currently the default type, and closure iterators, which are similar to functions. Inline iterators create a hidden while loop whenever restrictions and increase the final code size of the executable, much as an explicit while loop would do. Closure iterators are real entities, like procedures, meaning we can assign them to variables. However, sub-procedures access variables of the outer scope. In this case, the sub-procedure is called a closure: proc digitScanner(s: string) = var pos = 0 proc nextDigit: char = while pos < s.len and0 码力 | 865 页 | 7.45 MB | 1 年前3
Computer Programming with the Nim Programming Language
currently provides two types of iterators — inline iterators, which are currently the default type, and closure iterators, which are similar to functions. Inline iterators create a hidden while loop whenever restrictions and increase the final code size of the executable, much as an explicit while loop would do. Closure iterators are real entities, like procedures, meaning we can assign them to variables. However, sub-procedures access variables of the outer scope. In this case, the sub-procedure is called a closure: proc digitScanner(s: string) = var pos = 0 proc nextDigit: char = while pos < s.len and0 码力 | 784 页 | 2.13 MB | 1 年前3
Computer Programming with the Nim Programming Languageprovides two types of itera tors — inline iterators, which are currently the default type, and closure iterators, which are simi lar to functions. Inline iterators create a hidden while loop whenever and increase the final code size 107 of the executable, much as an explicit while loop would do. Closure iterators are real entities, like procedures, meaning we can assign them to variables. However, sub- procedures access variables of the outer scope. In this case, the sub-procedure is called a closure: proc digitScanner(s: string) = var pos = 0 proc nextDigit: char = while pos < s.len and0 码力 | 512 页 | 3.54 MB | 1 年前3
Computer Programming with the Nim Programming Languagecurrently provides two types of iterators — inline iterators, which are currently the default type, and closure iterators, which are similar to functions. Inline iterators create a hidden while loop whenever restrictions and increase the final code size of the executable, much as an explicit while loop would do. Closure iterators are real entities, like procedures, mean ing we can assign them to variables. However sub-proce dures access variables of the outer scope. In this case, the sub-procedure is called a closure: proc digitScanner(s: string) = var pos = 0 proc nextDigit: char = while pos < s.len and0 码力 | 508 页 | 3.50 MB | 1 年前3
Computer Programming with the Nim Programming Languageprovides two types of itera tors — inline iterators, which are currently the default type, and closure iterators, which are simi lar to functions. Inline iterators create a hidden while loop whenever and increase the final code size 107 of the executable, much as an explicit while loop would do. Closure iterators are real entities, like procedures, meaning we can assign them to variables. However, sub- procedures access variables of the outer scope. In this case, the sub-procedure is called a closure: proc digitScanner(s: string) = var pos = 0 proc nextDigit: char = while pos < s.len and0 码力 | 512 页 | 3.53 MB | 1 年前3
Computer Programming with the Nim Programming Languagecurrently provides two types of iterators — inline iterators, which are currently the default type, and closure iterators, which are similar to functions. Inline iterators create a hidden while loop whenever restrictions and increase the final code size of the executable, much as an explicit while loop would do. Closure iterators are real entities, like procedures, mean ing we can assign them to variables. However sub-proce dures access variables of the outer scope. In this case, the sub-procedure is called a closure: proc digitScanner(s: string) = var pos = 0 proc nextDigit: char = while pos < s.len and0 码力 | 508 页 | 3.54 MB | 1 年前3
Computer Programming with the Nim Programming Languagecurrently provides two types of iterators — inline iterators, which are currently the default type, and closure iterators, which are similar to functions. Inline iterators create a hidden while loop whenever restrictions and increase the final code size of the executable, much as an explicit while loop would do. Closure iterators are real entities, like procedures, mean ing we can assign them to variables. However sub-proce dures access variables of the outer scope. In this case, the sub-procedure is called a closure: proc digitScanner(s: string) = var pos = 0 proc nextDigit: char = while pos < s.len and0 码力 | 508 页 | 3.50 MB | 1 年前3
共 33 条
- 1
- 2
- 3
- 4













