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 `&`[N1,N2, T1](arg1: array[N1,T1], arg2: array[N2,T1]): auto = | |
const length = (high(arg1) - low(arg1)) + (high(arg2) - low(arg2)) + 2 | |
var res: array[length, T1] | |
var i = 0 | |
for x in arg1: | |
res[i] = x | |
i += 1 | |
for x in arg2: | |
res[i] = x |
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 jsmn, streams, tables, hashes, strutils, macros, sequtils | |
type | |
ConstraintViolation* = object of Exception | |
proc checkConstraint(value: bool, message: string) = | |
if value: | |
raise newException(ConstraintViolation, message) |
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 jsmn, streams, tables, hashes, strutils, macros, sequtils | |
# StringRef support | |
type | |
StringRef = ref string | |
StringCache = TableRef[Hash, StringRef] | |
converter stringToStringRef(s: string): StringRef = | |
new(result) | |
result[] = s |
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
# Stringify an integer | |
stringified_int = Schema(All( | |
int, | |
Coerce(str) # Same as `lambda x: str(x) | |
)) | |
def AcceptSingleOrListOf(sub_schema): | |
""" | |
Returns a wrapped schema that either accepts the original schema, or a list |
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
# Copyright 2017 Mamy André-Ratsimbazafy | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, |
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
let hex = 0xDEADBEEF'u32 |
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 initNumber(i: int): int = i+1 | |
proc main() = | |
var resources: seq[int] = @[] | |
template initResource(initExpression: untyped): untyped = | |
var res = initExpression | |
resources.add(res) | |
res | |
var a, b: int |
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 linalg | |
{.experimental.} | |
# Global templates | |
template foreach(expression, iter: untyped): untyped = | |
for element in mitems(iter): | |
expression(element) |
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
main.nim(17, 17) template/generic instantiation from here | |
dadren/dadren/bsp.nim(63, 13) template/generic instantiation from here | |
dadren/dadren/bsp.nim(30, 20) Error: inheritance only works with non-final objects |
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
The below code is not valid C code - a preprocessor must be used: | |
``` | |
CHAKRA_API | |
JsParseModuleSource( | |
_In_ JsModuleRecord requestModule, | |
_In_ JsSourceContext sourceContext, | |
_In_ BYTE* script, | |
_In_ unsigned int scriptLength, | |
_In_ JsParseModuleSourceFlags sourceFlag, |