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
type | |
TMaybeKind = enum | |
kNone, | |
kJust | |
TMaybe[T] = object | |
case kind: TMaybeKind | |
of kJust: | |
v: ref T | |
else: nil |
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 enumConstructor(c: PContext, head: PNode): PNode = | |
var sym = lookUp(c, head.sons[0]) | |
var val = lookUp(c, head.sons[1]) | |
result = newNodeI(nkInfix, head.info) | |
result.addSon(newIdentNode(getIdent("or"), head.info)) | |
result.addSon(newIntNode(nkIntLit, sym.position)) | |
var x = newNodeIT(nkCast, head.info, getSysType(tyInt)) | |
x.addSon(newNodeIT(nkType, head.info, getSysType(tyInt))) | |
var y = newNodeIT(nkAddr, head.info, x.typ) | |
y.addSon(newSymNode(val, head.info)) |
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
type | |
TPnt = tuple[x,y: float] | |
TMaybe {.enumSumTyp.} = enum | |
None, | |
Just = TPnt | |
var | |
x = (x: 45.96, y: 25.25) | |
test = Just(x) |
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
{.hint[XDeclaredButNotUsed]: off.} | |
import baseutils, typetraits, macros | |
#---------------------------------------------------- | |
# SumType | |
#---------------------------------------------------- | |
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
tyGenericInvokation(tyGenericBody TFix(tyGenericParam T, tyDistinct TFix(tyGenericParam T)), | |
tyGenericInst(tyGenericBody TFix(tyGenericParam T, tyDistinct TFix(tyGenericParam T)), tyFloat float, tyDistinct TFix(tyFloat float))) | |
tyGenericInst(tyGenericBody TFix(tyGenericParam T, tyDistinct TFix(tyGenericParam T)), | |
tyGenericInst(tyGenericBody TFix(tyGenericParam T, tyDistinct TFix(tyGenericParam T)), tyInt int, tyDistinct TFix(tyInt int)), | |
tyDistinct TFix(tyGenericInst(tyGenericBody TFix(tyGenericParam T, tyDistinct TFix(tyGenericParam T)), tyInt int, tyDistinct TFix(tyInt int)))) | |
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
C:\Users\mflamer\Dropbox\DEV\Nimrod\babel-master>babel install | |
c:/users/mflamer/dropbox/dev/nimrod/nimrod/dist/mingw/bin/../lib/gcc/i686-w64-mingw32/4.8.1/../../../../i686-w64-mingw32/bin/ld.exe: cannot open output file c:\users\mflamer\dropbox\dev\nimrod\babel-master\babel.exe: Permission denied | |
collect2.exe: error: ld returned 1 exit status | |
c:\users\mflamer\dropbox\dev\nimrod\nimrod\config\nimrod.cfg(36, 2) Hint: added path: 'C:\Users\mflamer\.babel\pkgs\' [Path] | |
Hint: used config file 'C:\Users\mflamer\Dropbox\DEV\Nimrod\Nimrod\config\nimrod.cfg' [Conf] | |
Hint: used config file 'c:\users\mflamer\dropbox\dev\nimrod\babel-master\babel.nimrod.cfg' [Conf] | |
Hint: system [Processing] | |
Hint: babel [Processing] | |
Hint: httpclient [Processing] | |
Hint: sockets [Processing] |
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 NULL* = 0 | |
type | |
TagPtr = distinct int | |
Sum2[T1,T2] = TagPtr | |
proc copyHeap*[T](x: var T): ptr T = | |
var |
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
#---------------------------------------------------- | |
# ADT | |
#---------------------------------------------------- | |
type | |
SumT[T1,T2,T3,T4] = int | |
proc popFlags(x: int): int {.inline.} = x and 3 | |
proc popPtr(x: int): int {.inline.} = |
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
#---evals.nim--- | |
proc evalTypeTrait*(trait, operand: PNode, context: PSym): PNode = | |
InternalAssert operand.kind == nkSym | |
let typ = operand.sym.typ.skipTypes({tyTypeDesc}) | |
case trait.sym.name.s.normalize | |
of "name": | |
result = newStrNode(nkStrLit, typ.typeToString(preferName)) | |
result.typ = newType(tyString, context) |
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
#------Generic Tuples | |
type | |
Tup2[T1,T2] = tuple[x1:T1, x2:T2] | |
Tup3[T1,T2,T3] = tuple[x1:T1, x2:T2, x3:T3] | |
Tup4[T1,T2,T3,T4] = tuple[x1:T1, x2:T2, x3:T3, x4:T4] | |
Tup5[T1,T2,T3,T4,T5] = tuple[x1:T1, x2:T2, x3:T3, x4:T4, x5:T5] | |
#-------Function Composition | |
proc `&`[T1,T2,T3](g:proc(y:T2):T3, f:proc(x:T1):T2):proc(z:T1):T3 = |