Skip to content

Instantly share code, notes, and snippets.

View Varriount's full-sized avatar

Clay Sweetser Varriount

View GitHub Profile
proc this: void {.cdecl, exportc, dynlib.} =
var i = 1
var a = 2
var z = 3
proc foo(): int =
echo "here"
return i + a + z + 65
proc processClient(client: AsyncSocket): owned(Future[void]) =
var retFuture_17906029 = newFuture("processClient")
iterator processClientIter_17906030(): owned(FutureBase) {.closure.} =
while true:
var future_17906031 = recvLine(client, {SafeDisconn}, 1000000)
yield future_17906031
let line = read(future_17906031)
if len(line) == 0:
break
for c in items(clients):
import module_b
from module_c import nil
echo HelloFromModuleB
echo module_c.HelloFromModuleC
@Varriount
Varriount / forbench.nim
Created April 13, 2020 19:53
Note: Requires the `criterion` Nimble package.
import criterion
var cfg = newDefaultConfig()
cfg.brief = true
const
sepSet = {'/', '\\'}
sepArray = ['/', '\\']
proc dummy(a: string): bool =
from strutils import nil
template copy(target: string, tRegion: Slice|HSlice, source: string, sRegion: Slice|HSlice): untyped =
template resolve(c, i): untyped =
when i is BackwardsIndex:
len(c) - int(i)
else:
i
# Figure out the length of each slice
# A lazybuf is a lazily constructed path buffer.
# It supports append, reading previously appended chars,
# and retrieving the final string. It does not allocate a buffer
# to hold the output until that output diverges from s.
type lazybuf = object
path: string
buf: string
w: int
volAndPath: string
volLen: int
type
WindowsPath* = distinct string
PosixPath* = distinct string
when OS_IS_WINDOWS:
type
Path* = distinct WindowsPath
IPath* = distinct Path
else:
type
async proc foo(i: int) int =
await bar(i) // gives i+1
await bar(i+1) // gives i+2
await bar(i+2) // gives i+3
# To
proc foo(state: var State) =
if state.state == 1:
state.waiting_on = bar(state.bar_state, state.i)
def display_hint(value):
return 'string'
def to_string(value):
if value:
l = int(value['Sup']['len'])
return value['data'][0].address.string("utf-8", "ignore", l)
else:
return ""
@Varriount
Varriount / gist:b93c845f0632ca2d6b6099f7443a356d
Last active February 9, 2020 09:58
Compiletime -> Runtime Data Issue
/* Generated by Nim Compiler v1.1.1 */
/* (c) 2019 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: MacOSX, amd64, clang */
/* Command for C compiler:
clang -c -w -I/usr/local/Cellar/nim/HEAD-81a4379/nim/lib -I/Users/csweetser/Personal -o /Users/csweetser/.cache/nim/untitled_d/@muntitled.nim.c.o /Users/csweetser/.cache/nim/untitled_d/@muntitled.nim.c */
#define NIM_INTBITS 64
#include "nimbase.h"
#include <string.h>