aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2012-04-17 18:23:52 +0000
committerDimitri Sokolyuk <demon@dim13.org>2012-04-17 18:23:52 +0000
commit245459ae8c15554418d6d54ba0ab220b9eba0620 (patch)
tree355ad9c0566dfab3ecca102537806cd15b07efde
parent20e9a95075a7a95df90daa7c9bb4af0dff8ebf0d (diff)
cleanup, make it build on linux (freebsd-make)
-rw-r--r--Makefile2
-rw-r--r--dcpu16.h4
-rw-r--r--gramar.y18
-rw-r--r--main.c2
4 files changed, 19 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 6021e10..482290f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
# $Id$
PROG= dcpu
-SRCS= gramar.y lexer.l emu.c main.c tui.c
+SRCS= gramar.y lexer.l emu.c main.c tui.c y.tab.h
NOMAN=
LDADD+= -lcurses
#DEBUG= -Wall -ggdb -pg
diff --git a/dcpu16.h b/dcpu16.h
index 646dd5c..9ede832 100644
--- a/dcpu16.h
+++ b/dcpu16.h
@@ -41,7 +41,9 @@ enum { Res, JSR, BRK, nExt };
/* display: 32x12 (128x96) + 16 pixel boarder, font 8x4 */
-unsigned short *compile(FILE *);
+unsigned short *compile(FILE *, size_t);
int step(unsigned short *, unsigned short *);
+void tuiemu(unsigned short *, unsigned short *);
+
#endif
diff --git a/gramar.y b/gramar.y
index 61fdd1a..806917d 100644
--- a/gramar.y
+++ b/gramar.y
@@ -18,13 +18,18 @@
%{
#include <sys/queue.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include "dcpu16.h"
extern int yylineno;
extern FILE *yyin;
int yylex(void);
int yyparse(void);
+void yyerror(const char *);
+void push(int, char *);
+void popop(int);
+void popall(void);
+void addref(char *);
#if YYDEBUG
extern int yydebug;
@@ -39,8 +44,8 @@ int sp = 0;
int rp = 0;
int pc = 0;
-unsigned short buffer[MEMSZ];
-char *label[MEMSZ];
+unsigned short *buffer;
+char **label;
%}
@@ -267,14 +272,19 @@ restorerefs(void)
}
unsigned short *
-compile(FILE *fd)
+compile(FILE *fd, size_t sz)
{
+ buffer = calloc(sz, sizeof(unsigned short));
+ label = calloc(sz, sizeof(char *));
+
#if YYDEBUG
yydebug = 1;
#endif
+
yyin = fd;
yyparse();
restorerefs();
+ free(label);
return buffer;
}
diff --git a/main.c b/main.c
index 35a7411..d7cbfa0 100644
--- a/main.c
+++ b/main.c
@@ -81,7 +81,7 @@ main(int argc, char **argv)
if (!fd)
err(1, "cannot open file");
- m = compile(fd);
+ m = compile(fd, MEMSZ);
fclose(fd);
if (e_flag)