Skip to content

Instantly share code, notes, and snippets.

View -.nim
TTest* = object
pos*: range[0..15]
proc next(state: var TTest): int64 =
assert(state.pos >= 0 and state.pos < 16, "pos is " & $state.pos)
# Error: unhandled exception: state.pos >= 0 and state.pos < 16 pos is 140736480769200 [EAssertionFailed]
# 140736480769200 is incremented by a few million each execution
state.pos = (state.pos + 1) and 15
View -
import macros
macro void(name: expr, body: stmt): stmt {.immediate.} =
echo treeRepr name
void abc(int a, string b){
echo "test"
View -
import macros
macro void(name: expr): stmt {.immediate.} =
echo reprTree name
# Call
# Ident !"abc"
# Command
# Ident !"int"
flaviut / test.nim
Last active Aug 29, 2015
C in nimrod
View test.nim
import macros
template ctypedef(name: expr): stmt {.immediate.} =
macro `name`(body: expr): stmt {.immediate.} =
let head = body[0]
let procname = head[0]
var params = newSeq[PNimrodNode]()
for node in head.children:
case node.kind
of nnkCommand:
View nimdocs.ep
<?xml version="1.0"?>
<Document xmlns=""><Properties/><Pages><Page><Properties><Property name="name">Untitled Page</Property><Property name="id">1397597259991_8851</Property><Property name="width">1000</Property><Property name="height">1500</Property><Property name="dimBackground"/><Property name="transparentBackground">false</Property><Property name="backgroundColor">#C0C0C0FF</Property><Property name="fid">untitled_page</Property></Properties><Content><g xmlns="" p:type="Shape" xmlns:p="" p:def="Evolus.BasicWebElements:heading" p:sc="Heading 1" id="f632af5c128b455f867b3e967423d64e" transform="matrix(1,0,0,1,273,34)"><p:metadata><p:property name="textContent"><![CDATA[Prelude]]></p:property><p:property name="textFont"><![CDATA["Liberation Sans",Arial,sans-serif|bold|normal|24px|none]]></p:property><p:property name="textColor"><![CDATA[#000000FF]]></p:property><p:property name="customStyle"><![CDATA[]]></p:prop
View test6.nim
import macros, strutils
macro `:=`(a, b: expr): stmt {.immediate.} =
let tempVar = newIdentNode(!"tmp")
result = newLetStmt(tempVar, b)
var i = 0
for child in a.children:
var arrAccess = newNimNode(nnkBracketExpr)
View bitfield.nim
## Provides utility methods to make working with bit manipulations
## easier and less error prone
validBitfieldType = ["int", "int8", "int16", "int32", "int64", "uint",
"uint8", "uint16", "uint32", "uint64", "bool"]
macro bitfield(values: varargs[stmt]): stmt =
## Creates a bitfield with the given fields
# Validate and initial parameter processing
if values.len %% 3 != 0:
error("Each field requires three values")
flaviut / SMHasher Output
Last active Aug 29, 2015
Running the CrapWow hash through SMHasher
View SMHasher Output
--- Testing CrapWow (CrapWow)
[[[ Sanity Tests ]]]
Verification value 0x49ECB015 : Passed!
Running sanity check 1..........PASS
Running sanity check 2..........PASS
[[[ Speed Tests ]]]
View arithm.nim
{.emit: "#include <stdint.h>\n".}
FInt8* {.importc: "int8_t".} = object
proc `*`(a, b: FInt8): FInt8 =
{.emit: "return ((`a`)*(`b`));".}
proc toInt(a: FInt8): int =
{.emit: "return `a`;".}
var a: FInt8
View mysystem.nim
import exceptions
template checkBounds(idx, min, max: int) =
when not defined(release):
if idx < min or idx > max:
raiseException(errOutOfBounds, idx, min, max)
# TBuffer {{{