add pair.h

This commit is contained in:
Yuichi Nishiwaki 2013-10-20 12:34:57 +09:00
parent 6faaa5261c
commit 50b9c2bd97
6 changed files with 33 additions and 23 deletions

View File

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

12
include/picrin/pair.h Normal file
View File

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

View File

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

View File

@ -3,6 +3,7 @@
#include <stdio.h>
#include "picrin.h"
#include "picrin/pair.h"
#define YYERROR_VERBOSE 1

View File

@ -1,5 +1,4 @@
#include <time.h>
#include <stdio.h>
#include "picrin.h"

View File

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