add pair.h
This commit is contained in:
parent
6faaa5261c
commit
50b9c2bd97
|
@ -54,10 +54,6 @@ void pic_close(pic_state *);
|
|||
void pic_get_args(pic_state *, const char *, ...);
|
||||
void pic_defun(pic_state *, const char *, pic_func_t);
|
||||
|
||||
pic_value pic_cons(pic_state *, pic_value, pic_value);
|
||||
pic_value pic_car(pic_state *, pic_value);
|
||||
pic_value pic_cdr(pic_state *, pic_value);
|
||||
|
||||
bool pic_eq_p(pic_state *, pic_value, pic_value);
|
||||
|
||||
pic_value pic_intern_cstr(pic_state *, const char *);
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef PAIR_H__
|
||||
#define PAIR_H__
|
||||
|
||||
pic_value pic_cons(pic_state *, pic_value, pic_value);
|
||||
pic_value pic_car(pic_state *, pic_value);
|
||||
pic_value pic_cdr(pic_state *, pic_value);
|
||||
|
||||
pic_value pic_list(pic_state *, size_t, ...);
|
||||
|
||||
pic_value pic_assq(pic_state *, pic_value key, pic_value assoc);
|
||||
|
||||
#endif
|
19
src/pair.c
19
src/pair.c
|
@ -1,4 +1,5 @@
|
|||
#include "picrin.h"
|
||||
#include "picrin/pair.h"
|
||||
|
||||
pic_value
|
||||
pic_cons(pic_state *pic, pic_value car, pic_value cdr)
|
||||
|
@ -31,3 +32,21 @@ pic_cdr(pic_state *pic, pic_value obj)
|
|||
|
||||
return pair->cdr;
|
||||
}
|
||||
|
||||
pic_value
|
||||
pic_assq(pic_state *pic, pic_value key, pic_value assoc)
|
||||
{
|
||||
pic_value cell;
|
||||
|
||||
enter:
|
||||
|
||||
if (pic_nil_p(assoc))
|
||||
return assoc;
|
||||
|
||||
cell = pic_car(pic, assoc);
|
||||
if (pic_eq_p(pic, key, pic_car(pic, cell)))
|
||||
return cell;
|
||||
|
||||
assoc = pic_cdr(pic, assoc);
|
||||
goto enter;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/pair.h"
|
||||
|
||||
#define YYERROR_VERBOSE 1
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "picrin.h"
|
||||
|
||||
|
|
19
src/vm.c
19
src/vm.c
|
@ -5,24 +5,7 @@
|
|||
#include "picrin.h"
|
||||
#include "picrin/irep.h"
|
||||
#include "picrin/proc.h"
|
||||
|
||||
static pic_value
|
||||
pic_assq(pic_state *pic, pic_value key, pic_value assoc)
|
||||
{
|
||||
pic_value cell;
|
||||
|
||||
enter:
|
||||
|
||||
if (pic_nil_p(assoc))
|
||||
return assoc;
|
||||
|
||||
cell = pic_car(pic, assoc);
|
||||
if (pic_eq_p(pic, key, pic_car(pic, cell)))
|
||||
return cell;
|
||||
|
||||
assoc = pic_cdr(pic, assoc);
|
||||
goto enter;
|
||||
}
|
||||
#include "picrin/pair.h"
|
||||
|
||||
static bool
|
||||
env_lookup(pic_state *pic, pic_value sym, struct pic_env *env, int *depth, int *idx)
|
||||
|
|
Loading…
Reference in New Issue