summaryrefslogtreecommitdiff
path: root/doc/macros.txt
diff options
context:
space:
mode:
Diffstat (limited to 'doc/macros.txt')
-rw-r--r--doc/macros.txt25
1 files changed, 25 insertions, 0 deletions
diff --git a/doc/macros.txt b/doc/macros.txt
new file mode 100644
index 0000000..f39a30b
--- /dev/null
+++ b/doc/macros.txt
@@ -0,0 +1,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 }
+ }
+}