reorganize files
This commit is contained in:
parent
39b6103548
commit
b58a81ca39
18
Makefile
18
Makefile
|
@ -8,15 +8,11 @@ LIBPICRIN_SRCS = \
|
|||
lib/debug.c\
|
||||
lib/dict.c\
|
||||
lib/error.c\
|
||||
lib/eval.c\
|
||||
lib/gc.c\
|
||||
lib/lib.c\
|
||||
lib/load.c\
|
||||
lib/number.c\
|
||||
lib/pair.c\
|
||||
lib/port.c\
|
||||
lib/proc.c\
|
||||
lib/read.c\
|
||||
lib/record.c\
|
||||
lib/state.c\
|
||||
lib/string.c\
|
||||
|
@ -25,7 +21,11 @@ LIBPICRIN_SRCS = \
|
|||
lib/var.c\
|
||||
lib/vector.c\
|
||||
lib/weak.c\
|
||||
lib/write.c
|
||||
lib/ext/eval.c\
|
||||
lib/ext/lib.c\
|
||||
lib/ext/load.c\
|
||||
lib/ext/read.c\
|
||||
lib/ext/write.c
|
||||
LIBPICRIN_OBJS = $(LIBPICRIN_SRCS:.c=.o)
|
||||
|
||||
PICRIN_SRCS = \
|
||||
|
@ -47,7 +47,7 @@ REPL_ISSUE_TESTS = $(wildcard t/issue/*.sh)
|
|||
|
||||
TEST_RUNNER = picrin
|
||||
|
||||
CFLAGS += -I./lib/include -Wall -Wextra
|
||||
CFLAGS += -I./lib -I./lib/include -Wall -Wextra
|
||||
LDFLAGS += -lm
|
||||
|
||||
prefix ?= /usr/local
|
||||
|
@ -77,7 +77,7 @@ src/init_contrib.c:
|
|||
lib/boot.c: piclib/boot.scm
|
||||
bin/picrin-bootstrap tools/mkboot.scm < piclib/boot.scm > lib/boot.c
|
||||
|
||||
$(LIBPICRIN_OBJS) $(PICRIN_OBJS) $(CONTRIB_OBJS): lib/include/picrin.h lib/include/picrin/*.h
|
||||
$(LIBPICRIN_OBJS) $(PICRIN_OBJS) $(CONTRIB_OBJS): lib/include/picrin.h lib/include/picrin/*.h lib/khash.h lib/object.h lib/state.h lib/vm.h
|
||||
|
||||
doc: docs/*.rst docs/contrib.rst
|
||||
$(MAKE) -C docs html
|
||||
|
@ -94,8 +94,8 @@ test: test-contribs test-nostdlib test-issue
|
|||
|
||||
test-contribs: picrin $(CONTRIB_TESTS)
|
||||
|
||||
test-nostdlib:
|
||||
$(CC) -I./lib/include -D'PIC_USE_LIBC=0' -D'PIC_USE_STDIO=0' -D'PIC_USE_WRITE=0' -ffreestanding -nostdlib -Os -fPIC -shared -std=c89 -pedantic -Wall -Wextra -Werror -o libpicrin-tiny.so $(LIBPICRIN_SRCS) etc/libc_polyfill.c -fno-stack-protector
|
||||
test-nostdlib: lib/boot.c
|
||||
$(CC) -I./lib -I./lib/include -D'PIC_USE_LIBC=0' -D'PIC_USE_STDIO=0' -D'PIC_USE_WRITE=0' -ffreestanding -nostdlib -Os -fPIC -shared -std=c89 -pedantic -Wall -Wextra -Werror -o libpicrin-tiny.so $(LIBPICRIN_SRCS) etc/libc_polyfill.c -fno-stack-protector
|
||||
strip libpicrin-tiny.so
|
||||
ls -lh libpicrin-tiny.so
|
||||
rm -f libpicrin-tiny.so
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "picrin.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
struct fullcont {
|
||||
jmp_buf jmp;
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
pic_value
|
||||
pic_blob_value(pic_state *pic, const unsigned char *buf, int len)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
#if PIC_NAN_BOXING
|
||||
|
||||
|
@ -226,7 +226,7 @@ pic_bool_not(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "o", &v);
|
||||
|
||||
return pic_false_p(pic, v) ? pic_true_value(pic) : pic_false_value(pic);
|
||||
return pic_bool_value(pic, pic_false_p(pic, v));
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
@ -236,7 +236,7 @@ pic_bool_boolean_p(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "o", &v);
|
||||
|
||||
return (pic_true_p(pic, v) || pic_false_p(pic, v)) ? pic_true_value(pic) : pic_false_value(pic);
|
||||
return pic_bool_value(pic, pic_bool_p(pic, v));
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
@ -264,9 +264,7 @@ pic_init_bool(pic_state *pic)
|
|||
pic_defun(pic, "eq?", pic_bool_eq_p);
|
||||
pic_defun(pic, "eqv?", pic_bool_eqv_p);
|
||||
pic_defun(pic, "equal?", pic_bool_equal_p);
|
||||
|
||||
pic_defun(pic, "not", pic_bool_not);
|
||||
|
||||
pic_defun(pic, "boolean?", pic_bool_boolean_p);
|
||||
pic_defun(pic, "boolean=?", pic_bool_boolean_eq_p);
|
||||
}
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
static pic_value
|
||||
pic_char_char_p(pic_state *pic)
|
||||
|
@ -13,7 +12,7 @@ pic_char_char_p(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "o", &v);
|
||||
|
||||
return pic_char_p(pic, v) ? pic_true_value(pic) : pic_false_value(pic);
|
||||
return pic_bool_value(pic, pic_char_p(pic, v));
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
struct cont {
|
||||
PIC_JMPBUF *jmp;
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
/**
|
||||
* See Copyright Notice in picrin.h
|
||||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
bool
|
||||
pic_data_p(pic_state *pic, pic_value obj, const pic_data_type *type)
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
pic_value
|
||||
pic_get_backtrace(pic_state *pic)
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
KHASH_DEFINE(dict, symbol *, pic_value, kh_ptr_hash_func, kh_ptr_hash_equal)
|
||||
|
||||
|
|
11
lib/error.c
11
lib/error.c
|
@ -3,9 +3,8 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
void
|
||||
pic_panic(pic_state *pic, const char *msg)
|
||||
|
@ -14,10 +13,6 @@ pic_panic(pic_state *pic, const char *msg)
|
|||
pic->panicf(pic, msg);
|
||||
}
|
||||
|
||||
#if PIC_USE_STDIO
|
||||
fprintf(stderr, "picrin panic!: %s\n", msg);
|
||||
#endif
|
||||
|
||||
PIC_ABORT(pic);
|
||||
|
||||
PIC_UNREACHABLE();
|
||||
|
@ -296,7 +291,7 @@ pic_error_error_object_type(pic_state *pic)
|
|||
void
|
||||
pic_init_error(pic_state *pic)
|
||||
{
|
||||
pic_defvar(pic, "current-exception-handlers", pic_nil_value(pic), pic_false_value(pic));
|
||||
pic_defvar(pic, "current-exception-handlers", pic_nil_value(pic));
|
||||
pic_defun(pic, "with-exception-handler", pic_error_with_exception_handler);
|
||||
pic_defun(pic, "raise", pic_error_raise);
|
||||
pic_defun(pic, "raise-continuable", pic_error_raise_continuable);
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/vm.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
#include "vm.h"
|
||||
|
||||
static pic_value pic_compile(pic_state *, pic_value);
|
||||
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
KHASH_DEFINE(env, struct identifier *, symbol *, kh_ptr_hash_func, kh_ptr_hash_equal)
|
||||
KHASH_DEFINE(ltable, const char *, struct lib, kh_str_hash_func, kh_str_cmp_func)
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
#undef EOF
|
||||
#define EOF (-1)
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
struct writer_control {
|
||||
int mode;
|
4
lib/gc.c
4
lib/gc.c
|
@ -3,8 +3,8 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
#define PAGE_UNITS ((PIC_HEAP_PAGE_SIZE - offsetof(struct heap_page, basep)) / sizeof(union header))
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ void pic_gc(pic_state *);
|
|||
int pic_get_args(pic_state *, const char *fmt, ...);
|
||||
|
||||
void pic_defun(pic_state *, const char *name, pic_func_t f);
|
||||
void pic_defvar(pic_state *, const char *name, pic_value v, pic_value conv);
|
||||
void pic_defvar(pic_state *, const char *name, pic_value v);
|
||||
void pic_define(pic_state *, const char *lib, const char *name, pic_value v);
|
||||
pic_value pic_ref(pic_state *, const char *lib, const char *name);
|
||||
void pic_set(pic_state *, const char *lib, const char *name, pic_value v);
|
||||
|
@ -179,6 +179,7 @@ enum {
|
|||
#define pic_float_p(pic,v) (pic_type(pic,v) == PIC_TYPE_FLOAT)
|
||||
#define pic_char_p(pic,v) (pic_type(pic,v) == PIC_TYPE_CHAR)
|
||||
#define pic_eof_p(pic, v) (pic_type(pic, v) == PIC_TYPE_EOF)
|
||||
#define pic_bool_p(pic,v) (pic_type(pic,v) == PIC_TYPE_TRUE || pic_type(pic,v) == PIC_TYPE_FALSE)
|
||||
#define pic_true_p(pic,v) (pic_type(pic,v) == PIC_TYPE_TRUE)
|
||||
#define pic_false_p(pic,v) (pic_type(pic,v) == PIC_TYPE_FALSE)
|
||||
#define pic_id_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ID || pic_type(pic, v) == PIC_TYPE_SYMBOL)
|
||||
|
@ -270,6 +271,10 @@ int pic_str_hash(pic_state *, pic_value str);
|
|||
#define PIC_SEEK_END 1
|
||||
#define PIC_SEEK_SET 2
|
||||
|
||||
#define pic_stdin(pic) pic_funcall(pic, "picrin.base", "current-input-port", 0)
|
||||
#define pic_stdout(pic) pic_funcall(pic, "picrin.base", "current-output-port", 0)
|
||||
#define pic_stderr(pic) pic_funcall(pic, "picrin.base", "current-error-port", 0)
|
||||
|
||||
pic_value pic_funopen(pic_state *, void *cookie, int (*read)(pic_state *, void *, char *, int), int (*write)(pic_state *, void *, const char *, int), long (*seek)(pic_state *, void *, long, int), int (*close)(pic_state *, void *));
|
||||
size_t pic_fread(pic_state *, void *ptr, size_t size, size_t count, pic_value port);
|
||||
size_t pic_fwrite(pic_state *, const void *ptr, size_t size, size_t count, pic_value port);
|
||||
|
@ -291,6 +296,32 @@ int pic_printf(pic_state *, const char *fmt, ...);
|
|||
int pic_fprintf(pic_state *, pic_value port, const char *fmt, ...);
|
||||
int pic_vfprintf(pic_state *, pic_value port, const char *fmt, va_list ap);
|
||||
|
||||
pic_value pic_fmemopen(pic_state *, const char *buf, int len, const char *mode); /* deprecated */
|
||||
int pic_fgetbuf(pic_state *, pic_value port, const char **buf, int *len); /* deprecated */
|
||||
|
||||
|
||||
/* debug */
|
||||
void pic_warnf(pic_state *, const char *, ...);
|
||||
pic_value pic_get_backtrace(pic_state *);
|
||||
|
||||
|
||||
|
||||
/* utility macros */
|
||||
|
||||
#define pic_for_each(var, list, it) \
|
||||
for (it = (list); ! pic_nil_p(pic, it); it = pic_cdr(pic, it)) \
|
||||
if ((var = pic_car(pic, it)), true)
|
||||
|
||||
#define pic_push(pic, item, place) (place = pic_cons(pic, item, place))
|
||||
#define pic_pop(pic, place) (place = pic_cdr(pic, place))
|
||||
|
||||
#define pic_void(pic, exec) pic_void_(pic, PIC_GENSYM(ai), exec)
|
||||
#define pic_void_(pic,ai,exec) do { \
|
||||
size_t ai = pic_enter(pic); \
|
||||
exec; \
|
||||
pic_leave(pic, ai); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
|
|
@ -23,31 +23,9 @@ pic_value pic_eval(pic_state *, pic_value program, const char *lib);
|
|||
void pic_load(pic_state *, pic_value port);
|
||||
void pic_load_cstr(pic_state *, const char *);
|
||||
|
||||
#define pic_stdin(pic) pic_funcall(pic, "picrin.base", "current-input-port", 0)
|
||||
#define pic_stdout(pic) pic_funcall(pic, "picrin.base", "current-output-port", 0)
|
||||
#define pic_stderr(pic) pic_funcall(pic, "picrin.base", "current-error-port", 0)
|
||||
|
||||
#if PIC_USE_STDIO
|
||||
pic_value pic_fopen(pic_state *, FILE *, const char *mode);
|
||||
#endif
|
||||
pic_value pic_fmemopen(pic_state *, const char *buf, int len, const char *mode);
|
||||
int pic_fgetbuf(pic_state *, pic_value port, const char **buf, int *len);
|
||||
|
||||
/* utility macros */
|
||||
|
||||
#define pic_for_each(var, list, it) \
|
||||
for (it = (list); ! pic_nil_p(pic, it); it = pic_cdr(pic, it)) \
|
||||
if ((var = pic_car(pic, it)), true)
|
||||
|
||||
#define pic_push(pic, item, place) (place = pic_cons(pic, item, place))
|
||||
#define pic_pop(pic, place) (place = pic_cdr(pic, place))
|
||||
|
||||
#define pic_void(pic, exec) pic_void_(pic, PIC_GENSYM(ai), exec)
|
||||
#define pic_void_(pic,ai,exec) do { \
|
||||
size_t ai = pic_enter(pic); \
|
||||
exec; \
|
||||
pic_leave(pic, ai); \
|
||||
} while (0)
|
||||
|
||||
#define pic_deflibrary(pic, lib) do { \
|
||||
if (! pic_find_library(pic, lib)) { \
|
||||
|
@ -78,8 +56,6 @@ int pic_fgetbuf(pic_state *, pic_value port, const char **buf, int *len);
|
|||
|
||||
/* for debug */
|
||||
|
||||
void pic_warnf(pic_state *, const char *, ...);
|
||||
pic_value pic_get_backtrace(pic_state *);
|
||||
#if PIC_USE_WRITE
|
||||
void pic_print_error(pic_state *, pic_value port, pic_value err);
|
||||
#endif
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
#ifndef PICRIN_FILE_H
|
||||
#define PICRIN_FILE_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct file {
|
||||
/* buffer */
|
||||
char buf[1]; /* fallback buffer */
|
||||
long cnt; /* characters left */
|
||||
char *ptr; /* next character position */
|
||||
char *base; /* location of the buffer */
|
||||
/* operators */
|
||||
struct {
|
||||
void *cookie;
|
||||
int (*read)(pic_state *, void *, char *, int);
|
||||
int (*write)(pic_state *, void *, const char *, int);
|
||||
long (*seek)(pic_state *, void *, long, int);
|
||||
int (*close)(pic_state *, void *);
|
||||
} vtable;
|
||||
int flag; /* mode of the file access */
|
||||
};
|
||||
|
||||
enum {
|
||||
FILE_READ = 01,
|
||||
FILE_WRITE = 02,
|
||||
FILE_UNBUF = 04,
|
||||
FILE_EOF = 010,
|
||||
FILE_ERR = 020,
|
||||
FILE_LNBUF = 040
|
||||
};
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,28 +0,0 @@
|
|||
/**
|
||||
* See Copyright Notice in picrin.h
|
||||
*/
|
||||
|
||||
#ifndef PICRIN_GC_H
|
||||
#define PICRIN_GC_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if PIC_BITMAP_GC
|
||||
# define OBJECT_HEADER \
|
||||
unsigned char tt;
|
||||
#else
|
||||
# define OBJECT_HEADER \
|
||||
unsigned char tt; \
|
||||
char gc_mark;
|
||||
#endif
|
||||
|
||||
struct heap *pic_heap_open(pic_state *);
|
||||
void pic_heap_close(pic_state *, struct heap *);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
14
lib/number.c
14
lib/number.c
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
|
||||
static pic_value
|
||||
pic_number_number_p(pic_state *pic)
|
||||
|
@ -334,33 +333,20 @@ pic_number_string_to_number(pic_state *pic)
|
|||
void
|
||||
pic_init_number(pic_state *pic)
|
||||
{
|
||||
size_t ai = pic_enter(pic);
|
||||
|
||||
pic_defun(pic, "number?", pic_number_number_p);
|
||||
pic_leave(pic, ai);
|
||||
|
||||
pic_defun(pic, "exact?", pic_number_exact_p);
|
||||
pic_defun(pic, "inexact?", pic_number_inexact_p);
|
||||
pic_leave(pic, ai);
|
||||
|
||||
pic_defun(pic, "inexact", pic_number_inexact);
|
||||
pic_defun(pic, "exact", pic_number_exact);
|
||||
pic_leave(pic, ai);
|
||||
|
||||
pic_defun(pic, "=", pic_number_eq);
|
||||
pic_defun(pic, "<", pic_number_lt);
|
||||
pic_defun(pic, ">", pic_number_gt);
|
||||
pic_defun(pic, "<=", pic_number_le);
|
||||
pic_defun(pic, ">=", pic_number_ge);
|
||||
pic_leave(pic, ai);
|
||||
|
||||
pic_defun(pic, "+", pic_number_add);
|
||||
pic_defun(pic, "-", pic_number_sub);
|
||||
pic_defun(pic, "*", pic_number_mul);
|
||||
pic_defun(pic, "/", pic_number_div);
|
||||
pic_leave(pic, ai);
|
||||
|
||||
pic_defun(pic, "number->string", pic_number_number_to_string);
|
||||
pic_defun(pic, "string->number", pic_number_string_to_number);
|
||||
pic_leave(pic, ai);
|
||||
}
|
||||
|
|
|
@ -9,15 +9,16 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "picrin/private/file.h"
|
||||
#include "picrin/private/khash.h"
|
||||
#include "picrin/private/gc.h"
|
||||
#include "khash.h"
|
||||
|
||||
typedef struct identifier symbol;
|
||||
|
||||
KHASH_DECLARE(env, struct identifier *, symbol *)
|
||||
KHASH_DECLARE(dict, symbol *, pic_value)
|
||||
KHASH_DECLARE(weak, struct object *, pic_value)
|
||||
#if PIC_BITMAP_GC
|
||||
# define OBJECT_HEADER \
|
||||
unsigned char tt;
|
||||
#else
|
||||
# define OBJECT_HEADER \
|
||||
unsigned char tt; \
|
||||
char gc_mark;
|
||||
#endif
|
||||
|
||||
struct object; /* defined in gc.c */
|
||||
|
||||
|
@ -34,6 +35,10 @@ struct identifier {
|
|||
struct env *env;
|
||||
};
|
||||
|
||||
typedef struct identifier symbol;
|
||||
|
||||
KHASH_DECLARE(env, struct identifier *, symbol *)
|
||||
|
||||
struct env {
|
||||
OBJECT_HEADER
|
||||
khash_t(env) map;
|
||||
|
@ -58,11 +63,15 @@ struct string {
|
|||
struct rope *rope;
|
||||
};
|
||||
|
||||
KHASH_DECLARE(dict, symbol *, pic_value)
|
||||
|
||||
struct dict {
|
||||
OBJECT_HEADER
|
||||
khash_t(dict) hash;
|
||||
};
|
||||
|
||||
KHASH_DECLARE(weak, struct object *, pic_value)
|
||||
|
||||
struct weak {
|
||||
OBJECT_HEADER
|
||||
khash_t(weak) hash;
|
||||
|
@ -118,9 +127,33 @@ struct error {
|
|||
struct string *stack;
|
||||
};
|
||||
|
||||
enum {
|
||||
FILE_READ = 01,
|
||||
FILE_WRITE = 02,
|
||||
FILE_UNBUF = 04,
|
||||
FILE_EOF = 010,
|
||||
FILE_ERR = 020,
|
||||
FILE_LNBUF = 040
|
||||
};
|
||||
|
||||
struct port {
|
||||
OBJECT_HEADER
|
||||
struct file file;
|
||||
struct file {
|
||||
/* buffer */
|
||||
char buf[1]; /* fallback buffer */
|
||||
long cnt; /* characters left */
|
||||
char *ptr; /* next character position */
|
||||
char *base; /* location of the buffer */
|
||||
/* operators */
|
||||
struct {
|
||||
void *cookie;
|
||||
int (*read)(pic_state *, void *, char *, int);
|
||||
int (*write)(pic_state *, void *, const char *, int);
|
||||
long (*seek)(pic_state *, void *, long, int);
|
||||
int (*close)(pic_state *, void *);
|
||||
} vtable;
|
||||
int flag; /* mode of the file access */
|
||||
} file;
|
||||
};
|
||||
|
||||
struct checkpoint {
|
||||
|
@ -189,7 +222,7 @@ pic_value pic_make_identifier(pic_state *, pic_value id, pic_value env);
|
|||
pic_value pic_make_proc(pic_state *, pic_func_t, int, pic_value *);
|
||||
pic_value pic_make_proc_irep(pic_state *, struct irep *, struct context *);
|
||||
pic_value pic_make_env(pic_state *, pic_value env);
|
||||
pic_value pic_make_rec(pic_state *, pic_value type, pic_value datum);
|
||||
pic_value pic_make_record(pic_state *, pic_value type, pic_value datum);
|
||||
|
||||
pic_value pic_add_identifier(pic_state *, pic_value id, pic_value env);
|
||||
void pic_put_identifier(pic_state *, pic_value id, pic_value uid, pic_value env);
|
|
@ -3,8 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
pic_value
|
||||
pic_cons(pic_state *pic, pic_value car, pic_value cdr)
|
||||
|
|
38
lib/port.c
38
lib/port.c
|
@ -3,10 +3,8 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/file.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
#ifndef EOF
|
||||
# define EOF (-1)
|
||||
|
@ -758,32 +756,18 @@ pic_port_flush(pic_state *pic)
|
|||
return pic_undef_value(pic);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
coerce_port(pic_state *pic)
|
||||
{
|
||||
pic_value port;
|
||||
|
||||
pic_get_args(pic, "p", &port);
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
#if PIC_USE_STDIO
|
||||
# define DEFINE_PORT(pic, name, file, mode) \
|
||||
pic_defvar(pic, name, pic_fopen(pic, file, mode), coerce)
|
||||
#else
|
||||
# define DEFINE_PORT(pic, name, file, mode) \
|
||||
pic_defvar(pic, name, pic_fopen_null(pic, mode), coerce)
|
||||
#endif
|
||||
|
||||
void
|
||||
pic_init_port(pic_state *pic)
|
||||
{
|
||||
pic_value coerce = pic_lambda(pic, coerce_port, 0);
|
||||
|
||||
DEFINE_PORT(pic, "current-input-port", stdin, "r");
|
||||
DEFINE_PORT(pic, "current-output-port", stdout, "w");
|
||||
DEFINE_PORT(pic, "current-error-port", stderr, "w");
|
||||
#if PIC_USE_STDIO
|
||||
pic_defvar(pic, "current-input-port", pic_fopen(pic, stdin, "r"));
|
||||
pic_defvar(pic, "current-output-port", pic_fopen(pic, stdout, "w"));
|
||||
pic_defvar(pic, "current-error-port", pic_fopen(pic, stdout, "w"));
|
||||
#else
|
||||
pic_defvar(pic, "current-input-port", pic_fopen_null(pic, "r"));
|
||||
pic_defvar(pic, "current-output-port", pic_fopen_null(pic, "w"));
|
||||
pic_defvar(pic, "current-error-port", pic_fopen_null(pic, "w"));
|
||||
#endif
|
||||
|
||||
pic_defun(pic, "port?", pic_port_port_p);
|
||||
pic_defun(pic, "input-port?", pic_port_input_port_p);
|
||||
|
|
11
lib/proc.c
11
lib/proc.c
|
@ -3,10 +3,9 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/vm.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
#include "vm.h"
|
||||
|
||||
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
|
@ -827,9 +826,9 @@ pic_defun(pic_state *pic, const char *name, pic_func_t f)
|
|||
}
|
||||
|
||||
void
|
||||
pic_defvar(pic_state *pic, const char *name, pic_value init, pic_value conv)
|
||||
pic_defvar(pic_state *pic, const char *name, pic_value init)
|
||||
{
|
||||
pic_define(pic, pic_current_library(pic), name, pic_make_var(pic, init, conv));
|
||||
pic_define(pic, pic_current_library(pic), name, pic_make_var(pic, init, pic_false_value(pic)));
|
||||
pic_export(pic, pic_intern_cstr(pic, name));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
pic_value
|
||||
pic_make_rec(pic_state *pic, pic_value type, pic_value datum)
|
||||
pic_make_record(pic_state *pic, pic_value type, pic_value datum)
|
||||
{
|
||||
struct record *rec;
|
||||
|
||||
|
@ -24,7 +24,7 @@ pic_rec_make_record(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "oo", &type, &datum);
|
||||
|
||||
return pic_make_rec(pic, type, datum);
|
||||
return pic_make_record(pic, type, datum);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
static pic_value
|
||||
pic_features(pic_state *pic)
|
||||
|
|
|
@ -9,9 +9,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "picrin/private/khash.h"
|
||||
#include "picrin/private/vm.h"
|
||||
#include "picrin/private/gc.h"
|
||||
#include "khash.h"
|
||||
#include "vm.h"
|
||||
|
||||
struct lib {
|
||||
struct string *name;
|
||||
|
@ -69,6 +68,9 @@ struct pic_state {
|
|||
pic_panicf panicf;
|
||||
};
|
||||
|
||||
struct heap *pic_heap_open(pic_state *);
|
||||
void pic_heap_close(pic_state *, struct heap *);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
|
@ -3,8 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
struct rope {
|
||||
int refcnt;
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
#define kh_pic_str_hash(a) (pic_str_hash(pic, pic_obj_value(a)))
|
||||
#define kh_pic_str_cmp(a, b) (pic_str_cmp(pic, pic_obj_value(a), pic_obj_value(b)) == 0)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
#if PIC_NAN_BOXING
|
||||
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "picrin/private/state.h"
|
||||
#include "object.h"
|
||||
#include "state.h"
|
||||
|
||||
static pic_value
|
||||
var_conv(pic_state *pic, pic_value val, pic_value conv)
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/extra.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
pic_value
|
||||
pic_make_vec(pic_state *pic, int len, pic_value *argv)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "picrin.h"
|
||||
#include "picrin/private/object.h"
|
||||
#include "object.h"
|
||||
|
||||
KHASH_DEFINE(weak, struct object *, pic_value, kh_ptr_hash_func, kh_ptr_hash_equal)
|
||||
|
||||
|
|
Loading…
Reference in New Issue