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
| #define HTTP_STATUS_CODES(_) \ | |
| _(200, OK) \ | |
| _(404, NOT_FOUND) \ | |
| _(505, INTERNAL_ERROR) | |
| enum StatusCodes { | |
| #define GENERATE_ENUM(CODE, MSG) MSG = CODE, | |
| HTTP_STATUS_CODES(GENERATE_ENUM) | |
| } |
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
| --langdef=nimrod | |
| --langmap=nimrod:.nim | |
| --regex-nimrod=/(\w+)\*?\s*=\s*object/\1/c,Class/ | |
| --regex-nimrod=/proc\s+(\w+)/\1/m,Procedure/ | |
| --regex-nimrod=/proc\s+`([^`]+)`/\1/o,Operator/ |
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 testConcat(a: string, b: string): string {.compileTime pure.} = | |
| return a & b | |
| const X = testConcat("test", "me") | |
| proc test = | |
| when len(X) > 2: | |
| echo "big" | |
| else: | |
| echo "small" |
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 3DSpace = ... | |
| type Plane = ... | |
| type Line = ... | |
| proc SpaceSplitterType(p: Place) : Line | |
| proc SpaceSplitterType(p: 3DSpace) : Plane | |
| # This is a generic algorithm that should work both in 2D and 3D context | |
| proc ComputeProjection[S](space: S) = | |
| # instantiate the correct space splitter type (needed for the algorithm) |
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
| import macros, parseutils | |
| proc isEscaped(s: string, pos: int) : bool = | |
| var | |
| backslashes = 0 | |
| j = pos - 1 | |
| while j >= 0: | |
| if s[j] == '\\': | |
| inc backslashes |
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 = |> ^ %f^ nimrod c %f | tee build.log |> %B build.log | |
| !run = |> ^ running...^ ./%f > run.log && cat run.log |> run.log | |
| : hello.nim |> !nimrod |> | |
| : hello |> !run |> |
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
| template `:=` (lhs: expr, rhs: expr) : stmt = | |
| var lhs = rhs | |
| proc foo = | |
| bar := 20 |
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
| # Some generic functions that convert nimrod values to lua | |
| proc push(ls: PState, s: string) = pushstring(ls, s) | |
| proc push(ls: PState, i: int) = pushinteger(ls, i) | |
| proc push(ls: PState, f: float) = pushnumber(ls, f) | |
| # helpers for creating type safe variadic functions | |
| proc argsToTuple(expr: PNimrodNode) : PNimrodNode {.compileTime.} = | |
| result = newNimNode(nnkPar) | |
| for i in 1..expr.len-1: add(result, expr[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 myTypeMapper(x: int) : MegaInt | |
| proc myTypeMapper(x: float) : SmartFloat | |
| proc MappedTupleType[T, U](tp: tuple[T, U]) : tuple[ | |
| type(myTypeMapper (valueOf[T]())), | |
| type(myTypeMapper (valueOf[U]())), | |
| ] | |
| proc MappedTupleType[T](tp: tuple[T]) : tuple[ | |
| type(myTypeMapper (valueOf[T]())) |
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
| template repeatStmt(N: int, code: stmt) : stmt = | |
| when N > 0: | |
| code | |
| repeatStmt(N-1, code) | |
| template repeatTemplate(N: int, tmpl: expr) : stmt = | |
| when > 0: | |
| tmpl(N) | |
| repeatTemplate(N-1, tmpl) |
OlderNewer