summaryrefslogtreecommitdiff
path: root/doc/macros.txt
blob: f39a30bf84d186e52e45eaeb9eca7f3016d293c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * dollar sign identifiers are only valid within a macro body (what i believe
 * scheme folk call "hygienic")
 */

macro SWAP($a, $b) {
	let $tmp = $a
	$a := b
	$b := $tmp
}

proc foo(n ^Node) {
	SWAP(&n^.in.data[0], &n^.in.data[1])
}

/*
 * note that the macro body between the braces isn't a new scope, so you can
 * still e.g. have a macro that defines a variable.  or, perhaps, a function:
 */

macro V2OP($name, $op) {
	func $name(a, b vec2) vec2 {
		return vec2 { a.x $op b.x, a.y $op b.y }
	}
}