Skip to content

Instantly share code, notes, and snippets.

@Araq
Araq / closureExample.nim
Created March 10, 2012 11:00
closure issue
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
@Araq
Araq / closures.nim
Created June 18, 2012 22:21
another closure issue
proc outer =
var x = 0
proc innerB() =
capture x
while true:
var y = 0
proc innerA =
@Araq
Araq / desc.txt
Created September 29, 2012 21:34
Nimrod_description
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.
@Araq
Araq / opt_dispatch.nim
Created November 21, 2012 19:10
Optimizing dynamic dispatch
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
@Araq
Araq / contexts.nim
Created May 14, 2013 22:17
contexts
# module A
var a: int
template tmp*(): expr =
# declaration context: the 'a' from module A
a
@Araq
Araq / bench1
Last active December 20, 2015 23:39
Some stupid benchmark with high variance on my machine
# 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
@Araq
Araq / gist:6428326
Created September 3, 2013 19:18
asm test
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"
@Araq
Araq / release.bat
Last active January 18, 2016 14:20
Release instructions
REM - Run the full testsuite; tests\testament\tester all
REM - Uncomment the list of changes in news.txt
REM - write a news ticker entry
REM - Update the version
REM - Generate the full docs; koch web0
REM - Generate the installers;
REM - Update the version in system.nim
REM - Test the installers
type
VTable = object
methodA: proc (this: MyObject; a, b: int)
methodB: proc (this: MyObject; a, b: string)
OtherObject = object
fieldA: int
fieldB: int
MyObject = object
vtab {.delegate(this).}: ptr VTable
const CacheLineSize = 32 # true for most archs
type
Barrier = object
entered: int
cv: Semaphore # Semaphore takes 3 words at least
when sizeof(int) < 8:
cacheAlign: array[CacheLineSize-4*sizeof(int), byte]
left: int
cacheAlign2: array[CacheLineSize-sizeof(int), byte]