summaryrefslogtreecommitdiff
path: root/miniany/c4.c
diff options
context:
space:
mode:
Diffstat (limited to 'miniany/c4.c')
-rw-r--r--miniany/c4.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/miniany/c4.c b/miniany/c4.c
index 692ed1f..4f00e30 100644
--- a/miniany/c4.c
+++ b/miniany/c4.c
@@ -37,7 +37,7 @@ enum {
// opcodes
enum { LEA ,IMM ,JMP ,JSR ,BZ ,BNZ ,ENT ,ADJ ,LEV ,LI ,LC ,SI ,SC ,PSH ,
OR ,XOR ,AND ,EQ ,NE ,LT ,GT ,LE ,GE ,SHL ,SHR ,ADD ,SUB ,MUL ,DIV ,MOD ,
- OPEN,READ,CLOS,PRTF,PUTS,GETC,PUTC,MALC,FREE,MSET,MCMP,EXIT };
+ OPEN,READ,CLOS,PRTF,PUTS,GETC,PUTC,PUTI,PUTN,MALC,FREE,MSET,MCMP,EXIT };
// types
enum { CHAR, INT, PTR };
@@ -58,7 +58,7 @@ void next()
while (le < e) {
printf("%8.4s", &"LEA ,IMM ,JMP ,JSR ,BZ ,BNZ ,ENT ,ADJ ,LEV ,LI ,LC ,SI ,SC ,PSH ,"
"OR ,XOR ,AND ,EQ ,NE ,LT ,GT ,LE ,GE ,SHL ,SHR ,ADD ,SUB ,MUL ,DIV ,MOD ,"
- "OPEN,READ,CLOS,PRTF,PUTS,GETC,PUTC,MALC,FREE,MSET,MCMP,EXIT,"[*++le * 5]);
+ "OPEN,READ,CLOS,PRTF,PUTS,GETC,PUTC,PUTI,PUTN,MALC,FREE,MSET,MCMP,EXIT,"[*++le * 5]);
if (*le <= ADJ) printf(" %d\n", *++le); else printf("\n");
}
}
@@ -375,7 +375,7 @@ int main(int argc, char **argv)
p = "char else enum if int void return sizeof while "
"EOF EXIT_SUCCESS "
- "open read close printf puts getchar putchar malloc free memset memcmp exit void main";
+ "open read close printf putstring getchar putchar putint putnl malloc free memset memcmp exit void main";
i = Char; while (i <= While) { next(); id[Tk] = i++; } // add keywords to symbol table
// add library constants
next(); id[Class] = Num; id[Type] = INT; id[Val] = -1;
@@ -543,9 +543,11 @@ int main(int argc, char **argv)
else if (i == READ) a = read(sp[2], (char *)sp[1], *sp);
else if (i == CLOS) a = close(*sp);
else if (i == PRTF) { t = sp + pc[1]; a = printf((char *)t[-1], t[-2], t[-3], t[-4], t[-5], t[-6]); }
- else if (i == PUTS) { t = sp + pc[1]; a = printf("%s\n", (char *)t[-1]); }
+ else if (i == PUTS) { t = sp + pc[1]; a = printf("%s", (char *)t[-1]); }
else if (i == GETC) a = getchar();
- else if (i == PUTC) putchar(*sp);
+ else if (i == PUTC) a = putchar(*sp);
+ else if (i == PUTI) a = printf("%d", (int)t[-1]);
+ else if (i == PUTN) a = puts("");
else if (i == MALC) a = (int)malloc(*sp);
else if (i == FREE) free((void *)*sp);
else if (i == MSET) a = (int)memset((char *)sp[2], sp[1], *sp);