wiki:MagnoliaCoreNotes

Template level

forall T
def assign(out o |= T, a |= T);

def A {
  def B { }
  def C(out i |= Int) {
    call assign(i, 0);
  }
}

var foo |= Int;

call A.C(foo);

B will not appear in the instantiated version. The reason is that everything is a template.

Structured level

def assign_Int_Int(out o |= Int, a |= Int);

def A {
  def C_Int(out i |= Int) {
    call parent.parent.assign_Int_Int(i, parent.parent.0);
  }
}
var foo |= Int;
call A.C_Int(foo);

Only "var"s and parameters appear in the resulting type. "def" members usually have argument, they are built only on demand, when there is a expression building an object. For example A is not a member of the root object. When you ask for "A.C_Int(foo)", a "A" is needed. Then it is instantiated then. The "C_Int(foo)" as well and will be marked as child of the new "A".

The expression "A.C_Int(foo)" results on the instantiation of an object. But this object is also a frame. The "call" ask to call the function according to this frame.

C implementation

struct type_root {
  struct type_Int* int_0;
  struct type_foo* foo;
};

struct type_assign_Int_Int {
  struct type_root* parent;
  struct type_Int* o;
  struct type_Int* i;
};

void proc_assign_Int_Int(struct type_assign_Int_Int* frame);

struct type_A {
  struct type_root* parent;
};

struct type_A_C_Int {
  struct type_A* parent;
  struct type_Int* i;
};

void proc_A_C_Int(struct type_A_C_Int* frame) {
  struct type_assign_Int_Int frame_1;
  frame_1.parent = frame->parent->parent;
  frame_1.i = frame->parent->parent->int_0;
  frame_1.o = frame->i;
  proc_assign_Int_Int(&frame_1);
}

void proc_A(struct type_A* frame) {
}

struct type_foo {
  struct type_root* parent;
  struct type_Int* super;
};

void proc_foo(struct type_foo* frame);

void proc_root(struct type_root* frame) {
  struct type_A frame_1;
  struct type_A_C_Int frame_1_C_Int;

  frame_1_C_Int.parent = &frame_1;
  frame_1.parent = frame;
  frame_1_C_Int.i = frame->foo->super;

  proc_A_C_Int(&frame_1_C_Int);
}

struct type_Int {
  struct type_root* parent;
  int value;
};

void proc_assign_Int_Int(struct type_assign_Int_Int* frame) {
  frame->o->value = frame->i->value;
}

int main() {
  struct type_root frame_1;
  struct type_foo frame_1_foo;
  struct type_Int frame_1_foo_Int;
  struct type_Int frame_1_int_0;

  frame_1_foo_Int.parent = &frame_1;
  frame_1_foo.super = &frame_1_foo_Int;
  frame_1_foo.parent = &frame_1;
  frame_1.foo = &frame_1_foo;
  frame_1.int_0 = &frame_1_int_0;
  frame_1_int_0.value = 0;
  frame_1_int_0.parent = &frame_1;

  proc_root(&frame_1);
  return 0;
}
Last modified 15 years ago Last modified on Jul 9, 2009 6:07:00 PM
Note: See TracWiki for help on using the wiki.