codea: parameter reihenfolge sollte passen
authorBernhard Urban <lewurm@gmail.com>
Mon, 3 May 2010 11:09:47 +0000 (13:09 +0200)
committerBernhard Urban <lewurm@gmail.com>
Mon, 3 May 2010 11:09:47 +0000 (13:09 +0200)
codea/chelper.c
codea/parser.y
codea/symtable.c
codea/symtable.h

index bb0f7005ea1ccd5ac72f56087485889a8e04c9a2..70c8a662611eab493618b201113f4580bea854ec 100644 (file)
@@ -26,6 +26,7 @@ void ret(void)
 
 char *next_reg(char *s, short skip)
 {
+       /* TODO: warum enthaelt das register die parameter enthalten koennten? */
        char *regs[] = {"rax", "r10", "r11", "r9", "r8", "rcx", "rdx", "rsi", "rdi"};
        int i=0;
        if (s != (char*) NULL) {
index 3ccb81f705bb2cb25cb2accb7b697fd4480c0d44..f981df9e5f501f63083a676b53471583529268ac 100644 (file)
@@ -26,7 +26,8 @@
 
 @attributes { char *name; } IDENT
 @attributes { long val; } NUM
-@attributes { struct symbol *f; } FeldID Parms Structdef Program
+@attributes { struct symbol *f; int parms; } Parms
+@attributes { struct symbol *f; } FeldID Structdef Program
 @attributes { struct symbol *s; } Methoddef Statseq Exprs
 @attributes { struct symbol *s; struct treenode *node; } Lexpr Expr Minusterm Multerm Orterm Term Feld
 @attributes { struct symbol *sin; struct symbol *sout; struct treenode *node; } Statement
@@ -61,6 +62,7 @@ Program:
 Methoddef:
          METHOD IDENT '(' Parms ')' Statseq END
          @{
+           @i @Parms.parms@ = 1;
            @i @Statseq.s@ = tab_merge(@Methoddef.s@, @Parms.f@, 0);
            @gen @revorder(1) func_header(@IDENT.name@);
          @}
@@ -77,7 +79,8 @@ Parms:
          /* lokale Vars werden in Statement in die tabelle eingefuegt */
          IDENT Parms
          @{
-           @i @Parms.0.f@ = tab_add_symbol(@Parms.1.f@, @IDENT.name@, S_PARM, 1);
+           @i @Parms.1.parms@ = @Parms.parms@ + 1;
+           @i @Parms.0.f@ = tab_add_symbol(@Parms.1.f@, @IDENT.name@, S_PARM, 1, @Parms.parms@);
          @}
 
        |
@@ -89,7 +92,7 @@ Parms:
 FeldID:
          IDENT FeldID
          @{
-           @i @FeldID.0.f@ = tab_add_symbol(@FeldID.1.f@, @IDENT.name@, S_FIELD, 1);
+           @i @FeldID.0.f@ = tab_add_symbol(@FeldID.1.f@, @IDENT.name@, S_FIELD, 1, 0);
          @}
 
        |
@@ -122,7 +125,7 @@ Statement:
          @{
                /* tab_clone ist hier noetig, vgl. folgendes statement
                 * > var x := x - 1; */
-               @i @Statement.sout@ = tab_add_symbol(tab_clone(@Statement.sin@), @IDENT.name@, S_VAR, 1);
+               @i @Statement.sout@ = tab_add_symbol(tab_clone(@Statement.sin@), @IDENT.name@, S_VAR, 1, 0);
                xxputsin(@Expr.s@,)
            @i @Statement.node@ = TREENULL;
          @}
@@ -293,7 +296,12 @@ Term:
        | IDENT
          @{
            @c check(@Term.s@, @IDENT.name@, S_VAR|S_PARM);
-           @i @Term.node@ = new_node(O_ID, TREENULL, TREENULL); @Term.node@->param_index=1;
+           @i @Term.node@ = new_node(O_ID, TREENULL, TREENULL); {
+                       struct symbol *tmp;
+                       if((tmp = tab_lookup(@Term.s@, @IDENT.name@, S_PARM)) != TREENULL) {
+                               @Term.node@->param_index = tmp->param_index;
+                       }
+               }
            @reg fprintf(stderr, "wtf5\n");
          @}
 
index a889a1eedc634b24a1747f65b7ff5838a49c315a..006b6dd3a9b9c0957540da9a8193d96643f8fbbf 100755 (executable)
@@ -3,7 +3,7 @@
 #include <stdio.h>
 #include "symtable.h"
 
-#if 0
+#if 1
 #define DD
 #endif
 
@@ -17,22 +17,22 @@ struct symbol *tab_clone(struct symbol *tab)
        struct symbol *elm = tab;
        struct symbol *ntab = tab_new();
 #ifdef DD
-       printf("tab_clone: tab(%08X)\n", tab);
+       fprintf(stderr, "tab_clone: tab(%08X)\n", tab);
 #endif
 
        while(elm != SYMNULL) {
-               ntab = tab_add_symbol(ntab, elm->ident, elm->type, 0);
+               ntab = tab_add_symbol(ntab, elm->ident, elm->type, 0, elm->param_index ? elm->param_index : 0);
                elm = elm->next;
        }
        return ntab;
 }
 
-struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check)
+struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check, int param_index)
 {
        struct symbol *elm = tab;
        struct symbol *new_elm;
 #ifdef DD
-       printf("tab_add_symbol: tab(%08X), ident(%s), type(%i), check(%i)\n", tab, ident, type, check);
+       fprintf(stderr, "tab_add_symbol: tab(%08X), ident(%s), type(%i), check(%i), param_index(%i)\n", tab, ident, type, check, param_index);
 #endif
 
        if(tab_lookup(tab, ident, type) != SYMNULL) {
@@ -48,6 +48,9 @@ struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short
        new_elm->next = SYMNULL;
        new_elm->ident = strdup(ident);
        new_elm->type = type;
+       if(type == S_PARM) {
+               new_elm->param_index = param_index;
+       }
 
        if(tab == SYMNULL) {
                return new_elm;
@@ -84,11 +87,11 @@ struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check)
        struct symbol *elm = to_add;
        struct symbol *ntab = tab_clone(tab);
 #ifdef DD
-       printf("tab_merge: tab(%08X), to_add(%08X), check(%i), ntab(%08X)\n", tab, to_add, check, ntab);
+       fprintf(stderr, "tab_merge: tab(%08X), to_add(%08X), check(%i), ntab(%08X)\n", tab, to_add, check, ntab);
 #endif
        
        while(elm != SYMNULL) {
-               ntab = tab_add_symbol(ntab, elm->ident, elm->type, check);
+               ntab = tab_add_symbol(ntab, elm->ident, elm->type, check, elm->param_index ? elm->param_index : 0);
                elm = elm->next;
        }
 
@@ -122,7 +125,7 @@ void check(struct symbol *tab, char *ident, short type)
 {
        struct symbol *elm;
 #ifdef DD
-       printf("check: tab(%08X), ident(%s), type(%i), elm(%08X)\n", tab, ident, type, elm);
+       fprintf(stderr, "check: tab(%08X), ident(%s), type(%i), elm(%08X)\n", tab, ident, type, elm);
 #endif
 
        if(type & (S_VAR | S_PARM)) {
index 6b295615e2b482214df3dafd96db2292bcb608ab..5db4ed6d34dc419648efa9619c05fd7580d9a748 100755 (executable)
@@ -11,11 +11,12 @@ struct symbol {
        char *ident;
        struct symbol *next;
        short type;
+       int param_index;
 };
 
 struct symbol *tab_clone(struct symbol *tab);
 struct symbol *tab_new(void);
-struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check);
+struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check, int param_index);
 struct symbol *tab_lookup(struct symbol *tab, char *ident, short type);
 struct symbol *tab_remove_symbol(struct symbol *tab, char *ident, short type);
 struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check);