ソースの修正
authorj8takagi <j8takagi@nifty.com>
Thu, 17 Mar 2011 14:27:21 +0000 (23:27 +0900)
committerj8takagi <j8takagi@nifty.com>
Thu, 17 Mar 2011 14:27:21 +0000 (23:27 +0900)
include/assemble.h
src/assemble.c
src/cerr.c
src/cmd.c
src/label.c
src/struct.c
src/token.c

index aa2b599..f702328 100644 (file)
@@ -119,6 +119,11 @@ typedef enum {
     SECOND = 1,
 } PASS;
 
     SECOND = 1,
 } PASS;
 
+/**
+ * ラベルのエラーをエラーリストに追加
+ */
+void addcerrlist_label();
+
 /**
  * プログラム名とラベルに対応するアドレスをラベル表から検索する
  */
 /**
  * プログラム名とラベルに対応するアドレスをラベル表から検索する
  */
index 0e29454..35c3e9f 100644 (file)
@@ -626,6 +626,7 @@ void addcerrlist_assemble()
 {
     addcerrlist_tok();
     addcerrlist_word();
 {
     addcerrlist_tok();
     addcerrlist_word();
+    addcerrlist_label();
     addcerrlist(ARRAYSIZE(cerr_assemble), cerr_assemble);
 }
 
     addcerrlist(ARRAYSIZE(cerr_assemble), cerr_assemble);
 }
 
index d595275..6b9ab40 100644 (file)
@@ -10,7 +10,7 @@
  */
 void cerr_init()
 {
  */
 void cerr_init()
 {
-    cerr = malloc_chk(sizeof(CERR), "cerr");
+    cerr = malloc_chk(sizeof(CERR *), "cerr");
     cerr->num = 0;
 }
 
     cerr->num = 0;
 }
 
@@ -27,19 +27,19 @@ CERRLIST *cerrlist = NULL;
 /**
  * エラーリストを作成または追加する
  */
 /**
  * エラーリストを作成または追加する
  */
