This file contains 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 strutils | |
import macros except body | |
# TODO: avoid all the quasi-same macros. | |
# TODO: expand spec (links,style,img,src etc) | |
# TODO: allow specifying id, class | |
# TODO: render the ast to proper html, with proper indentation | |
# TODO: group similar kinds together, eg div,body,section,header,footer,etc are all containers. | |
# TODO: less verbose macros for a? also macro for id,class for other nodes |
This file contains 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 setItem (item:cstring,to:cstring){.importc, exportc:"localStorage.$1"} | |
proc getItem (item:cstring):string{.importc, exportc:"localStorage.$1"} | |
proc log(x:string) = {.emit :"console.log(`x`);"} | |
localStorage.setItem("hi","world") | |
log localStorage.getItem("hi") #> world |
This file contains 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
#!/bin/sh | |
# SEE: http://lists.nongnu.org/archive/html/tinycc-devel/2016-10/msg00146.html | |
# Config | |
DEFAULT_DEST="win32/reprobuild" # relative to top source dir | |
TMP_DIR="_tmp" # dir for intermidiate files inside each output dir | |
# Builds one windows tcc distribution | |
# args: TARGET_DIR, CC, {I386|X86_64}, [LIBS_CC, LIBS_AR] | |
# Doesn't touch anything outside of $TARGET_DIR - which must not exist on entry. | |
# libtcc1 objects are compiled with CC_LIBS and joined into libtcc1.a with AR_LIBS |
This file contains 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
C:\Users\silvio\Documents\Dev\nim\eval>nim c -r --cc:tcc testing.nim | |
Hint: used config file 'C:\Dev\Nim-devel\config\nim.cfg' [Conf] | |
Hint: system [Processing] | |
Hint: testing [Processing] | |
CC: testing | |
CC: stdlib_system | |
In file included from c:/users/silvio/documents/dev/nim/eval/nimcache/testing.c:9: | |
C:/Dev/Nim-devel/lib/nimbase.h:227: error: include file 'limits.h' not found | |
In file included from c:/users/silvio/documents/dev/nim/eval/nimcache/stdlib_system.c:9: | |
C:/Dev/Nim-devel/lib/nimbase.h:227: error: include file 'limits.h' not found |
This file contains 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
type A = object | |
data: ref seq[float] | |
proc `$`[T](a:ref seq[T]):string = $(a[]) | |
var ar : A | |
new ar.data | |
ar.data[] = @[0.0,1.0,2.0] | |
echo ar |
This file contains 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
## Original: https://nim-by-example.github.io/oop/ | |
## Running the above with non ref objects errors ## | |
type Animal = object of RootObj | |
name: string | |
age: int | |
method vocalize(this: Animal): string = "..." | |
method ageHumanYrs(this: Animal): int = this.age |
This file contains 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 times | |
proc possiblyleakingshift[T](a: var openarray[T]; d: int) = | |
if d == 0: discard # do nothing | |
elif abs(d) >= a.len: # reset all | |
zeroMem(addr a[0], a.len*sizeof(T)) | |
elif d > 0: # right shift | |
moveMem(addr a[d], addr a[0], (a.len - d)*sizeof(T)) | |
zeroMem(addr a[0], d*sizeof(T)) | |
elif d < 0: # left shift |
This file contains 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
## first.nim ### | |
proc test*(): string = "test1" | |
echo test() | |
## second.nim ### | |
from first import test | |
proc test2*(): string = "test2" | |
echo test2() |
This file contains 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
## lib.nim ######### | |
proc test1(): string {.exportc, dynlib .}= | |
result = "test" | |
## user.nim ######## | |
import dynlib, osproc | |
# compile libs so I don't have to do it by hand | |
let l1 = execCmd("nim c --app:lib lib.nim") |
This file contains 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 zmq | |
# Example in cpp: | |
# http://zguide.zeromq.org/cpp:mspoller | |
var spm2 = zmq.connect("tcp://localhost:5556", zmq.Dealer) | |
var conn2 = zmq.listen("tcp://*:5556", zmq.ROUTER) | |
var spm = zmq.connect("tcp://localhost:5555",zmq.Dealer) | |
var conn = zmq.listen("tcp://*:5555", zmq.ROUTER) |