replace list-set! impl with C impl

This commit is contained in:
Yuichi Nishiwaki 2014-01-22 21:35:13 +09:00
parent d07456466d
commit 74088d0130
3 changed files with 21 additions and 3 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -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);
}