Merge branch 'new->make'

This commit is contained in:
Yuichi Nishiwaki 2014-09-12 20:02:14 +09:00
commit a2f0d7f7ac
29 changed files with 91 additions and 91 deletions

8
blob.c
View File

@ -25,7 +25,7 @@ pic_strdup(pic_state *pic, const char *s)
} }
struct pic_blob * struct pic_blob *
pic_blob_new(pic_state *pic, size_t len) pic_make_blob(pic_state *pic, size_t len)
{ {
struct pic_blob *bv; struct pic_blob *bv;
@ -56,7 +56,7 @@ pic_blob_make_bytevector(pic_state *pic)
if (b < 0 || b > 255) if (b < 0 || b > 255)
pic_error(pic, "byte out of range"); pic_error(pic, "byte out of range");
blob = pic_blob_new(pic, k); blob = pic_make_blob(pic, k);
for (i = 0; i < k; ++i) { for (i = 0; i < k; ++i) {
blob->data[i] = b; blob->data[i] = b;
} }
@ -146,7 +146,7 @@ pic_blob_bytevector_copy(pic_state *pic)
end = from->len; end = from->len;
} }
to = pic_blob_new(pic, end - start); to = pic_make_blob(pic, end - start);
while (start < end) { while (start < end) {
to->data[i++] = from->data[start++]; to->data[i++] = from->data[start++];
} }
@ -169,7 +169,7 @@ pic_blob_bytevector_append(pic_state *pic)
len += pic_blob_ptr(argv[i])->len; len += pic_blob_ptr(argv[i])->len;
} }
blob = pic_blob_new(pic, len); blob = pic_make_blob(pic, len);
len = 0; len = 0;
for (i = 0; i < argc; ++i) { for (i = 0; i < argc; ++i) {

View File

@ -1501,5 +1501,5 @@ pic_compile(pic_state *pic, pic_value obj, struct pic_lib *lib)
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, pic_obj_value(irep)); pic_gc_protect(pic, pic_obj_value(irep));
return pic_proc_new_irep(pic, irep, NULL); return pic_make_proc_irep(pic, irep, NULL);
} }

4
cont.c
View File

@ -283,7 +283,7 @@ pic_callcc(pic_state *pic, struct pic_proc *proc)
else { else {
struct pic_proc *c; struct pic_proc *c;
c = pic_proc_new(pic, cont_call, "<continuation-procedure>"); c = pic_make_proc(pic, cont_call, "<continuation-procedure>");
/* save the continuation object in proc */ /* save the continuation object in proc */
pic_attr_set(pic, c, "@@cont", pic_obj_value(cont)); pic_attr_set(pic, c, "@@cont", pic_obj_value(cont));
@ -304,7 +304,7 @@ pic_callcc_trampoline(pic_state *pic, struct pic_proc *proc)
else { else {
struct pic_proc *c; struct pic_proc *c;
c = pic_proc_new(pic, cont_call, "<continuation-procedure>"); c = pic_make_proc(pic, cont_call, "<continuation-procedure>");
/* save the continuation object in proc */ /* save the continuation object in proc */
pic_attr_set(pic, c, "@@cont", pic_obj_value(cont)); pic_attr_set(pic, c, "@@cont", pic_obj_value(cont));

22
debug.c
View File

@ -14,18 +14,18 @@ pic_get_backtrace(pic_state *pic)
pic_callinfo *ci; pic_callinfo *ci;
pic_str *trace; pic_str *trace;
trace = pic_str_new(pic, NULL, 0); trace = pic_make_str(pic, NULL, 0);
for (ci = pic->ci; ci != pic->cibase; --ci) { for (ci = pic->ci; ci != pic->cibase; --ci) {
struct pic_proc *proc = pic_proc_ptr(ci->fp[0]); struct pic_proc *proc = pic_proc_ptr(ci->fp[0]);
trace = pic_strcat(pic, trace, pic_str_new_cstr(pic, " at ")); trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, " at "));
trace = pic_strcat(pic, trace, pic_str_new_cstr(pic, pic_symbol_name(pic, pic_proc_name(proc)))); trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, pic_symbol_name(pic, pic_proc_name(proc))));
if (pic_proc_func_p(proc)) { if (pic_proc_func_p(proc)) {
trace = pic_strcat(pic, trace, pic_str_new_cstr(pic, " (native function)\n")); trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, " (native function)\n"));
} else if (pic_proc_irep_p(proc)) { } else if (pic_proc_irep_p(proc)) {
trace = pic_strcat(pic, trace, pic_str_new_cstr(pic, " (unknown location)\n")); /* TODO */ trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, " (unknown location)\n")); /* TODO */
} }
} }
@ -43,20 +43,20 @@ pic_print_backtrace(pic_state *pic, struct pic_error *e)
assert(pic->err != NULL); assert(pic->err != NULL);
trace = pic_str_new(pic, NULL, 0); trace = pic_make_str(pic, NULL, 0);
switch (e->type) { switch (e->type) {
case PIC_ERROR_OTHER: case PIC_ERROR_OTHER:
trace = pic_strcat(pic, trace, pic_str_new_cstr(pic, "error: ")); trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, "error: "));
break; break;
case PIC_ERROR_FILE: case PIC_ERROR_FILE:
trace = pic_strcat(pic, trace, pic_str_new_cstr(pic, "file error: ")); trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, "file error: "));
break; break;
case PIC_ERROR_READ: case PIC_ERROR_READ:
trace = pic_strcat(pic, trace, pic_str_new_cstr(pic, "read error: ")); trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, "read error: "));
break; break;
case PIC_ERROR_RAISED: case PIC_ERROR_RAISED:
trace = pic_strcat(pic, trace, pic_str_new_cstr(pic, "raised: ")); trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, "raised: "));
break; break;
} }
@ -64,7 +64,7 @@ pic_print_backtrace(pic_state *pic, struct pic_error *e)
/* TODO: print error irritants */ /* TODO: print error irritants */
trace = pic_strcat(pic, trace, pic_str_new(pic, "\n", 1)); trace = pic_strcat(pic, trace, pic_make_str(pic, "\n", 1));
trace = pic_strcat(pic, trace, e->stack); trace = pic_strcat(pic, trace, e->stack);
/* print! */ /* print! */

