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
type A = object | |
type B = object | |
proc a(x: A) = echo "a" | |
proc b(x: B) = echo "b" | |
proc test(x: A|B) = | |
when x is A: | |
a(x) | |
else: |
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 StrUtils | |
# --- | |
type Vec4* {.incompleteStruct, importc:"__m128", header:"<xmmintrin.h>".} = object | |
type Vec4Array = array[4, float32] | |
# --- | |
proc newVec4 (w, z, y, x:float32): Vec4 {.importc:"_mm_set_ps".} |
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 StrUtils | |
# --- | |
type Foo = | |
ref object | |
value: int | |
type Bar = | |
ref object |
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
result.insert(0, | |
if baseName == nil: | |
(quote do: | |
type `typeName` = ref object)[0] | |
else: | |
(quote do: | |
type `typeName` = ref object of `baseName`)[0] | |
) | |
# Inspect the tree structure: | |
# |
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
body { | |
background:#f5f7f6; | |
line-height:20px; } | |
a:link { | |
color:#B45D47; } | |
#main pre code { | |
border-radius: 3px; | |
/* REMOVE: border: ... */ |
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
trait IActor: | |
method update* | |
trait IVisual: | |
method render* {.optional.} | |
class Person of TObject is IActor IVisual: | |
var name: string | |
var age: uint | |
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 macros | |
macro class*(head:expr, body:stmt): stmt {.immediate.} = | |
# The macro is immediate so that it doesn't | |
# resolve identifiers passed to it | |
var typeName, baseName: PNimrodNode | |
if head.kind == NnkIdent: |
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
macro class* (head:expr, body:stmt): stmt @keyword = | |
## builds OOP-style type/procs... | |
# @keyword makes this behave in the following ways.. | |
# - is compiled (no VM) for compile-time performance | |
# - is used with '=' instead of ':' (like 'proc' not 'for') | |
macro init* (head:expr, params:expr{param}, body:stmt): stmt @keyword = | |
## builds OOP-style alloc/init procs for a type | |
# NOTE: {param} means 'params' only accepts parameter syntax (a:T, b:U, ...) |
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
type Person: ref object @inheritable = | |
var | |
name*: string | |
age+: int | |
proc new*(name:string, age = 0) @init = | |
this.name = name | |
this.age = age | |
proc greet*() @pure = |
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
# engine.nim | |
proc update* = | |
Time.update() | |
Input.update() # update input every cycle (raw input) | |
GameParts.rawUpdate() # respond to input changes (often minimal, if needed at all) | |
if Time.elapsed >= Time.fixedStep: | |
Physics.update() # either unique thread, or uses thread pool | |