diff --git a/bool.c b/bool.c index 8f8c75f1..0b196f51 100644 --- a/bool.c +++ b/bool.c @@ -32,7 +32,7 @@ blob_equal_p(struct pic_blob *blob1, struct pic_blob *blob2) } static bool -internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash *ht) +internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash *xh, bool xh_initted_p) { pic_value local = pic_nil_value(); size_t c; @@ -42,10 +42,15 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash * pic_errorf(pic, "Stack overflow in equal\n"); } if (pic_pair_p(x) || pic_vec_p(x)) { - if (xh_get_ptr(ht, pic_obj_ptr(x)) != NULL) { + if (! xh_initted_p) { + xh_init_ptr(xh, 0); + xh_initted_p = true; + } + + if (xh_get_ptr(xh, pic_obj_ptr(x)) != NULL) { return true; /* `x' was seen already. */ } else { - xh_put_ptr(ht, pic_obj_ptr(x), NULL); + xh_put_ptr(xh, pic_obj_ptr(x), NULL); } } } @@ -71,7 +76,7 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash * if (pic_nil_p(local)) { local = x; } - if (internal_equal_p(pic, pic_car(pic, x), pic_car(pic, y), depth + 1, ht)) { + if (internal_equal_p(pic, pic_car(pic, x), pic_car(pic, y), depth + 1, xh, xh_initted_p)) { x = pic_cdr(pic, x); y = pic_cdr(pic, y); @@ -100,7 +105,7 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash * return false; } for (i = 0; i < u->len; ++i) { - if (! internal_equal_p(pic, u->data[i], v->data[i], depth + 1, ht)) + if (! internal_equal_p(pic, u->data[i], v->data[i], depth + 1, xh, xh_initted_p)) return false; } return true; @@ -111,12 +116,11 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash * } bool -pic_equal_p(pic_state *pic, pic_value x, pic_value y){ +pic_equal_p(pic_state *pic, pic_value x, pic_value y) +{ xhash ht; - xh_init_ptr(&ht, 0); - - return internal_equal_p(pic, x, y, 0, &ht); + return internal_equal_p(pic, x, y, 0, &ht, false); } static pic_value diff --git a/codegen.c b/codegen.c index f6183278..39b4bfc4 100644 --- a/codegen.c +++ b/codegen.c @@ -35,6 +35,7 @@ typedef struct analyze_state { pic_state *pic; analyze_scope *scope; pic_sym rCONS, rCAR, rCDR, rNILP; + pic_sym rSYMBOL_P, rPAIR_P; pic_sym rADD, rSUB, rMUL, rDIV; pic_sym rEQ, rLT, rLE, rGT, rGE, rNOT; pic_sym rVALUES, rCALL_WITH_VALUES; @@ -73,6 +74,8 @@ new_analyze_state(pic_state *pic) register_renamed_symbol(pic, state, rCAR, pic->PICRIN_BASE, "car"); register_renamed_symbol(pic, state, rCDR, pic->PICRIN_BASE, "cdr"); register_renamed_symbol(pic, state, rNILP, pic->PICRIN_BASE, "null?"); + register_renamed_symbol(pic, state, rSYMBOL_P, pic->PICRIN_BASE, "symbol?"); + register_renamed_symbol(pic, state, rPAIR_P, pic->PICRIN_BASE, "pair?"); register_renamed_symbol(pic, state, rADD, pic->PICRIN_BASE, "+"); register_renamed_symbol(pic, state, rSUB, pic->PICRIN_BASE, "-"); register_renamed_symbol(pic, state, rMUL, pic->PICRIN_BASE, "*"); @@ -492,7 +495,7 @@ analyze_if(analyze_state *state, pic_value obj, bool tailpos) pic_errorf(pic, "syntax error"); case 4: if_false = pic_list_ref(pic, obj, 3); - FALLTHROUGH; + PIC_FALLTHROUGH; case 3: if_true = pic_list_ref(pic, obj, 2); } @@ -788,6 +791,14 @@ analyze_node(analyze_state *state, pic_value obj, bool tailpos) ARGC_ASSERT(1); return CONSTRUCT_OP1(pic->sNILP); } + else if (sym == state->rSYMBOL_P) { + ARGC_ASSERT(1); + return CONSTRUCT_OP1(pic->sSYMBOL_P); + } + else if (sym == state->rPAIR_P) { + ARGC_ASSERT(1); + return CONSTRUCT_OP1(pic->sPAIR_P); + } else if (sym == state->rADD) { return analyze_add(state, obj, tailpos); } @@ -1299,6 +1310,18 @@ codegen(codegen_state *state, pic_value obj) cxt->clen++; return; } + else if (sym == pic->sSYMBOL_P) { + codegen(state, pic_list_ref(pic, obj, 1)); + cxt->code[cxt->clen].insn = OP_SYMBOL_P; + cxt->clen++; + return; + } + else if (sym == pic->sPAIR_P) { + codegen(state, pic_list_ref(pic, obj, 1)); + cxt->code[cxt->clen].insn = OP_PAIR_P; + cxt->clen++; + return; + } else if (sym == pic->sADD) { codegen(state, pic_list_ref(pic, obj, 1)); codegen(state, pic_list_ref(pic, obj, 2)); diff --git a/cont.c b/cont.c index 4e38e8c6..b1af6eca 100644 --- a/cont.c +++ b/cont.c @@ -93,7 +93,7 @@ pic_load_point(pic_state *pic, struct pic_escape *escape) escape->valid = false; } -noreturn static pic_value +static pic_value escape_call(pic_state *pic) { size_t argc; diff --git a/dict.c b/dict.c index 81bdea68..ca411551 100644 --- a/dict.c +++ b/dict.c @@ -14,7 +14,7 @@ xh_value_hash(const void *key, void *data) pic_value val = *(pic_value *)key; int hash, vtype; - UNUSED(data); + PIC_UNUSED(data); vtype = pic_vtype(val); @@ -96,7 +96,7 @@ pic_dict_ref(pic_state *pic, struct pic_dict *dict, pic_value key) void pic_dict_set(pic_state *pic, struct pic_dict *dict, pic_value key, pic_value val) { - UNUSED(pic); + PIC_UNUSED(pic); xh_put_value(&dict->hash, key, &val); } @@ -104,7 +104,7 @@ pic_dict_set(pic_state *pic, struct pic_dict *dict, pic_value key, pic_value val size_t pic_dict_size(pic_state *pic, struct pic_dict *dict) { - UNUSED(pic); + PIC_UNUSED(pic); return dict->hash.count; } @@ -112,7 +112,7 @@ pic_dict_size(pic_state *pic, struct pic_dict *dict) bool pic_dict_has(pic_state *pic, struct pic_dict *dict, pic_value key) { - UNUSED(pic); + PIC_UNUSED(pic); return xh_get_value(&dict->hash, key) != NULL; } diff --git a/error.c b/error.c index 3b462969..69c12206 100644 --- a/error.c +++ b/error.c @@ -17,7 +17,7 @@ void pic_panic(pic_state *pic, const char *msg) { - UNUSED(pic); + PIC_UNUSED(pic); fprintf(stderr, "abort: %s\n", msg); abort(); @@ -69,7 +69,7 @@ pic_errmsg(pic_state *pic) return pic_str_cstr(str); } -noreturn static pic_value +static pic_value native_exception_handler(pic_state *pic) { pic_value err; @@ -83,7 +83,7 @@ native_exception_handler(pic_state *pic) pic_apply1(pic, cont, pic_false_value()); - UNREACHABLE(); + PIC_UNREACHABLE(); } void @@ -166,7 +166,7 @@ pic_raise_continuable(pic_state *pic, pic_value err) return v; } -noreturn void +void pic_raise(pic_state *pic, pic_value err) { pic_value val; @@ -178,7 +178,7 @@ pic_raise(pic_state *pic, pic_value err) pic_errorf(pic, "error handler returned with ~s on error ~s", val, err); } -noreturn void +void pic_throw(pic_state *pic, pic_sym type, const char *msg, pic_value irrs) { struct pic_error *e; @@ -188,7 +188,7 @@ pic_throw(pic_state *pic, pic_sym type, const char *msg, pic_value irrs) pic_raise(pic, pic_obj_value(e)); } -noreturn void +void pic_error(pic_state *pic, const char *msg, pic_value irrs) { pic_throw(pic, pic_intern_cstr(pic, ""), msg, irrs); @@ -221,7 +221,7 @@ pic_error_with_exception_handler(pic_state *pic) return val; } -noreturn static pic_value +static pic_value pic_error_raise(pic_state *pic) { pic_value v; @@ -241,7 +241,7 @@ pic_error_raise_continuable(pic_state *pic) return pic_raise_continuable(pic, v); } -noreturn static pic_value +static pic_value pic_error_error(pic_state *pic) { const char *str; diff --git a/file.c b/file.c index 4a5f57d7..d438c23a 100644 --- a/file.c +++ b/file.c @@ -6,7 +6,7 @@ #include "picrin/port.h" #include "picrin/error.h" -static noreturn void +pic_noreturn static void file_error(pic_state *pic, const char *msg) { pic_throw(pic, pic->sFILE, msg, pic_nil_value()); diff --git a/gc.c b/gc.c index 7768f8b9..1e50649e 100644 --- a/gc.c +++ b/gc.c @@ -30,7 +30,7 @@ union header { size_t size; unsigned int mark : 1; } s; - long alignment[4]; + long alignment[2]; }; struct heap_page { @@ -170,7 +170,7 @@ pic_calloc(pic_state *pic, size_t count, size_t size) void pic_free(pic_state *pic, void *ptr) { - UNUSED(pic); + PIC_UNUSED(pic); free(ptr); } diff --git a/include/picrin.h b/include/picrin.h index 442e06a0..98b96d0c 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -89,6 +89,7 @@ typedef struct { pic_sym sCOND_EXPAND, sAND, sOR, sELSE, sLIBRARY; pic_sym sONLY, sRENAME, sPREFIX, sEXCEPT; pic_sym sCONS, sCAR, sCDR, sNILP; + pic_sym sSYMBOL_P, sPAIR_P; pic_sym sADD, sSUB, sMUL, sDIV, sMINUS; pic_sym sEQ, sLT, sLE, sGT, sGE, sNOT; pic_sym sREAD, sFILE; @@ -141,7 +142,7 @@ pic_value pic_gc_protect(pic_state *, pic_value); size_t pic_gc_arena_preserve(pic_state *); void pic_gc_arena_restore(pic_state *, size_t); #define pic_void(exec) \ - pic_void_(GENSYM(ai), exec) + pic_void_(PIC_GENSYM(ai), exec) #define pic_void_(ai,exec) do { \ size_t ai = pic_gc_arena_preserve(pic); \ exec; \ @@ -202,7 +203,7 @@ struct pic_lib *pic_open_library(pic_state *, pic_value); struct pic_lib *pic_find_library(pic_state *, pic_value); #define pic_deflibrary(pic, spec) \ - pic_deflibrary_helper_(pic, GENSYM(i), GENSYM(prev_lib), spec) + pic_deflibrary_helper_(pic, PIC_GENSYM(i), PIC_GENSYM(prev_lib), spec) #define pic_deflibrary_helper_(pic, i, prev_lib, spec) \ for (int i = 0; ! i; ) \ for (struct pic_lib *prev_lib; ! i; ) \ @@ -212,8 +213,8 @@ void pic_import(pic_state *, pic_value); void pic_import_library(pic_state *, struct pic_lib *); void pic_export(pic_state *, pic_sym); -noreturn void pic_panic(pic_state *, const char *); -noreturn void pic_errorf(pic_state *, const char *, ...); +pic_noreturn void pic_panic(pic_state *, const char *); +pic_noreturn void pic_errorf(pic_state *, const char *, ...); void pic_warnf(pic_state *, const char *, ...); const char *pic_errmsg(pic_state *); pic_str *pic_get_backtrace(pic_state *); diff --git a/include/picrin/config.h b/include/picrin/config.h index 76c30066..889e268b 100644 --- a/include/picrin/config.h +++ b/include/picrin/config.h @@ -58,11 +58,11 @@ #endif #ifndef PIC_ARENA_SIZE -# define PIC_ARENA_SIZE 1000 +# define PIC_ARENA_SIZE (8 * 1024) #endif #ifndef PIC_HEAP_PAGE_SIZE -# define PIC_HEAP_PAGE_SIZE 10000 +# define PIC_HEAP_PAGE_SIZE (2 * 1024 * 1024) #endif #ifndef PIC_STACK_SIZE @@ -74,7 +74,7 @@ #endif #ifndef PIC_SYM_POOL_SIZE -# define PIC_SYM_POOL_SIZE 128 +# define PIC_SYM_POOL_SIZE (2 * 1024) #endif #ifndef PIC_IREP_SIZE diff --git a/include/picrin/error.h b/include/picrin/error.h index 784b95f8..e4cc630a 100644 --- a/include/picrin/error.h +++ b/include/picrin/error.h @@ -27,7 +27,7 @@ struct pic_error *pic_make_error(pic_state *, pic_sym, const char *, pic_list); /* do not return from try block! */ #define pic_try \ - pic_try_(GENSYM(escape)) + pic_try_(PIC_GENSYM(escape)) #define pic_try_(escape) \ struct pic_escape *escape = pic_alloc(pic, sizeof(struct pic_escape)); \ pic_save_point(pic, escape); \ @@ -43,9 +43,9 @@ void pic_push_try(pic_state *, struct pic_escape *); void pic_pop_try(pic_state *); pic_value pic_raise_continuable(pic_state *, pic_value); -noreturn void pic_raise(pic_state *, pic_value); -noreturn void pic_throw(pic_state *, pic_sym, const char *, pic_list); -noreturn void pic_error(pic_state *, const char *, pic_list); +pic_noreturn void pic_raise(pic_state *, pic_value); +pic_noreturn void pic_throw(pic_state *, pic_sym, const char *, pic_list); +pic_noreturn void pic_error(pic_state *, const char *, pic_list); #if defined(__cplusplus) } diff --git a/include/picrin/irep.h b/include/picrin/irep.h index fe924bbc..5b10628a 100644 --- a/include/picrin/irep.h +++ b/include/picrin/irep.h @@ -35,6 +35,8 @@ enum pic_opcode { OP_CAR, OP_CDR, OP_NILP, + OP_SYMBOL_P, + OP_PAIR_P, OP_ADD, OP_SUB, OP_MUL, @@ -149,6 +151,12 @@ pic_dump_code(pic_code c) case OP_NILP: puts("OP_NILP"); break; + case OP_SYMBOL_P: + puts("OP_SYMBOL_P"); + break; + case OP_PAIR_P: + puts("OP_PAIR_P"); + break; case OP_CDR: puts("OP_CDR"); break; diff --git a/include/picrin/pair.h b/include/picrin/pair.h index d489b765..11859482 100644 --- a/include/picrin/pair.h +++ b/include/picrin/pair.h @@ -59,9 +59,9 @@ pic_value pic_list7(pic_state *, pic_value, pic_value, pic_value, pic_value, pic pic_value pic_list_by_array(pic_state *, size_t, pic_value *); pic_value pic_make_list(pic_state *, size_t, pic_value); -#define pic_for_each(var, list) \ - pic_for_each_helper_(var, GENSYM(tmp), list) -#define pic_for_each_helper_(var, tmp, list) \ +#define pic_for_each(var, list) \ + pic_for_each_helper_(var, PIC_GENSYM(tmp), list) +#define pic_for_each_helper_(var, tmp, list) \ for (pic_value tmp = (list); \ pic_nil_p(tmp) ? false : ((var = pic_car(pic, tmp)), true); \ tmp = pic_cdr(pic, tmp)) diff --git a/include/picrin/util.h b/include/picrin/util.h index d56cd9f6..afa0e037 100644 --- a/include/picrin/util.h +++ b/include/picrin/util.h @@ -11,33 +11,34 @@ extern "C" { #if __STDC_VERSION__ >= 201112L # include +# define pic_noreturn noreturn #elif __GNUC__ || __clang__ -# define noreturn __attribute__((noreturn)) +# define pic_noreturn __attribute__((noreturn)) #else -# define noreturn +# define pic_noreturn #endif -#define FALLTHROUGH ((void)0) -#define UNUSED(v) ((void)(v)) +#define PIC_FALLTHROUGH ((void)0) +#define PIC_UNUSED(v) ((void)(v)) -#define GENSYM2_(x,y) G##x##_##y##__ -#define GENSYM1_(x,y) GENSYM2_(x,y) +#define PIC_GENSYM2_(x,y) PIC_G##x##_##y##_ +#define PIC_GENSYM1_(x,y) PIC_GENSYM2_(x,y) #if defined(__COUNTER__) -# define GENSYM(x) GENSYM1_(__COUNTER__,x) +# define PIC_GENSYM(x) PIC_GENSYM1_(__COUNTER__,x) #else -# define GENSYM(x) GENSYM1_(__LINE__,x) +# define PIC_GENSYM(x) PIC_GENSYM1_(__LINE__,x) #endif #if GCC_VERSION >= 40500 || __clang__ -# define UNREACHABLE() (__builtin_unreachable()) +# define PIC_UNREACHABLE() (__builtin_unreachable()) #else # include -# define UNREACHABLE() (assert(false)) +# define PIC_UNREACHABLE() (assert(false)) #endif -#define SWAP(type,a,b) \ - SWAP_HELPER_(type,GENSYM(tmp),a,b) -#define SWAP_HELPER_(type,tmp,a,b) \ +#define PIC_SWAP(type,a,b) \ + PIC_SWAP_HELPER_(type, PIC_GENSYM(tmp), a, b) +#define PIC_SWAP_HELPER_(type,tmp,a,b) \ do { \ type tmp = (a); \ (a) = (b); \ diff --git a/include/picrin/value.h b/include/picrin/value.h index 709fcf77..d21a8418 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -225,7 +225,7 @@ pic_type(pic_value v) return ((struct pic_object *)pic_ptr(v))->tt; } - UNREACHABLE(); + PIC_UNREACHABLE(); } static inline const char * @@ -279,7 +279,7 @@ pic_type_repr(enum pic_tt tt) case PIC_TT_RECORD: return "record"; } - UNREACHABLE(); + PIC_UNREACHABLE(); } static inline bool diff --git a/macro.c b/macro.c index c7cd243f..eb811253 100644 --- a/macro.c +++ b/macro.c @@ -25,7 +25,7 @@ pic_add_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym) void pic_put_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym rename) { - UNUSED(pic); + PIC_UNUSED(pic); xh_put_int(&senv->map, sym, &rename); } @@ -35,7 +35,7 @@ pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *ren { xh_entry *e; - UNUSED(pic); + PIC_UNUSED(pic); if ((e = xh_get_int(&senv->map, sym)) == NULL) { return false; diff --git a/proc.c b/proc.c index 210f157d..2b94201b 100644 --- a/proc.c +++ b/proc.c @@ -43,7 +43,7 @@ pic_proc_name(struct pic_proc *proc) case PIC_PROC_KIND_IREP: return proc->u.irep->name; } - UNREACHABLE(); + PIC_UNREACHABLE(); } static pic_value diff --git a/read.c b/read.c index be160c0d..46a056f8 100644 --- a/read.c +++ b/read.c @@ -18,7 +18,7 @@ static pic_value read(pic_state *pic, struct pic_port *port, int c); static pic_value read_nullable(pic_state *pic, struct pic_port *port, int c); -static noreturn void +pic_noreturn static void read_error(pic_state *pic, const char *msg) { pic_throw(pic, pic->sREAD, msg, pic_nil_value()); @@ -86,8 +86,8 @@ read_comment(pic_state *pic, struct pic_port *port, const char *str) { int c; - UNUSED(pic); - UNUSED(str); + PIC_UNUSED(pic); + PIC_UNUSED(str); do { c = next(port); @@ -102,8 +102,8 @@ read_block_comment(pic_state *pic, struct pic_port *port, const char *str) int x, y; int i = 1; - UNUSED(pic); - UNUSED(str); + PIC_UNUSED(pic); + PIC_UNUSED(str); y = next(port); @@ -124,7 +124,7 @@ read_block_comment(pic_state *pic, struct pic_port *port, const char *str) static pic_value read_datum_comment(pic_state *pic, struct pic_port *port, const char *str) { - UNUSED(str); + PIC_UNUSED(str); read(pic, port, next(port)); @@ -157,7 +157,7 @@ read_eval(pic_state *pic, struct pic_port *port, const char *str) { pic_value form; - UNUSED(str); + PIC_UNUSED(str); form = read(pic, port, next(port)); @@ -167,7 +167,7 @@ read_eval(pic_state *pic, struct pic_port *port, const char *str) static pic_value read_quote(pic_state *pic, struct pic_port *port, const char *str) { - UNUSED(str); + PIC_UNUSED(str); return pic_list2(pic, pic_sym_value(pic->sQUOTE), read(pic, port, next(port))); } @@ -175,7 +175,7 @@ read_quote(pic_state *pic, struct pic_port *port, const char *str) static pic_value read_quasiquote(pic_state *pic, struct pic_port *port, const char *str) { - UNUSED(str); + PIC_UNUSED(str); return pic_list2(pic, pic_sym_value(pic->sQUASIQUOTE), read(pic, port, next(port))); } @@ -183,7 +183,7 @@ read_quasiquote(pic_state *pic, struct pic_port *port, const char *str) static pic_value read_unquote(pic_state *pic, struct pic_port *port, const char *str) { - UNUSED(str); + PIC_UNUSED(str); return pic_list2(pic, pic_sym_value(pic->sUNQUOTE), read(pic, port, next(port))); } @@ -191,7 +191,7 @@ read_unquote(pic_state *pic, struct pic_port *port, const char *str) static pic_value read_unquote_splicing(pic_state *pic, struct pic_port *port, const char *str) { - UNUSED(str); + PIC_UNUSED(str); return pic_list2(pic, pic_sym_value(pic->sUNQUOTE_SPLICING), read(pic, port, next(port))); } @@ -354,9 +354,9 @@ read_plus(pic_state *pic, struct pic_port *port, const char *str) static pic_value read_true(pic_state *pic, struct pic_port *port, const char *str) { - UNUSED(pic); - UNUSED(port); - UNUSED(str); + PIC_UNUSED(pic); + PIC_UNUSED(port); + PIC_UNUSED(str); return pic_true_value(); } @@ -364,9 +364,9 @@ read_true(pic_state *pic, struct pic_port *port, const char *str) static pic_value read_false(pic_state *pic, struct pic_port *port, const char *str) { - UNUSED(pic); - UNUSED(port); - UNUSED(str); + PIC_UNUSED(pic); + PIC_UNUSED(port); + PIC_UNUSED(str); return pic_false_value(); } @@ -376,7 +376,7 @@ read_char(pic_state *pic, struct pic_port *port, const char *str) { int c; - UNUSED(str); + PIC_UNUSED(str); c = next(port); @@ -418,7 +418,7 @@ read_string(pic_state *pic, struct pic_port *port, const char *name) size_t size, cnt; pic_str *str; - UNUSED(name); + PIC_UNUSED(name); size = 256; buf = pic_alloc(pic, size); @@ -459,7 +459,7 @@ read_pipe(pic_state *pic, struct pic_port *port, const char *str) size_t i = 0; int c; - UNUSED(str); + PIC_UNUSED(str); size = 256; buf = pic_alloc(pic, size); @@ -504,7 +504,7 @@ read_blob(pic_state *pic, struct pic_port *port, const char *str) unsigned char *dat; pic_blob *blob; - UNUSED(str); + PIC_UNUSED(str); nbits = 0; @@ -631,13 +631,13 @@ read_label_set(pic_state *pic, struct pic_port *port, int i) xh_put_int(&pic->reader->labels, i, &val); tmp = pic_vec_ptr(read(pic, port, c)); - SWAP(pic_value *, tmp->data, pic_vec_ptr(val)->data); - SWAP(size_t, tmp->len, pic_vec_ptr(val)->len); + PIC_SWAP(pic_value *, tmp->data, pic_vec_ptr(val)->data); + PIC_SWAP(size_t, tmp->len, pic_vec_ptr(val)->len); return val; } - FALLTHROUGH; + PIC_FALLTHROUGH; } default: { @@ -655,7 +655,7 @@ read_label_ref(pic_state *pic, struct pic_port *port, int i) { xh_entry *e; - UNUSED(port); + PIC_UNUSED(port); e = xh_get_int(&pic->reader->labels, i); if (! e) { @@ -687,8 +687,8 @@ read_label(pic_state *pic, struct pic_port *port, const char *str) static pic_value read_unmatch(pic_state *pic, struct pic_port *port, const char *str) { - UNUSED(port); - UNUSED(str); + PIC_UNUSED(port); + PIC_UNUSED(str); read_error(pic, "unmatched parenthesis"); } diff --git a/record.c b/record.c index 52fbe050..7ba4be29 100644 --- a/record.c +++ b/record.c @@ -39,7 +39,7 @@ pic_record_ref(pic_state *pic, struct pic_record *rec, pic_sym slot) void pic_record_set(pic_state *pic, struct pic_record *rec, pic_sym slot, pic_value val) { - UNUSED(pic); + PIC_UNUSED(pic); xh_put_int(&rec->hash, slot, &val); } diff --git a/state.c b/state.c index 688e4a6f..75e940f3 100644 --- a/state.c +++ b/state.c @@ -123,6 +123,8 @@ pic_open(int argc, char *argv[], char **envp) S(sCAR, "car"); S(sCDR, "cdr"); S(sNILP, "null?"); + S(sSYMBOL_P, "symbol?"); + S(sPAIR_P, "pair?"); S(sADD, "+"); S(sSUB, "-"); S(sMUL, "*"); diff --git a/var.c b/var.c index ea9cbff5..84ecda61 100644 --- a/var.c +++ b/var.c @@ -73,7 +73,7 @@ var_call(pic_state *pic) return val; } } - UNREACHABLE(); + PIC_UNREACHABLE(); } struct pic_proc * diff --git a/vm.c b/vm.c index 8eb67b71..66ed3871 100644 --- a/vm.c +++ b/vm.c @@ -693,6 +693,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args) &&L_OP_GREF, &&L_OP_GSET, &&L_OP_LREF, &&L_OP_LSET, &&L_OP_CREF, &&L_OP_CSET, &&L_OP_JMP, &&L_OP_JMPIF, &&L_OP_NOT, &&L_OP_CALL, &&L_OP_TAILCALL, &&L_OP_RET, &&L_OP_LAMBDA, &&L_OP_CONS, &&L_OP_CAR, &&L_OP_CDR, &&L_OP_NILP, + &&L_OP_SYMBOL_P, &&L_OP_PAIR_P, &&L_OP_ADD, &&L_OP_SUB, &&L_OP_MUL, &&L_OP_DIV, &&L_OP_MINUS, &&L_OP_EQ, &&L_OP_LT, &&L_OP_LE, &&L_OP_STOP }; @@ -1035,6 +1036,20 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value args) NEXT; } + CASE(OP_SYMBOL_P) { + pic_value p; + p = POP(); + PUSH(pic_bool_value(pic_sym_p(p))); + NEXT; + } + + CASE(OP_PAIR_P) { + pic_value p; + p = POP(); + PUSH(pic_bool_value(pic_pair_p(p))); + NEXT; + } + #define DEFINE_ARITH_OP(opcode, op, guard) \ CASE(opcode) { \ pic_value a, b; \ diff --git a/write.c b/write.c index fb01addc..dde4b3a7 100644 --- a/write.c +++ b/write.c @@ -164,7 +164,7 @@ write_str(pic_state *pic, struct pic_string *str, xFILE *file) size_t i; const char *cstr = pic_str_cstr(str); - UNUSED(pic); + PIC_UNUSED(pic); for (i = 0; i < pic_strlen(str); ++i) { if (cstr[i] == '"' || cstr[i] == '\\') {