summaryrefslogtreecommitdiff
path: root/util/muse.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2012-06-16 14:06:54 -0400
committerOri Bernstein <ori@eigenstate.org>2012-06-16 14:06:54 -0400
commit6b0e53468c9078efde8c5daaede91ea70bbd6e1d (patch)
tree1507b79824b1d0684fe08b3f6e3a998d6fe2f501 /util/muse.c
parenta6c7b6c46c1c4e9d8b4f246cdbc82ac5916cfd71 (diff)
downloadmc-6b0e53468c9078efde8c5daaede91ea70bbd6e1d.tar.gz
Work towards getting usefiles going.
Diffstat (limited to 'util/muse.c')
-rw-r--r--util/muse.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/util/muse.c b/util/muse.c
new file mode 100644
index 0000000..325af40
--- /dev/null
+++ b/util/muse.c
@@ -0,0 +1,83 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <ctype.h>
+#include <string.h>
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "parse.h"
+
+/* FIXME: move into one place...? */
+Node *file;
+char *outfile;
+int debug;
+char **incpaths;
+size_t nincpaths;
+
+static void usage(char *prog)
+{
+ printf("%s [-h] [-o outfile] inputs\n", prog);
+ printf("\t-h\tPrint this help\n");
+ printf("\t-I path\tAdd 'path' to use search path\n");
+ printf("\t-d\tPrint debug dumps\n");
+ printf("\t-o\tOutput to outfile\n");
+}
+
+int main(int argc, char **argv)
+{
+ int opt;
+ int i;
+ Stab *globls;
+ Node *rdback;
+ FILE *tmp;
+
+ while ((opt = getopt(argc, argv, "dho:")) != -1) {
+ switch (opt) {
+ case 'o':
+ outfile = optarg;
+ break;
+ case 'h':
+ case 'd':
+ debug++;
+ break;
+ default:
+ usage(argv[0]);
+ exit(0);
+ break;
+ }
+ }
+
+ for (i = optind; i < argc; i++) {
+ globls = mkstab();
+ tyinit(globls);
+ tokinit(argv[i]);
+ file = mkfile(argv[i]);
+ file->file.exports = mkstab();
+ file->file.globls = globls;
+ yyparse();
+
+ if (debug) {
+ /* test storing tree to file */
+ tmp = fopen("a.pkl", "w");
+ pickle(file, tmp);
+ fclose(tmp);
+
+ /* and reading it back */
+ tmp = fopen("a.pkl", "r");
+ rdback = unpickle(tmp);
+ dump(rdback, stdout);
+ fclose(tmp);
+
+ /* before we do anything to the parse */
+ dump(file, stdout);
+ }
+ infer(file);
+ die("FIXME: IMPLEMENT ME!");
+ }
+
+ return 0;
+}