]> khamidou — GitHub mirrors - mojo.git/commitdiff
run mojo directly on a file master
authorkarim hamidou <khamidou@gmail.com>
Thu, 16 May 2013 07:09:45 +0000 (09:09 +0200)
committerkarim hamidou <khamidou@gmail.com>
Thu, 16 May 2013 07:09:45 +0000 (09:09 +0200)
interp.c
interp.h
main.c
tests/basic.mj

index 603fc0808c58757a421b79f3416539b8fd0ca977..75cacae41d9d1649e84f8141d8f9194d112e09e3 100644 (file)
--- a/interp.c
+++ b/interp.c
@@ -22,10 +22,10 @@ extern int yyleng;
 extern FILE *yyin;
 extern char *yytext;
 
 extern FILE *yyin;
 extern char *yytext;
 
-int compile_image(FILE *fp)
+int compile_image()
 {
    
 {
    
-    while(!feof(fp)) {
+    while(!feof(yyin)) {
         struct Object* ast = create_list_object(); // clone_object(list_object);
         struct Object* scope = create_list_object(); //clone_object(list_object);
      
         struct Object* ast = create_list_object(); // clone_object(list_object);
         struct Object* scope = create_list_object(); //clone_object(list_object);
      
index 053d4adb56a101779942f628b4b8d23d6e4aa74e..3c373e5f3869ead86d6e2373c9a88b7dc171ddd5 100644 (file)
--- a/interp.h
+++ b/interp.h
@@ -3,7 +3,7 @@
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
-int compile_image(FILE *fp);
+int compile_image();
 void execute(struct Object *ast);
 struct Object* execute_branch(struct Object *ast, struct Object *scope);
 
 void execute(struct Object *ast);
 struct Object* execute_branch(struct Object *ast, struct Object *scope);
 
diff --git a/main.c b/main.c
index d6d451eead74205706438a2098d4ee108410b8ab..97f906d154c4d799b3a230cbc3bd43e81ed9e6bb 100644 (file)
--- a/main.c
+++ b/main.c
@@ -2,11 +2,22 @@
 
 #include "object.h"
 #include "interp.h"
 
 #include "object.h"
 #include "interp.h"
+#include "error.h"
 
 
-int main() {
+extern FILE *yyin;
+
+int main(int argc, char **argv) {
+
+    yyin = stdin;
+    if(argc == 2) {
+        yyin = fopen(argv[1], "r");
+        if (yyin == NULL) {
+            fail("unable to open file : %s", argv[1]);
+        }
+    }
 
        init_object_system();
     puts("this is mojo.");
 
        init_object_system();
     puts("this is mojo.");
-       compile_image(stdin);
+       compile_image();
     return 0;
 }
     return 0;
 }
index b14645c5ba57b0ab73173763c3be63f92562a4b7..2d2288194c5d5c276282c55178b359db4dacc9c9 100644 (file)
@@ -1,6 +1,2 @@
-%{
-       /* Everything is supposed to be under control */
-%}
-z := truc
-s := 3
-Lexer yylex;
+2 + 2 ;
+2 + 2 ;