トークンのアセンブルをリファクタリング
authorj8takagi <j8takagi@nifty.com>
Sun, 24 Apr 2011 22:59:57 +0000 (07:59 +0900)
committerj8takagi <j8takagi@nifty.com>
Sun, 24 Apr 2011 23:01:23 +0000 (08:01 +0900)
src/assemble.c
src/casl2.c
src/exec.c

index aff5380..d8d8bc6 100644 (file)
@@ -112,7 +112,7 @@ WORD getliteral(const char *str, PASS pass)
 
 /**
  * アセンブラ命令をメモリに書込
 
 /**
  * アセンブラ命令をメモリに書込
- * 実行に成功した場合はtrue、それ以外の場合はfalseを返す
+ * アセンブラ命令の場合はtrue、それ以外の場合はfalseを返す
  */
 bool assemblecmd(const CMDLINE *cmdl, PASS pass)
 {
  */
 bool assemblecmd(const CMDLINE *cmdl, PASS pass)
 {
@@ -130,7 +130,7 @@ bool assemblecmd(const CMDLINE *cmdl, PASS pass)
         if(strcmp(cmdl->cmd, ascmd[i].cmd) == 0) {
             if(cmdl->opd->opdc < ascmd[i].opdc_min || cmdl->opd->opdc > ascmd[i].opdc_max) {
                 setcerr(106, NULL);    /* operand count mismatch */
         if(strcmp(cmdl->cmd, ascmd[i].cmd) == 0) {
             if(cmdl->opd->opdc < ascmd[i].opdc_min || cmdl->opd->opdc > ascmd[i].opdc_max) {
                 setcerr(106, NULL);    /* operand count mismatch */
-                return false;
+                return true;
             }
             cmdid = ascmd[i].cmdid;
             break;
             }
             cmdid = ascmd[i].cmdid;
             break;
@@ -142,7 +142,7 @@ bool assemblecmd(const CMDLINE *cmdl, PASS pass)
     case START:
         if(cmdl->label == NULL) {
             setcerr(107, NULL);    /* no label in START */
     case START:
         if(cmdl->label == NULL) {
             setcerr(107, NULL);    /* no label in START */
-            return false;
+            return true;
         }
         /* プログラム名の設定 */
         asptr->prog = strdup_chk(cmdl->label, "asptr.prog");
         }
         /* プログラム名の設定 */
         asptr->prog = strdup_chk(cmdl->label, "asptr.prog");
@@ -183,13 +183,13 @@ bool assemblecmd(const CMDLINE *cmdl, PASS pass)
     default:
         return false;
     }
     default:
         return false;
     }
-    return (cerr->num == 0) ? true : false;
+    return true;
 }
 
 /**
  *  macrocmd
 }
 
 /**
  *  macrocmd
- *  マクロ命令をメモリに書込
- *  書込に成功した場合はtrue、それ以外の場合はfalseを返す
+ * マクロ命令をメモリに書込
+ * マクロ命令の場合はtrue、それ以外の場合はfalseを返す
  */
 bool macrocmd(const CMDLINE *cmdl, PASS pass)
 {
  */
 bool macrocmd(const CMDLINE *cmdl, PASS pass)
 {
@@ -209,7 +209,7 @@ bool macrocmd(const CMDLINE *cmdl, PASS pass)
                cmdl->opd->opdc > macrocmd[i].opdc_max)
             {
                 setcerr(106, NULL);    /* operand count mismatch */
                cmdl->opd->opdc > macrocmd[i].opdc_max)
             {
                 setcerr(106, NULL);    /* operand count mismatch */
-                return false;
+                return true;
             }
             cmdid = macrocmd[i].cmdid;
             break;
             }
             cmdid = macrocmd[i].cmdid;
             break;
@@ -219,19 +219,20 @@ bool macrocmd(const CMDLINE *cmdl, PASS pass)
     {
     case IN:
         writeIN(cmdl->opd->opdv[0], cmdl->opd->opdv[1], pass);
     {
     case IN:
         writeIN(cmdl->opd->opdv[0], cmdl->opd->opdv[1], pass);
-        return true;
+        break;
     case OUT:
         writeOUT(cmdl->opd->opdv[0], cmdl->opd->opdv[1], pass);
     case OUT:
         writeOUT(cmdl->opd->opdv[0], cmdl->opd->opdv[1], pass);
-        return true;
+        break;
     case RPUSH:
         writeRPUSH(pass);
     case RPUSH:
         writeRPUSH(pass);
-        return true;
+        break;
     case RPOP:
         writeRPOP(pass);
     case RPOP:
         writeRPOP(pass);
-        return true;
+        break;
     default:
         return false;
     }
     default:
         return false;
     }
+    return true;
 }
 
 /**
 }
 
 /**
@@ -502,32 +503,18 @@ void writeDC(const char *str, PASS pass)
  */
 bool assembletok(const CMDLINE *cmdl, PASS pass)
 {
  */
 bool assembletok(const CMDLINE *cmdl, PASS pass)
 {
-    bool status = false;
-
     /* 命令がない場合 */
     if(cmdl->cmd == NULL){
     /* 命令がない場合 */
     if(cmdl->cmd == NULL){
-        ;
-    }
-    /* アセンブラ命令の処理 */
-    else if(cerr->num == 0 && assemblecmd(cmdl, pass) == true) {
-        ;
-    }
-    /* マクロ命令の書込 */
-    else if(cerr->num == 0 && macrocmd(cmdl, pass) == true) {
-        ;
-    }
-    /* 機械語命令の書込 */
-    else if(cerr->num == 0 && cometcmd(cmdl, pass) == true) {
-        ;
-    }
-    else if(cerr->num == 0) {
-        setcerr(113, cmdl->cmd);    /* operand too many in COMET II command */
+        return true;
     }
     }
-    /* エラーが発生していないか確認 */
-    if(cerr->num == 0) {
-        status = true;
+    /* アセンブラ命令またはマクロ命令の書込 */
+    if(assemblecmd(cmdl, pass) == false && macrocmd(cmdl, pass) == false) {
+        /* COMET II命令の書込 */
+        if(cometcmd(cmdl, pass) == false && cerr->num == 0) {
+            setcerr(113, cmdl->cmd);    /* operand too many in COMET II command */
+        }
     }
     }
-    return status;
+    return (cerr->num == 0) ? true : false;
 }
 
 /**
 }
 
 /**
index cf44e68..c40a0a7 100644 (file)
@@ -104,7 +104,7 @@ asfin:
  */
 int main(int argc, char *argv[])
 {
  */
 int main(int argc, char *argv[])
 {
-    int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS, opt, i, status;
+    int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS, opt, i, stat;
     char *af[argc];
     char *objfile = NULL;
     const char *usage =
     char *af[argc];
     char *objfile = NULL;
     const char *usage =
@@ -190,7 +190,7 @@ int main(int argc, char *argv[])
     }
 casl2fin:
     shutdown();                                    /* 仮想マシンCOMET IIのシャットダウン */
     }
 casl2fin:
     shutdown();                                    /* 仮想マシンCOMET IIのシャットダウン */
-    status = (cerr->num == 0) ? 0 : -1;
+    stat = (cerr->num == 0) ? 0 : -1;
     freecerr();                                    /* エラーの解放 */
     freecerr();                                    /* エラーの解放 */
-    return status;
+    return stat;
 }
 }
index d8df852..1bc891e 100644 (file)
@@ -54,7 +54,7 @@ void addcerrlist_exec()
 bool loadassemble(const char *file)
 {
     FILE *fp;
 bool loadassemble(const char *file)
 {
     FILE *fp;
-    bool status = true;
+    bool stat = true;
 
     assert(file != NULL);
     if((fp = fopen(file, "r")) == NULL) {
 
     assert(file != NULL);
     if((fp = fopen(file, "r")) == NULL) {
@@ -66,10 +66,10 @@ bool loadassemble(const char *file)
     if(execptr->end == sys->memsize) {
         setcerr(210, file);    /* load - memory overflow */
         fprintf(stderr, "Load error - %d: %s\n", cerr->num, cerr->msg);
     if(execptr->end == sys->memsize) {
         setcerr(210, file);    /* load - memory overflow */
         fprintf(stderr, "Load error - %d: %s\n", cerr->num, cerr->msg);
-        status = false;
+        stat = false;
     }
     fclose(fp);
     }
     fclose(fp);
-    return status;
+    return stat;
 }
 
 /**
 }
 
 /**