This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const CacheLineSize = 32 # true for most archs | |
| type | |
| Barrier {.compilerProc.} = object | |
| entered: int | |
| cv: CondVar # condvar takes 3 words at least | |
| when sizeof(int) < 8: | |
| cacheAlign: array[CacheLineSize-4*sizeof(int), byte] | |
| left: int | |
| cacheAlign2: array[CacheLineSize-sizeof(int), byte] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const | |
| Identity = [ | |
| [1, 0, 0], | |
| [0, 1, 0], | |
| [0, 0, 1] | |
| ] | |
| Identity = Matrix([ | |
| [1, 0, 0], | |
| [0, 1, 0], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| proc test() = | |
| asm """ | |
| ".byte 0xCC\n" | |
| "push %rcx\n" | |
| "push %rdx\n" | |
| "push %r8\n" | |
| "mov `navmBackendS1`, %rax\n" | |
| "mov `navmBackendS2`, %r8\n" | |
| "mov `navmBackendTempAdr`, %rdx\n" | |
| "call *%rdx\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Compile with nimrod c -d:release --passC:-fopenmp --passL:-fopenmp PN.nim | |
| import os, strutils, unsigned | |
| const | |
| TileDim = 50'i32 | |
| Miw = 2 | |
| MaxWid = 8 | |
| NumLevs = 800 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # module A | |
| var a: int | |
| template tmp*(): expr = | |
| # declaration context: the 'a' from module A | |
| a | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if a of Z: | |
| echo "Z" | |
| elif a of Y: | |
| echo "Y" | |
| elif a of X: | |
| echo "X" | |
| 'of' is expensive and will become MORE expensive for proper DLL support | |
| (string comparisons!). Thus we reserve a slot for the exact matched object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Nimrod is a statically typed, imperative programming language that tries to | |
| give the programmer ultimate power without compromises on runtime efficiency. | |
| This means it focuses on compile-time mechanisms in all its | |
| various forms. Beneath a nice infix/indentation based syntax with a | |
| powerful (AST based, hygienic) macro system lies a semantic model that supports | |
| a soft realtime GC on thread local heaps. Asynchronous message passing is used | |
| between threads, so no "stop the world" mechanism is necessary. An unsafe | |
| shared memory heap is also provided for the increased efficiency that results | |
| from that model. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| proc outer = | |
| var x = 0 | |
| proc innerB() = | |
| capture x | |
| while true: | |
| var y = 0 | |
| proc innerA = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var funcs: seq[proc (): int {.closure.}] = @[] | |
| proc main() = | |
| var i = 0 | |
| while i <= 10: | |
| funcs.add((proc (): int = | |
| var x = i | |
| return x * x)) | |
| inc i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| proc p = | |
| var delta = 7 | |
| proc accumulator(start: int): proc(): int = | |
| var x = start-1 | |
| result = proc (): int = | |
| x = x + delta | |
| inc delta | |
| return x | |
| var a = accumulator(3) |