Permalink
Browse files

support command line argument

install/uninstall in makefile
  • Loading branch information...
1 parent a9a6b4b commit 038df6c8a241cb0c73508d142d99bdadcb247e17 @cpylua committed Apr 19, 2012
Showing with 63 additions and 40 deletions.
  1. +1 −3 .gitignore
  2. +8 −2 README.md
  3. +3 −0 config.h
  4. +1 −1 ioproc.c
  5. +2 −1 lib/core.scm
  6. +5 −1 main.c
  7. +24 −3 makefile
  8. +18 −3 repl.c
  9. +1 −1 repl.h
  10. 0 {lib → test}/amb.scm
  11. 0 {lib → test}/coop-threads.scm
  12. +0 −6 test/makefile
  13. +0 −8 test/test.c
  14. +0 −11 test/test.scm
View
@@ -1,6 +1,4 @@
*.o
-scheme
+asc
gmon.out
-test/test
-test/*.o
*.html
View
@@ -28,6 +28,12 @@ character, pair, vector
+ macro(define-macro)
+ promise(delay, force)
+Install:
+---------
+`make`
+`sudo make install`
+`asc`
+
Documentation:
--------------
If you already know Scheme, just start typing code in the REPL.
@@ -57,8 +63,8 @@ Todo list:
+ rewrite environment using rbtree(variable lookup is too slow) **[DONE] ~2x speedup**
+ call/cc **[DONE]**
+ macro support **[DONE]**
-+ command line options
-+ make install
++ command line options **[DONE]**
++ make install **[DONE]**
Thanks for *Peter Michaux's* excellent
[introduction series.](http://peter.michaux.ca/articles/scheme-from-scratch-introduction)
View
@@ -39,5 +39,8 @@
/* enable rb-tree verification after each insertion */
/* #define VERIFY_RB_TREE */
+/* application fold */
+#define APP_DIR "/usr/share/asc/"
+
#endif
View
@@ -257,7 +257,7 @@ static int open_output_port_proc(object *params, object **result) {
return SC_E_ARG_TYPE;
}
filename = obj_sv(obj);
- out = fopen(filename, "a");
+ out = fopen(filename, "w");
if (out == NULL) {
return SC_E_IO_OPEN;
}
View
@@ -6,8 +6,9 @@
;
+(define *DATA_TOP* "/usr/share/asc/")
(define (reload-core)
- (load "lib/core.scm"))
+ (load (string-append *DATA_TOP* "lib/core.scm")))
; number functions
(define (number? x)
View
6 main.c
@@ -70,7 +70,11 @@ int main(int argc, char **argv) {
return ret;
}
- ret = sc_repl();
+ if (argc == 2) {
+ ret = sc_repl(argv[1]);
+ } else {
+ ret = sc_repl(NULL);
+ }
dispose();
View
@@ -20,12 +20,33 @@ ifeq ($(PROFILE), 1)
LFLAG += -pg
endif
-scheme: $(OBJS)
- cc $^ $(LFLAG) -o scheme
+asc: $(OBJS)
+ cc $^ $(LFLAG) -o asc
%.o: %.c
cc $(CFLAG) $< -o $@
+INSTALL_BIN = /usr/bin
+INSTALL_TOP = /usr/share/asc
+INSTALL_LIB = $(INSTALL_TOP)/lib
+MKDIR = mkdir -p
+INSTALL = install -p
+INSTALL_EXEC = $(INSTALL) -m 0755
+INSTALL_DATA = $(INSTALL) -m 0644
+UNINSTALL = rm -f
+UNINSTALL_DIR = $(UNINSTALL) -r
+BIN = asc
+LIB = lib/core.scm
+install:
+ $(MKDIR) $(INSTALL_BIN) $(INSTALL_LIB)
+ $(INSTALL) $(BIN) $(INSTALL_BIN)
+ $(INSTALL) $(LIB) $(INSTALL_LIB)
+
+uninstall:
+ cd $(INSTALL_BIN) && $(UNINSTALL) $(BIN)
+ $(UNINSTALL_DIR) $(INSTALL_TOP)
+
+RM = rm -f
.PHONY: clean
clean:
- rm *.o scheme
+ $(RM) *.o asc
View
21 repl.c
@@ -8,11 +8,12 @@
#include "env.h"
#include "gc.h"
+#define CORE_LIB_PATH APP_DIR "lib/core.scm"
+
static int keep_run = 1;
static object *global_env;
-static int load_core_lib(void) {
- char filename[] = "./lib/core.scm";
+static int load_src(char *filename) {
FILE *in;
object *exp;
@@ -42,6 +43,10 @@ static int load_core_lib(void) {
return 0;
}
+static int load_core_lib() {
+ return load_src(CORE_LIB_PATH);
+}
+
static int init(void) {
global_env = make_base_env();
if (global_env == NULL) {
@@ -56,7 +61,7 @@ static int init(void) {
return 0;
}
-int sc_repl(void) {
+int sc_repl(char *run_file) {
object *exp, *val;
int ret = 0;
int err_cnt = 0;
@@ -66,6 +71,16 @@ int sc_repl(void) {
return -1;
}
+ /* execute program */
+ if (run_file) {
+ int ret = load_src(run_file);
+ if (ret != 0) {
+ fprintf(stderr, "failed to load %s\n", run_file);
+ }
+ return ret;
+ }
+
+ /* inteactive mode */
in = stdin;
out = stdout;
printf("%s", WELCOME_STR);
View
2 repl.h
@@ -3,7 +3,7 @@
#include "object.h"
-int sc_repl(void);
+int sc_repl(char *file);
void repl_exit(void);
object* get_repl_env(void);
File renamed without changes.
File renamed without changes.
View
@@ -1,6 +0,0 @@
-test : test.c
- gcc -O2 -o test test.c
-
-.PHONY : clean
-clean :
- rm *.o test
View
@@ -1,8 +0,0 @@
-#include <stdio.h>
-#include "../object.h"
-
-int main() {
- printf("sizeof(object)=%d\n", sizeof(object));
- return 0;
-}
-
View
@@ -1,11 +0,0 @@
-(define (double n)
- (* 2 n))
-
-(define (map f seq)
- (if (null? seq)
- '()
- (cons (f (car seq))
- (map f (cdr seq)))))
-
-(map double '(1 2 3))
-

0 comments on commit 038df6c

Please sign in to comment.