4
dict.c
View File

@ -7,7 +7,7 @@
#include "picrin/cont.h" #include "picrin/cont.h"
struct pic_dict * struct pic_dict *
pic_dict_new(pic_state *pic) pic_make_dict(pic_state *pic)
{ {
struct pic_dict *dict; struct pic_dict *dict;
@ -70,7 +70,7 @@ pic_dict_dict(pic_state *pic)
pic_get_args(pic, ""); pic_get_args(pic, "");
dict = pic_dict_new(pic); dict = pic_make_dict(pic);
return pic_obj_value(dict); return pic_obj_value(dict);
} }

View File

@ -72,7 +72,7 @@ pic_pop_try(pic_state *pic)
} }
static struct pic_error * static struct pic_error *
error_new(pic_state *pic, short type, pic_str *msg, pic_value irrs) make_error(pic_state *pic, short type, pic_str *msg, pic_value irrs)
{ {
struct pic_error *e; struct pic_error *e;
pic_str *stack; pic_str *stack;
@ -109,7 +109,7 @@ pic_throw(pic_state *pic, short type, const char *msg, pic_value irrs)
{ {
struct pic_error *e; struct pic_error *e;
e = error_new(pic, type, pic_str_new_cstr(pic, msg), irrs); e = make_error(pic, type, pic_make_str_cstr(pic, msg), irrs);
pic_throw_error(pic, e); pic_throw_error(pic, e);
} }

View File

@ -18,7 +18,7 @@ struct pic_blob {
#define pic_blob_p(v) (pic_type(v) == PIC_TT_BLOB) #define pic_blob_p(v) (pic_type(v) == PIC_TT_BLOB)
#define pic_blob_ptr(v) ((struct pic_blob *)pic_ptr(v)) #define pic_blob_ptr(v) ((struct pic_blob *)pic_ptr(v))
struct pic_blob *pic_blob_new(pic_state *, size_t); struct pic_blob *pic_make_blob(pic_state *, size_t);
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View File

@ -17,7 +17,7 @@ struct pic_dict {
#define pic_dict_p(v) (pic_type(v) == PIC_TT_DICT) #define pic_dict_p(v) (pic_type(v) == PIC_TT_DICT)
#define pic_dict_ptr(v) ((struct pic_dict *)pic_ptr(v)) #define pic_dict_ptr(v) ((struct pic_dict *)pic_ptr(v))
struct pic_dict *pic_dict_new(pic_state *); struct pic_dict *pic_make_dict(pic_state *);
pic_value pic_dict_ref(pic_state *, struct pic_dict *, pic_sym); 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_set(pic_state *, struct pic_dict *, pic_sym, pic_value);

View File

@ -33,7 +33,7 @@ struct pic_senv *pic_null_syntactic_environment(pic_state *);
bool pic_identifier_p(pic_state *pic, pic_value obj); 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); 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 *); struct pic_senv *pic_make_senv(pic_state *, struct pic_senv *);
pic_sym pic_add_rename(pic_state *, struct pic_senv *, pic_sym); 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 */); bool pic_find_rename(pic_state *, struct pic_senv *, pic_sym, pic_sym * /* = NULL */);

View File

@ -46,8 +46,8 @@ struct pic_proc {
#define pic_env_p(o) (pic_type(o) == PIC_TT_ENV) #define pic_env_p(o) (pic_type(o) == PIC_TT_ENV)
#define pic_env_ptr(o) ((struct pic_env *)pic_ptr(o)) #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_make_proc(pic_state *, pic_func_t, const char *);
struct pic_proc *pic_proc_new_irep(pic_state *, struct pic_irep *, struct pic_env *); struct pic_proc *pic_make_proc_irep(pic_state *, struct pic_irep *, struct pic_env *);
pic_sym pic_proc_name(struct pic_proc *); pic_sym pic_proc_name(struct pic_proc *);

View File

@ -29,7 +29,7 @@ void pic_init_reader(pic_state *);
void pic_define_reader(pic_state *, const char *, pic_func_t); void pic_define_reader(pic_state *, const char *, pic_func_t);
struct pic_trie *pic_trie_new(pic_state *); struct pic_trie *pic_make_trie(pic_state *);
void pic_trie_delete(pic_state *, struct pic_trie *); void pic_trie_delete(pic_state *, struct pic_trie *);
#if defined(__cplusplus) #if defined(__cplusplus)

View File

@ -17,7 +17,7 @@ struct pic_record {
#define pic_record_p(v) (pic_type(v) == PIC_TT_RECORD) #define pic_record_p(v) (pic_type(v) == PIC_TT_RECORD)
#define pic_record_ptr(v) ((struct pic_record *)pic_ptr(v)) #define pic_record_ptr(v) ((struct pic_record *)pic_ptr(v))
struct pic_record *pic_record_new(pic_state *, pic_value); struct pic_record *pic_make_record(pic_state *, pic_value);
pic_value pic_record_type(pic_state *, struct pic_record *); pic_value pic_record_type(pic_state *, struct pic_record *);
pic_value pic_record_ref(pic_state *, struct pic_record *, pic_sym); pic_value pic_record_ref(pic_state *, struct pic_record *, pic_sym);

View File

@ -17,9 +17,9 @@ struct pic_string {
#define pic_str_p(v) (pic_type(v) == PIC_TT_STRING) #define pic_str_p(v) (pic_type(v) == PIC_TT_STRING)
#define pic_str_ptr(o) ((struct pic_string *)pic_ptr(o)) #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_make_str(pic_state *, const char * /* nullable */, size_t);
pic_str *pic_str_new_cstr(pic_state *, const char *); pic_str *pic_make_str_cstr(pic_state *, const char *);
pic_str *pic_str_new_fill(pic_state *, size_t, char); pic_str *pic_make_str_fill(pic_state *, size_t, char);
size_t pic_strlen(pic_str *); size_t pic_strlen(pic_str *);
char pic_str_ref(pic_state *, pic_str *, size_t); char pic_str_ref(pic_state *, pic_str *, size_t);

View File

@ -18,7 +18,7 @@ struct pic_var {
#define pic_var_p(o) (pic_type(o) == PIC_TT_VAR) #define pic_var_p(o) (pic_type(o) == PIC_TT_VAR)
#define pic_var_ptr(o) ((struct pic_var *)pic_ptr(o)) #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 */); struct pic_var *pic_make_var(pic_state *, pic_value, struct pic_proc * /* = NULL */);
pic_value pic_var_ref(pic_state *, struct pic_var *); pic_value pic_var_ref(pic_state *, struct pic_var *);
void pic_var_set(pic_state *, struct pic_var *, pic_value); void pic_var_set(pic_state *, struct pic_var *, pic_value);

View File

@ -18,8 +18,8 @@ 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_vec_new(pic_state *, size_t); struct pic_vector *pic_make_vec(pic_state *, size_t);
struct pic_vector *pic_vec_new_from_list(pic_state *, pic_value); struct pic_vector *pic_make_vec_from_list(pic_state *, pic_value);
#if defined(__cplusplus) #if defined(__cplusplus)
} }

2
lib.c
View File

@ -78,7 +78,7 @@ import_table(pic_state *pic, pic_value spec)
pic_sym sym; pic_sym sym;
xh_iter it; xh_iter it;
imports = pic_dict_new(pic); imports = pic_make_dict(pic);
if (pic_list_p(spec)) { if (pic_list_p(spec)) {
if (pic_eq_p(pic_car(pic, spec), pic_sym_value(sONLY))) { if (pic_eq_p(pic_car(pic, spec), pic_sym_value(sONLY))) {

View File

@ -164,7 +164,7 @@ macroexpand_lambda(pic_state *pic, pic_value expr, struct pic_senv *senv)
pic_error(pic, "syntax error"); pic_error(pic, "syntax error");
} }
in = pic_senv_new(pic, senv); in = pic_make_senv(pic, senv);
for (a = pic_cadr(pic, expr); pic_pair_p(a); a = pic_cdr(pic, a)) { for (a = pic_cadr(pic, expr); pic_pair_p(a); a = pic_cdr(pic, a)) {
pic_value v = pic_car(pic, a); pic_value v = pic_car(pic, a);
@ -386,7 +386,7 @@ pic_macroexpand(pic_state *pic, pic_value expr, struct pic_lib *lib)
} }
struct pic_senv * struct pic_senv *
pic_senv_new(pic_state *pic, struct pic_senv *up) pic_make_senv(pic_state *pic, struct pic_senv *up)
{ {
struct pic_senv *senv; struct pic_senv *senv;
@ -403,7 +403,7 @@ pic_null_syntactic_environment(pic_state *pic)
{ {
struct pic_senv *senv; struct pic_senv *senv;
senv = pic_senv_new(pic, NULL); senv = pic_make_senv(pic, NULL);
pic_define_syntactic_keyword(pic, senv, pic->sDEFINE_LIBRARY, pic->rDEFINE_LIBRARY); pic_define_syntactic_keyword(pic, senv, pic->sDEFINE_LIBRARY, pic->rDEFINE_LIBRARY);
pic_define_syntactic_keyword(pic, senv, pic->sIMPORT, pic->rIMPORT); pic_define_syntactic_keyword(pic, senv, pic->sIMPORT, pic->rIMPORT);
@ -430,7 +430,7 @@ pic_defmacro(pic_state *pic, pic_sym name, pic_sym id, pic_func_t func)
pic_put_rename(pic, pic->lib->env, name, id); pic_put_rename(pic, pic->lib->env, name, id);
/* symbol registration */ /* symbol registration */
define_macro(pic, id, pic_proc_new(pic, func, pic_symbol_name(pic, name)), NULL); define_macro(pic, id, pic_make_proc(pic, func, pic_symbol_name(pic, name)), NULL);
/* auto export! */ /* auto export! */
pic_export(pic, name); pic_export(pic, name);

View File

@ -539,14 +539,14 @@ pic_number_number_to_string(pic_state *pic)
number_string(ival, radix, ilen, buf); number_string(ival, radix, ilen, buf);
return pic_obj_value(pic_str_new(pic, buf, sizeof buf - 1)); return pic_obj_value(pic_make_str(pic, buf, sizeof buf - 1));
} }
else { else {
char buf[snprintf(NULL, 0, "%a", f) + 1]; char buf[snprintf(NULL, 0, "%a", f) + 1];
snprintf(buf, sizeof buf, "%a", f); snprintf(buf, sizeof buf, "%a", f);
return pic_obj_value(pic_str_new(pic, buf, sizeof buf - 1)); return pic_obj_value(pic_make_str(pic, buf, sizeof buf - 1));
} }
} }

12
port.c
View File

@ -101,7 +101,7 @@ pic_get_output_string(pic_state *pic, struct pic_port *port)
buf[size] = 0; buf[size] = 0;
xfread(buf, size, 1, port->file); xfread(buf, size, 1, port->file);
return pic_str_new(pic, buf, size); return pic_make_str(pic, buf, size);
} }
void void
@ -360,7 +360,7 @@ pic_port_get_output_bytevector(pic_state *pic)
xrewind(port->file); xrewind(port->file);
/* copy to buf */ /* copy to buf */
blob = pic_blob_new(pic, endpos); blob = pic_make_blob(pic, endpos);
xfread(blob->data, 1, endpos, port->file); xfread(blob->data, 1, endpos, port->file);
return pic_obj_value(blob); return pic_obj_value(blob);
@ -528,7 +528,7 @@ pic_port_read_blob(pic_state *pic)
assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "read-bytevector"); assert_port_profile(port, PIC_PORT_IN | PIC_PORT_BINARY, PIC_PORT_OPEN, "read-bytevector");
blob = pic_blob_new(pic, k); blob = pic_make_blob(pic, k);
i = xfread(blob->data, sizeof(char), k, port->file); i = xfread(blob->data, sizeof(char), k, port->file);
if ( i == 0 ) { if ( i == 0 ) {
@ -682,9 +682,9 @@ pic_port_flush(pic_state *pic)
void void
pic_init_port(pic_state *pic) pic_init_port(pic_state *pic)
{ {
pic_define(pic, "current-input-port", pic_obj_value(pic_var_new(pic, pic_obj_value(pic->xSTDIN), NULL))); pic_define(pic, "current-input-port", pic_obj_value(pic_make_var(pic, pic_obj_value(pic->xSTDIN), NULL)));
pic_define(pic, "current-output-port", pic_obj_value(pic_var_new(pic, pic_obj_value(pic->xSTDOUT), NULL))); pic_define(pic, "current-output-port", pic_obj_value(pic_make_var(pic, pic_obj_value(pic->xSTDOUT), NULL)));
pic_define(pic, "current-error-port", pic_obj_value(pic_var_new(pic, pic_obj_value(pic->xSTDERR), NULL))); pic_define(pic, "current-error-port", pic_obj_value(pic_make_var(pic, pic_obj_value(pic->xSTDERR), NULL)));
pic_defun(pic, "call-with-port", pic_port_call_with_port); pic_defun(pic, "call-with-port", pic_port_call_with_port);

6
proc.c
View File

@ -9,7 +9,7 @@
#include "picrin/dict.h" #include "picrin/dict.h"
struct pic_proc * struct pic_proc *
pic_proc_new(pic_state *pic, pic_func_t func, const char *name) pic_make_proc(pic_state *pic, pic_func_t func, const char *name)
{ {
struct pic_proc *proc; struct pic_proc *proc;
@ -25,7 +25,7 @@ pic_proc_new(pic_state *pic, pic_func_t func, const char *name)
} }
struct pic_proc * struct pic_proc *
pic_proc_new_irep(pic_state *pic, struct pic_irep *irep, struct pic_env *env) pic_make_proc_irep(pic_state *pic, struct pic_irep *irep, struct pic_env *env)
{ {
struct pic_proc *proc; struct pic_proc *proc;
@ -53,7 +53,7 @@ struct pic_dict *
pic_attr(pic_state *pic, struct pic_proc *proc) pic_attr(pic_state *pic, struct pic_proc *proc)
{ {
if (proc->attr == NULL) { if (proc->attr == NULL) {
proc->attr = pic_dict_new(pic); proc->attr = pic_make_dict(pic);
} }
return proc->attr; return proc->attr;
} }

16
read.c
View File

@ -443,7 +443,7 @@ read_string(pic_state *pic, struct pic_port *port, const char *name)
} }
buf[cnt] = '\0'; buf[cnt] = '\0';
str = pic_str_new(pic, buf, cnt); str = pic_make_str(pic, buf, cnt);
pic_free(pic, buf); pic_free(pic, buf);
return pic_obj_value(str); return pic_obj_value(str);
} }
@ -534,7 +534,7 @@ read_blob(pic_state *pic, struct pic_port *port, const char *str)
c = next(port); c = next(port);
} }
blob = pic_blob_new(pic, len); blob = pic_make_blob(pic, len);
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
blob->data[i] = dat[i]; blob->data[i] = dat[i];
} }
@ -588,7 +588,7 @@ read_vector(pic_state *pic, struct pic_port *port, const char *str)
list = read(pic, port, str[1]); list = read(pic, port, str[1]);
return pic_obj_value(pic_vec_new_from_list(pic, list)); return pic_obj_value(pic_make_vec_from_list(pic, list));
} }
static pic_value static pic_value
@ -625,7 +625,7 @@ read_label_set(pic_state *pic, struct pic_port *port, int i)
if (vect) { if (vect) {
pic_vec *tmp; pic_vec *tmp;
val = pic_obj_value(pic_vec_new(pic, 0)); val = pic_obj_value(pic_make_vec(pic, 0));
xh_put_int(&pic->reader->labels, i, &val); xh_put_int(&pic->reader->labels, i, &val);
@ -730,7 +730,7 @@ read_nullable(pic_state *pic, struct pic_port *port, int c)
if (trie->proc == NULL) { if (trie->proc == NULL) {
read_error(pic, "no reader registered for current string"); read_error(pic, "no reader registered for current string");
} }
str = pic_str_new(pic, buf, i); str = pic_make_str(pic, buf, i);
return pic_apply2(pic, trie->proc, pic_obj_value(port), pic_obj_value(str)); return pic_apply2(pic, trie->proc, pic_obj_value(port), pic_obj_value(str));
} }
@ -751,7 +751,7 @@ read(pic_state *pic, struct pic_port *port, int c)
} }
struct pic_trie * struct pic_trie *
pic_trie_new(pic_state *pic) pic_make_trie(pic_state *pic)
{ {
struct pic_trie *trie; struct pic_trie *trie;
@ -784,11 +784,11 @@ pic_define_reader(pic_state *pic, const char *str, pic_func_t reader)
while ((c = *str++)) { while ((c = *str++)) {
if (trie->table[c] == NULL) { if (trie->table[c] == NULL) {
trie->table[c] = pic_trie_new(pic); trie->table[c] = pic_make_trie(pic);
} }
trie = trie->table[c]; trie = trie->table[c];
} }
trie->proc = pic_proc_new(pic, reader, "reader"); trie->proc = pic_make_proc(pic, reader, "reader");
} }
#define DEFINE_READER(name) \ #define DEFINE_READER(name) \

