From cffaccf8ef6a549d9f4b436abc4a45815427a76c Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Mon, 26 May 2014 03:21:26 +0900 Subject: [PATCH 01/41] implement the rest procedures of `input` but `u8-ready?` is incomlete like `char-ready?` --- README.md | 2 +- src/port.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++-- t/byteio.scm | 29 +++++++++++ 3 files changed, 169 insertions(+), 6 deletions(-) create mode 100644 t/byteio.scm diff --git a/README.md b/README.md index 301423ba..bdd982e9 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ At the REPL start-up time, some usuful built-in libraries listed below will be a | 6.11 Exceptions | yes | `raise-continuable` is not supported | | 6.12 Environments and evaluation | N/A | | | 6.13.1 Ports | yes | | -| 6.13.2 Input | incomplete | TODO: binary input | +| 6.13.2 Input | yes | | | 6.13.3 Output | yes | | | 6.14 System interface | yes | | diff --git a/src/port.c b/src/port.c index 84f60297..80fd98db 100644 --- a/src/port.c +++ b/src/port.c @@ -434,6 +434,140 @@ pic_port_char_ready_p(pic_state *pic) return pic_true_value(); /* FIXME: always returns #t */ } +static pic_value +pic_port_read_string(pic_state *pic){ + struct pic_port *port = pic_stdin(pic), *buf; + pic_str *str; + int k, i; + char c; + + pic_get_args(pic, "i|p", &k, &port); + + assert_port_profile(port, PIC_PORT_IN | PIC_PORT_TEXT, PIC_PORT_OPEN, "read-stritg"); + + buf = pic_open_output_string(pic); + for(i = 0; i < k; ++i) { + c = xfgetc(port->file); + if( c == EOF){ + break; + } + xfputc(c, buf->file); + } + + str = pic_get_output_string(pic, buf); + if (pic_strlen(str) == 0 && c == EOF) { + return pic_eof_object(); + } + else { + return pic_obj_value(str); + } + +} + +static pic_value +pic_port_read_byte(pic_state *pic){ + struct pic_port *port = pic_stdin(pic); + + pic_get_args(pic, "|p", &port); + + assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "read-u8"); + + return pic_int_value((char) xfgetc(port->file)); +} + +static pic_value +pic_port_peek_byte(pic_state *pic) +{ + char c; + struct pic_port *port = pic_stdin(pic); + + pic_get_args(pic, "|p", &port); + + assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "peek-u8"); + + if ((c = xfgetc(port->file)) == EOF) { + return pic_eof_object(); + } + else { + xungetc(c, port->file); + return pic_int_value(c); + } +} + +static pic_value +pic_port_byte_ready_p(pic_state *pic) +{ + struct pic_port *port = pic_stdin(pic); + + assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "char-ready?"); + + pic_get_args(pic, "|p", &port); + + return pic_true_value(); /* FIXME: always returns #t */ +} + + +static pic_value +pic_port_read_blob(pic_state *pic){ + struct pic_port *port = pic_stdin(pic); + int k, i; + char c, *buf; + + pic_get_args(pic, "i|p", &k, &port); + + assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "read-bytevector"); + + buf = pic_calloc(pic, k, sizeof(char)); + for(i = 0; i < k; i++){ + c = xfgetc(port->file); + if( c == EOF ){ + break; + } + buf[i] = c; + } + if ( i == 0 && c == EOF) { + return pic_eof_object(); + } + else { + pic_realloc(pic, buf, i); + return pic_obj_value(pic_blob_new(pic, buf, i)); + } +} + +static pic_value +pic_port_read_blob_ip(pic_state *pic){ + struct pic_port *port; + struct pic_blob *bv; + int i, n, start, end; + char c; + + n = pic_get_args(pic, "b|pii", &bv, &port, &start, &end); + switch (n) { + case 1: + port = pic_stdin(pic); + case 2: + start = 0; + case 3: + end = bv->len; + } + + assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "read-bytevector!"); + + for(i = start; i < end; i++){ + c = xfgetc(port->file); + if( c == EOF ){ + break; + } + bv->data[i] = c; + } + if ( i == start && c == EOF) { + return pic_eof_object(); + } + else { + return pic_int_value(i - start); + } +} + static pic_value pic_port_newline(pic_state *pic) { @@ -571,12 +705,12 @@ pic_init_port(pic_state *pic) pic_defun(pic, "eof-object?", pic_port_eof_object_p); pic_defun(pic, "eof-object", pic_port_eof_object); pic_defun(pic, "char-ready?", pic_port_char_ready_p); - /* pic_defun(pic, "read-string", pic_port_read_string); */ - /* pic_defun(pic, "read-u8", pic_port_read_byte); */ - /* pic_defun(pic, "peek-u8", pic_port_peek_byte); */ + pic_defun(pic, "read-string", pic_port_read_string); + pic_defun(pic, "read-u8", pic_port_read_byte); + pic_defun(pic, "peek-u8", pic_port_peek_byte); /* pic_defun(pic, "u8-ready?", pic_port_byte_ready_p); */ - /* pic_defun(pic, "read-bytevector", pic_port_read_blob); */ - /* pic_defun(pic, "peek-bytevector!", pic_port_read_blob_ip); */ + pic_defun(pic, "read-bytevector", pic_port_read_blob); + pic_defun(pic, "read-bytevector!", pic_port_read_blob_ip); /* output */ pic_defun(pic, "newline", pic_port_newline); diff --git a/t/byteio.scm b/t/byteio.scm new file mode 100644 index 00000000..d47b0ae6 --- /dev/null +++ b/t/byteio.scm @@ -0,0 +1,29 @@ +(import (scheme base) + (scheme write) + (scheme file)) + + +(let ((string-port (open-input-string "hello"))) + (display "read-string: ") + (write (read-string 4 string-port)) + (newline) + (display "read-string more: ") + (write (read-string 4 string-port)) + (newline)) + +(let ((byte-port (open-input-bytevector (bytevector 1 2 3 4 5 6 7 8))) + (buf (make-bytevector 4 98))) + (display "read-u8: ") + (write (read-u8 byte-port)) + (newline) + (display "peek-u8: ") + (write (peek-u8 byte-port)) + (newline) + (display "read-bytevector: ") + (write (read-bytevector 4 byte-port)) + (newline) + (display "read-bytevector!: read size: ") + (write (read-bytevector! buf byte-port 1 3)) + (display " read content: ") + (write buf) + (newline)) From a73a92cfdb1c8f234759c8d056f2b7d3a2046161 Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Mon, 26 May 2014 04:08:39 +0900 Subject: [PATCH 02/41] make `read-bytevector(!)` efficint, export `u8-ready?`. --- src/port.c | 35 ++++++++++++++--------------------- t/byteio.scm | 7 ++++++- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/port.c b/src/port.c index 80fd98db..8c54cb01 100644 --- a/src/port.c +++ b/src/port.c @@ -511,21 +511,15 @@ static pic_value pic_port_read_blob(pic_state *pic){ struct pic_port *port = pic_stdin(pic); int k, i; - char c, *buf; + char *buf; pic_get_args(pic, "i|p", &k, &port); assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "read-bytevector"); buf = pic_calloc(pic, k, sizeof(char)); - for(i = 0; i < k; i++){ - c = xfgetc(port->file); - if( c == EOF ){ - break; - } - buf[i] = c; - } - if ( i == 0 && c == EOF) { + i = xfread(buf, sizeof(char), k, port->file); + if ( i == 0 ) { return pic_eof_object(); } else { @@ -538,8 +532,8 @@ static pic_value pic_port_read_blob_ip(pic_state *pic){ struct pic_port *port; struct pic_blob *bv; - int i, n, start, end; - char c; + int i, n, start, end, len; + char *buf; n = pic_get_args(pic, "b|pii", &bv, &port, &start, &end); switch (n) { @@ -552,19 +546,18 @@ pic_port_read_blob_ip(pic_state *pic){ } assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "read-bytevector!"); + len = end - start; - for(i = start; i < end; i++){ - c = xfgetc(port->file); - if( c == EOF ){ - break; - } - bv->data[i] = c; - } - if ( i == start && c == EOF) { + buf = pic_calloc(pic, len, sizeof(char)); + i = xfread(buf, sizeof(char), len, port->file); + memcpy(bv->data + start, buf, i); + pic_free(pic, buf); + + if ( i == 0) { return pic_eof_object(); } else { - return pic_int_value(i - start); + return pic_int_value(i); } } @@ -708,7 +701,7 @@ pic_init_port(pic_state *pic) pic_defun(pic, "read-string", pic_port_read_string); pic_defun(pic, "read-u8", pic_port_read_byte); pic_defun(pic, "peek-u8", pic_port_peek_byte); - /* pic_defun(pic, "u8-ready?", pic_port_byte_ready_p); */ + pic_defun(pic, "u8-ready?", pic_port_byte_ready_p); pic_defun(pic, "read-bytevector", pic_port_read_blob); pic_defun(pic, "read-bytevector!", pic_port_read_blob_ip); diff --git a/t/byteio.scm b/t/byteio.scm index d47b0ae6..e0770a27 100644 --- a/t/byteio.scm +++ b/t/byteio.scm @@ -24,6 +24,11 @@ (newline) (display "read-bytevector!: read size: ") (write (read-bytevector! buf byte-port 1 3)) - (display " read content: ") + (display ": read content: ") + (write buf) + (newline) + (display "read-bytevector!: read size: ") + (write (read-bytevector! buf byte-port)) + (display ": read content: ") (write buf) (newline)) From 0fea822ac09304e042f323c3f43f0e21007e079c Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Tue, 27 May 2014 13:24:59 +0900 Subject: [PATCH 03/41] allow `else` and `=>` keyword in `case` --- piclib/built-in.scm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index ddb175eb..e2648cd8 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -263,10 +263,14 @@ ,(let loop ((clauses clauses)) (if (null? clauses) #f - `(,(r 'if) (,(r 'or) - ,@(map (lambda (x) `(,(r 'eqv?) ,(r 'key) (,(r 'quote) ,x))) - (caar clauses))) - (begin ,@(cdar clauses)) + `(,(r 'if) ,(if (compare (r 'else) (caar clauses)) + '#t + `(,(r 'or) + ,@(map (lambda (x) `(,(r 'eqv?) ,(r 'key) (,(r 'quote) ,x))) + (caar clauses)))) + ,(if (compare (r '=>) (cadar clauses)) + `(,(r 'begin) ,@(cddar clauses)) + `(,(r 'begin) ,@(cdar clauses))) ,(loop (cdr clauses)))))))))) (define-syntax syntax-error From b9a783c23e26e2c128d8f5bb6b885fc886eb0dd0 Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Tue, 27 May 2014 17:49:51 +0900 Subject: [PATCH 04/41] if `=>` is specified, treat expression as a function --- piclib/built-in.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index e2648cd8..6210136f 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -269,7 +269,7 @@ ,@(map (lambda (x) `(,(r 'eqv?) ,(r 'key) (,(r 'quote) ,x))) (caar clauses)))) ,(if (compare (r '=>) (cadar clauses)) - `(,(r 'begin) ,@(cddar clauses)) + `(,(caddar clauses) ,(r 'key)) `(,(r 'begin) ,@(cdar clauses))) ,(loop (cdr clauses)))))))))) From cb3a975ed6b57cb0829b3b5a3aa8afcd523f0645 Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Tue, 27 May 2014 18:49:04 +0900 Subject: [PATCH 05/41] fix analyze errer for (+) and (*) --- src/codegen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/codegen.c b/src/codegen.c index 2d052739..5e091d07 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -561,7 +561,7 @@ analyze_add(analyze_state *state, pic_value obj, bool tailpos) ARGC_ASSERT_GE(0); switch (pic_length(pic, obj)) { case 1: - return pic_int_value(0); + return pic_list2(pic, pic_symbol_value(pic->sQUOTE), pic_int_value(0)); case 2: return analyze(state, pic_car(pic, pic_cdr(pic, obj)), tailpos); default: @@ -598,7 +598,7 @@ analyze_mul(analyze_state *state, pic_value obj, bool tailpos) ARGC_ASSERT_GE(0); switch (pic_length(pic, obj)) { case 1: - return pic_int_value(1); + return pic_list2(pic, pic_symbol_value(pic->sQUOTE), pic_int_value(1)); case 2: return analyze(state, pic_car(pic, pic_cdr(pic, obj)), tailpos); default: From 49e2148d38c2ecdc393912566339c8f8b13fe1e4 Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Thu, 29 May 2014 00:31:40 +0900 Subject: [PATCH 06/41] fix bug of `bytevector-append` --- piclib/built-in.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index ddb175eb..7a06bb08 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -798,7 +798,7 @@ (bytevector-copy! res 0 v) (bytevector-copy! res (bytevector-length v) w) res)) - (fold bytevector-append-2-inv #() vs)) + (fold bytevector-append-2-inv #u8() vs)) (define (bytevector->list v start end) (do ((i start (+ i 1)) From fc6a9199147b26be966de550f5377fc3eeaa2ec9 Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Thu, 29 May 2014 01:04:37 +0900 Subject: [PATCH 07/41] fix errer message of `u8-ready?` --- src/port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/port.c b/src/port.c index 8c54cb01..3daa3939 100644 --- a/src/port.c +++ b/src/port.c @@ -499,7 +499,7 @@ pic_port_byte_ready_p(pic_state *pic) { struct pic_port *port = pic_stdin(pic); - assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "char-ready?"); + assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "u8-ready?"); pic_get_args(pic, "|p", &port); From c8de0ad4cebed0e2ac8149ec42d5b2c2b9f323c7 Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Thu, 29 May 2014 01:10:59 +0900 Subject: [PATCH 08/41] fix misaligned assertion --- src/port.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/port.c b/src/port.c index 3daa3939..b9781264 100644 --- a/src/port.c +++ b/src/port.c @@ -499,10 +499,10 @@ pic_port_byte_ready_p(pic_state *pic) { struct pic_port *port = pic_stdin(pic); - assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "u8-ready?"); - pic_get_args(pic, "|p", &port); + assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "u8-ready?"); + return pic_true_value(); /* FIXME: always returns #t */ } From 15a77fb1723799f8dfedc9cefad44561883d4afc Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 29 May 2014 01:27:02 +0900 Subject: [PATCH 09/41] add @KeenS to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 3f32dcb2..eb796f59 100644 --- a/AUTHORS +++ b/AUTHORS @@ -4,3 +4,4 @@ Yuito Murase (themamedaifuku@gmail.com) Hiromu Yakura (hiromu1996@gmail.com) Wataru Nakanishi (stibear1996@gmail.com) Hiroki Kobayashi (silentkiddie-2013@yahoo.co.jp) +Sunrim Kim (3han5chou7@gmail.com) From 6ccfa7ad6968cfbe6beff0900ad52bef36b2a3ff Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Thu, 29 May 2014 03:58:04 +0900 Subject: [PATCH 10/41] some bug fixes --- piclib/built-in.scm | 4 ++-- src/port.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 3d2820d9..64e2ee10 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -733,7 +733,7 @@ (end (if (>= (length opts) 2) (cadr opts) (vector-length v)))) - (let ((res (make-vector (vector-length v)))) + (let ((res (make-vector (- end start)))) (vector-copy! res 0 v start end) res))) @@ -792,7 +792,7 @@ (end (if (>= (length opts) 2) (cadr opts) (bytevector-length v)))) - (let ((res (make-bytevector (bytevector-length v)))) + (let ((res (make-bytevector (- end start)))) (bytevector-copy! res 0 v start end) res))) diff --git a/src/port.c b/src/port.c index b9781264..419b8aee 100644 --- a/src/port.c +++ b/src/port.c @@ -467,12 +467,15 @@ pic_port_read_string(pic_state *pic){ static pic_value pic_port_read_byte(pic_state *pic){ struct pic_port *port = pic_stdin(pic); - + char c; pic_get_args(pic, "|p", &port); assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "read-u8"); + if ((c = xfgetc(port->file)) == EOF) { + return pic_eof_object(); + } - return pic_int_value((char) xfgetc(port->file)); + return pic_int_value(c); } static pic_value From 2f75715c846cc30e868eb96e0e4392c34807fc26 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 30 May 2014 10:34:44 +0900 Subject: [PATCH 11/41] fix #123. add another build option 'USE_C11_FEATURE' --- CMakeLists.txt | 10 +++++++++- README.md | 6 +++--- docs/intro.rst | 6 +++--- include/picrin/config.h | 6 +++++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41dbde5d..93012159 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,16 @@ execute_process( set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib) -set(CMAKE_C_FLAGS "-Wall -Wextra -std=c99") +set(CMAKE_C_FLAGS "-Wall -Wextra") set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG=1") + +option(USE_C11_FEATURE "Enable c11 feature" OFF) +if(USE_C11_FEATURE) + add_definitions(-std=c11) +else() + add_definitions(-std=c99) # at least c99 is required +endif() + include_directories(include extlib) # build picrin diff --git a/README.md b/README.md index 4152ea6b..f7cfe12b 100644 --- a/README.md +++ b/README.md @@ -35,12 +35,12 @@ There is a chat room on chat.freenode.org, channel #picrin. - make `Makefile` - Change directory to `build` then run `cmake` to create Makefile. Once `Makefile` is generated you can run `make` command to build picrin. + Change directory to `build` then run `ccmake` to create Makefile. Once `Makefile` is generated you can run `make` command to build picrin. $ cd build - $ cmake .. + $ ccmake .. - Actually you don't necessarily need to move to `build` directory before running `cmake` (in that case `$ cmake .`), but I strongly recommend to follow above instruction. + Actually you don't necessarily need to move to `build` directory before running `ccmake` (in that case `$ ccmake .`), but I strongly recommend to follow above instruction. - build diff --git a/docs/intro.rst b/docs/intro.rst index 06e75b88..e81632df 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -21,13 +21,13 @@ Installation - make `Makefile` -Change directory to `build` then run `cmake` to create Makefile. Once `Makefile` is generated you can run `make` command to build picrin:: +Change directory to `build` then run `ccmake` to create Makefile. Once `Makefile` is generated you can run `make` command to build picrin:: $ cd build - $ cmake .. + $ ccmake .. -Actually you don't necessarily need to move to `build` directory before running `cmake` (in that case `$ cmake .`), but I strongly recommend to follow above instruction. +Actually you don't necessarily need to move to `build` directory before running `ccmake` (in that case `$ ccmake .`), but I strongly recommend to follow above instruction. - build diff --git a/include/picrin/config.h b/include/picrin/config.h index 2d5fd2a2..2acfe0ea 100644 --- a/include/picrin/config.h +++ b/include/picrin/config.h @@ -45,6 +45,10 @@ /* #define GC_DEBUG 1 */ /* #define GC_DEBUG_DETAIL 1 */ +#if __STDC_VERSION__ < 199901L +# error please activate c99 features +#endif + #ifndef PIC_CONTRIB_INITS # define PIC_CONTRIB_INITS #endif @@ -56,7 +60,7 @@ #endif #ifndef PIC_NAN_BOXING -# if __x86_64__ +# if __x86_64__ && __STDC_VERSION__ >= 201112L # define PIC_NAN_BOXING 1 # endif #endif From bc94a35b625ca5464ed8523dab0231f7e592cb28 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 2 Jun 2014 08:26:29 +0900 Subject: [PATCH 12/41] add reference to botbot.me --- README.md | 2 +- docs/intro.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7cfe12b..30c7c21c 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ https://github.com/wasabiz/picrin ## IRC -There is a chat room on chat.freenode.org, channel #picrin. +There is a chat room on chat.freenode.org, channel #picrin. IRC logs here: https://botbot.me/freenode/picrin/ ## How to use it diff --git a/docs/intro.rst b/docs/intro.rst index e81632df..91b52e0a 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -80,7 +80,7 @@ https://github.com/wasabiz/picrin IRC --- -There is a chat room on chat.freenode.org, channel #picrin. +There is a chat room on chat.freenode.org, channel #picrin. IRC logs here: https://botbot.me/freenode/picrin/ LICENSE ------- From 81c314769541785afe080f24f06dd5b074c907b3 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 3 Jun 2014 23:30:00 +0900 Subject: [PATCH 13/41] move pic_import and pic_export to lib.c --- src/lib.c | 37 +++++++++++++++++++++++++++++++++++++ src/macro.c | 37 ------------------------------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/lib.c b/src/lib.c index 726f3a53..c33f694f 100644 --- a/src/lib.c +++ b/src/lib.c @@ -60,3 +60,40 @@ pic_find_library(pic_state *pic, pic_value spec) } return pic_lib_ptr(pic_cdr(pic, v)); } + +void +pic_import(pic_state *pic, pic_value spec) +{ + struct pic_lib *lib; + xh_iter it; + + lib = pic_find_library(pic, spec); + if (! lib) { + pic_errorf(pic, "library not found: ~a", spec); + } + xh_begin(&it, &lib->exports); + while (xh_next(&it)) { + +#if DEBUG + printf("* importing %s as %s\n", pic_symbol_name(pic, xh_key(it.e, pic_sym)), pic_symbol_name(pic, xh_val(it.e, pic_sym))); +#endif + + pic_put_rename(pic, pic->lib->senv, xh_key(it.e, pic_sym), xh_val(it.e, pic_sym)); + } +} + +void +pic_export(pic_state *pic, pic_sym sym) +{ + pic_sym rename; + + if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) { + pic_errorf(pic, "export: symbol not defined %s", pic_symbol_name(pic, sym)); + } + +#if DEBUG + printf("* exporting %s as %s\n", pic_symbol_name(pic, sym), pic_symbol_name(pic, rename)); +#endif + + xh_put(&pic->lib->exports, sym, &rename); +} diff --git a/src/macro.c b/src/macro.c index 2790efb0..bcea0909 100644 --- a/src/macro.c +++ b/src/macro.c @@ -71,43 +71,6 @@ pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *ren return true; } -void -pic_import(pic_state *pic, pic_value spec) -{ - struct pic_lib *lib; - xh_iter it; - - lib = pic_find_library(pic, spec); - if (! lib) { - pic_errorf(pic, "library not found: ~a", spec); - } - xh_begin(&it, &lib->exports); - while (xh_next(&it)) { - -#if DEBUG - printf("* importing %s as %s\n", pic_symbol_name(pic, xh_key(it.e, pic_sym)), pic_symbol_name(pic, xh_val(it.e, pic_sym))); -#endif - - pic_put_rename(pic, pic->lib->senv, xh_key(it.e, pic_sym), xh_val(it.e, pic_sym)); - } -} - -void -pic_export(pic_state *pic, pic_sym sym) -{ - pic_sym rename; - - if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) { - pic_errorf(pic, "export: symbol not defined %s", pic_symbol_name(pic, sym)); - } - -#if DEBUG - printf("* exporting %s as %s\n", pic_symbol_name(pic, sym), pic_symbol_name(pic, rename)); -#endif - - xh_put(&pic->lib->exports, sym, &rename); -} - static void define_macro(pic_state *pic, pic_sym rename, struct pic_proc *proc, struct pic_senv *senv) { From 53f76b7a474dab06648f6bbf5e063e52ae137dc2 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 3 Jun 2014 23:54:51 +0900 Subject: [PATCH 14/41] support renaming export --- src/lib.c | 16 ++++++++++++++++ src/macro.c | 24 ++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/lib.c b/src/lib.c index c33f694f..0cdcff73 100644 --- a/src/lib.c +++ b/src/lib.c @@ -97,3 +97,19 @@ pic_export(pic_state *pic, pic_sym sym) xh_put(&pic->lib->exports, sym, &rename); } + +void +pic_export_as(pic_state *pic, pic_sym sym, pic_sym as) +{ + pic_sym rename; + + if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) { + pic_errorf(pic, "export: symbol not defined %s", pic_symbol_name(pic, sym)); + } + +#if DEBUG + printf("* exporting %s as %s\n", pic_symbol_name(pic, as), pic_symbol_name(pic, rename)); +#endif + + xh_put(&pic->lib->exports, as, &rename); +} diff --git a/src/macro.c b/src/macro.c index bcea0909..59e53c0c 100644 --- a/src/macro.c +++ b/src/macro.c @@ -267,14 +267,34 @@ macroexpand_import(pic_state *pic, pic_value expr) static pic_value macroexpand_export(pic_state *pic, pic_value expr) { + extern pic_value pic_export_as(pic_state *, pic_sym, pic_sym); pic_value spec; + pic_sym sRENAME, sym, as; + + sRENAME = pic_intern_cstr(pic, "rename"); pic_for_each (spec, pic_cdr(pic, expr)) { - if (! pic_sym_p(spec)) { + if (pic_sym_p(spec)) { + sym = as = pic_sym(spec); + } + else if (pic_list_p(spec) && pic_eq_p(pic_car(pic, spec), pic_sym_value(sRENAME))) { + if (pic_length(pic, spec) != 3) { + pic_error(pic, "syntax error"); + } + if (! pic_sym_p(pic_list_ref(pic, spec, 1))) { + pic_error(pic, "syntax error"); + } + sym = pic_sym(pic_list_ref(pic, spec, 1)); + if (! pic_sym_p(pic_list_ref(pic, spec, 2))) { + pic_error(pic, "syntax error"); + } + as = pic_sym(pic_list_ref(pic, spec, 2)); + } + else { pic_error(pic, "syntax error"); } /* TODO: warn if symbol is shadowed by local variable */ - pic_export(pic, pic_sym(spec)); + pic_export_as(pic, sym, as); } return pic_none_value(); From d5dfd9547fe5d48a503e5f2e960df88e5179d843 Mon Sep 17 00:00:00 2001 From: OGINO Masanori Date: Thu, 5 Jun 2014 22:08:07 +0900 Subject: [PATCH 15/41] Match the case of package name for find_package. This mismatch causes build failure on Linux. Signed-off-by: OGINO Masanori --- tools/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 54276bde..ad7824be 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,6 +1,6 @@ list(APPEND REPL_LIBRARIES picrin) -find_package(LIBEDIT) +find_package(Libedit) if (Libedit_FOUND) include_directories(${Libedit_INCLUDE_DIRS}) add_definitions(${Libedit_DEFINITIONS} -DPIC_READLINE_FOUND=1) From 6b171f27160aabe7eecfa592c8822f9a5589f28b Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Sat, 7 Jun 2014 02:20:29 +0900 Subject: [PATCH 16/41] silence warning from gc.c --- src/gc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gc.c b/src/gc.c index 2821be35..a2dc677e 100644 --- a/src/gc.c +++ b/src/gc.c @@ -533,8 +533,7 @@ gc_mark_phase(pic_state *pic) { pic_value *stack; pic_callinfo *ci; - size_t i; - int j; + size_t i, j; xh_iter it; /* block */ From 8d34da029591a285533bb37c367bc197263fa7dc Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Tue, 10 Jun 2014 21:50:14 +0900 Subject: [PATCH 17/41] correct error message --- src/number.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/number.c b/src/number.c index fb9a4c1f..593c130a 100644 --- a/src/number.c +++ b/src/number.c @@ -224,7 +224,7 @@ pic_number_max(pic_state *pic) f = fmax(f, pic_float(argv[i])); } else { - pic_error(pic, "min: number required"); + pic_error(pic, "max: number required"); } } From 77cb18bfd4e1b6823b62abb06f15f3727fa855c9 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 14 Jun 2014 16:08:12 +0900 Subject: [PATCH 18/41] add commentary on pic_get_args --- src/vm.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/vm.c b/src/vm.c index 6c89d8a8..1d79a89e 100644 --- a/src/vm.c +++ b/src/vm.c @@ -33,6 +33,27 @@ pic_get_proc(pic_state *pic) return pic_proc_ptr(v); } +/** + * char type + * ---- ---- + * o object + * i int + * I int with exactness + * f float + * F float with exactness + * s string object + * z c string + * m symbol + * v vector object + * b bytevector object + * c char + * l lambda object + * p port object + * + * | optional operator + * * variable length operator + */ + int pic_get_args(pic_state *pic, const char *format, ...) { From f9e733a7b168907804fafd46d5a35bd55402ba3a Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 14 Jun 2014 20:59:31 +0900 Subject: [PATCH 19/41] update xhash --- extlib/xhash | 2 +- src/codegen.c | 10 +++++----- src/lib.c | 4 ++-- src/macro.c | 8 ++++---- src/read.c | 8 ++++---- src/symbol.c | 6 +++--- src/vm.c | 4 ++-- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/extlib/xhash b/extlib/xhash index 985d9af6..47a31fdb 160000 --- a/extlib/xhash +++ b/extlib/xhash @@ -1 +1 @@ -Subproject commit 985d9af6188a1426788e56db03025847c32e519b +Subproject commit 47a31fdbf88ea61f060b7cb45203b3a2f0149e9f diff --git a/src/codegen.c b/src/codegen.c index 5e091d07..1940ea8f 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -294,7 +294,7 @@ analyze_global_var(analyze_state *state, pic_sym sym) xh_entry *e; size_t i; - if ((e = xh_get(&pic->global_tbl, sym))) { + if ((e = xh_get_int(&pic->global_tbl, sym))) { i = xh_val(e, size_t); } else { @@ -302,7 +302,7 @@ analyze_global_var(analyze_state *state, pic_sym sym) if (i >= pic->gcapa) { pic_error(pic, "global table overflow"); } - xh_put(&pic->global_tbl, sym, &i); + xh_put_int(&pic->global_tbl, sym, &i); } return pic_list2(pic, pic_symbol_value(state->sGREF), pic_int_value(i)); } @@ -929,18 +929,18 @@ create_activation(codegen_context *cxt) for (i = 0; i < cxt->args.size; ++i) { var = xv_get(&cxt->args, i); n = i + offset; - xh_put(®s, *var, &n); + xh_put_int(®s, *var, &n); } offset += i; for (i = 0; i < cxt->locals.size; ++i) { var = xv_get(&cxt->locals, i); n = i + offset; - xh_put(®s, *var, &n); + xh_put_int(®s, *var, &n); } for (i = 0; i < cxt->captures.size; ++i) { var = xv_get(&cxt->captures, i); - if ((n = xh_val(xh_get(®s, *var), size_t)) <= cxt->args.size || (cxt->varg && n == cxt->args.size + 1)) { + if ((n = xh_val(xh_get_int(®s, *var), size_t)) <= cxt->args.size || (cxt->varg && n == cxt->args.size + 1)) { /* copy arguments to capture variable area */ cxt->code[cxt->clen].insn = OP_LREF; cxt->code[cxt->clen].u.i = n; diff --git a/src/lib.c b/src/lib.c index 0cdcff73..b12e8c9b 100644 --- a/src/lib.c +++ b/src/lib.c @@ -95,7 +95,7 @@ pic_export(pic_state *pic, pic_sym sym) printf("* exporting %s as %s\n", pic_symbol_name(pic, sym), pic_symbol_name(pic, rename)); #endif - xh_put(&pic->lib->exports, sym, &rename); + xh_put_int(&pic->lib->exports, sym, &rename); } void @@ -111,5 +111,5 @@ pic_export_as(pic_state *pic, pic_sym sym, pic_sym as) printf("* exporting %s as %s\n", pic_symbol_name(pic, as), pic_symbol_name(pic, rename)); #endif - xh_put(&pic->lib->exports, as, &rename); + xh_put_int(&pic->lib->exports, as, &rename); } diff --git a/src/macro.c b/src/macro.c index 59e53c0c..12752cec 100644 --- a/src/macro.c +++ b/src/macro.c @@ -52,7 +52,7 @@ pic_put_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym renam { UNUSED(pic); - xh_put(&senv->renames, sym, &rename); + xh_put_int(&senv->renames, sym, &rename); } bool @@ -62,7 +62,7 @@ pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *ren UNUSED(pic); - if ((e = xh_get(&senv->renames, sym)) == NULL) { + if ((e = xh_get_int(&senv->renames, sym)) == NULL) { return false; } if (rename != NULL) { @@ -80,7 +80,7 @@ define_macro(pic_state *pic, pic_sym rename, struct pic_proc *proc, struct pic_s mac->senv = senv; mac->proc = proc; - xh_put(&pic->macros, rename, &mac); + xh_put_int(&pic->macros, rename, &mac); } static struct pic_macro * @@ -88,7 +88,7 @@ find_macro(pic_state *pic, pic_sym rename) { xh_entry *e; - if ((e = xh_get(&pic->macros, rename)) == NULL) { + if ((e = xh_get_int(&pic->macros, rename)) == NULL) { return NULL; } return xh_val(e, struct pic_macro *); diff --git a/src/read.c b/src/read.c index 030ee0e3..6f1d39ba 100644 --- a/src/read.c +++ b/src/read.c @@ -53,7 +53,7 @@ read_label_set(int i, yyscan_t scanner) val = pic_cons(pic, pic_none_value(), pic_none_value()); - xh_put(&yylabels, i, &val); + xh_put_int(&yylabels, i, &val); tmp = read(tok, scanner); pic_pair_ptr(val)->car = pic_car(pic, tmp); @@ -67,7 +67,7 @@ read_label_set(int i, yyscan_t scanner) val = pic_obj_value(pic_vec_new(pic, 0)); - xh_put(&yylabels, i, &val); + xh_put_int(&yylabels, i, &val); tmp = pic_vec_ptr(read(tok, scanner)); SWAP(pic_value *, tmp->data, pic_vec_ptr(val)->data); @@ -79,7 +79,7 @@ read_label_set(int i, yyscan_t scanner) { val = read(tok, scanner); - xh_put(&yylabels, i, &val); + xh_put_int(&yylabels, i, &val); return val; } @@ -91,7 +91,7 @@ read_label_ref(int i, yyscan_t scanner) { xh_entry *e; - e = xh_get(&yylabels, i); + e = xh_get_int(&yylabels, i); if (! e) { error("label of given index not defined", scanner); } diff --git a/src/symbol.c b/src/symbol.c index aa57d655..863e41f3 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -27,7 +27,7 @@ pic_intern(pic_state *pic, const char *str, size_t len) id = pic->sym_cnt++; xh_put(&pic->syms, cstr, &id); - xh_put(&pic->sym_names, id, &cstr); + xh_put_int(&pic->sym_names, id, &cstr); return id; } @@ -50,7 +50,7 @@ pic_gensym(pic_state *pic, pic_sym base) /* don't put the symbol to pic->syms to keep it uninterned */ uniq = pic->sym_cnt++; - xh_put(&pic->sym_names, uniq, &str); + xh_put_int(&pic->sym_names, uniq, &str); return uniq; } @@ -64,7 +64,7 @@ pic_interned_p(pic_state *pic, pic_sym sym) const char * pic_symbol_name(pic_state *pic, pic_sym sym) { - return xh_val(xh_get(&pic->sym_names, sym), const char *); + return xh_val(xh_get_int(&pic->sym_names, sym), const char *); } static pic_value diff --git a/src/vm.c b/src/vm.c index 1d79a89e..8709b574 100644 --- a/src/vm.c +++ b/src/vm.c @@ -360,7 +360,7 @@ global_ref(pic_state *pic, const char *name) if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) { return SIZE_MAX; } - if (! (e = xh_get(&pic->global_tbl, rename))) { + if (! (e = xh_get_int(&pic->global_tbl, rename))) { return SIZE_MAX; } return xh_val(e, size_t); @@ -386,7 +386,7 @@ global_def(pic_state *pic, const char *name) if (pic->glen >= pic->gcapa) { pic_error(pic, "global table overflow"); } - xh_put(&pic->global_tbl, rename, &gidx); + xh_put_int(&pic->global_tbl, rename, &gidx); return gidx; } From da553b900132b5dc89d2af325a53d3f2c55c5f41 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 14 Jun 2014 22:10:25 +0900 Subject: [PATCH 20/41] primary symbol to object hashtable support (dictionary) --- extlib/xhash | 2 +- include/picrin/dict.h | 24 ++++++++++++ include/picrin/value.h | 8 +++- src/codegen.c | 1 + src/dict.c | 85 ++++++++++++++++++++++++++++++++++++++++++ src/gc.c | 16 ++++++++ src/init.c | 2 + src/macro.c | 1 + src/vm.c | 19 ++++++++++ src/write.c | 3 ++ 10 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 include/picrin/dict.h create mode 100644 src/dict.c diff --git a/extlib/xhash b/extlib/xhash index 47a31fdb..ddc2ea28 160000 --- a/extlib/xhash +++ b/extlib/xhash @@ -1 +1 @@ -Subproject commit 47a31fdbf88ea61f060b7cb45203b3a2f0149e9f +Subproject commit ddc2ea288b37b3f5de37024ff2648d11aa18811a diff --git a/include/picrin/dict.h b/include/picrin/dict.h new file mode 100644 index 00000000..bb720534 --- /dev/null +++ b/include/picrin/dict.h @@ -0,0 +1,24 @@ +/** + * See Copyright Notice in picrin.h + */ + +#ifndef PICRIN_DICT_H__ +#define PICRIN_DICT_H__ + +#if defined(__cplusplus) +extern "C" { +#endif + +struct pic_dict { + PIC_OBJECT_HEADER + xhash hash; +}; + +#define pic_dict_p(v) (pic_type(v) == PIC_TT_DICT) +#define pic_dict_ptr(v) ((struct pic_dict *)pic_ptr(v)) + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/include/picrin/value.h b/include/picrin/value.h index 600140b7..44dd0763 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -116,7 +116,8 @@ enum pic_tt { PIC_TT_VAR, PIC_TT_IREP, PIC_TT_DATA, - PIC_TT_BOX + PIC_TT_BOX, + PIC_TT_DICT }; #define PIC_OBJECT_HEADER \ @@ -146,7 +147,8 @@ typedef struct pic_blob pic_blob; #define pic_sym(v) ((v).u.sym) #define pic_char(v) ((v).u.c) -#define pic_obj_ptr(o) ((struct pic_object *)pic_ptr(o)) +#define pic_obj_p(v) (pic_vtype(v) == PIC_VTYPE_HEAP) +#define pic_obj_ptr(v) ((struct pic_object *)pic_ptr(v)) #define pic_nil_p(v) (pic_vtype(v) == PIC_VTYPE_NIL) #define pic_true_p(v) (pic_vtype(v) == PIC_VTYPE_TRUE) @@ -269,6 +271,8 @@ pic_type_repr(enum pic_tt tt) return "data"; case PIC_TT_BOX: return "box"; + case PIC_TT_DICT: + return "dict"; } UNREACHABLE(); } diff --git a/src/codegen.c b/src/codegen.c index 1940ea8f..63abd247 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -825,6 +825,7 @@ analyze_node(analyze_state *state, pic_value obj, bool tailpos) case PIC_TT_IREP: case PIC_TT_DATA: case PIC_TT_BOX: + case PIC_TT_DICT: pic_errorf(pic, "invalid expression given: ~s", obj); } UNREACHABLE(); diff --git a/src/dict.c b/src/dict.c new file mode 100644 index 00000000..d23204eb --- /dev/null +++ b/src/dict.c @@ -0,0 +1,85 @@ +/** + * See Copyright Notice in picrin.h + */ + +#include "picrin.h" +#include "picrin/dict.h" + +static pic_value +pic_dict_dict(pic_state *pic) +{ + struct pic_dict *dict; + + pic_get_args(pic, ""); + + dict = (struct pic_dict *)pic_obj_alloc(pic, sizeof(struct pic_dict), PIC_TT_DICT); + + xh_init_int(&dict->hash, sizeof(pic_value)); + + return pic_obj_value(dict); +} + +static pic_value +pic_dict_dict_p(pic_state *pic) +{ + pic_value obj; + + pic_get_args(pic, "o", &obj); + + return pic_bool_value(pic_dict_p(obj)); +} + +static pic_value +pic_dict_dict_ref(pic_state *pic) +{ + struct pic_dict *dict; + pic_sym key; + xh_entry *e; + + pic_get_args(pic, "dm", &dict, &key); + + e = xh_get_int(&dict->hash, key); + if (! e) { + return pic_none_value(); + } + return xh_val(e, pic_value); +} + +static pic_value +pic_dict_dict_set(pic_state *pic) +{ + struct pic_dict *dict; + pic_sym key; + pic_value val; + + pic_get_args(pic, "dmo", &dict, &key, &val); + + xh_put_int(&dict->hash, key, &val); + + return pic_none_value(); +} + +static pic_value +pic_dict_dict_del(pic_state *pic) +{ + struct pic_dict *dict; + pic_sym key; + + pic_get_args(pic, "dm", &dict, &key); + + xh_del_int(&dict->hash, key); + + return pic_none_value(); +} + +void +pic_init_dict(pic_state *pic) +{ + pic_deflibrary ("(picrin dictionary)") { + pic_defun(pic, "dictionary", pic_dict_dict); + pic_defun(pic, "dictionary?", pic_dict_dict_p); + pic_defun(pic, "dictionary-ref", pic_dict_dict_ref); + pic_defun(pic, "dictionary-set!", pic_dict_dict_set); + pic_defun(pic, "dictionary-delete", pic_dict_dict_del); + } +} diff --git a/src/gc.c b/src/gc.c index a2dc677e..efbd98f5 100644 --- a/src/gc.c +++ b/src/gc.c @@ -20,6 +20,7 @@ #include "picrin/var.h" #include "picrin/data.h" #include "picrin/box.h" +#include "picrin/dict.h" #if GC_DEBUG # include @@ -504,6 +505,16 @@ gc_mark_object(pic_state *pic, struct pic_object *obj) gc_mark(pic, box->value); break; } + case PIC_TT_DICT: { + struct pic_dict *dict = (struct pic_dict *)obj; + xh_iter it; + + xh_begin(&it, &dict->hash); + while (xh_next(&it)) { + gc_mark(pic, xh_val(it.e, pic_value)); + } + break; + } case PIC_TT_NIL: case PIC_TT_BOOL: case PIC_TT_FLOAT: @@ -657,6 +668,11 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj) case PIC_TT_BOX: { break; } + case PIC_TT_DICT: { + struct pic_dict *dict = (struct pic_dict *)obj; + xh_destroy(&dict->hash); + break; + } case PIC_TT_NIL: case PIC_TT_BOOL: case PIC_TT_FLOAT: diff --git a/src/init.c b/src/init.c index 26050194..91e55daa 100644 --- a/src/init.c +++ b/src/init.c @@ -29,6 +29,7 @@ void pic_init_macro(pic_state *); void pic_init_var(pic_state *); void pic_init_load(pic_state *); void pic_init_write(pic_state *); +void pic_init_dict(pic_state *); void pic_load_piclib(pic_state *); @@ -93,6 +94,7 @@ pic_init_core(pic_state *pic) pic_init_var(pic); DONE; pic_init_load(pic); DONE; pic_init_write(pic); DONE; + pic_init_dict(pic); DONE; pic_load_piclib(pic); DONE; diff --git a/src/macro.c b/src/macro.c index 12752cec..7783c0e4 100644 --- a/src/macro.c +++ b/src/macro.c @@ -569,6 +569,7 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv, pic_valu case PIC_TT_IREP: case PIC_TT_DATA: case PIC_TT_BOX: + case PIC_TT_DICT: pic_errorf(pic, "unexpected value type: ~s", expr); } UNREACHABLE(); diff --git a/src/vm.c b/src/vm.c index 8709b574..c2d0b1e0 100644 --- a/src/vm.c +++ b/src/vm.c @@ -19,6 +19,7 @@ #include "picrin/lib.h" #include "picrin/macro.h" #include "picrin/error.h" +#include "picrin/dict.h" #define GET_OPERAND(pic,n) ((pic)->ci->fp[(n)]) @@ -49,6 +50,7 @@ pic_get_proc(pic_state *pic) * c char * l lambda object * p port object + * d dictionary object * * | optional operator * * variable length operator @@ -327,6 +329,23 @@ pic_get_args(pic_state *pic, const char *format, ...) } break; } + case 'd': { + struct pic_dict **d; + pic_value v; + + d = va_arg(ap, struct pic_dict **); + if (i < argc) { + v = GET_OPERAND(pic,i); + if (pic_dict_p(v)) { + *d = pic_dict_ptr(v); + } + else { + pic_error(pic, "pic_get_args, expected dictionary"); + } + i++; + } + break; + } default: pic_error(pic, "pic_get_args: invalid argument specifier given"); } diff --git a/src/write.c b/src/write.c index 2eb3575e..952bf436 100644 --- a/src/write.c +++ b/src/write.c @@ -338,6 +338,9 @@ write_core(struct writer_control *p, pic_value obj) case PIC_TT_BOX: xfprintf(file, "#", pic_ptr(obj)); break; + case PIC_TT_DICT: + xfprintf(file, "#", pic_ptr(obj)); + break; } } From a8a56aa34ebe012b48230429f4e0cbb27586d553 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 00:36:38 +0900 Subject: [PATCH 21/41] add dictionary-size --- src/dict.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dict.c b/src/dict.c index d23204eb..7ad254ec 100644 --- a/src/dict.c +++ b/src/dict.c @@ -40,7 +40,7 @@ pic_dict_dict_ref(pic_state *pic) e = xh_get_int(&dict->hash, key); if (! e) { - return pic_none_value(); + pic_errorf(pic, "element not found for a key: ~s", pic_sym_value(key)); } return xh_val(e, pic_value); } @@ -72,6 +72,16 @@ pic_dict_dict_del(pic_state *pic) return pic_none_value(); } +static pic_value +pic_dict_dict_size(pic_state *pic) +{ + struct pic_dict *dict; + + pic_get_args(pic, "d", &dict); + + return pic_int_value(dict->hash.count); +} + void pic_init_dict(pic_state *pic) { @@ -81,5 +91,6 @@ pic_init_dict(pic_state *pic) pic_defun(pic, "dictionary-ref", pic_dict_dict_ref); pic_defun(pic, "dictionary-set!", pic_dict_dict_set); pic_defun(pic, "dictionary-delete", pic_dict_dict_del); + pic_defun(pic, "dictionary-size", pic_dict_dict_size); } } From 037967fd58dc1e7efe3f1635e2df387a836022b8 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 01:46:31 +0900 Subject: [PATCH 22/41] dictionary-delete raises an error when no binding with given name is registered --- src/dict.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/dict.c b/src/dict.c index 7ad254ec..ddbe2cb5 100644 --- a/src/dict.c +++ b/src/dict.c @@ -67,6 +67,10 @@ pic_dict_dict_del(pic_state *pic) pic_get_args(pic, "dm", &dict, &key); + if (xh_get_int(&dict->hash, key) == NULL) { + pic_errorf(pic, "no slot named ~s found in dictionary", pic_sym_value(key)); + } + xh_del_int(&dict->hash, key); return pic_none_value(); From 0d30b293fc01f1449216b2bdee9b0b3c84148bba Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 01:48:28 +0900 Subject: [PATCH 23/41] add dictionary documentation --- docs/lang.rst | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/lang.rst b/docs/lang.rst index 9d6c6786..220addb2 100644 --- a/docs/lang.rst +++ b/docs/lang.rst @@ -55,6 +55,37 @@ Libraries Delimited control operators. +- ``(picrin dictionary)`` + + Symbol to Object table. Internally it is implemented on hash-table. + + Note that dictionary is not a weak map; if you are going to make a highly memory-consuming program with dictionaries, you should know that dictionaries keep their bound objects and never let them free until you explicitly deletes bindings. + + - ``(dictionary)`` + + Returns a newly allocated empty dictionary. In the future, it is planned to extend this function to take optional arguments for initial key/values. + + - ``(dictionary? obj)`` + + Returns ``#t`` if obj is a dictionary. + + - ``(dictionary-ref dict key)`` + + Look up dictionary dict for a value associated with symbol key. If no object is associated with key, it will raise an error. + + - ``(dictionary-set! dict key obj)`` + + If there is no value already associated with key, this function newly creates a binding of key with obj. Otherwise, updates the existing binding with given obj. + + - ``(dictionary-delete dict key)`` + + Deletes the binding associated with key from dict. If no binding on dict is associated with key, an error will be raised. + + + - ``(dictionary-size dict)`` + + Returns the number of registered elements in dict. + - ``(picrin user)`` When you start the REPL, you are dropped into here. From 94e2bc295ba13b9927aeb00508ac1517d0094e56 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 02:27:01 +0900 Subject: [PATCH 24/41] add libs.rst --- docs/index.rst | 1 + docs/lang.rst | 101 +----------------------------------------- docs/libs.rst | 116 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 100 deletions(-) create mode 100644 docs/libs.rst diff --git a/docs/index.rst b/docs/index.rst index a0b96729..d1401fa6 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -13,6 +13,7 @@ Contents: intro.rst lang.rst + libs.rst Indices and tables ================== diff --git a/docs/lang.rst b/docs/lang.rst index 220addb2..ec149d98 100644 --- a/docs/lang.rst +++ b/docs/lang.rst @@ -1,106 +1,7 @@ Language ======== -The language provided by picrin. - -Libraries ---------- - -- ``(scheme base)`` -- ``(scheme write)`` -- ``(scheme cxr)`` -- ``(scheme file)`` -- ``(scheme inexact)`` -- ``(scheme time)`` -- ``(scheme process-context)`` -- ``(scheme load)`` -- ``(scheme lazy)`` -- ``(picrin macro)`` - - - ``define-macro`` - - ``gensym`` - - ``macroexpand`` - - Old-fashioned macro. - - - ``make-syntactic-closure`` - - ``identifier?`` - - ``identifier=?`` - - Syntactic closures. - - - ``er-macro-transformer`` - - ``ir-macro-transformer`` - - Explicit renaming macro family. - -- ``(picrin regexp)`` - - - ``(regexp? obj)`` - - ``(regexp ptrn [flags])`` - - Compiles pattern string into a regexp object. A string ``flags`` may contain any of #\g, #\i, #\m. - - - ``(regexp-match re input)`` - - Returns two values: a list of match strings, and a list of match indeces. - - - ``(regexp-replace re input txt)`` - - ``(regexp-split re input)`` - -- ``(picrin control)`` - - - ``(reset h)`` - - ``(shift k)`` - - Delimited control operators. - -- ``(picrin dictionary)`` - - Symbol to Object table. Internally it is implemented on hash-table. - - Note that dictionary is not a weak map; if you are going to make a highly memory-consuming program with dictionaries, you should know that dictionaries keep their bound objects and never let them free until you explicitly deletes bindings. - - - ``(dictionary)`` - - Returns a newly allocated empty dictionary. In the future, it is planned to extend this function to take optional arguments for initial key/values. - - - ``(dictionary? obj)`` - - Returns ``#t`` if obj is a dictionary. - - - ``(dictionary-ref dict key)`` - - Look up dictionary dict for a value associated with symbol key. If no object is associated with key, it will raise an error. - - - ``(dictionary-set! dict key obj)`` - - If there is no value already associated with key, this function newly creates a binding of key with obj. Otherwise, updates the existing binding with given obj. - - - ``(dictionary-delete dict key)`` - - Deletes the binding associated with key from dict. If no binding on dict is associated with key, an error will be raised. - - - - ``(dictionary-size dict)`` - - Returns the number of registered elements in dict. - -- ``(picrin user)`` - - When you start the REPL, you are dropped into here. - -- ``(srfi 1)`` - - List manipulation library. - -- ``(srfi 26)`` - - Cut/cute macros. - -- ``(srfi 95)`` - - Sorting and Marging. +Picrin's core language is the R7RS scheme with some powerful extensions. Please visit http://r7rs.org/ for the information of R7RS's design and underlying thoughts. The REPL -------- diff --git a/docs/libs.rst b/docs/libs.rst new file mode 100644 index 00000000..79457e17 --- /dev/null +++ b/docs/libs.rst @@ -0,0 +1,116 @@ +Libraries +========= + +Picrin's all built-in libraries are described below. + +Scheme standard libraries +------------------------- + +- (scheme write) +- (scheme cxr) +- (scheme file) +- (scheme inexact) +- (scheme time) +- (scheme process-context) +- (scheme load) +- (scheme lazy) + +SRFI libraries +-------------- + +- (srfi 1) + + List manipulation library. + +- (srfi 26) + + Cut/cute macros. + +- (srfi 95) + + Sorting and Marging. + + +Macros +------ + +(picrin macro) +^^^^^^^^^^^^^^ + +- define-macro +- gensym +- macroexpand + +Old-fashioned macro. + +- make-syntactic-closure +- identifier? +- identifier=? + +Syntactic closures. + +- er-macro-transformer +- ir-macro-transformer + +Explicit renaming macro family. + +(picrin regexp) +^^^^^^^^^^^^^^^ + +- (regexp? obj) +- (regexp ptrn [flags]) + +Compiles pattern string into a regexp object. A string flags may contain any of #\g, #\i, #\m. + +- (regexp-match re input) + +Returns two values: a list of match strings, and a list of match indeces. + +- (regexp-replace re input txt) +- (regexp-split re input) + +(picrin control) +^^^^^^^^^^^^^^^^ + +- (reset h) +- (shift k) + +Delimited control operators. + +(picrin dictionary) +^^^^^^^^^^^^^^^^^^^ + +Symbol to Object table. Internally it is implemented on hash-table. + +Note that dictionary is not a weak map; if you are going to make a highly memory-consuming program with dictionaries, you should know that dictionaries keep their bound objects and never let them free until you explicitly deletes bindings. + +- (dictionary) + + Returns a newly allocated empty dictionary. In the future, it is planned to extend this function to take optional arguments for initial key/values. + +- (dictionary? obj) + + Returns #t if obj is a dictionary. + +- (dictionary-ref dict key) + + Look up dictionary dict for a value associated with symbol key. If no object is associated with key, it will raise an error. + +- (dictionary-set! dict key obj) + + If there is no value already associated with key, this function newly creates a binding of key with obj. Otherwise, updates the existing binding with given obj. + +- (dictionary-delete dict key) + + Deletes the binding associated with key from dict. If no binding on dict is associated with key, an error will be raised. + + +- (dictionary-size dict) + + Returns the number of registered elements in dict. + +(picrin user) +^^^^^^^^^^^^^ + +When you start the REPL, you are dropped into here. + From 96521cfdf960d37a7468bbae26c427005c08b392 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 02:36:11 +0900 Subject: [PATCH 25/41] experimentally changed document nest lavel --- docs/libs.rst | 62 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/docs/libs.rst b/docs/libs.rst index 79457e17..e2a7dba0 100644 --- a/docs/libs.rst +++ b/docs/libs.rst @@ -30,12 +30,10 @@ SRFI libraries Sorting and Marging. - -Macros ------- - (picrin macro) -^^^^^^^^^^^^^^ +-------------- + +Utility functions and syntaces for macro definition. - define-macro - gensym @@ -55,62 +53,80 @@ Syntactic closures. Explicit renaming macro family. (picrin regexp) -^^^^^^^^^^^^^^^ +--------------- -- (regexp? obj) -- (regexp ptrn [flags]) +(regexp ptrn [flags]) +^^^^^^^^^^^^^^^^^^^^^ Compiles pattern string into a regexp object. A string flags may contain any of #\g, #\i, #\m. -- (regexp-match re input) +(regexp? obj) +^^^^^^^^^^^^^ + +Judges if obj is a regexp object or not. + +(regexp-match re input) +^^^^^^^^^^^^^^^^^^^^^^^ Returns two values: a list of match strings, and a list of match indeces. -- (regexp-replace re input txt) -- (regexp-split re input) +(regexp-replace re input txt) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +(regexp-split re input) +^^^^^^^^^^^^^^^^^^^^^^^ (picrin control) -^^^^^^^^^^^^^^^^ - -- (reset h) -- (shift k) +---------------- Delimited control operators. +(reset h) +^^^^^^^^^ + +(shift k) +^^^^^^^^^ + (picrin dictionary) -^^^^^^^^^^^^^^^^^^^ +------------------- Symbol to Object table. Internally it is implemented on hash-table. Note that dictionary is not a weak map; if you are going to make a highly memory-consuming program with dictionaries, you should know that dictionaries keep their bound objects and never let them free until you explicitly deletes bindings. -- (dictionary) +(dictionary) +^^^^^^^^^^^^ Returns a newly allocated empty dictionary. In the future, it is planned to extend this function to take optional arguments for initial key/values. -- (dictionary? obj) +(dictionary? obj) +^^^^^^^^^^^^^^^^^ Returns #t if obj is a dictionary. -- (dictionary-ref dict key) +(dictionary-ref dict key) +^^^^^^^^^^^^^^^^^^^^^^^^^ Look up dictionary dict for a value associated with symbol key. If no object is associated with key, it will raise an error. -- (dictionary-set! dict key obj) +(dictionary-set! dict key obj) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ If there is no value already associated with key, this function newly creates a binding of key with obj. Otherwise, updates the existing binding with given obj. -- (dictionary-delete dict key) +(dictionary-delete dict key) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Deletes the binding associated with key from dict. If no binding on dict is associated with key, an error will be raised. -- (dictionary-size dict) +(dictionary-size dict) +^^^^^^^^^^^^^^^^^^^^^^ Returns the number of registered elements in dict. (picrin user) -^^^^^^^^^^^^^ +------------- When you start the REPL, you are dropped into here. From e150916a0fbb2212672c896dfe9f9ce84300fac8 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 02:41:18 +0900 Subject: [PATCH 26/41] use topic directive instead --- docs/libs.rst | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/docs/libs.rst b/docs/libs.rst index e2a7dba0..ebec4f88 100644 --- a/docs/libs.rst +++ b/docs/libs.rst @@ -55,26 +55,21 @@ Explicit renaming macro family. (picrin regexp) --------------- -(regexp ptrn [flags]) -^^^^^^^^^^^^^^^^^^^^^ +.. topic:: (regexp ptrn [flags]) Compiles pattern string into a regexp object. A string flags may contain any of #\g, #\i, #\m. -(regexp? obj) -^^^^^^^^^^^^^ +.. topic:: (regexp? obj) Judges if obj is a regexp object or not. -(regexp-match re input) -^^^^^^^^^^^^^^^^^^^^^^^ +.. topic:: (regexp-match re input) Returns two values: a list of match strings, and a list of match indeces. -(regexp-replace re input txt) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. topic:: (regexp-replace re input txt) -(regexp-split re input) -^^^^^^^^^^^^^^^^^^^^^^^ +.. topic:: (regexp-split re input) (picrin control) ---------------- From da2a71fe650683d5a6fbd61c5e8cbc36d5cb0ef5 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 02:46:02 +0900 Subject: [PATCH 27/41] try using glossary directive --- docs/libs.rst | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/libs.rst b/docs/libs.rst index ebec4f88..7a6ab15e 100644 --- a/docs/libs.rst +++ b/docs/libs.rst @@ -55,21 +55,22 @@ Explicit renaming macro family. (picrin regexp) --------------- -.. topic:: (regexp ptrn [flags]) +.. glossary:: -Compiles pattern string into a regexp object. A string flags may contain any of #\g, #\i, #\m. + (regexp ptrn [flags]) -.. topic:: (regexp? obj) + Compiles pattern string into a regexp object. A string flags may contain any of #\g, #\i, #\m. -Judges if obj is a regexp object or not. + (regexp? obj) -.. topic:: (regexp-match re input) + Judges if obj is a regexp object or not. -Returns two values: a list of match strings, and a list of match indeces. + (regexp-match re input) -.. topic:: (regexp-replace re input txt) + Returns two values: a list of match strings, and a list of match indeces. -.. topic:: (regexp-split re input) + (regexp-replace re input txt) + (regexp-split re input) (picrin control) ---------------- From d5e1f3f8ef4609bd060fb1596bd5b478e9751353 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 02:51:06 +0900 Subject: [PATCH 28/41] use list notation and italic --- docs/libs.rst | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/docs/libs.rst b/docs/libs.rst index 7a6ab15e..ee3c536c 100644 --- a/docs/libs.rst +++ b/docs/libs.rst @@ -37,7 +37,7 @@ Utility functions and syntaces for macro definition. - define-macro - gensym -- macroexpand +- macroexpand expr Old-fashioned macro. @@ -55,33 +55,30 @@ Explicit renaming macro family. (picrin regexp) --------------- -.. glossary:: +- *(regexp ptrn [flags])* - (regexp ptrn [flags]) + Compiles pattern string into a regexp object. A string flags may contain any of #\g, #\i, #\m. - Compiles pattern string into a regexp object. A string flags may contain any of #\g, #\i, #\m. +- *(regexp? obj)* - (regexp? obj) + Judges if obj is a regexp object or not. - Judges if obj is a regexp object or not. +- *(regexp-match re input)* - (regexp-match re input) + Returns two values: a list of match strings, and a list of match indeces. - Returns two values: a list of match strings, and a list of match indeces. +- *(regexp-replace re input txt)* +- *(regexp-split re input)* - (regexp-replace re input txt) - (regexp-split re input) (picrin control) ---------------- Delimited control operators. -(reset h) -^^^^^^^^^ +- *(reset h)* +- *(shift k)* -(shift k) -^^^^^^^^^ (picrin dictionary) ------------------- @@ -90,37 +87,31 @@ Symbol to Object table. Internally it is implemented on hash-table. Note that dictionary is not a weak map; if you are going to make a highly memory-consuming program with dictionaries, you should know that dictionaries keep their bound objects and never let them free until you explicitly deletes bindings. -(dictionary) -^^^^^^^^^^^^ +- *(dictionary)* Returns a newly allocated empty dictionary. In the future, it is planned to extend this function to take optional arguments for initial key/values. -(dictionary? obj) -^^^^^^^^^^^^^^^^^ +- *(dictionary? obj)* Returns #t if obj is a dictionary. -(dictionary-ref dict key) -^^^^^^^^^^^^^^^^^^^^^^^^^ +- *(dictionary-ref dict key)* Look up dictionary dict for a value associated with symbol key. If no object is associated with key, it will raise an error. -(dictionary-set! dict key obj) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- *(dictionary-set! dict key obj)* If there is no value already associated with key, this function newly creates a binding of key with obj. Otherwise, updates the existing binding with given obj. -(dictionary-delete dict key) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- *(dictionary-delete dict key)* Deletes the binding associated with key from dict. If no binding on dict is associated with key, an error will be raised. - -(dictionary-size dict) -^^^^^^^^^^^^^^^^^^^^^^ +- *(dictionary-size dict)* Returns the number of registered elements in dict. + (picrin user) ------------- From e52aed64fbff0cc8bddc8eb89ce6832c85d21070 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 02:52:27 +0900 Subject: [PATCH 29/41] bold is more rational --- docs/libs.rst | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/libs.rst b/docs/libs.rst index ee3c536c..9d71963f 100644 --- a/docs/libs.rst +++ b/docs/libs.rst @@ -55,20 +55,20 @@ Explicit renaming macro family. (picrin regexp) --------------- -- *(regexp ptrn [flags])* +- **(regexp ptrn [flags])** Compiles pattern string into a regexp object. A string flags may contain any of #\g, #\i, #\m. -- *(regexp? obj)* +- **(regexp? obj)** Judges if obj is a regexp object or not. -- *(regexp-match re input)* +- **(regexp-match re input)** Returns two values: a list of match strings, and a list of match indeces. -- *(regexp-replace re input txt)* -- *(regexp-split re input)* +- **(regexp-replace re input txt)** +- **(regexp-split re input)** (picrin control) @@ -76,8 +76,8 @@ Explicit renaming macro family. Delimited control operators. -- *(reset h)* -- *(shift k)* +- **(reset h)** +- **(shift k)** (picrin dictionary) @@ -87,27 +87,27 @@ Symbol to Object table. Internally it is implemented on hash-table. Note that dictionary is not a weak map; if you are going to make a highly memory-consuming program with dictionaries, you should know that dictionaries keep their bound objects and never let them free until you explicitly deletes bindings. -- *(dictionary)* +- **(dictionary)** Returns a newly allocated empty dictionary. In the future, it is planned to extend this function to take optional arguments for initial key/values. -- *(dictionary? obj)* +- **(dictionary? obj)** Returns #t if obj is a dictionary. -- *(dictionary-ref dict key)* +- **(dictionary-ref dict key)** Look up dictionary dict for a value associated with symbol key. If no object is associated with key, it will raise an error. -- *(dictionary-set! dict key obj)* +- **(dictionary-set! dict key obj)** If there is no value already associated with key, this function newly creates a binding of key with obj. Otherwise, updates the existing binding with given obj. -- *(dictionary-delete dict key)* +- **(dictionary-delete dict key)** Deletes the binding associated with key from dict. If no binding on dict is associated with key, an error will be raised. -- *(dictionary-size dict)* +- **(dictionary-size dict)** Returns the number of registered elements in dict. From 6a3f6f615b6d80d116268b8886b40db648f0bed2 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 02:58:22 +0900 Subject: [PATCH 30/41] fix grammatical error --- docs/lang.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/lang.rst b/docs/lang.rst index ec149d98..fe0e60f7 100644 --- a/docs/lang.rst +++ b/docs/lang.rst @@ -18,7 +18,7 @@ At the REPL start-up time, some usuful built-in libraries listed below will be a - ``(scheme lazy)`` - ``(scheme time)`` -Compiliance with R7RS +Compliance with R7RS --------------------- ================================================ ========== ========================================================================================================================== From 08b50a39e7b8342750cb1077d3319426957658a0 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 03:31:00 +0900 Subject: [PATCH 31/41] add deploy.rst --- docs/deploy.rst | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ docs/intro.rst | 54 -------------------------------------------- 2 files changed, 59 insertions(+), 54 deletions(-) create mode 100644 docs/deploy.rst diff --git a/docs/deploy.rst b/docs/deploy.rst new file mode 100644 index 00000000..fe985010 --- /dev/null +++ b/docs/deploy.rst @@ -0,0 +1,59 @@ +Installation +============ + +Installation instructions below. + + +Build and Install +----------------- + +- make `Makefile` + +Change directory to `build` then run `ccmake` to create Makefile. Once `Makefile` is generated you can run `make` command to build picrin:: + + $ cd build + + $ ccmake .. + +Actually you don't necessarily need to move to `build` directory before running `ccmake` (in that case `$ ccmake .`), but I strongly recommend to follow above instruction. + +- build + +A built executable binary will be under bin/ directory and shared libraries under lib/:: + + $ make + +If you are building picrin on other systems than x86_64, PIC_NAN_BOXING flag is automatically turned on (see include/picrin/config.h for detail). + +- install + +Just running `make install`, picrin library, headers, and runtime binary are install on your system, by default into `/usr/local` directory. You can change this value via ccmake:: + + $ make install + +- run + +Before installing picrin, you can try picrin without breaking any of your system. Simply directly run the binary `bin/picrin` from terminal, or you can use `make` to execute it like this:: + + $ make run + +- debug run + +If you execute `cmake` with debug flag `-DCMAKE_BUILD_TYPE=Debug`, it builds the binary with all debug flags enabled (PIC_GC_STRESS, VM_DEBUG, DEBUG):: + + $ cmake -DCMAKE_BUILD_TYPE=Debug .. + + +Requirement +----------- + +Picrin scheme depends on some external libraries to build the binary: + +- perl +- lex (preferably, flex) +- getopt +- readline (optional) +- regex.h of POSIX.1 (optional) + +Optional libraries are, if cmake detected them, automatically enabled. +The compilation is tested only on Mac OSX and Ubuntu. I think (or hope) it'll be ok to compile and run on other operating systems such as Arch or Windows, but I don't guarantee :( diff --git a/docs/intro.rst b/docs/intro.rst index 91b52e0a..780f249e 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -16,60 +16,6 @@ Picrin is a lightweight scheme implementation intended to comply with full R7RS - advanced REPL support (multi-line input, etc) - tiny & portable library (all functions will be in `libpicrin.so`) -Installation ------------- - -- make `Makefile` - -Change directory to `build` then run `ccmake` to create Makefile. Once `Makefile` is generated you can run `make` command to build picrin:: - - $ cd build - - $ ccmake .. - -Actually you don't necessarily need to move to `build` directory before running `ccmake` (in that case `$ ccmake .`), but I strongly recommend to follow above instruction. - -- build - -A built executable binary will be under bin/ directory and shared libraries under lib/:: - - $ make - -If you are building picrin on other systems than x86_64, PIC_NAN_BOXING flag is automatically turned on (see include/picrin/config.h for detail). - -- install - -Just running `make install`, picrin library, headers, and runtime binary are install on your system, by default into `/usr/local` directory. You can change this value via ccmake:: - - $ make install - -- run - -Before installing picrin, you can try picrin without breaking any of your system. Simply directly run the binary `bin/picrin` from terminal, or you can use `make` to execute it like this:: - - $ make run - -- debug run - -If you execute `cmake` with debug flag `-DCMAKE_BUILD_TYPE=Debug`, it builds the binary with all debug flags enabled (PIC_GC_STRESS, VM_DEBUG, DEBUG):: - - $ cmake -DCMAKE_BUILD_TYPE=Debug .. - - -Requirement ------------ - -Picrin scheme depends on some external libraries to build the binary: - -- perl -- lex (preferably, flex) -- getopt -- readline (optional) -- regex.h of POSIX.1 (optional) - -Optional libraries are, if cmake detected them, automatically enabled. -The compilation is tested only on Mac OSX and Ubuntu. I think (or hope) it'll be ok to compile and run on other operating systems such as Arch or Windows, but I don't guarantee :( - Homepage -------- From c1faf5d1917d427e414e3f0b4538641c5fd0565a Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 03:31:44 +0900 Subject: [PATCH 32/41] forgot to update index.rst --- docs/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.rst b/docs/index.rst index d1401fa6..0b1a4491 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -12,6 +12,7 @@ Contents: :maxdepth: 2 intro.rst + deploy.rst lang.rst libs.rst From 3d8017933c62b551e6d7d8dbdde7b044431afe83 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 03:35:55 +0900 Subject: [PATCH 33/41] add doc url --- docs/intro.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/intro.rst b/docs/intro.rst index 780f249e..05cd0c38 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -23,6 +23,11 @@ Currently picrin is hosted on Github. You can freely send a bug report or pull-r https://github.com/wasabiz/picrin +Documentation +------------- + +See http://picrin.readthedocs.org/ + IRC --- From 9aa85c4eb2f5e4764952a25b21de2015a2fbe42b Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 16 Jun 2014 01:44:38 +0900 Subject: [PATCH 34/41] __builtin_unreachable appeared in gcc 4.5.0 --- include/picrin/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/picrin/util.h b/include/picrin/util.h index 1ad80950..f2f5e719 100644 --- a/include/picrin/util.h +++ b/include/picrin/util.h @@ -28,7 +28,7 @@ extern "C" { # define GENSYM(x) GENSYM1__(__LINE__,x) #endif -#if __GNUC__ || __clang__ +#if GCC_VERSION >= 40500 || __clang__ # define UNREACHABLE() (__builtin_unreachable()) #else # include From c208bf2259cdef727926084634b565ed5eeff66c Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 16 Jun 2014 02:07:53 +0900 Subject: [PATCH 35/41] add a commentary on build pre-requisites --- README.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 30c7c21c..62bc0515 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,14 @@ There is a chat room on chat.freenode.org, channel #picrin. IRC logs here: https ## How to use it -- make `Makefile` +To build picrin, you need some build tools installed on your platform. + +- cmake (>= 2.8) +- git + +Because of submodule dependencies, it is necessary to get picrin's source code via git clone command. Basically our git dependencies are only due to submodules, so in fact, If you have no git on your machine, it is possible to build it by downloading a tarball from github page as well. But in such case, you are assumed to modify CMakeLists.txt by yourself to get it work completely. We just strongly recommend you to use git-clone. + +### Generate `Makefile` Change directory to `build` then run `ccmake` to create Makefile. Once `Makefile` is generated you can run `make` command to build picrin. @@ -42,7 +49,7 @@ There is a chat room on chat.freenode.org, channel #picrin. IRC logs here: https Actually you don't necessarily need to move to `build` directory before running `ccmake` (in that case `$ ccmake .`), but I strongly recommend to follow above instruction. -- build +### Build A built executable binary will be under bin/ directory and shared libraries under lib/. @@ -50,19 +57,19 @@ There is a chat room on chat.freenode.org, channel #picrin. IRC logs here: https If you are building picrin on other systems than x86_64, PIC_NAN_BOXING flag is automatically turned on (see include/picrin/config.h for detail). -- install +### Install Just running `make install`, picrin library, headers, and runtime binary are install on your system, by default into `/usr/local` directory. You can change this value via ccmake. $ make install -- run +### Run Before installing picrin, you can try picrin without breaking any of your system. Simply directly run the binary `bin/picrin` from terminal, or you can use `make` to execute it like this. $ make run -- debug run +### Debug run If you execute `cmake` with debug flag `-DCMAKE_BUILD_TYPE=Debug`, it builds the binary with all debug flags enabled (PIC_GC_STRESS, VM_DEBUG, DEBUG). From 2bfc373ed4f0a01b6b1d91b889cf200d0a74a7b0 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 16 Jun 2014 02:12:05 +0900 Subject: [PATCH 36/41] fix indentions --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 62bc0515..20cf6671 100644 --- a/README.md +++ b/README.md @@ -40,40 +40,40 @@ To build picrin, you need some build tools installed on your platform. Because of submodule dependencies, it is necessary to get picrin's source code via git clone command. Basically our git dependencies are only due to submodules, so in fact, If you have no git on your machine, it is possible to build it by downloading a tarball from github page as well. But in such case, you are assumed to modify CMakeLists.txt by yourself to get it work completely. We just strongly recommend you to use git-clone. -### Generate `Makefile` +### Generate Makefile - Change directory to `build` then run `ccmake` to create Makefile. Once `Makefile` is generated you can run `make` command to build picrin. +Change directory to `build` then run `ccmake` to create Makefile. Once `Makefile` is generated you can run `make` command to build picrin. - $ cd build - $ ccmake .. + $ cd build + $ ccmake .. - Actually you don't necessarily need to move to `build` directory before running `ccmake` (in that case `$ ccmake .`), but I strongly recommend to follow above instruction. +Actually you don't necessarily need to move to `build` directory before running `ccmake` (in that case `$ ccmake .`), but I strongly recommend to follow above instruction. ### Build - A built executable binary will be under bin/ directory and shared libraries under lib/. +A built executable binary will be under bin/ directory and shared libraries under lib/. - $ make + $ make - If you are building picrin on other systems than x86_64, PIC_NAN_BOXING flag is automatically turned on (see include/picrin/config.h for detail). +If you are building picrin on other systems than x86_64, PIC_NAN_BOXING flag is automatically turned on (see include/picrin/config.h for detail). ### Install - Just running `make install`, picrin library, headers, and runtime binary are install on your system, by default into `/usr/local` directory. You can change this value via ccmake. +Just running `make install`, picrin library, headers, and runtime binary are install on your system, by default into `/usr/local` directory. You can change this value via ccmake. - $ make install + $ make install ### Run - Before installing picrin, you can try picrin without breaking any of your system. Simply directly run the binary `bin/picrin` from terminal, or you can use `make` to execute it like this. +Before installing picrin, you can try picrin without breaking any of your system. Simply directly run the binary `bin/picrin` from terminal, or you can use `make` to execute it like this. - $ make run + $ make run ### Debug run - If you execute `cmake` with debug flag `-DCMAKE_BUILD_TYPE=Debug`, it builds the binary with all debug flags enabled (PIC_GC_STRESS, VM_DEBUG, DEBUG). +If you execute `cmake` with debug flag `-DCMAKE_BUILD_TYPE=Debug`, it builds the binary with all debug flags enabled (PIC_GC_STRESS, VM_DEBUG, DEBUG). - $ cmake -DCMAKE_BUILD_TYPE=Debug .. + $ cmake -DCMAKE_BUILD_TYPE=Debug .. ## Requirement From faf0c7f4a5db43cfbe9f2f87f626bf01e8cda4b8 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 16 Jun 2014 02:17:16 +0900 Subject: [PATCH 37/41] update sphinx doc --- docs/deploy.rst | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/deploy.rst b/docs/deploy.rst index fe985010..2f7ec4f1 100644 --- a/docs/deploy.rst +++ b/docs/deploy.rst @@ -7,7 +7,15 @@ Installation instructions below. Build and Install ----------------- -- make `Makefile` +To build picrin, you need some build tools installed on your platform. + +- cmake (>= 2.8) +- git + +Because of submodule dependencies, it is necessary to get picrin's source code via git clone command. Basically our git dependencies are only due to submodules, so in fact, If you have no git on your machine, it is possible to build it by downloading a tarball from github page as well. But in such case, you are assumed to modify CMakeLists.txt by yourself to get it work completely. We just strongly recommend you to use git-clone. + +Generate Makefile +^^^^^^^^^^^^^^^^^ Change directory to `build` then run `ccmake` to create Makefile. Once `Makefile` is generated you can run `make` command to build picrin:: @@ -17,7 +25,8 @@ Change directory to `build` then run `ccmake` to create Makefile. Once `Makefile Actually you don't necessarily need to move to `build` directory before running `ccmake` (in that case `$ ccmake .`), but I strongly recommend to follow above instruction. -- build +Build +^^^^^ A built executable binary will be under bin/ directory and shared libraries under lib/:: @@ -25,19 +34,22 @@ A built executable binary will be under bin/ directory and shared libraries unde If you are building picrin on other systems than x86_64, PIC_NAN_BOXING flag is automatically turned on (see include/picrin/config.h for detail). -- install +Install +^^^^^^^ Just running `make install`, picrin library, headers, and runtime binary are install on your system, by default into `/usr/local` directory. You can change this value via ccmake:: $ make install -- run +Run +^^^ Before installing picrin, you can try picrin without breaking any of your system. Simply directly run the binary `bin/picrin` from terminal, or you can use `make` to execute it like this:: $ make run -- debug run +Debug run +^^^^^^^^^ If you execute `cmake` with debug flag `-DCMAKE_BUILD_TYPE=Debug`, it builds the binary with all debug flags enabled (PIC_GC_STRESS, VM_DEBUG, DEBUG):: From 1fb2ac9aa45201ce394e740ef0aa243bf9d2fde9 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 16 Jun 2014 02:22:09 +0900 Subject: [PATCH 38/41] downgrade cmake version to 2.6 --- CMakeLists.txt | 2 +- README.md | 2 +- cmake/FindFLEX.cmake | 179 +++++++++++++++++++++++++++++++++++++++++++ cmake/FindGit.cmake | 46 +++++++++++ docs/deploy.rst | 2 +- 5 files changed, 228 insertions(+), 3 deletions(-) create mode 100644 cmake/FindFLEX.cmake create mode 100644 cmake/FindGit.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 93012159..22cc4f9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.6) PROJECT(picrin) diff --git a/README.md b/README.md index 20cf6671..9d61ad13 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ There is a chat room on chat.freenode.org, channel #picrin. IRC logs here: https To build picrin, you need some build tools installed on your platform. -- cmake (>= 2.8) +- cmake (>= 2.6) - git Because of submodule dependencies, it is necessary to get picrin's source code via git clone command. Basically our git dependencies are only due to submodules, so in fact, If you have no git on your machine, it is possible to build it by downloading a tarball from github page as well. But in such case, you are assumed to modify CMakeLists.txt by yourself to get it work completely. We just strongly recommend you to use git-clone. diff --git a/cmake/FindFLEX.cmake b/cmake/FindFLEX.cmake new file mode 100644 index 00000000..c56e8eda --- /dev/null +++ b/cmake/FindFLEX.cmake @@ -0,0 +1,179 @@ +# - Find flex executable and provides a macro to generate custom build rules +# +# The module defines the following variables: +# FLEX_FOUND - true is flex executable is found +# FLEX_EXECUTABLE - the path to the flex executable +# FLEX_VERSION - the version of flex +# FLEX_LIBRARIES - The flex libraries +# +# The minimum required version of flex can be specified using the +# standard syntax, e.g. FIND_PACKAGE(FLEX 2.5.13) +# +# +# If flex is found on the system, the module provides the macro: +# FLEX_TARGET(Name FlexInput FlexOutput [COMPILE_FLAGS ]) +# which creates a custom command to generate the file from +# the file. If COMPILE_FLAGS option is specified, the next +# parameter is added to the flex command line. Name is an alias used to +# get details of this custom command. Indeed the macro defines the +# following variables: +# FLEX_${Name}_DEFINED - true is the macro ran successfully +# FLEX_${Name}_OUTPUTS - the source file generated by the custom rule, an +# alias for FlexOutput +# FLEX_${Name}_INPUT - the flex source file, an alias for ${FlexInput} +# +# Flex scanners oftenly use tokens defined by Bison: the code generated +# by Flex depends of the header generated by Bison. This module also +# defines a macro: +# ADD_FLEX_BISON_DEPENDENCY(FlexTarget BisonTarget) +# which adds the required dependency between a scanner and a parser +# where and are the first parameters of +# respectively FLEX_TARGET and BISON_TARGET macros. +# +# ==================================================================== +# Example: +# +# find_package(BISON) +# find_package(FLEX) +# +# BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp +# FLEX_TARGET(MyScanner lexer.l ${CMAKE_CURRENT_BIANRY_DIR}/lexer.cpp) +# ADD_FLEX_BISON_DEPENDENCY(MyScanner MyParser) +# +# include_directories(${CMAKE_CURRENT_BINARY_DIR}) +# add_executable(Foo +# Foo.cc +# ${BISON_MyParser_OUTPUTS} +# ${FLEX_MyScanner_OUTPUTS} +# ) +# ==================================================================== + +#============================================================================= +# Copyright 2009 Kitware, Inc. +# Copyright 2006 Tristan Carel +# Modified 2010 by Jon Siwek, backporting for CMake 2.6 compat +# +# Distributed under the OSI-approved BSD License (the "License"): +# CMake - Cross Platform Makefile Generator +# Copyright 2000-2009 Kitware, Inc., Insight Software Consortium +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the names of Kitware, Inc., the Insight Software Consortium, +# nor the names of their contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= + +FIND_PROGRAM(FLEX_EXECUTABLE flex DOC "path to the flex executable") +MARK_AS_ADVANCED(FLEX_EXECUTABLE) + +FIND_LIBRARY(FL_LIBRARY NAMES fl + DOC "path to the fl library") +MARK_AS_ADVANCED(FL_LIBRARY) +SET(FLEX_LIBRARIES ${FL_LIBRARY}) + +IF(FLEX_EXECUTABLE) + + EXECUTE_PROCESS(COMMAND ${FLEX_EXECUTABLE} --version + OUTPUT_VARIABLE FLEX_version_output + ERROR_VARIABLE FLEX_version_error + RESULT_VARIABLE FLEX_version_result + OUTPUT_STRIP_TRAILING_WHITESPACE) + IF(NOT ${FLEX_version_result} EQUAL 0) + IF(FLEX_FIND_REQUIRED) + MESSAGE(SEND_ERROR "Command \"${FLEX_EXECUTABLE} --version\" failed with output:\n${FLEX_version_output}\n${FLEX_version_error}") + ELSE() + MESSAGE("Command \"${FLEX_EXECUTABLE} --version\" failed with output:\n${FLEX_version_output}\n${FLEX_version_error}\nFLEX_VERSION will not be available") + ENDIF() + ELSE() + STRING(REGEX REPLACE "^flex (.*)$" "\\1" + FLEX_VERSION "${FLEX_version_output}") + ENDIF() + + #============================================================ + # FLEX_TARGET (public macro) + #============================================================ + # + MACRO(FLEX_TARGET Name Input Output) + SET(FLEX_TARGET_usage "FLEX_TARGET( [COMPILE_FLAGS ]") + IF(${ARGC} GREATER 3) + IF(${ARGC} EQUAL 5) + IF("${ARGV3}" STREQUAL "COMPILE_FLAGS") + SET(FLEX_EXECUTABLE_opts "${ARGV4}") + SEPARATE_ARGUMENTS(FLEX_EXECUTABLE_opts) + ELSE() + MESSAGE(SEND_ERROR ${FLEX_TARGET_usage}) + ENDIF() + ELSE() + MESSAGE(SEND_ERROR ${FLEX_TARGET_usage}) + ENDIF() + ENDIF() + + ADD_CUSTOM_COMMAND(OUTPUT ${Output} + COMMAND ${FLEX_EXECUTABLE} + ARGS ${FLEX_EXECUTABLE_opts} -o${Output} ${Input} + DEPENDS ${Input} + COMMENT "[FLEX][${Name}] Building scanner with flex ${FLEX_VERSION}" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + + SET(FLEX_${Name}_DEFINED TRUE) + SET(FLEX_${Name}_OUTPUTS ${Output}) + SET(FLEX_${Name}_INPUT ${Input}) + SET(FLEX_${Name}_COMPILE_FLAGS ${FLEX_EXECUTABLE_opts}) + ENDMACRO(FLEX_TARGET) + #============================================================ + + + #============================================================ + # ADD_FLEX_BISON_DEPENDENCY (public macro) + #============================================================ + # + MACRO(ADD_FLEX_BISON_DEPENDENCY FlexTarget BisonTarget) + + IF(NOT FLEX_${FlexTarget}_OUTPUTS) + MESSAGE(SEND_ERROR "Flex target `${FlexTarget}' does not exists.") + ENDIF() + + IF(NOT BISON_${BisonTarget}_OUTPUT_HEADER) + MESSAGE(SEND_ERROR "Bison target `${BisonTarget}' does not exists.") + ENDIF() + + SET_SOURCE_FILES_PROPERTIES(${FLEX_${FlexTarget}_OUTPUTS} + PROPERTIES OBJECT_DEPENDS ${BISON_${BisonTarget}_OUTPUT_HEADER}) + ENDMACRO(ADD_FLEX_BISON_DEPENDENCY) + #============================================================ + +ENDIF(FLEX_EXECUTABLE) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLEX FLEX_EXECUTABLE + FLEX_VERSION) + +# FindFLEX.cmake ends here diff --git a/cmake/FindGit.cmake b/cmake/FindGit.cmake new file mode 100644 index 00000000..2d821428 --- /dev/null +++ b/cmake/FindGit.cmake @@ -0,0 +1,46 @@ +# The module defines the following variables: +# GIT_EXECUTABLE - path to git command line client +# GIT_FOUND - true if the command line client was found +# Example usage: +# find_package(Git) +# if(GIT_FOUND) +# message("git found: ${GIT_EXECUTABLE}") +# endif() + +#============================================================================= +# Copyright 2010 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distributed this file outside of CMake, substitute the full +# License text for the above reference.) + +# Look for 'git' or 'eg' (easy git) +# +set(git_names git eg) + +# Prefer .cmd variants on Windows unless running in a Makefile +# in the MSYS shell. +# +if(WIN32) + if(NOT CMAKE_GENERATOR MATCHES "MSYS") + set(git_names git.cmd git eg.cmd eg) + endif() +endif() + +find_program(GIT_EXECUTABLE + NAMES ${git_names} + DOC "git command line client" + ) +mark_as_advanced(GIT_EXECUTABLE) + +# Handle the QUIETLY and REQUIRED arguments and set GIT_FOUND to TRUE if +# all listed variables are TRUE + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Git DEFAULT_MSG GIT_EXECUTABLE) diff --git a/docs/deploy.rst b/docs/deploy.rst index 2f7ec4f1..2268ad01 100644 --- a/docs/deploy.rst +++ b/docs/deploy.rst @@ -9,7 +9,7 @@ Build and Install To build picrin, you need some build tools installed on your platform. -- cmake (>= 2.8) +- cmake (>= 2.6) - git Because of submodule dependencies, it is necessary to get picrin's source code via git clone command. Basically our git dependencies are only due to submodules, so in fact, If you have no git on your machine, it is possible to build it by downloading a tarball from github page as well. But in such case, you are assumed to modify CMakeLists.txt by yourself to get it work completely. We just strongly recommend you to use git-clone. From 3bc12d883e005705278fcef5352b488073be07b3 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 16 Jun 2014 02:34:24 +0900 Subject: [PATCH 39/41] R7RS compatibility is no longer 'partial' --- README.md | 2 +- docs/intro.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d61ad13..9c61e195 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Picrin is a lightweight scheme implementation intended to comply with full R7RS ## Features -- R7RS compatibility (but partial support) +- R7RS compatibility - reentrant design (all VM states are stored in single global state object) - bytecode interpreter (based on stack VM) - direct threaded VM diff --git a/docs/intro.rst b/docs/intro.rst index 05cd0c38..ea251f2c 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -3,7 +3,7 @@ Introduction Picrin is a lightweight scheme implementation intended to comply with full R7RS specification. Its code is written in pure C99 and does not requires any special external libraries installed on the platform. -- R7RS compatibility (but partial support) +- R7RS compatibility - reentrant design (all VM states are stored in single global state object) - bytecode interpreter (based on stack VM) - direct threaded VM From e88617a0657f86999476521d3687f89743efd234 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 17 Jun 2014 21:28:20 +0900 Subject: [PATCH 40/41] ignore shebang (#134) --- src/scan.l | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/scan.l b/src/scan.l index c3d9b1b8..747f31a7 100644 --- a/src/scan.l +++ b/src/scan.l @@ -33,6 +33,9 @@ %option extra-type="struct parser_control *" %option never-interactive + /* shebang */ +shebang #!.*$ + /* comment */ comment ;.*$ @@ -71,6 +74,7 @@ label #{uinteger} [ \t\n\r] /* skip whitespace */ {comment} /* skip comment */ +{shebang} /* skip shebang */ "#|" { BEGIN(BLOCK_COMMENT); From e013cfd291d35937f6a145b2a88c250edaa05248 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 17 Jun 2014 21:28:33 +0900 Subject: [PATCH 41/41] add shebang test case --- t/shebang.scm | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 t/shebang.scm diff --git a/t/shebang.scm b/t/shebang.scm new file mode 100755 index 00000000..3200aacf --- /dev/null +++ b/t/shebang.scm @@ -0,0 +1,9 @@ +#! /bin/sh +#| -*- scheme -*- +exec picrin $0 "$@" +|# + +(import (scheme base) + (scheme write)) + +(write (list 1 2 3))