about summary refs log tree commit diff
path: root/examples/sum.th
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2026-04-22 16:11:33 +0300
committerNakidai <nakidai@disroot.org>2026-04-22 16:11:33 +0300
commit0f84b003914e2d9f14ef787c6e45db4fdc0a9929 (patch)
tree5447065ea465fa4911713db1ad5ee0d37fa6290f /examples/sum.th
parent956b50a00167ed073375e0213e022ea0fb177309 (diff)
downloadthac-0f84b003914e2d9f14ef787c6e45db4fdc0a9929.tar.gz
thac-0f84b003914e2d9f14ef787c6e45db4fdc0a9929.zip
Add adder example HEAD master
Diffstat (limited to 'examples/sum.th')
-rw-r--r--examples/sum.th15
1 files changed, 15 insertions, 0 deletions
diff --git a/examples/sum.th b/examples/sum.th
new file mode 100644
index 0000000..dd79876
--- /dev/null
+++ b/examples/sum.th
@@ -0,0 +1,15 @@
+and = 0;
+xor = 1;
+bits = 4;
+a = [bits]node(xor, 0);
+b = [bits]node(xor, 1);
+c = node(and) <- node(xor, 2);
+out = [bits+1]node(xor);
+p = [bits]node(xor) <- a <- b;
+g = [bits]node(and) <- a <- b;
+out[0:bits] <- ([bits]node(and) <- p);
+foreach (out) {
+	@ <- (node(and) <- p[0:@0] <- c);
+	for (i = 0; i < @0; ++i)
+		@ <- (node(and) <- p[i+1:@0] <- g[i]);
+}