View File

@ -6,7 +6,7 @@
#include "picrin/record.h" #include "picrin/record.h"
struct pic_record * struct pic_record *
pic_record_new(pic_state *pic, pic_value rectype) pic_make_record(pic_state *pic, pic_value rectype)
{ {
struct pic_record *rec; struct pic_record *rec;
@ -52,7 +52,7 @@ pic_record_make_record(pic_state *pic)
pic_get_args(pic, "o", &rectype); pic_get_args(pic, "o", &rectype);
rec = pic_record_new(pic, rectype); rec = pic_make_record(pic, rectype);
return pic_obj_value(rec); return pic_obj_value(rec);
} }

View File

@ -67,7 +67,7 @@ pic_open(int argc, char *argv[], char **envp)
/* reader */ /* reader */
pic->reader = malloc(sizeof(struct pic_reader)); pic->reader = malloc(sizeof(struct pic_reader));
pic->reader->typecase = PIC_CASE_DEFAULT; pic->reader->typecase = PIC_CASE_DEFAULT;
pic->reader->trie = pic_trie_new(pic); pic->reader->trie = pic_make_trie(pic);
xh_init_int(&pic->reader->labels, sizeof(pic_value)); xh_init_int(&pic->reader->labels, sizeof(pic_value));
/* error handling */ /* error handling */