-void addcerrlist(int newerrc, CERR newerrv[])
+void addcerrlist(int errc, CERR errv[])
 {
     int i;
 {
     int i;
-    CERRLIST *p = NULL, *q;
+    CERRLIST *p = NULL, *q = malloc_chk(sizeof(CERRLIST *), "cerrlist");
 
 
-    assert(newerrc > 0 && newerrv != NULL);
-    for(i = 0; i < newerrc; i++) {
+    assert(errc > 0 && errv != NULL);
+    for(i = 0; i < errc; i++) {
         if(p == NULL) {
         if(p == NULL) {
-            p = q = malloc_chk(sizeof(CERRLIST), "cerrlist");
+            p = q;
         } else {
         } else {
-            p = p->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
+            p = p->next = malloc_chk(sizeof(CERRLIST *), "cerrlist.next");
         }
         }
-        p->cerr = &newerrv[i];
+        p->cerr = &errv[i];
         p->next = NULL;
     }
     p->next = cerrlist;
         p->next = NULL;
     }
     p->next = cerrlist;
index 870d975..f393c9a 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -73,11 +73,11 @@ unsigned hash_cmdtype(const char *cmd, CMDTYPE type)
     unsigned hashval;
 
     /* 命令名を設定 */
     unsigned hashval;
 
     /* 命令名を設定 */
-    keys[0] = malloc_chk(sizeof(HKEY), "hash_cmdtype.keys[0]");
+    keys[0] = malloc_chk(sizeof(HKEY *), "hash_cmdtype.keys[0]");
     keys[0]->type = CHARS;
     keys[0]->val.s = strdup_chk(cmd, "keys[0].val.s");
     /* 命令タイプを設定 */
     keys[0]->type = CHARS;
     keys[0]->val.s = strdup_chk(cmd, "keys[0].val.s");
     /* 命令タイプを設定 */
-    keys[1] = malloc_chk(sizeof(HKEY), "hash_cmdtype.keys[1]");
+    keys[1] = malloc_chk(sizeof(HKEY *), "hash_cmdtype.keys[1]");
     keys[1]->type = INT;
     keys[1]->val.i = (int)(type & 070);
     /* ハッシュ値の計算 */
     keys[1]->type = INT;
     keys[1]->val.i = (int)(type & 070);
     /* ハッシュ値の計算 */
@@ -101,7 +101,7 @@ bool create_cmdtype_code()
     cmdtabsize = comet2cmdsize;                                            /* ハッシュ表のサイズ */
     cmdtype_code = calloc_chk(cmdtabsize, sizeof(CMDTAB *), "cmdtype_code");
     for(i = 0; i < comet2cmdsize; i++) {
     cmdtabsize = comet2cmdsize;                                            /* ハッシュ表のサイズ */
     cmdtype_code = calloc_chk(cmdtabsize, sizeof(CMDTAB *), "cmdtype_code");
     for(i = 0; i < comet2cmdsize; i++) {
-        p = malloc_chk(sizeof(CMDTAB), "create_cmdtype_code.p");
+        p = malloc_chk(sizeof(CMDTAB *), "create_cmdtype_code.p");
         hashval = hash_cmdtype(comet2cmd[i].name, comet2cmd[i].type);    /* ハッシュ値の生成 */
         p->next = cmdtype_code[hashval];                                 /* ハッシュ表に値を追加 */
         p->cmd = &comet2cmd[i];
         hashval = hash_cmdtype(comet2cmd[i].name, comet2cmd[i].type);    /* ハッシュ値の生成 */
         p->next = cmdtype_code[hashval];                                 /* ハッシュ表に値を追加 */
         p->cmd = &comet2cmd[i];
@@ -154,7 +154,7 @@ unsigned hash_code(WORD code)
     unsigned h;
 
     /* 命令コードを設定 */
     unsigned h;
 
     /* 命令コードを設定 */
-    keys[0] = malloc_chk(sizeof(HKEY), "hash_code.key");
+    keys[0] = malloc_chk(sizeof(HKEY *), "hash_code.key");
     keys[0]->type = INT;
     keys[0]->val.i = (int)(code >> 8);
     h = hash(1, keys, cmdtabsize);
     keys[0]->type = INT;
     keys[0]->val.i = (int)(code >> 8);
     h = hash(1, keys, cmdtabsize);
@@ -174,7 +174,7 @@ bool create_code_type()
     cmdtabsize = comet2cmdsize;                    /* ハッシュ表のサイズ */
     code_type = calloc_chk(comet2cmdsize, sizeof(CMDTAB *), "code_type");
     for(i = 0; i < comet2cmdsize; i++) {
     cmdtabsize = comet2cmdsize;                    /* ハッシュ表のサイズ */
     code_type = calloc_chk(comet2cmdsize, sizeof(CMDTAB *), "code_type");
     for(i = 0; i < comet2cmdsize; i++) {
-        p = malloc_chk(sizeof(CMDTAB), "code_type.p");
+        p = malloc_chk(sizeof(CMDTAB *), "code_type.p");
         hashval = hash_code((&comet2cmd[i])->code);    /* ハッシュ値の生成 */
         p->next = code_type[hashval];                  /* ハッシュ表に値を追加 */
         p->cmd = &comet2cmd[i];
         hashval = hash_code((&comet2cmd[i])->code);    /* ハッシュ値の生成 */
         p->next = code_type[hashval];                  /* ハッシュ表に値を追加 */
         p->cmd = &comet2cmd[i];
index a8baa1d..04a757d 100644 (file)
 static int labelcnt = 0;                /* ラベル数 */
 static LABELTAB *labels[LABELTABSIZE];  /* ラベル表 */
 
 static int labelcnt = 0;                /* ラベル数 */
 static LABELTAB *labels[LABELTABSIZE];  /* ラベル表 */
 
+/**
+ * ラベルのエラー定義
+ */
+static CERR cerr_label[] = {
+    { 101, "label already defined" },
+    { 102, "label table is full" },
+    { 103, "label not found" },
+};
+
+/**
+ * ラベルのエラーをエラーリストに追加
+ */
+void addcerrlist_label()
+{
+    addcerrlist(ARRAYSIZE(cerr_label), cerr_label);
+}
+
 /**
  * プログラム名とラベルに対応するハッシュ値を返す
  */
 /**
  * プログラム名とラベルに対応するハッシュ値を返す
  */
@@ -61,7 +78,7 @@ WORD getlabel(const char *prog, const char *label)
 bool addlabel(const char *prog, const char *label, WORD adr)
 {
     assert(label != NULL);
 bool addlabel(const char *prog, const char *label, WORD adr)
 {
     assert(label != NULL);
-    LABELTAB *np;
+    LABELTAB *p;
     unsigned hashval;
 
     /* 登録されたラベルを検索。すでに登録されている場合はエラー発生 */
     unsigned hashval;
 
     /* 登録されたラベルを検索。すでに登録されている場合はエラー発生 */
@@ -70,23 +87,23 @@ bool addlabel(const char *prog, const char *label, WORD adr)
         return false;
     }
     /* メモリを確保 */
         return false;
     }
     /* メモリを確保 */
-    np = malloc_chk(sizeof(LABELTAB), "labels.next");
+    p = malloc_chk(sizeof(LABELTAB), "labels.next");
     /* プログラム名を設定 */
     if(prog == NULL) {
     /* プログラム名を設定 */
     if(prog == NULL) {
-        np->prog = NULL;
+        p->prog = NULL;
     } else {
     } else {
-        np->prog = strdup_chk(prog, "labels.prog");
+        p->prog = strdup_chk(prog, "labels.prog");
     }
     /* ラベルを設定 */
     }
     /* ラベルを設定 */
-    np->label = strdup_chk(label, "labels.label");
+    p->label = strdup_chk(label, "labels.label");
     /* アドレスを設定 */
     /* アドレスを設定 */
-    np->adr = adr;
+    p->adr = adr;
     /* ラベル数を設定 */
     labelcnt++;
     /* ハッシュ表へ追加 */
     hashval = labelhash(prog, label);
     /* ラベル数を設定 */
     labelcnt++;
     /* ハッシュ表へ追加 */
     hashval = labelhash(prog, label);
-    np->next = labels[hashval];
-    labels[hashval] = np;
+    p->next = labels[hashval];
+    labels[hashval] = p;
     return true;
 }
 
     return true;
 }
 
@@ -103,29 +120,29 @@ int compare_adr(const void *a, const void *b)
  */
 void printlabel()
 {
  */
 void printlabel()
 {
-    int i, asize = 0;
+    int i, s = 0;
     LABELTAB *p;
     LABELTAB *p;
-    LABELARRAY *ar[labelcnt];
+    LABELARRAY *l[labelcnt];
 
     for(i = 0; i < LABELTABSIZE; i++) {
         for(p = labels[i]; p != NULL; p = p->next) {
             assert(p->label != NULL);
 
     for(i = 0; i < LABELTABSIZE; i++) {
         for(p = labels[i]; p != NULL; p = p->next) {
             assert(p->label != NULL);
-            ar[asize] = malloc_chk(sizeof(LABELARRAY), "ar[]");
+            l[s] = malloc_chk(sizeof(LABELARRAY), "l[]");
             if(p->prog == NULL) {
             if(p->prog == NULL) {
-                ar[asize]->prog = NULL;
+                l[s]->prog = NULL;
             } else {
             } else {
-                ar[asize]->prog = strdup_chk(p->prog, "ar[].prog");
+                l[s]->prog = strdup_chk(p->prog, "l[].prog");
             }
             }
-            ar[asize]->label = strdup_chk(p->label, "ar[].label");
-            ar[asize++]->adr = p->adr;
+            l[s]->label = strdup_chk(p->label, "l[].label");
+            l[s++]->adr = p->adr;
         }
     }
         }
     }
-    qsort(ar, asize, sizeof(*ar), compare_adr);
-    for(i = 0; i < asize; i++) {
-        if(ar[i]->prog != NULL) {
-            fprintf(stdout, "%s.", ar[i]->prog);
+    qsort(l, s, sizeof(*l), compare_adr);
+    for(i = 0; i < s; i++) {
+        if(l[i]->prog != NULL) {
+            fprintf(stdout, "%s.", l[i]->prog);
         }
         }
-        fprintf(stdout, "%s ---> #%04X\n", ar[i]->label, ar[i]->adr);
+        fprintf(stdout, "%s ---> #%04X\n", l[i]->label, l[i]->adr);
     }
 }
 
     }
 }
 
index ef9a844..725ca00 100644 (file)
@@ -32,7 +32,7 @@ void reset(int memsize, int clocks)
     }
     sys->cpu->sp = sys->cpu->pr = sys->cpu->fr = 0x0;
     /* CASL2プログラムの開始と終了のアドレスを初期化 */
     }
     sys->cpu->sp = sys->cpu->pr = sys->cpu->fr = 0x0;
     /* CASL2プログラムの開始と終了のアドレスを初期化 */
-    execptr = malloc_chk(sizeof(execptr), "prog");
+    execptr = malloc_chk(sizeof(EXECPTR *), "prog");
 }
 
 /**
 }
 
 /**
index c7bfade..ce2a69b 100644 (file)
@@ -105,7 +105,7 @@ CMDLINE *linetok(const char *line)
     bool quoting = false;
     CMDLINE *cmdl = NULL;
 
     bool quoting = false;
     CMDLINE *cmdl = NULL;
 
-    if(line == NULL || strlen(line) == 0) {
+    if(*line == '\0') {
         return NULL;
     }
     tokens = strdup_chk(line, "tokens");
         return NULL;
     }
     tokens = strdup_chk(line, "tokens");