From 74088d0130db50112533b1bfc09ef1e392b576c5 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 22 Jan 2014 21:35:13 +0900 Subject: [PATCH] replace list-set! impl with C impl --- include/picrin/pair.h | 1 + piclib/built-in.scm | 3 --- src/pair.c | 20 ++++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/picrin/pair.h b/include/picrin/pair.h index f2ba887e..20b48dfd 100644 --- a/include/picrin/pair.h +++ b/include/picrin/pair.h @@ -32,6 +32,7 @@ pic_value pic_cddr(pic_state *, pic_value); pic_value pic_list_tail(pic_state *, pic_value ,int); pic_value pic_list_ref(pic_state *, pic_value, int); +void pic_list_set(pic_state *, pic_value, int, pic_value); #if defined(__cplusplus) } diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 2e30a7f7..248ab4e2 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -462,9 +462,6 @@ (cons (car args) (make-list (- k 1) (car args)))))) -(define (list-set! list k obj) - (set-car! (list-tail list k) obj)) - (define (list-copy obj) (if (null? obj) obj diff --git a/src/pair.c b/src/pair.c index 8f39df43..3c1e8bbc 100644 --- a/src/pair.c +++ b/src/pair.c @@ -213,6 +213,12 @@ pic_list_ref(pic_state *pic, pic_value list, int i) return pic_car(pic, pic_list_tail(pic, list, i)); } +void +pic_list_set(pic_state *pic, pic_value list, int i, pic_value obj) +{ + pic_pair_ptr(pic_list_tail(pic, list, i))->car = obj; +} + static pic_value pic_pair_pair_p(pic_state *pic) { @@ -410,6 +416,19 @@ pic_pair_list_ref(pic_state *pic) return pic_list_ref(pic, list, i); } +static pic_value +pic_pair_list_set(pic_state *pic) +{ + pic_value list, obj; + int i; + + pic_get_args(pic, "oio", &list, &i, &obj); + + pic_list_set(pic, list, i, obj); + + return pic_none_value(); +} + void pic_init_pair(pic_state *pic) { @@ -431,4 +450,5 @@ pic_init_pair(pic_state *pic) pic_defun(pic, "reverse", pic_pair_reverse); pic_defun(pic, "list-tail", pic_pair_list_tail); pic_defun(pic, "list-ref", pic_pair_list_ref); + pic_defun(pic, "list-set!", pic_pair_list_set); }