View File

@ -10,7 +10,7 @@
#include "picrin/port.h" #include "picrin/port.h"
static pic_str * static pic_str *
str_new_rope(pic_state *pic, xrope *rope) make_str_rope(pic_state *pic, xrope *rope)
{ {
pic_str *str; pic_str *str;
@ -20,22 +20,22 @@ str_new_rope(pic_state *pic, xrope *rope)
} }
pic_str * pic_str *
pic_str_new(pic_state *pic, const char *imbed, size_t len) pic_make_str(pic_state *pic, const char *imbed, size_t len)
{ {
if (imbed == NULL && len > 0) { if (imbed == NULL && len > 0) {
pic_errorf(pic, "zero length specified against NULL ptr"); pic_errorf(pic, "zero length specified against NULL ptr");
} }
return str_new_rope(pic, xr_new_copy(imbed, len)); return make_str_rope(pic, xr_new_copy(imbed, len));
} }
pic_str * pic_str *
pic_str_new_cstr(pic_state *pic, const char *cstr) pic_make_str_cstr(pic_state *pic, const char *cstr)
{ {
return pic_str_new(pic, cstr, strlen(cstr)); return pic_make_str(pic, cstr, strlen(cstr));
} }
pic_str * pic_str *
pic_str_new_fill(pic_state *pic, size_t len, char fill) pic_make_str_fill(pic_state *pic, size_t len, char fill)
{ {
size_t i; size_t i;
char buf[len + 1]; char buf[len + 1];
@ -45,7 +45,7 @@ pic_str_new_fill(pic_state *pic, size_t len, char fill)
} }
buf[i] = '\0'; buf[i] = '\0';
return pic_str_new(pic, buf, len); return pic_make_str(pic, buf, len);
} }
size_t size_t
@ -76,7 +76,7 @@ pic_str_set(pic_state *pic, pic_str *str, size_t i, char c)
} }
x = pic_substr(pic, str, 0, i); x = pic_substr(pic, str, 0, i);
y = pic_str_new_fill(pic, 1, c); y = pic_make_str_fill(pic, 1, c);
z = pic_substr(pic, str, i + 1, pic_strlen(str)); z = pic_substr(pic, str, i + 1, pic_strlen(str));
tmp = pic_strcat(pic, x, pic_strcat(pic, y, z)); tmp = pic_strcat(pic, x, pic_strcat(pic, y, z));
@ -89,13 +89,13 @@ pic_str_set(pic_state *pic, pic_str *str, size_t i, char c)
pic_str * pic_str *
pic_strcat(pic_state *pic, pic_str *a, pic_str *b) pic_strcat(pic_state *pic, pic_str *a, pic_str *b)
{ {
return str_new_rope(pic, xr_cat(a->rope, b->rope)); return make_str_rope(pic, xr_cat(a->rope, b->rope));
} }
pic_str * pic_str *
pic_substr(pic_state *pic, pic_str *str, size_t s, size_t e) pic_substr(pic_state *pic, pic_str *str, size_t s, size_t e)
{ {
return str_new_rope(pic, xr_sub(str->rope, s, e)); return make_str_rope(pic, xr_sub(str->rope, s, e));
} }
int int
@ -258,7 +258,7 @@ pic_str_make_string(pic_state *pic)
pic_get_args(pic, "i|c", &len, &c); pic_get_args(pic, "i|c", &len, &c);
return pic_obj_value(pic_str_new_fill(pic, len, c)); return pic_obj_value(pic_make_str_fill(pic, len, c));
} }
static pic_value static pic_value
@ -377,7 +377,7 @@ pic_str_string_append(pic_state *pic)
pic_get_args(pic, "*", &argc, &argv); pic_get_args(pic, "*", &argc, &argv);
str = pic_str_new(pic, NULL, 0); str = pic_make_str(pic, NULL, 0);
for (i = 0; i < argc; ++i) { for (i = 0; i < argc; ++i) {
if (! pic_str_p(argv[i])) { if (! pic_str_p(argv[i])) {
pic_error(pic, "type error"); pic_error(pic, "type error");
@ -418,7 +418,7 @@ pic_str_list_to_string(pic_state *pic)
pic_get_args(pic, "o", &list); pic_get_args(pic, "o", &list);
str = pic_str_new_fill(pic, pic_length(pic, list), ' '); str = pic_make_str_fill(pic, pic_length(pic, list), ' ');
pic_for_each (e, list) { pic_for_each (e, list) {
pic_assert_type(pic, e, char); pic_assert_type(pic, e, char);

View File

@ -135,7 +135,7 @@ pic_symbol_symbol_to_string(pic_state *pic)
pic_error(pic, "symbol->string: expected symbol"); pic_error(pic, "symbol->string: expected symbol");
} }
return pic_obj_value(pic_str_new_cstr(pic, pic_symbol_name(pic, pic_sym(v)))); return pic_obj_value(pic_make_str_cstr(pic, pic_symbol_name(pic, pic_sym(v))));
} }
static pic_value static pic_value

View File

@ -20,7 +20,7 @@ pic_system_cmdline(pic_state *pic)
for (i = 0; i < pic->argc; ++i) { for (i = 0; i < pic->argc; ++i) {
size_t ai = pic_gc_arena_preserve(pic); size_t ai = pic_gc_arena_preserve(pic);
v = pic_cons(pic, pic_obj_value(pic_str_new_cstr(pic, pic->argv[i])), v); v = pic_cons(pic, pic_obj_value(pic_make_str_cstr(pic, pic->argv[i])), v);
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
} }
@ -87,7 +87,7 @@ pic_system_getenv(pic_state *pic)
if (val == NULL) if (val == NULL)
return pic_nil_value(); return pic_nil_value();
else else
return pic_obj_value(pic_str_new_cstr(pic, val)); return pic_obj_value(pic_make_str_cstr(pic, val));
} }
static pic_value static pic_value
@ -110,8 +110,8 @@ pic_system_getenvs(pic_state *pic)
for (i = 0; (*envp)[i] != '='; ++i) for (i = 0; (*envp)[i] != '='; ++i)
; ;
key = pic_str_new(pic, *envp, i); key = pic_make_str(pic, *envp, i);
val = pic_str_new_cstr(pic, getenv(pic_str_cstr(key))); val = pic_make_str_cstr(pic, getenv(pic_str_cstr(key)));
/* push */ /* push */
data = pic_acons(pic, pic_obj_value(key), pic_obj_value(val), data); data = pic_acons(pic, pic_obj_value(key), pic_obj_value(val), data);

