From: j8takagi Date: Mon, 21 Mar 2011 14:52:40 +0000 (+0900) Subject: ソースコードの推敲 X-Git-Tag: v0.1p28 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d609e3d54f40e0c4bd497a5287288d2fe3d78212;p=YACASL2.git ソースコードの推敲 --- diff --git a/include/assemble.h b/include/assemble.h index f702328..68e86b0 100644 --- a/include/assemble.h +++ b/include/assemble.h @@ -35,7 +35,7 @@ typedef struct { extern ASMODE asmode; /** - * アセンブル時の、現在およびリテラルのアドレスと入口名 + * アセンブル時の、現在およびリテラルのアドレスとプログラム入口名 */ typedef struct { WORD ptr; /**<現在のアドレス */ diff --git a/src/assemble.c b/src/assemble.c index 35c3e9f..8b3aa61 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -13,7 +13,7 @@ ASMODE asmode = {false, false, false, false, false}; /** - * アセンブルのプロパティ: ptr, lptr, *prog + * アセンブル時の、現在およびリテラルのアドレスとプログラム入口名: ptr, lptr, prog */ ASPTR *asptr; @@ -80,6 +80,7 @@ WORD getgr(const char *str, bool is_x) { assert(str != NULL); WORD r; + /* 「GR[0-7]」以外の文字列では、0xFFFFを返して終了 */ if(!(strlen(str) == 3 && strncmp(str, "GR", 2) == 0 && (*(str+2) >= '0' && *(str+2) <= '0' + (GRSIZE - 1)))) @@ -101,8 +102,9 @@ WORD getgr(const char *str, bool is_x) */ WORD getliteral(const char *str, PASS pass) { - WORD adr = asptr->lptr; assert(*str == '='); + WORD adr = asptr->lptr; + if(*(++str) == '\'') { /* 文字定数 */ writestr(str, true, pass); } else { @@ -204,7 +206,7 @@ bool macrocmd(const CMDLINE *cmdl, PASS pass) { int i = 0; MACROCMDID cmdid = 0; - MACROCMD macrocmd[] = { + MACROCMD macrocmd[] = { { IN, 2, 2, "IN" }, { OUT, 2, 2, "OUT" }, { RPUSH, 0, 0, "RPUSH" }, @@ -255,7 +257,7 @@ bool macrocmd(const CMDLINE *cmdl, PASS pass) */ void writeIN(const char *ibuf, const char *len, PASS pass) { - char *line = malloc_chk(LINESIZE+1, "writeIN.line"); + char *line = malloc_chk(LINESIZE + 1, "writeIN.line"); assembleline(" PUSH 0,GR1", pass); assembleline(" PUSH 0,GR2", pass); @@ -285,7 +287,7 @@ void writeIN(const char *ibuf, const char *len, PASS pass) */ void writeOUT(const char *obuf, const char *len, PASS pass) { - char *line = malloc_chk(LINESIZE+1, "writeOUT.line"); + char *line = malloc_chk(LINESIZE + 1, "writeOUT.line"); assembleline(" PUSH 0,GR1", pass); assembleline(" PUSH 0,GR2", pass); @@ -314,7 +316,7 @@ void writeOUT(const char *obuf, const char *len, PASS pass) void writeRPUSH(PASS pass) { int i; - char *line = malloc_chk(LINESIZE+1, "writeRPUSH.line"); + char *line = malloc_chk(LINESIZE + 1, "writeRPUSH.line"); for(i = 1; i <= GRSIZE-1; i++) { sprintf(line, " PUSH 0,GR%d", i); @@ -337,7 +339,7 @@ void writeRPUSH(PASS pass) void writeRPOP(PASS pass) { int i; - char *line = malloc_chk(LINESIZE+1, "writeRPOP.line"); + char *line = malloc_chk(LINESIZE + 1, "writeRPOP.line"); for(i = GRSIZE-1; i >= 1; i--) { sprintf(line, " POP GR%d", i); @@ -476,7 +478,7 @@ bool writememory(WORD word, WORD adr, PASS pass) */ void writestr(const char *str, bool literal, PASS pass) { - assert(cerr->num == 0 && *str == '\''); + assert(*str == '\''); const char *p = str + 1; bool lw = false; @@ -509,6 +511,7 @@ void writestr(const char *str, bool literal, PASS pass) void writeDC(const char *str, PASS pass) { WORD adr = 0x0; + if(*str == '\'') { writestr(str, false, pass); } else { @@ -571,6 +574,7 @@ void printline(FILE *stream, const char *filename, int lineno, char *line) WORD getadr(const char *prog, const char *str, PASS pass) { WORD adr = 0x0; + if(*str == '=') { adr = getliteral(str, pass); } else if(isdigit(*str) || *str == '-' || *str == '#') { @@ -638,7 +642,7 @@ bool assemble(const char *file, PASS pass) { int lineno = 0; bool status = true; - char *line = malloc_chk(LINESIZE + 1, "line"); + char *line = malloc_chk(LINESIZE + 1, "assemble.line"); FILE *fp; if((fp = fopen(file, "r")) == NULL) { diff --git a/src/word.c b/src/word.c index 415dfa4..e355a67 100644 --- a/src/word.c +++ b/src/word.c @@ -95,9 +95,9 @@ WORD nh2word(const char *str) char *word2n(WORD word) { enum { - MAXLEN = 6, /* WORD値を10進数で表したときの最大桁数 */ + MAXLEN = 5, /* WORD値を10進数で表したときの最大桁数 */ }; - char *p = malloc_chk(MAXLEN, "word2n.p"), *digit = malloc_chk(MAXLEN, "word2n.digit"); + char *p = malloc_chk(MAXLEN + 1, "word2n.p"), *digit = malloc_chk(MAXLEN + 1, "word2n.digit"); int i = 0, j; do{