summaryrefslogtreecommitdiff
path: root/docs/2026_REBASE/demos
diff options
context:
space:
mode:
Diffstat (limited to 'docs/2026_REBASE/demos')
-rw-r--r--docs/2026_REBASE/demos/aliases.smp5
-rw-r--r--docs/2026_REBASE/demos/arithmetic.smp3
-rw-r--r--docs/2026_REBASE/demos/backend.smp6
-rw-r--r--docs/2026_REBASE/demos/control.smp9
-rw-r--r--docs/2026_REBASE/demos/inline.smp3
-rw-r--r--docs/2026_REBASE/demos/memory.smp10
-rw-r--r--docs/2026_REBASE/demos/methods.smp11
-rw-r--r--docs/2026_REBASE/demos/sccp.smp4
8 files changed, 51 insertions, 0 deletions
diff --git a/docs/2026_REBASE/demos/aliases.smp b/docs/2026_REBASE/demos/aliases.smp
new file mode 100644
index 00000000..a8ee471f
--- /dev/null
+++ b/docs/2026_REBASE/demos/aliases.smp
@@ -0,0 +1,5 @@
+struct Pair { int x; int y; };
+val p = new Pair { x = arg; y = 10; };
+int before = p.x;
+p.y = 99;
+return p.x - before;
diff --git a/docs/2026_REBASE/demos/arithmetic.smp b/docs/2026_REBASE/demos/arithmetic.smp
new file mode 100644
index 00000000..ef19a5bd
--- /dev/null
+++ b/docs/2026_REBASE/demos/arithmetic.smp
@@ -0,0 +1,3 @@
+int x = arg + 0;
+int y = 1 + x + 2;
+return y + x + 3;
diff --git a/docs/2026_REBASE/demos/backend.smp b/docs/2026_REBASE/demos/backend.smp
new file mode 100644
index 00000000..de8f7665
--- /dev/null
+++ b/docs/2026_REBASE/demos/backend.smp
@@ -0,0 +1,6 @@
+struct Box { int x; };
+return { !Box box, int arg ->
+ int n = arg < 0 ? -arg : arg;
+ box.x += n;
+ return n;
+};
diff --git a/docs/2026_REBASE/demos/control.smp b/docs/2026_REBASE/demos/control.smp
new file mode 100644
index 00000000..6b7b1b17
--- /dev/null
+++ b/docs/2026_REBASE/demos/control.smp
@@ -0,0 +1,9 @@
+int n = arg;
+if( n < 0 ) n = -n;
+int sum = 0;
+int i = 0;
+while( i < n ) {
+ i = i + 1;
+ sum = sum + i;
+}
+return sum;
diff --git a/docs/2026_REBASE/demos/inline.smp b/docs/2026_REBASE/demos/inline.smp
new file mode 100644
index 00000000..9d38e5b0
--- /dev/null
+++ b/docs/2026_REBASE/demos/inline.smp
@@ -0,0 +1,3 @@
+val add1 = { int x -> x + 1; };
+val twice = { int x -> x * 2; };
+return twice(1 + add1(2)) + 3;
diff --git a/docs/2026_REBASE/demos/memory.smp b/docs/2026_REBASE/demos/memory.smp
new file mode 100644
index 00000000..466c0476
--- /dev/null
+++ b/docs/2026_REBASE/demos/memory.smp
@@ -0,0 +1,10 @@
+struct Totals { int sum; int visits; };
+val t = new Totals;
+val data = new int[4];
+for( int i = 0; i < data#; i++ )
+ data[i] = arg + i;
+for( int i = 0; i < data#; i++ ) {
+ t.sum = t.sum + data[i];
+ t.visits++;
+}
+return t.sum + t.visits;
diff --git a/docs/2026_REBASE/demos/methods.smp b/docs/2026_REBASE/demos/methods.smp
new file mode 100644
index 00000000..683540c3
--- /dev/null
+++ b/docs/2026_REBASE/demos/methods.smp
@@ -0,0 +1,11 @@
+struct Counter {
+ int n;
+ val add = { int delta ->
+ n += delta;
+ return self;
+ };
+ val get = { -> return n; };
+};
+!Counter c = new Counter { n = arg; };
+c.add(3).add(4);
+return c.get();
diff --git a/docs/2026_REBASE/demos/sccp.smp b/docs/2026_REBASE/demos/sccp.smp
new file mode 100644
index 00000000..da91691d
--- /dev/null
+++ b/docs/2026_REBASE/demos/sccp.smp
@@ -0,0 +1,4 @@
+int x = 1;
+for( int i = 0; i < arg; i++ )
+ x = 2 - x;
+return x;