Skip to content

Instantly share code, notes, and snippets.

..\src\tensor\display.nim(27, 27) template/generic instantiation of `disp4d` from here
..\src\tensor\private\p_display.nim(117, 30) Error: type mismatch: got <Tensor[system.string], Tensor[system.string], seq[string], axis: int literal(1)>
but expected one of:
proc concat[T](t_list: varargs[Tensor[T]]; axis: int): Tensor[T]
first type mismatch at position: 1
required type: varargs[Tensor[concat.T]]
but expression 'hbuffer[i]' is of type: Tensor[system.string]
proc concat[T](seqs: varargs[seq[T]]): seq[T]
first type mismatch at position: 1
required type: varargs[seq[T]]
# The 'lexer' macro generates not only the lexing proc but also
# the relevant 'Token' type, including a TokenKind enum that is
# extracted from the actions via the 'token Kind()' syntax.
# There are two special TokenKind values always available:
# Error and Eof.
# '_' refers to the matched string.
lexer:
"[A-Za-z][A-Za-z0-9]*":
# 'keywords' is a special construct. We want to map the pattern
type
PtrTable = ptr object
counter, max: int
data: array[0xff_ffff, (pointer, pointer)]
template hashPtr(key: pointer): int = cast[int](key) shr 8
template allocPtrTable: untyped =
cast[PtrTable](alloc0(sizeof(int)*2 + sizeof(pointer)*2*cap))
proc rehash(t: PtrTable): PtrTable =
nimble install nimfuzz
Downloading https://github.com/apense/nimfuzz using git
Verifying dependencies for nimfuzz@1.3.0
Installing nimfuzz@1.3.0
Building nimfuzz/nimfuzz.exe using c backend
Prompt: Build failed for 'nimfuzz@1.3.0', would you like to try installing 'nimfuzz@#head' (latest unstable)? [y/N]
Answer: y
Downloading https://github.com/apense/nimfuzz using git
Verifying dependencies for nimfuzz@#head
Installing nimfuzz@#head
commit 33d38c072f164745f7adfd2a97dea8a550c1c02c
Author: PMunch <peterme@peterme.net>
Date: Wed Oct 31 22:14:29 2018 +0100
Quote do now works with result in block (#7343)
* Fix result not being able to use in quote do
This fixes the annoying issue of not be able to use result inside a
quote do block. It works by a simple trick. The quote do mechanic is
proc isLastRead(n: PNode; c: var Con): bool =
# first we need to search for the instruction that belongs to 'n':
doAssert n.kind == nkSym
c.otherRead = nil
var instr = -1
for i in 0..<c.g.len:
if c.g[i].n == n:
if instr < 0: instr = i
else:
# eh, we found two positions that belong to 'n'?
@Araq
Araq / decimals.nim
Created September 18, 2018 15:26
barebones decimal number implementation for Nim
## Decimal data representation
## (c) Andreas Rumpf
from strutils import intToStr
type
Decimal* = object ## Represents a decimal value.
dv: int32
val: int64
{.experimental: "caseStmtMacros".}
import macros
macro match(n: tuple): untyped =
result = newTree(nnkIfStmt)
let selector = n[0]
for i in 1 ..< n.len:
let it = n[i]
case it.kind

Basic idea: A Nim DSL that describes the game model declaratively

There is a raw list/sequence of the data for fast iteration over all elements. The implementation should be either based on an ordinary contiguous sequence or something like: http://plflib.org/colony.htm which is essentially a linked list of growing arrays so that no reallocations are required.

In addition to the contiguous storage there can be multiple indexes into the data. The indexes can be hash based or based on a BTree depending on whether ranges queries need to be supported. There is always a primary key of type integer that can be used to index the contiguous array.

An example:

type
SeqHeader = object
len, reserved: int
proc isLiteral(s: string): bool {.inline.} = (cast[ptr SeqHeader](s).reserved and (1 shl (sizeof(int)*8 - 2))) != 0
proc main(param: string) =
echo "param ", isLiteral(param)