2013-10-10 03:15:41 -04:00
|
|
|
#ifndef PICRIN_H__
|
|
|
|
#define PICRIN_H__
|
|
|
|
|
2013-10-10 04:54:35 -04:00
|
|
|
#include <stddef.h>
|
2013-10-11 04:36:51 -04:00
|
|
|
#include <stdbool.h>
|
2013-10-20 05:17:12 -04:00
|
|
|
#include <setjmp.h>
|
2013-10-27 05:38:41 -04:00
|
|
|
#include <stdio.h>
|
2013-10-10 04:54:35 -04:00
|
|
|
|
2013-11-15 02:48:02 -05:00
|
|
|
#include "config.h"
|
2013-10-10 03:34:24 -04:00
|
|
|
#include "picrin/value.h"
|
|
|
|
|
2013-10-16 02:30:52 -04:00
|
|
|
struct pic_code;
|
|
|
|
|
2013-11-04 16:07:36 -05:00
|
|
|
typedef struct {
|
2013-10-15 10:29:34 -04:00
|
|
|
int argc;
|
2013-10-16 02:30:52 -04:00
|
|
|
struct pic_code *pc;
|
2013-10-23 02:55:42 -04:00
|
|
|
pic_value *fp;
|
2013-10-28 21:16:56 -04:00
|
|
|
struct pic_env *env;
|
2013-10-15 10:29:34 -04:00
|
|
|
} pic_callinfo;
|
|
|
|
|
2013-11-11 04:04:21 -05:00
|
|
|
struct pic_block {
|
|
|
|
struct pic_block *prev;
|
|
|
|
int depth;
|
|
|
|
struct pic_proc *in, *out;
|
2013-11-14 21:51:58 -05:00
|
|
|
unsigned refcnt;
|
2013-11-11 04:04:21 -05:00
|
|
|
};
|
|
|
|
|
2013-10-10 03:15:41 -04:00
|
|
|
typedef struct {
|
2013-10-20 22:51:02 -04:00
|
|
|
int argc;
|
|
|
|
char **argv, **envp;
|
|
|
|
|
2013-11-11 04:04:21 -05:00
|
|
|
struct pic_block *blk;
|
|
|
|
|
2013-10-11 11:16:19 -04:00
|
|
|
pic_value *sp;
|
2013-10-11 11:20:53 -04:00
|
|
|
pic_value *stbase, *stend;
|
|
|
|
|
2013-10-15 10:29:34 -04:00
|
|
|
pic_callinfo *ci;
|
|
|
|
pic_callinfo *cibase, *ciend;
|
|
|
|
|
2013-11-17 02:02:58 -05:00
|
|
|
struct pic_proc **rescue;
|
|
|
|
size_t ridx, rlen;
|
|
|
|
|
2013-10-28 13:11:31 -04:00
|
|
|
pic_sym sDEFINE, sLAMBDA, sIF, sBEGIN, sQUOTE, sSETBANG;
|
|
|
|
pic_sym sQUASIQUOTE, sUNQUOTE, sUNQUOTE_SPLICING;
|
2013-10-30 03:37:43 -04:00
|
|
|
pic_sym sDEFINE_SYNTAX, sDEFINE_MACRO;
|
2013-12-07 05:31:04 -05:00
|
|
|
pic_sym sDEFINE_LIBRARY, sIMPORT, sEXPORT;
|
2013-10-28 13:11:31 -04:00
|
|
|
pic_sym sCONS, sCAR, sCDR, sNILP;
|
|
|
|
pic_sym sADD, sSUB, sMUL, sDIV;
|
|
|
|
pic_sym sEQ, sLT, sLE, sGT, sGE;
|
2013-10-13 02:14:15 -04:00
|
|
|
|
2013-10-28 13:11:31 -04:00
|
|
|
struct xhash *sym_tbl;
|
|
|
|
const char **sym_pool;
|
|
|
|
size_t slen, scapa;
|
2013-11-26 02:38:39 -05:00
|
|
|
int uniq_sym_count;
|
2013-10-20 01:05:35 -04:00
|
|
|
|
2013-10-22 09:22:35 -04:00
|
|
|
struct xhash *global_tbl;
|
2013-10-17 11:15:15 -04:00
|
|
|
pic_value *globals;
|
|
|
|
size_t glen, gcapa;
|
2013-10-22 09:22:35 -04:00
|
|
|
|
2013-12-07 08:36:14 -05:00
|
|
|
pic_value lib_tbl;
|
|
|
|
struct pic_lib *lib;
|
2013-11-26 11:30:30 -05:00
|
|
|
|
2013-10-15 22:53:25 -04:00
|
|
|
struct pic_irep **irep;
|
|
|
|
size_t ilen, icapa;
|
2013-10-20 20:29:56 -04:00
|
|
|
pic_value *pool;
|
|
|
|
size_t plen, pcapa;
|
2013-10-15 22:53:25 -04:00
|
|
|
|
2013-10-20 05:17:12 -04:00
|
|
|
jmp_buf *jmp;
|
|
|
|
const char *errmsg;
|
|
|
|
|
2013-11-22 10:19:31 -05:00
|
|
|
struct pic_heap *heap;
|
2013-10-13 04:02:29 -04:00
|
|
|
struct pic_object *arena[PIC_ARENA_SIZE];
|
|
|
|
int arena_idx;
|
2013-11-09 00:14:25 -05:00
|
|
|
|
|
|
|
pic_value *native_stack_start;
|
2013-10-10 03:15:41 -04:00
|
|
|
} pic_state;
|
|
|
|
|
2013-10-15 06:19:34 -04:00
|
|
|
typedef pic_value (*pic_func_t)(pic_state *);
|
|
|
|
|
2013-11-13 03:37:05 -05:00
|
|
|
enum pic_parser_res {
|
|
|
|
PIC_PARSER_INCOMPLETE = -1,
|
|
|
|
PIC_PARSER_ERROR = -2
|
|
|
|
/* if parser is successfully done, return the number of exprs (>= 0) */
|
|
|
|
};
|
|
|
|
|
2013-10-10 03:44:51 -04:00
|
|
|
void *pic_alloc(pic_state *, size_t);
|
2013-10-15 22:21:41 -04:00
|
|
|
void *pic_realloc(pic_state *, void *, size_t);
|
2013-11-30 22:44:43 -05:00
|
|
|
void *pic_calloc(pic_state *, size_t, size_t);
|
2013-10-13 03:55:07 -04:00
|
|
|
struct pic_object *pic_obj_alloc(pic_state *, size_t, enum pic_tt);
|
2013-11-15 05:30:53 -05:00
|
|
|
struct pic_object *pic_obj_alloc_unsafe(pic_state *, size_t, enum pic_tt);
|
2013-10-10 03:44:51 -04:00
|
|
|
void pic_free(pic_state *, void *);
|
|
|
|
|
2013-10-13 04:25:36 -04:00
|
|
|
void pic_gc_protect(pic_state *, pic_value);
|
|
|
|
int pic_gc_arena_preserve(pic_state *);
|
|
|
|
void pic_gc_arena_restore(pic_state *, int);
|
|
|
|
|
2013-10-20 22:51:02 -04:00
|
|
|
pic_state *pic_open(int argc, char *argv[], char **envp);
|
2013-10-10 03:19:10 -04:00
|
|
|
void pic_close(pic_state *);
|
2013-10-10 03:15:41 -04:00
|
|
|
|
2013-11-09 00:12:59 -05:00
|
|
|
struct pic_proc *pic_get_proc(pic_state *);
|
2013-10-21 00:57:02 -04:00
|
|
|
int pic_get_args(pic_state *, const char *, ...);
|
2013-10-15 06:19:34 -04:00
|
|
|
void pic_defun(pic_state *, const char *, pic_func_t);
|
2013-11-26 12:09:15 -05:00
|
|
|
void pic_defmacro(pic_state *, const char *, struct pic_proc *);
|
2013-10-15 06:19:34 -04:00
|
|
|
|
2013-12-07 09:29:29 -05:00
|
|
|
bool pic_equal_p(pic_state *, pic_value, pic_value);
|
|
|
|
|
2013-10-28 13:11:31 -04:00
|
|
|
pic_sym pic_intern_cstr(pic_state *, const char *);
|
|
|
|
const char *pic_symbol_name(pic_state *, pic_sym);
|
2013-10-10 04:06:26 -04:00
|
|
|
|
2013-11-17 10:28:42 -05:00
|
|
|
struct pic_string *pic_str_new(pic_state *, const char *, size_t);
|
|
|
|
struct pic_string *pic_str_new_cstr(pic_state *, const char *);
|
2013-10-20 21:48:03 -04:00
|
|
|
|
2013-10-29 02:51:37 -04:00
|
|
|
struct pic_vector *pic_vec_new(pic_state *, size_t);
|
|
|
|
struct pic_vector *pic_vec_new_from_list(pic_state *, pic_value);
|
2013-11-15 05:30:25 -05:00
|
|
|
void pic_vec_extend_ip(pic_state *, struct pic_vector *, int);
|
2013-10-29 02:51:37 -04:00
|
|
|
|
2013-10-30 04:06:01 -04:00
|
|
|
int pic_parse_file(pic_state *, FILE *file, pic_value *);
|
|
|
|
int pic_parse_cstr(pic_state *, const char *, pic_value *);
|
2013-12-07 21:38:47 -05:00
|
|
|
pic_value pic_parse(pic_state *, const char *);
|
2013-10-11 02:18:37 -04:00
|
|
|
|
2013-10-28 04:45:13 -04:00
|
|
|
pic_value pic_apply(pic_state *pic, struct pic_proc *, pic_value);
|
|
|
|
pic_value pic_apply_argv(pic_state *pic, struct pic_proc *, size_t, ...);
|
2013-10-22 09:22:35 -04:00
|
|
|
struct pic_proc *pic_codegen(pic_state *, pic_value);
|
2013-11-18 02:36:44 -05:00
|
|
|
pic_value pic_macroexpand(pic_state *, pic_value);
|
2013-10-11 04:36:51 -04:00
|
|
|
|
2013-12-07 21:27:08 -05:00
|
|
|
void pic_in_library(pic_state *, pic_value);
|
2013-12-07 21:44:14 -05:00
|
|
|
struct pic_lib *pic_make_library(pic_state *, pic_value);
|
2013-12-07 12:42:34 -05:00
|
|
|
struct pic_lib *pic_find_library(pic_state *, pic_value);
|
2013-12-07 10:05:06 -05:00
|
|
|
|
2013-12-08 02:17:28 -05:00
|
|
|
#define DEFLIBRARY(pic,name) \
|
|
|
|
{ \
|
|
|
|
struct pic_lib *lib__ = pic->lib; \
|
|
|
|
pic_make_library(pic, pic_parse(pic, name)); \
|
|
|
|
pic_in_library(pic, pic_parse(pic, name));
|
|
|
|
#define ENDLIBRARY(pic) \
|
|
|
|
pic->lib = lib__; \
|
|
|
|
}
|
|
|
|
|
2013-12-07 23:44:39 -05:00
|
|
|
void pic_export(pic_state *, pic_sym);
|
|
|
|
void pic_export_as(pic_state *, pic_sym, pic_sym);
|
|
|
|
|
2013-10-20 04:41:48 -04:00
|
|
|
void pic_abort(pic_state *, const char *);
|
|
|
|
void pic_raise(pic_state *, pic_value);
|
2013-10-20 05:17:12 -04:00
|
|
|
void pic_error(pic_state *, const char *);
|
2013-11-17 03:23:13 -05:00
|
|
|
void pic_errorf(pic_state *, const char *, size_t, ...);
|
2013-10-24 09:29:40 -04:00
|
|
|
void pic_warn(pic_state *, const char *);
|
2013-10-12 01:40:27 -04:00
|
|
|
|
2013-10-10 04:48:01 -04:00
|
|
|
void pic_debug(pic_state *, pic_value);
|
|
|
|
|
2013-10-10 03:15:41 -04:00
|
|
|
#endif
|