changeset 28:3e4a390a9c40

Add original sample sources
author atton
date Tue, 05 Jul 2016 09:47:13 +0000
parents 83db914f0da3
children 71d44ac76a70
files paper/src/cs.c paper/src/ds.c
diffstat 2 files changed, 77 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/cs.c	Tue Jul 05 09:47:13 2016 +0000
@@ -0,0 +1,37 @@
+#include<stdio.h>
+#include<stdlib.h>
+
+struct Context {
+    int x;
+};
+
+enum Code {
+    AddTen,
+    Twice,
+    ShowValue
+};
+
+__code addTen(struct Context* context) {
+    context->x = context->x+10;
+    goto meta(context, Twice);
+}
+
+__code twice(struct Context* context) {
+    context->x = context->x*2;
+    goto meta(context, ShowValue);
+}
+
+__code meta(struct Context* context, enum Code next) {
+    switch (next) {
+        case AddTen:
+            goto addTen(context);
+        case Twice:
+            goto twice(context);
+    }
+}
+
+int main(int argc, char* argv[]) {
+    struct Context* context = malloc(sizeof(struct Context));
+    context->x = 100;
+    goto meta(context, AddTen);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/ds.c	Tue Jul 05 09:47:13 2016 +0000
@@ -0,0 +1,40 @@
+#include<stdio.h>
+#include<stdlib.h>
+
+union Data {
+    struct Count {
+        int x;
+    } count;
+    struct Port {
+        unsigned int port;
+    } port;
+};
+
+__code addTen_stub(union Data* ds) {
+    goto addTen(ds, ds->count.x);
+}
+
+__code addTen(union Data* ds, int a) {
+    int b = a+10;
+    goto twice_stub(ds);
+}
+
+__code twice_stub(union Data* dataSegment) {
+    goto twice(dataSegment->count.x);
+}
+
+__code twice(int x) {
+    int y = 2*x;
+    goto showValue(y);
+}
+
+__code showValue(int z) {
+    printf("%d", z);
+    exit(0);
+}
+
+int main(int argc, char* argv[]) {
+    union Data* ds = malloc(sizeof(union Data));
+    ds->count.x = 22;
+    goto addTen_stub(ds);
+}