changeset 38:34a726a5c0d4

on going...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 16 Jun 2012 01:15:02 +0900
parents bda0b56c9231
children 09cd9c5c7c40
files paper/rectype.ind
diffstat 1 files changed, 41 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/paper/rectype.ind	Sat Jun 16 01:02:37 2012 +0900
+++ b/paper/rectype.ind	Sat Jun 16 01:15:02 2012 +0900
@@ -148,10 +148,46 @@
 it is the same type.
 
 
+--Recursive type syntax in a function body
 
+\rectype can be appeared in a function arguments, a function body or struct definition as a
+pointer type, otherwise it errors.
+
+In a function body, it has a type of the function itself.
+
+    __code csAs(int a,  __rectype *p) {
+       __rectype *p1 = p;
+       goto p1(a, csBs);
+    }
+
+It is possible to write the following way; 
+
+    __code csAs(int a,  __rectype *p) {
+       __code (*p)(int, __retype *);
+       p1 = p;
+       goto p1(a, csBs);
+    }
 
+but previous one is shorter.
 
---Recursive type syntax 
+We cannot allow non pointer type \rectype, because it generates infinite size of object.
+
+In case of struct, 
+
+     struct {
+         int a;
+         __rectype *next;
+     }
+
+is the same of this;
+
+     struct b {
+         int a;
+         struct b *next;
+     }
+
+this is a conventional way to represent recursive type in C. Using this technique we
+can write a continuation like this;
 
     struct interface {
        __code (*next)(struct interface);
@@ -159,22 +195,21 @@
 
     __code csA(struct interface p) {
         struct interface ds = { csB };
-        goto p.next(ds);
-    }
+        goto p.next(ds); }
 
     int main() {
         struct interface ds = { print };
         goto csA(ds);
+        /* NOTREACHED*/ 
         return 0;
     }
 
-
+\rectype is clearer but struct technique provides abstract representation. It requres
+extra struct declation, but it give us the same assembler output.
 
     __code fibonacci(__rectype *p, int num,  int count, int result, int prev) 
 
 
-
-
 --How to implement \rectype
 
 \rectype syntax is implemented overriding AST.