Merge branch 'api-change'
This commit is contained in:
commit
081fdf672f
|
@ -11,7 +11,7 @@ file_error(pic_state *pic, const char *msg)
|
||||||
{
|
{
|
||||||
struct pic_error *e;
|
struct pic_error *e;
|
||||||
|
|
||||||
e = pic_make_error(pic, pic_intern_cstr(pic, "file"), msg, pic_nil_value());
|
e = pic_make_error(pic, pic_intern(pic, "file"), msg, pic_nil_value());
|
||||||
|
|
||||||
pic_raise(pic, pic_obj_value(e));
|
pic_raise(pic, pic_obj_value(e));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,27 +4,20 @@
|
||||||
|
|
||||||
#include "picrin.h"
|
#include "picrin.h"
|
||||||
|
|
||||||
void
|
|
||||||
pic_load(pic_state *pic, const char *filename)
|
|
||||||
{
|
|
||||||
struct pic_port *port;
|
|
||||||
|
|
||||||
port = pic_open_file(pic, filename, PIC_PORT_IN | PIC_PORT_TEXT);
|
|
||||||
|
|
||||||
pic_load_port(pic, port);
|
|
||||||
|
|
||||||
pic_close_port(pic, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_load_load(pic_state *pic)
|
pic_load_load(pic_state *pic)
|
||||||
{
|
{
|
||||||
pic_value envid;
|
pic_value envid;
|
||||||
char *fn;
|
char *fn;
|
||||||
|
struct pic_port *port;
|
||||||
|
|
||||||
pic_get_args(pic, "z|o", &fn, &envid);
|
pic_get_args(pic, "z|o", &fn, &envid);
|
||||||
|
|
||||||
pic_load(pic, fn);
|
port = pic_open_file(pic, fn, PIC_PORT_IN | PIC_PORT_TEXT);
|
||||||
|
|
||||||
|
pic_load(pic, port);
|
||||||
|
|
||||||
|
pic_close_port(pic, port);
|
||||||
|
|
||||||
return pic_undef_value();
|
return pic_undef_value();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,16 @@ void
|
||||||
pic_str_set(pic_state *pic, pic_str *str, size_t i, char c)
|
pic_str_set(pic_state *pic, pic_str *str, size_t i, char c)
|
||||||
{
|
{
|
||||||
pic_str *x, *y, *z, *tmp;
|
pic_str *x, *y, *z, *tmp;
|
||||||
|
char buf[1];
|
||||||
|
|
||||||
if (pic_str_len(str) <= i) {
|
if (pic_str_len(str) <= i) {
|
||||||
pic_errorf(pic, "index out of range %d", i);
|
pic_errorf(pic, "index out of range %d", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf[0] = c;
|
||||||
|
|
||||||
x = pic_str_sub(pic, str, 0, i);
|
x = pic_str_sub(pic, str, 0, i);
|
||||||
y = pic_make_str_fill(pic, 1, c);
|
y = pic_make_str(pic, buf, 1);
|
||||||
z = pic_str_sub(pic, str, i + 1, pic_str_len(str));
|
z = pic_str_sub(pic, str, i + 1, pic_str_len(str));
|
||||||
|
|
||||||
tmp = pic_str_cat(pic, x, pic_str_cat(pic, y, z));
|
tmp = pic_str_cat(pic, x, pic_str_cat(pic, y, z));
|
||||||
|
|
|
@ -22,13 +22,13 @@ pic_attr(pic_state *pic, pic_value obj)
|
||||||
pic_value
|
pic_value
|
||||||
pic_attr_ref(pic_state *pic, pic_value obj, const char *key)
|
pic_attr_ref(pic_state *pic, pic_value obj, const char *key)
|
||||||
{
|
{
|
||||||
return pic_dict_ref(pic, pic_attr(pic, obj), pic_intern_cstr(pic, key));
|
return pic_dict_ref(pic, pic_attr(pic, obj), pic_intern(pic, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pic_attr_set(pic_state *pic, pic_value obj, const char *key, pic_value v)
|
pic_attr_set(pic_state *pic, pic_value obj, const char *key, pic_value v)
|
||||||
{
|
{
|
||||||
pic_dict_set(pic, pic_attr(pic, obj), pic_intern_cstr(pic, key), v);
|
pic_dict_set(pic, pic_attr(pic, obj), pic_intern(pic, key), v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
|
|
|
@ -45,7 +45,7 @@ pic_print_backtrace(pic_state *pic, xFILE *file)
|
||||||
pic_value elem, it;
|
pic_value elem, it;
|
||||||
|
|
||||||
e = pic_error_ptr(pic->err);
|
e = pic_error_ptr(pic->err);
|
||||||
if (e->type != pic_intern_cstr(pic, "")) {
|
if (e->type != pic_intern(pic, "")) {
|
||||||
pic_fwrite(pic, pic_obj_value(e->type), file);
|
pic_fwrite(pic, pic_obj_value(e->type), file);
|
||||||
xfprintf(pic, file, " ");
|
xfprintf(pic, file, " ");
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,22 +47,6 @@ pic_errorf(pic_state *pic, const char *fmt, ...)
|
||||||
pic_error(pic, msg, irrs);
|
pic_error(pic, msg, irrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
|
||||||
pic_errmsg(pic_state *pic)
|
|
||||||
{
|
|
||||||
pic_str *str;
|
|
||||||
|
|
||||||
assert(! pic_invalid_p(pic->err));
|
|
||||||
|
|
||||||
if (! pic_error_p(pic->err)) {
|
|
||||||
str = pic_format(pic, "~s", pic->err);
|
|
||||||
} else {
|
|
||||||
str = pic_error_ptr(pic->err)->msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pic_str_cstr(pic, str);
|
|
||||||
}
|
|
||||||
|
|
||||||
pic_value
|
pic_value
|
||||||
pic_native_exception_handler(pic_state *pic)
|
pic_native_exception_handler(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
@ -158,7 +142,7 @@ pic_error(pic_state *pic, const char *msg, pic_value irrs)
|
||||||
{
|
{
|
||||||
struct pic_error *e;
|
struct pic_error *e;
|
||||||
|
|
||||||
e = pic_make_error(pic, pic_intern_cstr(pic, ""), msg, irrs);
|
e = pic_make_error(pic, pic_intern(pic, ""), msg, irrs);
|
||||||
|
|
||||||
pic_raise(pic, pic_obj_value(e));
|
pic_raise(pic, pic_obj_value(e));
|
||||||
}
|
}
|
||||||
|
@ -212,22 +196,6 @@ pic_error_error(pic_state *pic)
|
||||||
pic_error(pic, str, pic_list_by_array(pic, argc, argv));
|
pic_error(pic, str, pic_list_by_array(pic, argc, argv));
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
|
||||||
pic_error_make_error_object(pic_state *pic)
|
|
||||||
{
|
|
||||||
struct pic_error *e;
|
|
||||||
pic_sym *type;
|
|
||||||
pic_str *msg;
|
|
||||||
size_t argc;
|
|
||||||
pic_value *argv;
|
|
||||||
|
|
||||||
pic_get_args(pic, "ms*", &type, &msg, &argc, &argv);
|
|
||||||
|
|
||||||
e = pic_make_error(pic, type, pic_str_cstr(pic, msg), pic_list_by_array(pic, argc, argv));
|
|
||||||
|
|
||||||
return pic_obj_value(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_error_error_object_p(pic_state *pic)
|
pic_error_error_object_p(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
@ -275,7 +243,6 @@ pic_init_error(pic_state *pic)
|
||||||
pic_defun(pic, "raise", pic_error_raise);
|
pic_defun(pic, "raise", pic_error_raise);
|
||||||
pic_defun(pic, "raise-continuable", pic_error_raise_continuable);
|
pic_defun(pic, "raise-continuable", pic_error_raise_continuable);
|
||||||
pic_defun(pic, "error", pic_error_error);
|
pic_defun(pic, "error", pic_error_error);
|
||||||
pic_defun(pic, "make-error-object", pic_error_make_error_object);
|
|
||||||
pic_defun(pic, "error-object?", pic_error_error_object_p);
|
pic_defun(pic, "error-object?", pic_error_error_object_p);
|
||||||
pic_defun(pic, "error-object-message", pic_error_error_object_message);
|
pic_defun(pic, "error-object-message", pic_error_error_object_message);
|
||||||
pic_defun(pic, "error-object-irritants", pic_error_error_object_irritants);
|
pic_defun(pic, "error-object-irritants", pic_error_error_object_irritants);
|
||||||
|
|
|
@ -487,12 +487,6 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PIC_TT_BOX: {
|
|
||||||
struct pic_box *box = (struct pic_box *)obj;
|
|
||||||
|
|
||||||
gc_mark(pic, box->value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PIC_TT_NIL:
|
case PIC_TT_NIL:
|
||||||
case PIC_TT_BOOL:
|
case PIC_TT_BOOL:
|
||||||
#if PIC_ENABLE_FLOAT
|
#if PIC_ENABLE_FLOAT
|
||||||
|
@ -739,9 +733,6 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
|
||||||
case PIC_TT_CP: {
|
case PIC_TT_CP: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PIC_TT_BOX: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PIC_TT_NIL:
|
case PIC_TT_NIL:
|
||||||
case PIC_TT_BOOL:
|
case PIC_TT_BOOL:
|
||||||
#if PIC_ENABLE_FLOAT
|
#if PIC_ENABLE_FLOAT
|
||||||
|
|
|
@ -144,7 +144,6 @@ void *pic_malloc(pic_state *, size_t);
|
||||||
void *pic_realloc(pic_state *, void *, size_t);
|
void *pic_realloc(pic_state *, void *, size_t);
|
||||||
void *pic_calloc(pic_state *, size_t, 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(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_free(pic_state *, void *);
|
||||||
|
|
||||||
void pic_gc_run(pic_state *);
|
void pic_gc_run(pic_state *);
|
||||||
|
@ -173,14 +172,14 @@ bool pic_eq_p(pic_value, pic_value);
|
||||||
bool pic_eqv_p(pic_value, pic_value);
|
bool pic_eqv_p(pic_value, pic_value);
|
||||||
bool pic_equal_p(pic_state *, pic_value, pic_value);
|
bool pic_equal_p(pic_state *, pic_value, pic_value);
|
||||||
|
|
||||||
pic_sym *pic_intern(pic_state *, pic_str *);
|
pic_sym *pic_intern(pic_state *, const char *);
|
||||||
pic_sym *pic_intern_cstr(pic_state *, const char *);
|
pic_sym *pic_intern_str(pic_state *, pic_str *);
|
||||||
const char *pic_symbol_name(pic_state *, pic_sym *);
|
const char *pic_symbol_name(pic_state *, pic_sym *);
|
||||||
|
|
||||||
pic_value pic_read(pic_state *, struct pic_port *);
|
pic_value pic_read(pic_state *, struct pic_port *);
|
||||||
pic_value pic_read_cstr(pic_state *, const char *);
|
pic_value pic_read_cstr(pic_state *, const char *);
|
||||||
|
|
||||||
void pic_load_port(pic_state *, struct pic_port *);
|
void pic_load(pic_state *, struct pic_port *);
|
||||||
void pic_load_cstr(pic_state *, const char *);
|
void pic_load_cstr(pic_state *, const char *);
|
||||||
|
|
||||||
void pic_define(pic_state *, const char *, pic_value);
|
void pic_define(pic_state *, const char *, pic_value);
|
||||||
|
@ -209,7 +208,6 @@ pic_value pic_apply5(pic_state *, struct pic_proc *, pic_value, pic_value, pic_v
|
||||||
pic_value pic_apply_trampoline(pic_state *, struct pic_proc *, size_t, pic_value *);
|
pic_value pic_apply_trampoline(pic_state *, struct pic_proc *, size_t, pic_value *);
|
||||||
pic_value pic_apply_trampoline_list(pic_state *, struct pic_proc *, pic_value);
|
pic_value pic_apply_trampoline_list(pic_state *, struct pic_proc *, pic_value);
|
||||||
pic_value pic_eval(pic_state *, pic_value, struct pic_env *);
|
pic_value pic_eval(pic_state *, pic_value, struct pic_env *);
|
||||||
struct pic_proc *pic_compile(pic_state *, pic_value, struct pic_env *);
|
|
||||||
|
|
||||||
struct pic_proc *pic_make_var(pic_state *, pic_value, struct pic_proc *);
|
struct pic_proc *pic_make_var(pic_state *, pic_value, struct pic_proc *);
|
||||||
|
|
||||||
|
@ -233,9 +231,9 @@ void pic_export(pic_state *, pic_sym *);
|
||||||
PIC_NORETURN void pic_panic(pic_state *, const char *);
|
PIC_NORETURN void pic_panic(pic_state *, const char *);
|
||||||
PIC_NORETURN void pic_errorf(pic_state *, const char *, ...);
|
PIC_NORETURN void pic_errorf(pic_state *, const char *, ...);
|
||||||
void pic_warnf(pic_state *, const char *, ...);
|
void pic_warnf(pic_state *, const char *, ...);
|
||||||
const char *pic_errmsg(pic_state *);
|
|
||||||
pic_str *pic_get_backtrace(pic_state *);
|
pic_str *pic_get_backtrace(pic_state *);
|
||||||
void pic_print_backtrace(pic_state *, xFILE *);
|
void pic_print_backtrace(pic_state *, xFILE *);
|
||||||
|
|
||||||
struct pic_dict *pic_attr(pic_state *, pic_value);
|
struct pic_dict *pic_attr(pic_state *, pic_value);
|
||||||
pic_value pic_attr_ref(pic_state *, pic_value, const char *);
|
pic_value pic_attr_ref(pic_state *, pic_value, const char *);
|
||||||
void pic_attr_set(pic_state *, pic_value, const char *, pic_value);
|
void pic_attr_set(pic_state *, pic_value, const char *, pic_value);
|
||||||
|
@ -271,7 +269,6 @@ pic_value pic_fdisplay(pic_state *, pic_value, xFILE *);
|
||||||
#include "picrin/symbol.h"
|
#include "picrin/symbol.h"
|
||||||
#include "picrin/vector.h"
|
#include "picrin/vector.h"
|
||||||
#include "picrin/reg.h"
|
#include "picrin/reg.h"
|
||||||
#include "picrin/box.h"
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
/**
|
|
||||||
* See Copyright Notice in picrin.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef PICRIN_BOX_H
|
|
||||||
#define PICRIN_BOX_H
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct pic_box {
|
|
||||||
PIC_OBJECT_HEADER
|
|
||||||
pic_value value;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define pic_box_p(v) (pic_type(v) == PIC_TT_BOX)
|
|
||||||
#define pic_box_ptr(o) ((struct pic_box *)pic_ptr(o))
|
|
||||||
|
|
||||||
PIC_INLINE pic_value
|
|
||||||
pic_box(pic_state *pic, pic_value value)
|
|
||||||
{
|
|
||||||
struct pic_box *box;
|
|
||||||
|
|
||||||
box = (struct pic_box *)pic_obj_alloc(pic, sizeof(struct pic_box), PIC_TT_BOX);
|
|
||||||
box->value = value;
|
|
||||||
|
|
||||||
return pic_obj_value(box);
|
|
||||||
}
|
|
||||||
|
|
||||||
PIC_INLINE pic_value
|
|
||||||
pic_unbox(pic_state *pic, pic_value box)
|
|
||||||
{
|
|
||||||
if (! pic_box_p(box)) {
|
|
||||||
pic_errorf(pic, "box required");
|
|
||||||
}
|
|
||||||
return pic_box_ptr(box)->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
PIC_INLINE void
|
|
||||||
pic_set_box(pic_state *pic, pic_value box, pic_value value)
|
|
||||||
{
|
|
||||||
if (! pic_box_p(box)) {
|
|
||||||
pic_errorf(pic, "box required");
|
|
||||||
}
|
|
||||||
pic_box_ptr(box)->value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -35,6 +35,7 @@ pic_sym *pic_resolve(pic_state *, pic_value, struct pic_env *);
|
||||||
pic_value pic_expand(pic_state *, pic_value, struct pic_env *);
|
pic_value pic_expand(pic_state *, pic_value, struct pic_env *);
|
||||||
pic_value pic_analyze(pic_state *, pic_value);
|
pic_value pic_analyze(pic_state *, pic_value);
|
||||||
struct pic_irep *pic_codegen(pic_state *, pic_value);
|
struct pic_irep *pic_codegen(pic_state *, pic_value);
|
||||||
|
struct pic_proc *pic_compile(pic_state *, pic_value, struct pic_env *);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ void pic_rope_decref(pic_state *, struct pic_rope *);
|
||||||
|
|
||||||
pic_str *pic_make_str(pic_state *, const char * /* nullable */, size_t);
|
pic_str *pic_make_str(pic_state *, const char * /* nullable */, size_t);
|
||||||
pic_str *pic_make_str_cstr(pic_state *, const char *);
|
pic_str *pic_make_str_cstr(pic_state *, const char *);
|
||||||
pic_str *pic_make_str_fill(pic_state *, size_t, char);
|
|
||||||
|
|
||||||
char pic_str_ref(pic_state *, pic_str *, size_t);
|
char pic_str_ref(pic_state *, pic_str *, size_t);
|
||||||
size_t pic_str_len(pic_str *);
|
size_t pic_str_len(pic_str *);
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
* See Copyright Notice in picrin.h
|
* See Copyright Notice in picrin.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PICRIN_VALUE_H
|
#ifndef PICRIN_TYPE_H
|
||||||
#define PICRIN_VALUE_H
|
#define PICRIN_TYPE_H
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -163,7 +163,6 @@ enum pic_tt {
|
||||||
PIC_TT_DATA,
|
PIC_TT_DATA,
|
||||||
PIC_TT_DICT,
|
PIC_TT_DICT,
|
||||||
PIC_TT_REG,
|
PIC_TT_REG,
|
||||||
PIC_TT_BOX,
|
|
||||||
PIC_TT_RECORD,
|
PIC_TT_RECORD,
|
||||||
PIC_TT_CXT,
|
PIC_TT_CXT,
|
||||||
PIC_TT_IREP,
|
PIC_TT_IREP,
|
||||||
|
@ -338,8 +337,6 @@ pic_type_repr(enum pic_tt tt)
|
||||||
return "reg";
|
return "reg";
|
||||||
case PIC_TT_RECORD:
|
case PIC_TT_RECORD:
|
||||||
return "record";
|
return "record";
|
||||||
case PIC_TT_BOX:
|
|
||||||
return "box";
|
|
||||||
case PIC_TT_CP:
|
case PIC_TT_CP:
|
||||||
return "checkpoint";
|
return "checkpoint";
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,7 @@ struct pic_vector {
|
||||||
#define pic_vec_p(v) (pic_type(v) == PIC_TT_VECTOR)
|
#define pic_vec_p(v) (pic_type(v) == PIC_TT_VECTOR)
|
||||||
#define pic_vec_ptr(o) ((struct pic_vector *)pic_ptr(o))
|
#define pic_vec_ptr(o) ((struct pic_vector *)pic_ptr(o))
|
||||||
|
|
||||||
struct pic_vector *pic_make_vec(pic_state *, size_t);
|
pic_vec *pic_make_vec(pic_state *, size_t);
|
||||||
struct pic_vector *pic_make_vec_from_list(pic_state *, pic_value);
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "picrin.h"
|
#include "picrin.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
pic_load_port(pic_state *pic, struct pic_port *port)
|
pic_load(pic_state *pic, struct pic_port *port)
|
||||||
{
|
{
|
||||||
pic_value form;
|
pic_value form;
|
||||||
size_t ai = pic_gc_arena_preserve(pic);
|
size_t ai = pic_gc_arena_preserve(pic);
|
||||||
|
@ -23,7 +23,7 @@ pic_load_cstr(pic_state *pic, const char *src)
|
||||||
struct pic_port *port = pic_open_input_string(pic, src);
|
struct pic_port *port = pic_open_input_string(pic, src);
|
||||||
|
|
||||||
pic_try {
|
pic_try {
|
||||||
pic_load_port(pic, port);
|
pic_load(pic, port);
|
||||||
}
|
}
|
||||||
pic_catch {
|
pic_catch {
|
||||||
pic_close_port(pic, port);
|
pic_close_port(pic, port);
|
||||||
|
|
|
@ -56,7 +56,7 @@ pic_uniq(pic_state *pic, pic_value var)
|
||||||
|
|
||||||
str = pic_format(pic, "%s.%d", pic_symbol_name(pic, pic_var_name(pic, var)), pic->ucnt++);
|
str = pic_format(pic, "%s.%d", pic_symbol_name(pic, pic_var_name(pic, var)), pic->ucnt++);
|
||||||
|
|
||||||
return pic_intern(pic, str);
|
return pic_intern_str(pic, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_sym *
|
pic_sym *
|
||||||
|
|
|
@ -103,7 +103,7 @@ file_error(pic_state *pic, const char *msg)
|
||||||
{
|
{
|
||||||
struct pic_error *e;
|
struct pic_error *e;
|
||||||
|
|
||||||
e = pic_make_error(pic, pic_intern_cstr(pic, "file"), msg, pic_nil_value());
|
e = pic_make_error(pic, pic_intern(pic, "file"), msg, pic_nil_value());
|
||||||
|
|
||||||
pic_raise(pic, pic_obj_value(e));
|
pic_raise(pic, pic_obj_value(e));
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,19 +42,19 @@ pic_proc_env(pic_state *pic, struct pic_proc *proc)
|
||||||
bool
|
bool
|
||||||
pic_proc_env_has(pic_state *pic, struct pic_proc *proc, const char *key)
|
pic_proc_env_has(pic_state *pic, struct pic_proc *proc, const char *key)
|
||||||
{
|
{
|
||||||
return pic_dict_has(pic, pic_proc_env(pic, proc), pic_intern_cstr(pic, key));
|
return pic_dict_has(pic, pic_proc_env(pic, proc), pic_intern(pic, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_value
|
pic_value
|
||||||
pic_proc_env_ref(pic_state *pic, struct pic_proc *proc, const char *key)
|
pic_proc_env_ref(pic_state *pic, struct pic_proc *proc, const char *key)
|
||||||
{
|
{
|
||||||
return pic_dict_ref(pic, pic_proc_env(pic, proc), pic_intern_cstr(pic, key));
|
return pic_dict_ref(pic, pic_proc_env(pic, proc), pic_intern(pic, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pic_proc_env_set(pic_state *pic, struct pic_proc *proc, const char *key, pic_value val)
|
pic_proc_env_set(pic_state *pic, struct pic_proc *proc, const char *key, pic_value val)
|
||||||
{
|
{
|
||||||
pic_dict_set(pic, pic_proc_env(pic, proc), pic_intern_cstr(pic, key), val);
|
pic_dict_set(pic, pic_proc_env(pic, proc), pic_intern(pic, key), val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
|
|
|
@ -14,7 +14,7 @@ read_error(pic_state *pic, const char *msg)
|
||||||
{
|
{
|
||||||
struct pic_error *e;
|
struct pic_error *e;
|
||||||
|
|
||||||
e = pic_make_error(pic, pic_intern_cstr(pic, "read"), msg, pic_nil_value());
|
e = pic_make_error(pic, pic_intern(pic, "read"), msg, pic_nil_value());
|
||||||
|
|
||||||
pic_raise(pic, pic_obj_value(e));
|
pic_raise(pic, pic_obj_value(e));
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ read_symbol(pic_state *pic, struct pic_port *port, int c)
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sym = pic_intern_cstr(pic, buf);
|
sym = pic_intern(pic, buf);
|
||||||
pic_free(pic, buf);
|
pic_free(pic, buf);
|
||||||
|
|
||||||
return pic_obj_value(sym);
|
return pic_obj_value(sym);
|
||||||
|
@ -537,7 +537,7 @@ read_pipe(pic_state *pic, struct pic_port *port, int c)
|
||||||
}
|
}
|
||||||
buf[cnt] = '\0';
|
buf[cnt] = '\0';
|
||||||
|
|
||||||
sym = pic_intern_cstr(pic, buf);
|
sym = pic_intern(pic, buf);
|
||||||
pic_free(pic, buf);
|
pic_free(pic, buf);
|
||||||
|
|
||||||
return pic_obj_value(sym);
|
return pic_obj_value(sym);
|
||||||
|
@ -643,11 +643,19 @@ read_pair(pic_state *pic, struct pic_port *port, int c)
|
||||||
static pic_value
|
static pic_value
|
||||||
read_vector(pic_state *pic, struct pic_port *port, int c)
|
read_vector(pic_state *pic, struct pic_port *port, int c)
|
||||||
{
|
{
|
||||||
pic_value list;
|
pic_value list, it, elem;
|
||||||
|
pic_vec *vec;
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
list = read(pic, port, c);
|
list = read(pic, port, c);
|
||||||
|
|
||||||
return pic_obj_value(pic_make_vec_from_list(pic, list));
|
vec = pic_make_vec(pic, pic_length(pic, list));
|
||||||
|
|
||||||
|
pic_for_each (elem, list, it) {
|
||||||
|
vec->data[i++] = elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pic_obj_value(vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
|
|
|
@ -15,7 +15,7 @@ pic_make_record(pic_state *pic, pic_value rectype)
|
||||||
rec = (struct pic_record *)pic_obj_alloc(pic, sizeof(struct pic_record), PIC_TT_RECORD);
|
rec = (struct pic_record *)pic_obj_alloc(pic, sizeof(struct pic_record), PIC_TT_RECORD);
|
||||||
rec->data = data;
|
rec->data = data;
|
||||||
|
|
||||||
pic_record_set(pic, rec, pic_intern_cstr(pic, "@@type"), rectype);
|
pic_record_set(pic, rec, pic_intern(pic, "@@type"), rectype);
|
||||||
|
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ pic_make_record(pic_state *pic, pic_value rectype)
|
||||||
pic_value
|
pic_value
|
||||||
pic_record_type(pic_state *pic, struct pic_record *rec)
|
pic_record_type(pic_state *pic, struct pic_record *rec)
|
||||||
{
|
{
|
||||||
return pic_record_ref(pic, rec, pic_intern_cstr(pic, "@@type"));
|
return pic_record_ref(pic, rec, pic_intern(pic, "@@type"));
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_value
|
pic_value
|
||||||
|
|
|
@ -15,7 +15,7 @@ pic_set_argv(pic_state *pic, int argc, char *argv[], char **envp)
|
||||||
void
|
void
|
||||||
pic_add_feature(pic_state *pic, const char *feature)
|
pic_add_feature(pic_state *pic, const char *feature)
|
||||||
{
|
{
|
||||||
pic_push(pic, pic_obj_value(pic_intern_cstr(pic, feature)), pic->features);
|
pic_push(pic, pic_obj_value(pic_intern(pic, feature)), pic->features);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pic_init_undef(pic_state *);
|
void pic_init_undef(pic_state *);
|
||||||
|
@ -113,10 +113,10 @@ pic_features(pic_state *pic)
|
||||||
#define DONE pic_gc_arena_restore(pic, ai);
|
#define DONE pic_gc_arena_restore(pic, ai);
|
||||||
|
|
||||||
#define define_builtin_syntax(uid, name) \
|
#define define_builtin_syntax(uid, name) \
|
||||||
pic_define_syntactic_keyword_(pic, pic->lib->env, pic_intern_cstr(pic, name), uid)
|
pic_define_syntactic_keyword_(pic, pic->lib->env, pic_intern(pic, name), uid)
|
||||||
|
|
||||||
#define VM(uid, name) \
|
#define VM(uid, name) \
|
||||||
pic_define_syntactic_keyword_(pic, pic->lib->env, pic_intern_cstr(pic, name), uid)
|
pic_define_syntactic_keyword_(pic, pic->lib->env, pic_intern(pic, name), uid)
|
||||||
|
|
||||||
#define VM3(name) \
|
#define VM3(name) \
|
||||||
pic->c##name = pic_vm_gref_slot(pic, pic->u##name);
|
pic->c##name = pic_vm_gref_slot(pic, pic->u##name);
|
||||||
|
@ -343,7 +343,7 @@ pic_open(pic_allocf allocf, void *userdata)
|
||||||
|
|
||||||
ai = pic_gc_arena_preserve(pic);
|
ai = pic_gc_arena_preserve(pic);
|
||||||
|
|
||||||
#define S(slot,name) pic->slot = pic_intern_cstr(pic, name)
|
#define S(slot,name) pic->slot = pic_intern(pic, name)
|
||||||
|
|
||||||
S(sQUOTE, "quote");
|
S(sQUOTE, "quote");
|
||||||
S(sQUASIQUOTE, "quasiquote");
|
S(sQUASIQUOTE, "quasiquote");
|
||||||
|
@ -364,7 +364,7 @@ pic_open(pic_allocf allocf, void *userdata)
|
||||||
|
|
||||||
pic_gc_arena_restore(pic, ai);
|
pic_gc_arena_restore(pic, ai);
|
||||||
|
|
||||||
#define U(slot,name) pic->slot = pic_uniq(pic, pic_obj_value(pic_intern_cstr(pic, name)))
|
#define U(slot,name) pic->slot = pic_uniq(pic, pic_obj_value(pic_intern(pic, name)))
|
||||||
|
|
||||||
U(uDEFINE, "define");
|
U(uDEFINE, "define");
|
||||||
U(uLAMBDA, "lambda");
|
U(uLAMBDA, "lambda");
|
||||||
|
|
|
@ -240,25 +240,6 @@ pic_make_str_cstr(pic_state *pic, const char *cstr)
|
||||||
return pic_make_str(pic, cstr, strlen(cstr));
|
return pic_make_str(pic, cstr, strlen(cstr));
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_str *
|
|
||||||
pic_make_str_fill(pic_state *pic, size_t len, char fill)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
char *buf = pic_malloc(pic, len);
|
|
||||||
pic_str *str;
|
|
||||||
|
|
||||||
for (i = 0; i < len; ++i) {
|
|
||||||
buf[i] = fill;
|
|
||||||
}
|
|
||||||
buf[i] = '\0';
|
|
||||||
|
|
||||||
str = pic_make_str(pic, buf, len);
|
|
||||||
|
|
||||||
pic_free(pic, buf);
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
pic_str_len(pic_str *str)
|
pic_str_len(pic_str *str)
|
||||||
{
|
{
|
||||||
|
@ -471,10 +452,18 @@ pic_str_make_string(pic_state *pic)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char c = ' ';
|
char c = ' ';
|
||||||
|
char *buf;
|
||||||
|
pic_value ret;
|
||||||
|
|
||||||
pic_get_args(pic, "k|c", &len, &c);
|
pic_get_args(pic, "k|c", &len, &c);
|
||||||
|
|
||||||
return pic_obj_value(pic_make_str_fill(pic, len, c));
|
buf = pic_malloc(pic, len);
|
||||||
|
memset(buf, c, len);
|
||||||
|
|
||||||
|
ret = pic_obj_value(pic_make_str(pic, buf, len));
|
||||||
|
|
||||||
|
pic_free(pic, buf);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
|
|
|
@ -7,13 +7,13 @@
|
||||||
KHASH_DEFINE(s, const char *, pic_sym *, kh_str_hash_func, kh_str_hash_equal)
|
KHASH_DEFINE(s, const char *, pic_sym *, kh_str_hash_func, kh_str_hash_equal)
|
||||||
|
|
||||||
pic_sym *
|
pic_sym *
|
||||||
pic_intern(pic_state *pic, pic_str *str)
|
pic_intern_str(pic_state *pic, pic_str *str)
|
||||||
{
|
{
|
||||||
return pic_intern_cstr(pic, pic_str_cstr(pic, str));
|
return pic_intern(pic, pic_str_cstr(pic, str));
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_sym *
|
pic_sym *
|
||||||
pic_intern_cstr(pic_state *pic, const char *cstr)
|
pic_intern(pic_state *pic, const char *cstr)
|
||||||
{
|
{
|
||||||
khash_t(s) *h = &pic->syms;
|
khash_t(s) *h = &pic->syms;
|
||||||
pic_sym *sym;
|
pic_sym *sym;
|
||||||
|
@ -93,7 +93,7 @@ pic_symbol_string_to_symbol(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "s", &str);
|
pic_get_args(pic, "s", &str);
|
||||||
|
|
||||||
return pic_obj_value(pic_intern(pic, str));
|
return pic_obj_value(pic_intern_str(pic, str));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -19,22 +19,6 @@ pic_make_vec(pic_state *pic, size_t len)
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pic_vector *
|
|
||||||
pic_make_vec_from_list(pic_state *pic, pic_value data)
|
|
||||||
{
|
|
||||||
struct pic_vector *vec;
|
|
||||||
size_t len, i;
|
|
||||||
|
|
||||||
len = pic_length(pic, data);
|
|
||||||
|
|
||||||
vec = pic_make_vec(pic, len);
|
|
||||||
for (i = 0; i < len; ++i) {
|
|
||||||
vec->data[i] = pic_car(pic, data);
|
|
||||||
data = pic_cdr(pic, data);
|
|
||||||
}
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_vec_vector_p(pic_state *pic)
|
pic_vec_vector_p(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1114,7 +1114,7 @@ pic_define_(pic_state *pic, const char *name, pic_value val)
|
||||||
{
|
{
|
||||||
pic_sym *sym, *uid;
|
pic_sym *sym, *uid;
|
||||||
|
|
||||||
sym = pic_intern_cstr(pic, name);
|
sym = pic_intern(pic, name);
|
||||||
|
|
||||||
if ((uid = pic_find_variable(pic, pic->lib->env, pic_obj_value(sym))) == NULL) {
|
if ((uid = pic_find_variable(pic, pic->lib->env, pic_obj_value(sym))) == NULL) {
|
||||||
uid = pic_add_variable(pic, pic->lib->env, pic_obj_value(sym));
|
uid = pic_add_variable(pic, pic->lib->env, pic_obj_value(sym));
|
||||||
|
@ -1131,7 +1131,7 @@ void
|
||||||
pic_define(pic_state *pic, const char *name, pic_value val)
|
pic_define(pic_state *pic, const char *name, pic_value val)
|
||||||
{
|
{
|
||||||
pic_define_(pic, name, val);
|
pic_define_(pic, name, val);
|
||||||
pic_export(pic, pic_intern_cstr(pic, name));
|
pic_export(pic, pic_intern(pic, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1144,7 +1144,7 @@ void
|
||||||
pic_defun(pic_state *pic, const char *name, pic_func_t cfunc)
|
pic_defun(pic_state *pic, const char *name, pic_func_t cfunc)
|
||||||
{
|
{
|
||||||
pic_defun_(pic, name, cfunc);
|
pic_defun_(pic, name, cfunc);
|
||||||
pic_export(pic, pic_intern_cstr(pic, name));
|
pic_export(pic, pic_intern(pic, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1157,7 +1157,7 @@ void
|
||||||
pic_defvar(pic_state *pic, const char *name, pic_value init, struct pic_proc *conv)
|
pic_defvar(pic_state *pic, const char *name, pic_value init, struct pic_proc *conv)
|
||||||
{
|
{
|
||||||
pic_defvar_(pic, name, init, conv);
|
pic_defvar_(pic, name, init, conv);
|
||||||
pic_export(pic, pic_intern_cstr(pic, name));
|
pic_export(pic, pic_intern(pic, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_value
|
pic_value
|
||||||
|
@ -1165,7 +1165,7 @@ pic_ref(pic_state *pic, struct pic_lib *lib, const char *name)
|
||||||
{
|
{
|
||||||
pic_sym *sym, *uid;
|
pic_sym *sym, *uid;
|
||||||
|
|
||||||
sym = pic_intern_cstr(pic, name);
|
sym = pic_intern(pic, name);
|
||||||
|
|
||||||
if ((uid = pic_find_variable(pic, lib->env, pic_obj_value(sym))) == NULL) {
|
if ((uid = pic_find_variable(pic, lib->env, pic_obj_value(sym))) == NULL) {
|
||||||
pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name);
|
pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name);
|
||||||
|
@ -1179,7 +1179,7 @@ pic_set(pic_state *pic, struct pic_lib *lib, const char *name, pic_value val)
|
||||||
{
|
{
|
||||||
pic_sym *sym, *uid;
|
pic_sym *sym, *uid;
|
||||||
|
|
||||||
sym = pic_intern_cstr(pic, name);
|
sym = pic_intern(pic, name);
|
||||||
|
|
||||||
if ((uid = pic_find_variable(pic, lib->env, pic_obj_value(sym))) == NULL) {
|
if ((uid = pic_find_variable(pic, lib->env, pic_obj_value(sym))) == NULL) {
|
||||||
pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name);
|
pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name);
|
||||||
|
|
Loading…
Reference in New Issue