diff --git a/include/picrin.h b/include/picrin.h deleted file mode 100644 index e58d5a61..00000000 --- a/include/picrin.h +++ /dev/null @@ -1,223 +0,0 @@ -/** - * Copyright (c) 2013-2014 Yuichi Nishiwaki and other picrin contributors. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef PICRIN_H__ -#define PICRIN_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include "xvect/xvect.h" -#include "xhash/xhash.h" -#include "xfile/xfile.h" -#include "xrope/xrope.h" - -#include "picrin/config.h" -#include "picrin/util.h" -#include "picrin/value.h" - -typedef struct pic_code pic_code; - -typedef struct { - int argc, retc; - pic_code *ip; - pic_value *fp; - struct pic_env *env; - int regc; - pic_value *regs; - struct pic_env *up; -} pic_callinfo; - -typedef struct { - int argc; - char **argv, **envp; - - struct pic_block *blk; - - pic_value *sp; - pic_value *stbase, *stend; - - pic_callinfo *ci; - pic_callinfo *cibase, *ciend; - - pic_code *ip; - - struct pic_lib *lib; - - pic_sym sDEFINE, sLAMBDA, sIF, sBEGIN, sQUOTE, sSETBANG; - pic_sym sQUASIQUOTE, sUNQUOTE, sUNQUOTE_SPLICING; - pic_sym sDEFINE_SYNTAX, sIMPORT, sEXPORT; - pic_sym sDEFINE_LIBRARY, sIN_LIBRARY; - pic_sym sCONS, sCAR, sCDR, sNILP; - pic_sym sADD, sSUB, sMUL, sDIV, sMINUS; - pic_sym sEQ, sLT, sLE, sGT, sGE, sNOT; - - pic_sym rDEFINE, rLAMBDA, rIF, rBEGIN, rQUOTE, rSETBANG; - pic_sym rDEFINE_SYNTAX, rIMPORT, rEXPORT; - pic_sym rDEFINE_LIBRARY, rIN_LIBRARY; - - xhash syms; /* name to symbol */ - xhash sym_names; /* symbol to name */ - int sym_cnt; - int uniq_sym_cnt; - - xhash globals; - xhash macros; - pic_value libs; - - struct pic_reader *reader; - - jmp_buf *jmp; - struct pic_error *err; - struct pic_jmpbuf *try_jmps; - size_t try_jmp_size, try_jmp_idx; - - struct pic_heap *heap; - struct pic_object **arena; - size_t arena_size, arena_idx; - - char *native_stack_start; -} pic_state; - -typedef pic_value (*pic_func_t)(pic_state *); - -void *pic_alloc(pic_state *, size_t); -#define pic_malloc(pic,size) pic_alloc(pic,size) /* obsoleted */ -void *pic_realloc(pic_state *, void *, size_t); -void *pic_calloc(pic_state *, size_t, size_t); -struct pic_object *pic_obj_alloc(pic_state *, size_t, enum pic_tt); -struct pic_object *pic_obj_alloc_unsafe(pic_state *, size_t, enum pic_tt); -void pic_free(pic_state *, void *); - -void pic_gc_run(pic_state *); -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) -#define pic_void_(ai,exec) do { \ - size_t ai = pic_gc_arena_preserve(pic); \ - exec; \ - pic_gc_arena_restore(pic, ai); \ - } while (0) - -pic_state *pic_open(int argc, char *argv[], char **envp); -void pic_close(pic_state *); - -void pic_define(pic_state *, const char *, pic_value); /* automatic export */ -pic_value pic_ref(pic_state *, const char *); -void pic_set(pic_state *, const char *, pic_value); - -pic_value pic_funcall(pic_state *pic, const char *name, pic_list args); - -struct pic_proc *pic_get_proc(pic_state *); -int pic_get_args(pic_state *, const char *, ...); -void pic_defun(pic_state *, const char *, pic_func_t); - -bool pic_equal_p(pic_state *, pic_value, pic_value); - -pic_sym pic_intern(pic_state *, const char *, size_t); -pic_sym pic_intern_cstr(pic_state *, const char *); -const char *pic_symbol_name(pic_state *, pic_sym); -pic_sym pic_gensym(pic_state *, pic_sym); -pic_sym pic_ungensym(pic_state *, pic_sym); -bool pic_interned_p(pic_state *, pic_sym); - -char *pic_strdup(pic_state *, const char *); -char *pic_strndup(pic_state *, const char *, size_t); - -pic_value pic_read(pic_state *, struct pic_port *); -pic_value pic_read_cstr(pic_state *, const char *); -pic_list pic_parse_file(pic_state *, FILE *); /* #f for incomplete input */ -pic_list pic_parse_cstr(pic_state *, const char *); - -pic_value pic_load(pic_state *, const char *); -pic_value pic_load_cstr(pic_state *, const char *); - -pic_value pic_apply(pic_state *, struct pic_proc *, pic_value); -pic_value pic_apply0(pic_state *, struct pic_proc *); -pic_value pic_apply1(pic_state *, struct pic_proc *, pic_value); -pic_value pic_apply2(pic_state *, struct pic_proc *, pic_value, pic_value); -pic_value pic_apply3(pic_state *, struct pic_proc *, pic_value, pic_value, pic_value); -pic_value pic_apply4(pic_state *, struct pic_proc *, pic_value, pic_value, pic_value, pic_value); -pic_value pic_apply5(pic_state *, struct pic_proc *, pic_value, pic_value, pic_value, pic_value, pic_value); -pic_value pic_apply_trampoline(pic_state *, struct pic_proc *, pic_value); -pic_value pic_eval(pic_state *, pic_value, struct pic_lib *); -struct pic_proc *pic_compile(pic_state *, pic_value, struct pic_lib *); -pic_value pic_macroexpand(pic_state *, pic_value, struct pic_lib *); - -void pic_in_library(pic_state *, pic_value); -struct pic_lib *pic_make_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) -#define pic_deflibrary_helper__(pic, i, prev_lib, spec) \ - for (int i = 0; ! i; ) \ - for (struct pic_lib *prev_lib; ! i; ) \ - for ((prev_lib = pic->lib), pic_make_library(pic, pic_read_cstr(pic, spec)), pic_in_library(pic, pic_read_cstr(pic, spec)); ! i++; pic->lib = prev_lib) - -void pic_import(pic_state *, pic_value); -void pic_export(pic_state *, pic_sym); - -noreturn void pic_abort(pic_state *, const char *); -noreturn void pic_errorf(pic_state *, const char *, ...); -void pic_warnf(pic_state *, const char *, ...); -pic_str *pic_get_backtrace(pic_state *); -void pic_print_backtrace(pic_state *, struct pic_error *); - -/* obsoleted */ -noreturn static inline void pic_error(pic_state *pic, const char *msg) -{ - pic_errorf(pic, msg); -} -static inline void pic_warn(pic_state *pic, const char *msg) -{ - pic_warnf(pic, msg); -} - -const char *pic_errmsg(pic_state *); - -pic_value pic_write(pic_state *, pic_value); /* returns given obj */ -pic_value pic_fwrite(pic_state *, pic_value, xFILE *); -void pic_printf(pic_state *, const char *, ...); -pic_value pic_display(pic_state *, pic_value); -pic_value pic_fdisplay(pic_state *, pic_value, xFILE *); -/* obsoleted macros */ -#define pic_debug(pic,obj) pic_write(pic,obj) -#define pic_fdebug(pic,obj,file) pic_fwrite(pic,obj,file) - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/blob.h b/include/picrin/blob.h deleted file mode 100644 index f61f588d..00000000 --- a/include/picrin/blob.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_BLOB_H__ -#define PICRIN_BLOB_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_blob { - PIC_OBJECT_HEADER - char *data; - size_t len; -}; - -#define pic_blob_p(v) (pic_type(v) == PIC_TT_BLOB) -#define pic_blob_ptr(v) ((struct pic_blob *)pic_ptr(v)) - -struct pic_blob *pic_blob_new(pic_state *, size_t); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/config.h b/include/picrin/config.h deleted file mode 100644 index 79b8fc3c..00000000 --- a/include/picrin/config.h +++ /dev/null @@ -1,115 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -/** contribution libraries */ -/* #define PIC_CONTRIB_INITS */ - -/** switch normal VM and direct threaded VM */ -/* #define PIC_DIRECT_THREADED_VM 1 */ - -/** switch internal value representation */ -/* #define PIC_NAN_BOXING 1 */ - -/** enable readline module */ -/* #define PIC_ENABLE_READLINE 1 */ - -/** treat false value as none */ -/* #define PIC_NONE_IS_FALSE 1 */ - -/** initial memory size (to be dynamically extended if necessary) */ -/* #define PIC_ARENA_SIZE 1000 */ - -/* #define PIC_HEAP_PAGE_SIZE 10000 */ - -/* #define PIC_STACK_SIZE 1024 */ - -/* #define PIC_RESCUE_SIZE 30 */ - -/* #define PIC_SYM_POOL_SIZE 128 */ - -/* #define PIC_IREP_SIZE 8 */ - -/* #define PIC_POOL_SIZE 8 */ - -/* #define PIC_ISEQ_SIZE 1024 */ - -/** enable all debug flags */ -/* #define DEBUG 1 */ - -/** auxiliary debug flags */ -/* #define GC_STRESS 1 */ -/* #define VM_DEBUG 1 */ -/* #define GC_DEBUG 1 */ -/* #define GC_DEBUG_DETAIL 1 */ - -#if __STDC_VERSION__ < 199901L -# error please activate c99 features -#endif - -#ifndef PIC_CONTRIB_INITS -# define PIC_CONTRIB_INITS -#endif - -#ifndef PIC_DIRECT_THREADED_VM -# if defined(__GNUC__) || defined(__CLANG__) -# define PIC_DIRECT_THREADED_VM 1 -# endif -#endif - -#ifndef PIC_NAN_BOXING -# if __x86_64__ && __STDC_VERSION__ >= 201112L -# define PIC_NAN_BOXING 1 -# endif -#endif - -#ifndef PIC_ENABLE_READLINE -# if PIC_READLINE_FOUND -# define PIC_ENABLE_READLINE 1 -# else -# define PIC_ENABLE_READLINE 0 -# endif -#endif - -#ifndef PIC_NONE_IS_FALSE -# define PIC_NONE_IS_FALSE 1 -#endif - -#ifndef PIC_ARENA_SIZE -# define PIC_ARENA_SIZE 1000 -#endif - -#ifndef PIC_HEAP_PAGE_SIZE -# define PIC_HEAP_PAGE_SIZE 10000 -#endif - -#ifndef PIC_STACK_SIZE -# define PIC_STACK_SIZE 1024 -#endif - -#ifndef PIC_RESCUE_SIZE -# define PIC_RESCUE_SIZE 30 -#endif - -#ifndef PIC_SYM_POOL_SIZE -# define PIC_SYM_POOL_SIZE 128 -#endif - -#ifndef PIC_IREP_SIZE -# define PIC_IREP_SIZE 8 -#endif - -#ifndef PIC_POOL_SIZE -# define PIC_POOL_SIZE 8 -#endif - -#ifndef PIC_ISEQ_SIZE -# define PIC_ISEQ_SIZE 1024 -#endif - -#if DEBUG -# define GC_STRESS 0 -# define VM_DEBUG 1 -# define GC_DEBUG 0 -# define GC_DEBUG_DETAIL 0 -#endif diff --git a/include/picrin/cont.h b/include/picrin/cont.h deleted file mode 100644 index 0a0da9f1..00000000 --- a/include/picrin/cont.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_CONT_H__ -#define PICRIN_CONT_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_block { - PIC_OBJECT_HEADER - struct pic_block *prev; - int depth; - struct pic_proc *in, *out; -}; - -struct pic_cont { - PIC_OBJECT_HEADER - jmp_buf jmp; - - struct pic_block *blk; - - char *stk_pos, *stk_ptr; - ptrdiff_t stk_len; - - pic_value *st_ptr; - size_t sp_offset, st_len; - - pic_callinfo *ci_ptr; - size_t ci_offset, ci_len; - - pic_code *ip; - - struct pic_object **arena; - size_t arena_size; - int arena_idx; - - struct pic_jmpbuf *try_jmps; - size_t try_jmp_idx, try_jmp_size; - - pic_value results; -}; - -pic_value pic_values0(pic_state *); -pic_value pic_values1(pic_state *, pic_value); -pic_value pic_values2(pic_state *, pic_value, pic_value); -pic_value pic_values3(pic_state *, pic_value, pic_value, pic_value); -pic_value pic_values4(pic_state *, pic_value, pic_value, pic_value, pic_value); -pic_value pic_values5(pic_state *, pic_value, pic_value, pic_value, pic_value, pic_value); -pic_value pic_values_by_array(pic_state *, size_t, pic_value *); -pic_value pic_values_by_list(pic_state *, pic_value); -size_t pic_receive(pic_state *, size_t, pic_value *); - -pic_value pic_callcc(pic_state *, struct pic_proc *); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/data.h b/include/picrin/data.h deleted file mode 100644 index a80ff209..00000000 --- a/include/picrin/data.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_DATA_H__ -#define PICRIN_DATA_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -typedef struct { - const char *type_name; - void (*dtor)(pic_state *, void *); -} pic_data_type; - -struct pic_data { - PIC_OBJECT_HEADER; - const pic_data_type *type; - xhash storage; /* const char * to pic_value table */ - void *data; -}; - -#define pic_data_p(o) (pic_type(o) == PIC_TT_DATA) -#define pic_data_ptr(o) ((struct pic_data *)pic_ptr(o)) - -static inline bool pic_data_type_p(const pic_value obj, const pic_data_type *type) { - return pic_data_p(obj) && pic_data_ptr(obj)->type == type; -} - -struct pic_data *pic_data_alloc(pic_state *, const pic_data_type *, void *); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/dict.h b/include/picrin/dict.h deleted file mode 100644 index 8bc58ad8..00000000 --- a/include/picrin/dict.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_DICT_H__ -#define PICRIN_DICT_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_dict { - PIC_OBJECT_HEADER - xhash hash; -}; - -#define pic_dict_p(v) (pic_type(v) == PIC_TT_DICT) -#define pic_dict_ptr(v) ((struct pic_dict *)pic_ptr(v)) - -struct pic_dict *pic_dict_new(pic_state *); - -pic_value pic_dict_ref(pic_state *, struct pic_dict *, pic_sym); -void pic_dict_set(pic_state *, struct pic_dict *, pic_sym, pic_value); -void pic_dict_del(pic_state *, struct pic_dict *, pic_sym); -size_t pic_dict_size(pic_state *, struct pic_dict *); -bool pic_dict_has(pic_state *, struct pic_dict *, pic_sym); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/error.h b/include/picrin/error.h deleted file mode 100644 index bea590e2..00000000 --- a/include/picrin/error.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_ERROR_H__ -#define PICRIN_ERROR_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_jmpbuf { - jmp_buf here; - struct pic_proc *handler; - ptrdiff_t ci_offset; - ptrdiff_t sp_offset; - pic_code *ip; - jmp_buf *prev_jmp; -}; - -/* do not return from try block! */ - -#define pic_try \ - pic_try_with_handler(NULL) -#define pic_try_with_handler(handler) \ - pic_push_try(pic, handler); \ - if (setjmp(*pic->jmp) == 0) \ - do -#define pic_catch \ - while (pic_pop_try(pic), 0); \ - else \ - if (pic_pop_try(pic), 1) - -void pic_push_try(pic_state *, struct pic_proc *); -void pic_pop_try(pic_state *); - -noreturn void pic_throw(pic_state *, short, const char *, pic_value); -noreturn void pic_throw_error(pic_state *, struct pic_error *); - -struct pic_error { - PIC_OBJECT_HEADER - enum pic_error_kind { - PIC_ERROR_OTHER, - PIC_ERROR_FILE, - PIC_ERROR_READ, - PIC_ERROR_RAISED - } type; - struct pic_string *msg; - pic_value irrs; - pic_str *stack; -}; - -#define pic_error_p(v) (pic_type(v) == PIC_TT_ERROR) -#define pic_error_ptr(v) ((struct pic_error *)pic_ptr(v)) - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/gc.h b/include/picrin/gc.h deleted file mode 100644 index c5f33e6a..00000000 --- a/include/picrin/gc.h +++ /dev/null @@ -1,24 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_GC_H__ -#define PICRIN_GC_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -#define PIC_GC_UNMARK 0 -#define PIC_GC_MARK 1 - -struct pic_heap; - -struct pic_heap *pic_heap_open(); -void pic_heap_close(struct pic_heap *); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/irep.h b/include/picrin/irep.h deleted file mode 100644 index 4cb1cfba..00000000 --- a/include/picrin/irep.h +++ /dev/null @@ -1,206 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_IREP_H__ -#define PICRIN_IREP_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -enum pic_opcode { - OP_NOP, - OP_POP, - OP_PUSHNIL, - OP_PUSHTRUE, - OP_PUSHFALSE, - OP_PUSHINT, - OP_PUSHCHAR, - OP_PUSHCONST, - OP_GREF, - OP_GSET, - OP_LREF, - OP_LSET, - OP_CREF, - OP_CSET, - OP_JMP, - OP_JMPIF, - OP_NOT, - OP_CALL, - OP_TAILCALL, - OP_RET, - OP_LAMBDA, - OP_CONS, - OP_CAR, - OP_CDR, - OP_NILP, - OP_ADD, - OP_SUB, - OP_MUL, - OP_DIV, - OP_MINUS, - OP_EQ, - OP_LT, - OP_LE, - OP_STOP -}; - -struct pic_code { - enum pic_opcode insn; - union { - int i; - char c; - struct { - short depth; - short idx; - } r; - } u; -}; - -struct pic_irep { - PIC_OBJECT_HEADER - pic_sym name; - pic_code *code; - int argc, localc, capturec; - bool varg; - struct pic_irep **irep; - pic_value *pool; - size_t clen, ilen, plen; -}; - -pic_value pic_analyze(pic_state *, pic_value); -struct pic_irep *pic_codegen(pic_state *, pic_value); - -static inline void -pic_dump_code(pic_code c) -{ - printf("[%2d] ", c.insn); - switch (c.insn) { - case OP_NOP: - puts("OP_NOP"); - break; - case OP_POP: - puts("OP_POP"); - break; - case OP_PUSHNIL: - puts("OP_PUSHNIL"); - break; - case OP_PUSHTRUE: - puts("OP_PUSHTRUE"); - break; - case OP_PUSHFALSE: - puts("OP_PUSHFALSE"); - break; - case OP_PUSHINT: - printf("OP_PUSHINT\t%d\n", c.u.i); - break; - case OP_PUSHCHAR: - printf("OP_PUSHCHAR\t%c\n", c.u.c); - break; - case OP_PUSHCONST: - printf("OP_PUSHCONST\t%d\n", c.u.i); - break; - case OP_GREF: - printf("OP_GREF\t%i\n", c.u.i); - break; - case OP_GSET: - printf("OP_GSET\t%i\n", c.u.i); - break; - case OP_LREF: - printf("OP_LREF\t%d\n", c.u.i); - break; - case OP_LSET: - printf("OP_LSET\t%d\n", c.u.i); - break; - case OP_CREF: - printf("OP_CREF\t%d\t%d\n", c.u.r.depth, c.u.r.idx); - break; - case OP_CSET: - printf("OP_CSET\t%d\t%d\n", c.u.r.depth, c.u.r.idx); - break; - case OP_JMP: - printf("OP_JMP\t%x\n", c.u.i); - break; - case OP_JMPIF: - printf("OP_JMPIF\t%x\n", c.u.i); - break; - case OP_NOT: - puts("OP_NOT"); - break; - case OP_CALL: - printf("OP_CALL\t%d\n", c.u.i); - break; - case OP_TAILCALL: - printf("OP_TAILCALL\t%d\n", c.u.i); - break; - case OP_RET: - printf("OP_RET\t%d\n", c.u.i); - break; - case OP_LAMBDA: - printf("OP_LAMBDA\t%d\n", c.u.i); - break; - case OP_CONS: - puts("OP_CONS"); - break; - case OP_CAR: - puts("OP_CAR"); - break; - case OP_NILP: - puts("OP_NILP"); - break; - case OP_CDR: - puts("OP_CDR"); - break; - case OP_ADD: - puts("OP_ADD"); - break; - case OP_SUB: - puts("OP_SUB"); - break; - case OP_MUL: - puts("OP_MUL"); - break; - case OP_DIV: - puts("OP_DIV"); - break; - case OP_MINUS: - puts("OP_MINUS"); - break; - case OP_EQ: - puts("OP_EQ"); - break; - case OP_LT: - puts("OP_LT"); - break; - case OP_LE: - puts("OP_LE"); - break; - case OP_STOP: - puts("OP_STOP"); - break; - } -} - -static inline void -pic_dump_irep(struct pic_irep *irep) -{ - unsigned i; - - printf("## irep %p\n", (void *)irep); - printf("[clen = %zd, argc = %d, localc = %d, capturec = %d]\n", irep->clen, irep->argc, irep->localc, irep->capturec); - for (i = 0; i < irep->clen; ++i) { - printf("%02x ", i); - pic_dump_code(irep->code[i]); - } - - for (i = 0; i < irep->ilen; ++i) { - pic_dump_irep(irep->irep[i]); - } -} - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/lib.h b/include/picrin/lib.h deleted file mode 100644 index ba43e49d..00000000 --- a/include/picrin/lib.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_LIB_H__ -#define PICRIN_LIB_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_lib { - PIC_OBJECT_HEADER - pic_value name; - struct pic_senv *env; - xhash exports; -}; - -#define pic_lib_ptr(o) ((struct pic_lib *)pic_ptr(o)) - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/macro.h b/include/picrin/macro.h deleted file mode 100644 index d655a735..00000000 --- a/include/picrin/macro.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_MACRO_H__ -#define PICRIN_MACRO_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_senv { - PIC_OBJECT_HEADER - xhash map; - struct pic_senv *up; -}; - -struct pic_macro { - PIC_OBJECT_HEADER - struct pic_proc *proc; - struct pic_senv *senv; -}; - -#define pic_macro_p(v) (pic_type(v) == PIC_TT_MACRO) -#define pic_macro_ptr(v) ((struct pic_macro *)pic_ptr(v)) - -#define pic_senv_p(v) (pic_type(v) == PIC_TT_SENV) -#define pic_senv_ptr(v) ((struct pic_senv *)pic_ptr(v)) - -struct pic_senv *pic_null_syntactic_environment(pic_state *); - -bool pic_identifier_p(pic_state *pic, pic_value obj); -bool pic_identifier_eq_p(pic_state *, struct pic_senv *, pic_sym, struct pic_senv *, pic_sym); - -struct pic_senv *pic_senv_new(pic_state *, struct pic_senv *); - -pic_sym pic_add_rename(pic_state *, struct pic_senv *, pic_sym); -bool pic_find_rename(pic_state *, struct pic_senv *, pic_sym, pic_sym * /* = NULL */); -void pic_put_rename(pic_state *, struct pic_senv *, pic_sym, pic_sym); - -void pic_define_syntactic_keyword(pic_state *, struct pic_senv *, pic_sym, pic_sym); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/pair.h b/include/picrin/pair.h deleted file mode 100644 index 49de01cc..00000000 --- a/include/picrin/pair.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_PAIR_H__ -#define PICRIN_PAIR_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_pair { - PIC_OBJECT_HEADER - pic_value car; - pic_value cdr; -}; - -#define pic_pair_p(v) (pic_type(v) == PIC_TT_PAIR) -#define pic_pair_ptr(o) ((struct pic_pair *)pic_ptr(o)) - -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); -void pic_set_car(pic_state *, pic_value, pic_value); -void pic_set_cdr(pic_state *, pic_value, pic_value); - -bool pic_list_p(pic_value); -pic_value pic_list1(pic_state *, pic_value); -pic_value pic_list2(pic_state *, pic_value, pic_value); -pic_value pic_list3(pic_state *, pic_value, pic_value, pic_value); -pic_value pic_list4(pic_state *, pic_value, pic_value, pic_value, pic_value); -pic_value pic_list5(pic_state *, pic_value, pic_value, pic_value, pic_value, pic_value); -pic_value pic_list6(pic_state *, pic_value, pic_value, pic_value, pic_value, pic_value, pic_value); -pic_value pic_list7(pic_state *, pic_value, pic_value, pic_value, pic_value, pic_value, pic_value, pic_value); -pic_value pic_list_by_array(pic_state *, size_t, pic_value *); -pic_value pic_make_list(pic_state *, int, pic_value); - -#define pic_for_each(var, list) \ - pic_for_each_helper__(var, 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)) - -#define pic_push(pic, item, place) (place = pic_cons(pic, item, place)) -#define pic_pop(pic, place) (place = pic_cdr(pic, place)) - -int pic_length(pic_state *, pic_value); -pic_value pic_reverse(pic_state *, pic_value); -pic_value pic_append(pic_state *, pic_value, pic_value); - -pic_value pic_memq(pic_state *, pic_value key, pic_value list); -pic_value pic_memv(pic_state *, pic_value key, pic_value list); -pic_value pic_member(pic_state *, pic_value key, pic_value list, struct pic_proc * /* = NULL */); - -pic_value pic_assq(pic_state *, pic_value key, pic_value assoc); -pic_value pic_assv(pic_state *, pic_value key, pic_value assoc); -pic_value pic_assoc(pic_state *, pic_value key, pic_value assoc, struct pic_proc * /* = NULL */); - -pic_value pic_acons(pic_state *, pic_value key, pic_value val, pic_value assoc); - -pic_value pic_caar(pic_state *, pic_value); -pic_value pic_cadr(pic_state *, pic_value); -pic_value pic_cdar(pic_state *, pic_value); -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); -pic_value pic_list_copy(pic_state *, pic_value); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/port.h b/include/picrin/port.h deleted file mode 100644 index e51d8759..00000000 --- a/include/picrin/port.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_PORT_H__ -#define PICRIN_PORT_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -enum pic_port_flag { - PIC_PORT_IN = 1, - PIC_PORT_OUT = 2, - PIC_PORT_TEXT = 4, - PIC_PORT_BINARY = 8, -}; - -enum pic_port_status { - PIC_PORT_OPEN, - PIC_PORT_CLOSE, -}; - -struct pic_port { - PIC_OBJECT_HEADER - xFILE *file; - int flags; - int status; -}; - -#define pic_port_p(v) (pic_type(v) == PIC_TT_PORT) -#define pic_port_ptr(v) ((struct pic_port *)pic_ptr(v)) - -pic_value pic_eof_object(); - -struct pic_port *pic_stdin(pic_state *); -struct pic_port *pic_stdout(pic_state *); -struct pic_port *pic_stderr(pic_state *); - -struct pic_port *pic_open_input_string(pic_state *, const char *); -struct pic_port *pic_open_output_string(pic_state *); -struct pic_string *pic_get_output_string(pic_state *, struct pic_port *); - -void pic_close_port(pic_state *pic, struct pic_port *); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/proc.h b/include/picrin/proc.h deleted file mode 100644 index b91960de..00000000 --- a/include/picrin/proc.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_PROC_H__ -#define PICRIN_PROC_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -/* native C function */ -struct pic_func { - pic_func_t f; - pic_sym name; -}; - -struct pic_env { - PIC_OBJECT_HEADER - pic_value *regs; - int regc; - struct pic_env *up; - pic_value storage[]; -}; - -struct pic_proc { - PIC_OBJECT_HEADER - char kind; - union { - struct pic_func func; - struct pic_irep *irep; - } u; - struct pic_env *env; - struct pic_dict *attr; -}; - -#define PIC_PROC_KIND_FUNC 1 -#define PIC_PROC_KIND_IREP 2 - -#define pic_proc_func_p(proc) ((proc)->kind == PIC_PROC_KIND_FUNC) -#define pic_proc_irep_p(proc) ((proc)->kind == PIC_PROC_KIND_IREP) - -#define pic_proc_p(o) (pic_type(o) == PIC_TT_PROC) -#define pic_proc_ptr(o) ((struct pic_proc *)pic_ptr(o)) - -#define pic_env_p(o) (pic_type(o) == PIC_TT_ENV) -#define pic_env_ptr(o) ((struct pic_env *)pic_ptr(o)) - -struct pic_proc *pic_proc_new(pic_state *, pic_func_t, const char *); -struct pic_proc *pic_proc_new_irep(pic_state *, struct pic_irep *, struct pic_env *); - -pic_sym pic_proc_name(struct pic_proc *); - -struct pic_dict *pic_attr(pic_state *, struct pic_proc *); -pic_value pic_attr_ref(pic_state *, struct pic_proc *, const char *); -void pic_attr_set(pic_state *, struct pic_proc *, const char *, pic_value); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/read.h b/include/picrin/read.h deleted file mode 100644 index 8b977d58..00000000 --- a/include/picrin/read.h +++ /dev/null @@ -1,39 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_READ_H__ -#define PICRIN_READ_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -enum pic_typecase { - PIC_CASE_DEFAULT, - PIC_CASE_FOLD, -}; - -struct pic_trie { - struct pic_trie *table[256]; - struct pic_proc *proc; -}; - -struct pic_reader { - short typecase; - xhash labels; - struct pic_trie *trie; -}; - -void pic_init_reader(pic_state *); - -void pic_define_reader(pic_state *, const char *, pic_func_t); - -struct pic_trie *pic_trie_new(pic_state *); -void pic_trie_delete(pic_state *, struct pic_trie *); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/record.h b/include/picrin/record.h deleted file mode 100644 index bf8698f1..00000000 --- a/include/picrin/record.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_RECORD_H -#define PICRIN_RECORD_H - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_record { - PIC_OBJECT_HEADER - xhash hash; -}; - -#define pic_record_p(v) (pic_type(v) == PIC_TT_RECORD) -#define pic_record_ptr(v) ((struct pic_record *)pic_ptr(v)) - -struct pic_record *pic_record_new(pic_state *, pic_value); - -pic_value pic_record_type(pic_state *, struct pic_record *); -pic_value pic_record_ref(pic_state *, struct pic_record *, pic_sym); -void pic_record_set(pic_state *, struct pic_record *, pic_sym, pic_value); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/string.h b/include/picrin/string.h deleted file mode 100644 index c2564ffe..00000000 --- a/include/picrin/string.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_STRING_H__ -#define PICRIN_STRING_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_string { - PIC_OBJECT_HEADER - xrope *rope; -}; - -#define pic_str_p(v) (pic_type(v) == PIC_TT_STRING) -#define pic_str_ptr(o) ((struct pic_string *)pic_ptr(o)) - -pic_str *pic_str_new(pic_state *, const char * /* nullable */, size_t); -pic_str *pic_str_new_cstr(pic_state *, const char *); -pic_str *pic_str_new_fill(pic_state *, size_t, char); - -size_t pic_strlen(pic_str *); -char pic_str_ref(pic_state *, pic_str *, size_t); -void pic_str_set(pic_state *, pic_str *, size_t, char); - -pic_str *pic_strcat(pic_state *, pic_str *, pic_str *); -pic_str *pic_substr(pic_state *, pic_str *, size_t, size_t); -int pic_strcmp(pic_str *, pic_str *); - -const char *pic_str_cstr(pic_str *); - -pic_value pic_format(pic_state *, const char *, ...); -pic_value pic_vformat(pic_state *, const char *, va_list); -pic_value pic_vfformat(pic_state *, xFILE *, const char *, va_list); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/util.h b/include/picrin/util.h deleted file mode 100644 index f2f5e719..00000000 --- a/include/picrin/util.h +++ /dev/null @@ -1,51 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_UTIL_H__ -#define PICRIN_UTIL_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -#if __STDC_VERSION__ >= 201112L -# include -#elif __GNUC__ || __clang__ -# define noreturn __attribute__((noreturn)) -#else -# define noreturn -#endif - -#define FALLTHROUGH ((void)0) -#define UNUSED(v) ((void)(v)) - -#define GENSYM2__(x,y) G##x##_##y##__ -#define GENSYM1__(x,y) GENSYM2__(x,y) -#if defined(__COUNTER__) -# define GENSYM(x) GENSYM1__(__COUNTER__,x) -#else -# define GENSYM(x) GENSYM1__(__LINE__,x) -#endif - -#if GCC_VERSION >= 40500 || __clang__ -# define UNREACHABLE() (__builtin_unreachable()) -#else -# include -# define UNREACHABLE() (assert(false)) -#endif - -#define SWAP(type,a,b) \ - SWAP_HELPER__(type,GENSYM(tmp),a,b) -#define SWAP_HELPER__(type,tmp,a,b) \ - do { \ - type tmp = (a); \ - (a) = (b); \ - (b) = tmp; \ - } while (0) - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/value.h b/include/picrin/value.h deleted file mode 100644 index 6137c2eb..00000000 --- a/include/picrin/value.h +++ /dev/null @@ -1,484 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_VALUE_H__ -#define PICRIN_VALUE_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -/** - * pic_sym is just an alias to unsigned int. - */ - -typedef int pic_sym; - -/** - * `undef` values never seen from user-end: that is, - * it's used only for repsenting internal special state - */ - -enum pic_vtype { - PIC_VTYPE_NIL = 1, - PIC_VTYPE_TRUE, - PIC_VTYPE_FALSE, - PIC_VTYPE_UNDEF, - PIC_VTYPE_FLOAT, - PIC_VTYPE_INT, - PIC_VTYPE_SYMBOL, - PIC_VTYPE_CHAR, - PIC_VTYPE_EOF, - PIC_VTYPE_HEAP -}; - -#if PIC_NAN_BOXING - -/** - * value representation by nan-boxing: - * float : FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF - * ptr : 111111111111TTTT PPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP - * int : 1111111111110110 0000000000000000 IIIIIIIIIIIIIIII IIIIIIIIIIIIIIII - * sym : 1111111111110111 0000000000000000 SSSSSSSSSSSSSSSS SSSSSSSSSSSSSSSS - * char : 1111111111111000 0000000000000000 CCCCCCCCCCCCCCCC ................ - */ - -typedef struct { - union { - void *data; - double f; - struct { - union { - int i; - pic_sym sym; - char c; - }; - uint32_t type_; - }; - } u; -} pic_value; - -#define pic_ptr(v) ((void *)((uint64_t)0xffffffffffff & (uint64_t)(v).u.data)) -#define pic_init_value(v,vtype) (((v).u.type_ = (((uint32_t)0xfff00000)|((uint32_t)((vtype)<<16)))), (v).u.i = 0) - -static inline enum pic_vtype -pic_vtype(pic_value v) -{ - return 0xfff00000 >= v.u.type_ - ? PIC_VTYPE_FLOAT - : (v.u.type_ & 0xf0000)>>16; -} - -#else - -typedef struct { - enum pic_vtype type; - union { - void *data; - double f; - int i; - pic_sym sym; - char c; - } u; -} pic_value; - -#define pic_ptr(v) ((v).u.data) -#define pic_vtype(v) ((v).type) -#define pic_init_value(v,vtype) ((v).type = (vtype), (v).u.data = NULL) - -#endif - -enum pic_tt { - /* immediate */ - PIC_TT_NIL, - PIC_TT_BOOL, - PIC_TT_FLOAT, - PIC_TT_INT, - PIC_TT_SYMBOL, - PIC_TT_CHAR, - PIC_TT_EOF, - PIC_TT_UNDEF, - /* heap */ - PIC_TT_PAIR, - PIC_TT_STRING, - PIC_TT_VECTOR, - PIC_TT_BLOB, - PIC_TT_PROC, - PIC_TT_PORT, - PIC_TT_ERROR, - PIC_TT_ENV, - PIC_TT_CONT, - PIC_TT_SENV, - PIC_TT_MACRO, - PIC_TT_LIB, - PIC_TT_VAR, - PIC_TT_IREP, - PIC_TT_DATA, - PIC_TT_DICT, - PIC_TT_RECORD, - PIC_TT_BLK, -}; - -#define PIC_OBJECT_HEADER \ - enum pic_tt tt; - -struct pic_object { - PIC_OBJECT_HEADER -}; - -struct pic_pair; -struct pic_string; -struct pic_vector; -struct pic_blob; - -struct pic_proc; -struct pic_port; - -/* set aliases to basic types */ -typedef pic_value pic_list; -typedef struct pic_pair pic_pair; -typedef struct pic_string pic_str; -typedef struct pic_vector pic_vec; -typedef struct pic_blob pic_blob; - -#define pic_float(v) ((v).u.f) -#define pic_int(v) ((v).u.i) -#define pic_sym(v) ((v).u.sym) -#define pic_char(v) ((v).u.c) - -#define pic_obj_p(v) (pic_vtype(v) == PIC_VTYPE_HEAP) -#define pic_obj_ptr(v) ((struct pic_object *)pic_ptr(v)) - -#define pic_nil_p(v) (pic_vtype(v) == PIC_VTYPE_NIL) -#define pic_true_p(v) (pic_vtype(v) == PIC_VTYPE_TRUE) -#define pic_false_p(v) (pic_vtype(v) == PIC_VTYPE_FALSE) -#define pic_undef_p(v) (pic_vtype(v) == PIC_VTYPE_UNDEF) -#define pic_float_p(v) (pic_vtype(v) == PIC_VTYPE_FLOAT) -#define pic_int_p(v) (pic_vtype(v) == PIC_VTYPE_INT) -#define pic_sym_p(v) (pic_vtype(v) == PIC_VTYPE_SYMBOL) -#define pic_char_p(v) (pic_vtype(v) == PIC_VTYPE_CHAR) -#define pic_eof_p(v) (pic_vtype(v) == PIC_VTYPE_EOF) - -#define pic_test(v) (! pic_false_p(v)) - -static inline enum pic_tt pic_type(pic_value); -static inline const char *pic_type_repr(enum pic_tt); - -#define pic_assert_type(pic, v, type) \ - if (! pic_##type##_p(v)) { \ - pic_errorf(pic, "expected " #type ", but got ~s", v); \ - } - -static inline bool pic_valid_int(double); - -static inline pic_value pic_nil_value(); -static inline pic_value pic_true_value(); -static inline pic_value pic_false_value(); -static inline pic_value pic_bool_value(bool); -static inline pic_value pic_undef_value(); -static inline pic_value pic_obj_value(void *); -static inline pic_value pic_float_value(double); -static inline pic_value pic_int_value(int); -static inline pic_value pic_sym_value(pic_sym); -static inline pic_value pic_char_value(char c); -static inline pic_value pic_none_value(); - -#define pic_symbol_value(sym) pic_sym_value(sym) - -static inline bool pic_eq_p(pic_value, pic_value); -static inline bool pic_eqv_p(pic_value, pic_value); - -static inline enum pic_tt -pic_type(pic_value v) -{ - switch (pic_vtype(v)) { - case PIC_VTYPE_NIL: - return PIC_TT_NIL; - case PIC_VTYPE_TRUE: - return PIC_TT_BOOL; - case PIC_VTYPE_FALSE: - return PIC_TT_BOOL; - case PIC_VTYPE_UNDEF: - return PIC_TT_UNDEF; - case PIC_VTYPE_FLOAT: - return PIC_TT_FLOAT; - case PIC_VTYPE_INT: - return PIC_TT_INT; - case PIC_VTYPE_SYMBOL: - return PIC_TT_SYMBOL; - case PIC_VTYPE_CHAR: - return PIC_TT_CHAR; - case PIC_VTYPE_EOF: - return PIC_TT_EOF; - case PIC_VTYPE_HEAP: - return ((struct pic_object *)pic_ptr(v))->tt; - default: - return -1; /* logic flaw */ - } -} - -static inline const char * -pic_type_repr(enum pic_tt tt) -{ - switch (tt) { - case PIC_TT_NIL: - return "nil"; - case PIC_TT_BOOL: - return "boolean"; - case PIC_TT_FLOAT: - return "float"; - case PIC_TT_INT: - return "int"; - case PIC_TT_SYMBOL: - return "symbol"; - case PIC_TT_CHAR: - return "char"; - case PIC_TT_EOF: - return "eof"; - case PIC_TT_UNDEF: - return "undef"; - case PIC_TT_PAIR: - return "pair"; - case PIC_TT_STRING: - return "string"; - case PIC_TT_VECTOR: - return "vector"; - case PIC_TT_BLOB: - return "blob"; - case PIC_TT_PORT: - return "port"; - case PIC_TT_ERROR: - return "error"; - case PIC_TT_ENV: - return "env"; - case PIC_TT_CONT: - return "cont"; - case PIC_TT_PROC: - return "proc"; - case PIC_TT_SENV: - return "senv"; - case PIC_TT_MACRO: - return "macro"; - case PIC_TT_LIB: - return "lib"; - case PIC_TT_VAR: - return "var"; - case PIC_TT_IREP: - return "irep"; - case PIC_TT_DATA: - return "data"; - case PIC_TT_DICT: - return "dict"; - case PIC_TT_RECORD: - return "record"; - case PIC_TT_BLK: - return "block"; - } - UNREACHABLE(); -} - -static inline bool -pic_valid_int(double v) -{ - return INT_MIN <= v && v <= INT_MAX; -} - -static inline pic_value -pic_nil_value() -{ - pic_value v; - - pic_init_value(v, PIC_VTYPE_NIL); - return v; -} - -static inline pic_value -pic_true_value() -{ - pic_value v; - - pic_init_value(v, PIC_VTYPE_TRUE); - return v; -} - -static inline pic_value -pic_false_value() -{ - pic_value v; - - pic_init_value(v, PIC_VTYPE_FALSE); - return v; -} - -static inline pic_value -pic_bool_value(bool b) -{ - pic_value v; - - pic_init_value(v, b ? PIC_VTYPE_TRUE : PIC_VTYPE_FALSE); - return v; -} - -#if PIC_NAN_BOXING - -static inline pic_value -pic_obj_value(void *ptr) -{ - pic_value v; - - pic_init_value(v, PIC_VTYPE_HEAP); - v.u.data = (void*)((long long)v.u.data | ((long long)ptr)); - return v; -} - -static inline pic_value -pic_float_value(double f) -{ - pic_value v; - - if (f != f) { - v.u.type_ = 0x7ff80000; - v.u.i = 0; - } else { - v.u.f = f; - } - return v; -} - -#else - -static inline pic_value -pic_obj_value(void *ptr) -{ - pic_value v; - - pic_init_value(v, PIC_VTYPE_HEAP); - v.u.data = ptr; - return v; -} - -static inline pic_value -pic_float_value(double f) -{ - pic_value v; - - pic_init_value(v, PIC_VTYPE_FLOAT); - v.u.f = f; - return v; -} - -#endif - -static inline pic_value -pic_int_value(int i) -{ - pic_value v; - - pic_init_value(v, PIC_VTYPE_INT); - v.u.i = i; - return v; -} - -static inline pic_value -pic_symbol_value(pic_sym sym) -{ - pic_value v; - - pic_init_value(v, PIC_VTYPE_SYMBOL); - v.u.sym = sym; - return v; -} - -static inline pic_value -pic_char_value(char c) -{ - pic_value v; - - pic_init_value(v, PIC_VTYPE_CHAR); - v.u.c = c; - return v; -} - -static inline pic_value -pic_undef_value() -{ - pic_value v; - - pic_init_value(v, PIC_VTYPE_UNDEF); - return v; -} - -static inline pic_value -pic_none_value() -{ -#if PIC_NONE_IS_FALSE - return pic_false_value(); -#else -# error enable PIC_NONE_IS_FALSE -#endif -} - -#if PIC_NAN_BOXING - -static inline bool -pic_eq_p(pic_value x, pic_value y) -{ - return x.u.data == y.u.data; -} - -static inline bool -pic_eqv_p(pic_value x, pic_value y) -{ - return x.u.data == y.u.data; -} - -#else - -static inline bool -pic_eq_p(pic_value x, pic_value y) -{ - if (pic_type(x) != pic_type(y)) - return false; - - switch (pic_type(x)) { - case PIC_TT_NIL: - return true; - case PIC_TT_BOOL: - return pic_vtype(x) == pic_vtype(y); - case PIC_TT_SYMBOL: - return pic_sym(x) == pic_sym(y); - default: - return pic_ptr(x) == pic_ptr(y); - } -} - -static inline bool -pic_eqv_p(pic_value x, pic_value y) -{ - if (pic_type(x) != pic_type(y)) - return false; - - switch (pic_type(x)) { - case PIC_TT_NIL: - return true; - case PIC_TT_BOOL: - return pic_vtype(x) == pic_vtype(y); - case PIC_TT_SYMBOL: - return pic_sym(x) == pic_sym(y); - case PIC_TT_FLOAT: - return pic_float(x) == pic_float(y); - case PIC_TT_INT: - return pic_int(x) == pic_int(y); - default: - return pic_ptr(x) == pic_ptr(y); - } -} - -#endif - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/var.h b/include/picrin/var.h deleted file mode 100644 index d3bbaf4e..00000000 --- a/include/picrin/var.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_VAR_H__ -#define PICRIN_VAR_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_var { - PIC_OBJECT_HEADER - pic_value stack; - struct pic_proc *conv; -}; - -#define pic_var_p(o) (pic_type(o) == PIC_TT_VAR) -#define pic_var_ptr(o) ((struct pic_var *)pic_ptr(o)) - -struct pic_var *pic_var_new(pic_state *, pic_value, struct pic_proc * /* = NULL */); - -pic_value pic_var_ref(pic_state *, struct pic_var *); -void pic_var_set(pic_state *, struct pic_var *, pic_value); -void pic_var_push(pic_state *, struct pic_var *, pic_value); -void pic_var_pop(pic_state *, struct pic_var *); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/include/picrin/vector.h b/include/picrin/vector.h deleted file mode 100644 index 80a4cb73..00000000 --- a/include/picrin/vector.h +++ /dev/null @@ -1,29 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_VECTOR_H__ -#define PICRIN_VECTOR_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -struct pic_vector { - PIC_OBJECT_HEADER - pic_value *data; - size_t len; -}; - -#define pic_vec_p(v) (pic_type(v) == PIC_TT_VECTOR) -#define pic_vec_ptr(o) ((struct pic_vector *)pic_ptr(o)) - -struct pic_vector *pic_vec_new(pic_state *, size_t); -struct pic_vector *pic_vec_new_from_list(pic_state *, pic_value); -void pic_vec_extend_ip(pic_state *, struct pic_vector *, size_t); - -#if defined(__cplusplus) -} -#endif - -#endif