エラー処理にリストを使うよう仕様変更
[YACASL2.git] / src / assemble.c
index b9fbed7..50554a7 100644 (file)
@@ -1,6 +1,9 @@
 #include "casl2.h"
 #include "assemble.h"
 
+/* アセンブルモード: src, label, onlylabel, asdetail, onlyassemble */
+ASMODE asmode = {false, false, false, false, false};
+
 /* 値を格納するポインタ */
 WORD ptr;
 
@@ -24,7 +27,7 @@ WORD getgr(const char *str, bool is_x)
         return 0xFFFF;
     }
     r = (WORD)(*(str+2) - '0');
-    /* 指標レジスタとして用いることはできない */
+    /* GR0は指標レジスタとして用いることができない */
     if(is_x == true && r == 0x0) {
         setcerr(120, NULL);    /* GR0 in operand x */
         return 0x0;
@@ -62,7 +65,7 @@ bool writememory(WORD word, WORD adr, PASS pass)
     }
     if(cerrno == 0) {
         memory[adr] = word;
-        if(pass == SECOND && (&asmode)->asdetail == true) {
+        if(pass == SECOND && asmode.asdetail == true) {
             fprintf(stdout, "\t#%04X\t#%04X\n", adr, word);
         }
         status = true;
@@ -95,7 +98,7 @@ void writestr(const char *str, bool literal, PASS pass)
     for(; ;) {
         /* 閉じ「'」がないまま文字列が終了した場合 */
         if(*p == '\0') {
-            setcerr(123, str);    /* illegal string */
+            setcerr(123, str);    /* unclosed quote */
             break;
         }
         /* 「'」の場合、次の文字が「'」でない場合は正常終了 */
@@ -143,7 +146,7 @@ bool assemblecmd(const CMDLINE *cmdl, PASS pass)
     CMDARRAY ascmd[] = {
         { START, 0, 1, "START" },
         { END, 0, 0, "END" },
-        { DC, 0, OPDSIZE, "DC" },
+        { DC, 1, OPDSIZE, "DC" },
         { DS, 1, 1, "DS" },
         { 0, 0, 0, NULL }
     };
@@ -409,22 +412,19 @@ bool assemble(const char *file, PASS pass)
     char *line;
     FILE *fp;
 
-    if(create_cmdtype_code() == false) {
-        return false;
-    }
     if((fp = fopen(file, "r")) == NULL) {
         perror(file);
         return false;
     }
     for(; ;) {
         cmdl = malloc(sizeof(CMDLINE));
-        line = malloc(LINESIZE+1);
+        line = malloc(LINESIZE + 1);
         if((line = fgets(line, LINESIZE, fp)) == NULL) {
             break;
         }
         lineno++;
-        if((pass == FIRST && (&asmode)->src == true) ||
-           (pass == SECOND && (&asmode)->asdetail == true))
+        if((pass == FIRST && asmode.src == true) ||
+           (pass == SECOND && asmode.asdetail == true))
         {
             printline(stdout, file, lineno, line);
         }