summaryrefslogtreecommitdiff
path: root/chapter21/src
diff options
context:
space:
mode:
Diffstat (limited to 'chapter21/src')
-rw-r--r--chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java1
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java13
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/TestC.java1
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/progs/arg_count.c11
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/progs/arg_count.smp7
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/progs/person.c33
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/progs/person.smp (renamed from chapter21/src/test/java/com/seaofnodes/simple/progs/Person.smp)7
7 files changed, 66 insertions, 7 deletions
diff --git a/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java b/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java
index 10d70a4f..2a1087a0 100644
--- a/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java
+++ b/chapter21/src/main/java/com/seaofnodes/simple/codegen/Encoding.java
@@ -359,6 +359,7 @@ public class Encoding {
}
}
+
// Copy/slide the bits to make space for all the longer branches
int grow = _opStart[_code._cfg.at(len-1)._nid] - oldStarts[len-1];
if( grow > 0 ) { // If no short-form ops, nothing to do here
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
index 0ff43899..e3239c48 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java
@@ -104,7 +104,18 @@ public class Chapter21Test {
}
@Test public void testBrainFuck() throws IOException {
- String brain_fuck = "Hello World!\n";
+ String brain_fuck = "Hello World!\r\n";
TestC.run("brain_fuck", brain_fuck);
}
+
+ @Test public void testPerson() throws IOException {
+ String person = "6\n";
+ TestC.run("person", person);
+ }
+
+ @Ignore
+ @Test public void testArgCount() throws IOException {
+ String arg_count = "";
+ TestC.run("arg_count", arg_count);
+ }
}
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/TestC.java b/chapter21/src/test/java/com/seaofnodes/simple/TestC.java
index 704cb5d4..e4c69709 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/TestC.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/TestC.java
@@ -45,6 +45,7 @@ public abstract class TestC {
params.add(cfile);
params.add(sofile);
params.add("-lm");
+ params.add("-g");
params.add("-o");
params.add(efile);
Process gcc = new ProcessBuilder(params.toArray(String[]::new)).redirectErrorStream(true).start();
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/arg_count.c b/chapter21/src/test/java/com/seaofnodes/simple/progs/arg_count.c
new file mode 100644
index 00000000..60637b1e
--- /dev/null
+++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/arg_count.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+extern int test();
+
+int main() {
+ int result = test();
+ printf("d\n", result);
+return 0;
+} \ No newline at end of file
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/arg_count.smp b/chapter21/src/test/java/com/seaofnodes/simple/progs/arg_count.smp
new file mode 100644
index 00000000..58dbffba
--- /dev/null
+++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/arg_count.smp
@@ -0,0 +1,7 @@
+val addAll = { int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int o ->
+ return a+b+c+d+e+f+g+h+i+j+k+l+m+n+o;
+};
+
+val test = { ->
+ return addAll(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) + addAll(16,17,18,19,20,21,22,23,24,25,26,27,28,29,30);
+}; \ No newline at end of file
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/person.c b/chapter21/src/test/java/com/seaofnodes/simple/progs/person.c
new file mode 100644
index 00000000..8ea0c9f6
--- /dev/null
+++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/person.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+typedef struct Person {
+ int age;
+} Person;
+
+typedef struct PersonArray {
+ unsigned int length;
+ int pad;
+ Person* data[];
+} PersonArray;
+
+extern void fcn(PersonArray* people, int index);
+
+int main() {
+ Person base[5] = {{25},{1},{18},{45},{60}};
+ unsigned char buf[8+8*5];
+ PersonArray* people_array = (PersonArray*)buf;
+ people_array->length=5;
+ for (int i=0; i<people_array->length; i++) people_array->data[i] = &base[i];
+
+ fcn(people_array, 1);
+ fcn(people_array, 1);
+ fcn(people_array, 1);
+ fcn(people_array, 1);
+ fcn(people_array, 1);
+
+ printf("%d\n", people_array->data[1]->age); // expected: 6
+
+ return 0;
+} \ No newline at end of file
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/Person.smp b/chapter21/src/test/java/com/seaofnodes/simple/progs/person.smp
index ee3af311..9791f252 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/progs/Person.smp
+++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/person.smp
@@ -7,9 +7,4 @@ val fcn = { Person?[] ps, int x ->
val tmp = ps[x];
if( ps[x] )
ps[x].age++;
-};
-
-Person?[] !ps = new Person?[2];
-ps[0] = new Person;
-ps[1] = new Person;
-fcn(ps,1);
+}; \ No newline at end of file