Skip to content

Instantly share code, notes, and snippets.

@Yardanico
Yardanico / tat.nim
Last active October 21, 2017 03:40
import macros, tables
macro echoType(x: typed): untyped =
let impl = x.symbol.getImpl()
# we're called on some type
if impl.kind == nnkTypeDef:
echo "type ", toStrLit(impl)
# we're called on a variable
else:
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 20 Oct 2017 19:12:15 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: Express
X-Upstream: 127.0.0.1:5080
X-Server-ID: apps-01
#?braces
for x in 0..10 {
echo x
}
import macros
macro doNothing(input: untyped): untyped =
echo treeRepr input
result = input
echo input.toStrLit
doNothing:
echo "hello world"
import macros, sequtils, future
type
Container[T] = concept x
for item in x:
item is T
proc forCompImpl(yieldResult: bool, comp: NimNode): NimNode {.compileTime.} =
expectLen(comp, 3)
expectKind(comp, nnkInfix)
import macros, strutils, sequtils, future
type ForComprehension = distinct object
type ForComprehensionYield = distinct object
var fc*: ForComprehension
proc forCompImpl(yieldResult: bool, comp: NimNode): NimNode {.compileTime.} =
expectLen(comp, 3)
expectKind(comp, nnkInfix)
/* Generated by Nim Compiler v0.17.3 */
/* (c) 2017 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, amd64, gcc */
/* Command for C compiler:
gcc -c -w -O3 -fno-strict-aliasing -I/home/tiber/nim/lib -o /home/tiber/projects/experiments/nimcache/stdlib_system.o /home/tiber/projects/experiments/nimcache/stdlib_system.c */
#define NIM_NEW_MANGLING_RULES
#define NIM_INTBITS 64
#include "nimbase.h"
/* Generated by Nim Compiler v0.17.3 */
/* (c) 2017 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, amd64, gcc */
/* Command for C compiler:
gcc -c -w -O3 -fno-strict-aliasing -I/home/tiber/nim/lib -o /home/tiber/projects/experiments/nimcache/ffa.o /home/tiber/projects/experiments/nimcache/ffa.c */
#define NIM_NEW_MANGLING_RULES
#define NIM_INTBITS 64
#include "nimbase.h"
type
Comparable = concept a
(a < a) is bool
proc ada[T: Comparable](a, b: T): T =
if a < b:
return b
else:
return a
type
Comparable = concept a
(a < a) is bool
proc myMax(a, b: Comparable): Comparable =
if a < b:
return b
else:
return a