Permalink
Browse files

add a "failures" folder, which contians programs that should run but …

…don't.
  • Loading branch information...
1 parent 414aada commit e0b61cc28d5603bba58a9fa1f19d9cabb386cc4a @kjs kjs committed Jun 24, 2012
Showing with 42 additions and 0 deletions.
  1. +39 −0 failures/struct.m1
  2. +3 −0 src/instr.c
View
@@ -0,0 +1,39 @@
+struct C {
+ int x;
+}
+
+struct B {
+ C c;
+}
+
+struct A {
+ B b;
+}
+
+void main() {
+ A a = new A();
+ a.b = new B();
+ a.b.c = new C();
+
+ a.b.c.x = 42;
+
+ print(a.b.c.x, "\n");
+
+/* Select one of 3: any other combination fails. */
+// foo(a.b.c.x);
+// baz(a);
+ bar(a.b.c);
+
+}
+
+void foo(int a) {
+ print(a, "\n");
+}
+
+void bar(C c) {
+ print(c.x, "\n");
+}
+
+void baz(A a) {
+ print(a.b.c.x, "\n");
+}
View
@@ -145,6 +145,7 @@ write_instructions(M1_compiler *comp, m0_instr *i) {
}
+/* Allocate a new m0_instr node in memory. */
static m0_instr *
new_instr(M1_compiler *comp) {
m0_instr *ins = (m0_instr *)calloc(1, sizeof (m0_instr));
@@ -190,6 +191,7 @@ link_instr(M1_compiler *comp) {
return instr;
}
+/* Constructor for m0_instr; the format string parameter specifies which operands to expect. */
m0_instr *
mk_instr(M1_compiler *comp, m0_opcode opcode, char const * const format, ...) {
va_list argp;
@@ -262,6 +264,7 @@ mk_instr(M1_compiler *comp, m0_opcode opcode, char const * const format, ...) {
}
+/* Make an empty m0_instr node and store the specified label. */
void
mk_label(M1_compiler *comp, unsigned labelno) {
m0_instr *ins = link_instr(comp);

0 comments on commit e0b61cc

Please sign in to comment.