4
var.c
View File

@ -7,7 +7,7 @@
#include "picrin/pair.h" #include "picrin/pair.h"
struct pic_var * struct pic_var *
pic_var_new(pic_state *pic, pic_value init, struct pic_proc *conv) pic_make_var(pic_state *pic, pic_value init, struct pic_proc *conv)
{ {
struct pic_var *var; struct pic_var *var;
@ -58,7 +58,7 @@ pic_var_make_parameter(pic_state *pic)
pic_get_args(pic, "o|l", &init, &conv); pic_get_args(pic, "o|l", &init, &conv);
return pic_obj_value(pic_var_new(pic, init, conv)); return pic_obj_value(pic_make_var(pic, init, conv));
} }
static pic_value static pic_value

View File

@ -7,7 +7,7 @@
#include "picrin/pair.h" #include "picrin/pair.h"
struct pic_vector * struct pic_vector *
pic_vec_new(pic_state *pic, size_t len) pic_make_vec(pic_state *pic, size_t len)
{ {
struct pic_vector *vec; struct pic_vector *vec;
size_t i; size_t i;
@ -22,14 +22,14 @@ pic_vec_new(pic_state *pic, size_t len)
} }
struct pic_vector * struct pic_vector *
pic_vec_new_from_list(pic_state *pic, pic_value data) pic_make_vec_from_list(pic_state *pic, pic_value data)
{ {
struct pic_vector *vec; struct pic_vector *vec;
size_t i, len; size_t i, len;
len = pic_length(pic, data); len = pic_length(pic, data);
vec = pic_vec_new(pic, len); vec = pic_make_vec(pic, len);
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
vec->data[i] = pic_car(pic, data); vec->data[i] = pic_car(pic, data);
data = pic_cdr(pic, data); data = pic_cdr(pic, data);
@ -57,7 +57,7 @@ pic_vec_make_vector(pic_state *pic)
n = pic_get_args(pic, "i|o", &k, &v); n = pic_get_args(pic, "i|o", &k, &v);
vec = pic_vec_new(pic, k); vec = pic_make_vec(pic, k);
if (n == 2) { if (n == 2) {
for (i = 0; i < (size_t)k; ++i) { for (i = 0; i < (size_t)k; ++i) {
vec->data[i] = v; vec->data[i] = v;
@ -152,7 +152,7 @@ pic_vec_vector_copy(pic_state *pic)
end = vec->len; end = vec->len;
} }
to = pic_vec_new(pic, end - start); to = pic_make_vec(pic, end - start);
while (start < end) { while (start < end) {
to->data[i++] = vec->data[start++]; to->data[i++] = vec->data[start++];
} }
@ -175,7 +175,7 @@ pic_vec_vector_append(pic_state *pic)
len += pic_vec_ptr(argv[i])->len; len += pic_vec_ptr(argv[i])->len;
} }
vec = pic_vec_new(pic, len); vec = pic_make_vec(pic, len);
len = 0; len = 0;
for (i = 0; i < argc; ++i) { for (i = 0; i < argc; ++i) {
@ -219,7 +219,7 @@ pic_vec_list_to_vector(pic_state *pic)
pic_get_args(pic, "o", &list); pic_get_args(pic, "o", &list);
vec = pic_vec_new(pic, pic_length(pic, list)); vec = pic_make_vec(pic, pic_length(pic, list));
data = vec->data; data = vec->data;

4
vm.c
View File

@ -456,7 +456,7 @@ pic_defun(pic_state *pic, const char *name, pic_func_t cfunc)
{ {
struct pic_proc *proc; struct pic_proc *proc;
proc = pic_proc_new(pic, cfunc, name); proc = pic_make_proc(pic, cfunc, name);
pic_define(pic, name, pic_obj_value(proc)); pic_define(pic, name, pic_obj_value(proc));
} }
@ -906,7 +906,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
vm_push_env(pic); vm_push_env(pic);
} }
proc = pic_proc_new_irep(pic, irep->irep[c.u.i], pic->ci->env); proc = pic_make_proc_irep(pic, irep->irep[c.u.i], pic->ci->env);
PUSH(pic_obj_value(proc)); PUSH(pic_obj_value(proc));
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
NEXT; NEXT;