Skip to content

Instantly share code, notes, and snippets.

View owned_widgets.nim
import core / allocators
import system / ansi_c
type
Widget* = ref object of RootObj
drawImpl: owned(proc (self: Widget))
Button* = ref object of Widget
View wrongrefs.nim
import json
var j = newJObject()
var i = newJString("23")
j["foo"] = i
j["bar"] = i
echo j["foo"]
j["bar"].str = "34"
echo j["foo"]
View sysstr.nim
#
#
# Nim's Runtime Library
# (c) Copyright 2012 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
# string & sequence handling procedures needed by the code generator
View error_msg.txt
..\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]]
View parser_generator_ideas.nim
# 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
View copying_gc.nim
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 =
View nimble_log.txt
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
View dont_include_in_0.19.2.txt
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
View lastread.nim
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 Sep 18, 2018
barebones decimal number implementation for Nim
View decimals.nim
## Decimal data representation
## (c) Andreas Rumpf
from strutils import intToStr
type
Decimal* = object ## Represents a decimal value.
dv: int32
val: int64
You can’t perform that action at this time.