str_new -> make_str
This commit is contained in:
parent
1d03b07862
commit
df4bc3838b
22
debug.c
22
debug.c
|
@ -14,18 +14,18 @@ pic_get_backtrace(pic_state *pic)
|
|||
pic_callinfo *ci;
|
||||
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) {
|
||||
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_str_new_cstr(pic, pic_symbol_name(pic, pic_proc_name(proc))));
|
||||
trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, " at "));
|
||||
trace = pic_strcat(pic, trace, pic_make_str_cstr(pic, pic_symbol_name(pic, pic_proc_name(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)) {
|
||||
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);
|
||||
|
||||
trace = pic_str_new(pic, NULL, 0);
|
||||
trace = pic_make_str(pic, NULL, 0);
|
||||
|
||||
switch (e->type) {
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ pic_print_backtrace(pic_state *pic, struct pic_error *e)
|
|||
|
||||
/* 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);
|
||||
|
||||
/* print! */
|
||||
|
|
2
error.c
2
error.c
|
@ -109,7 +109,7 @@ pic_throw(pic_state *pic, short type, const char *msg, pic_value irrs)
|
|||
{
|
||||
struct pic_error *e;
|
||||
|
||||
e = make_error(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);
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ struct pic_string {
|
|||
#define pic_str_p(v) (pic_type(v) == PIC_TT_STRING)
|
||||
#define pic_str_ptr(o) ((struct pic_string *)pic_ptr(o))
|
||||
|
||||
pic_str *pic_str_new(pic_state *, const char * /* nullable */, size_t);
|
||||
pic_str *pic_str_new_cstr(pic_state *, const char *);
|
||||
pic_str *pic_str_new_fill(pic_state *, size_t, char);
|
||||
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_fill(pic_state *, size_t, char);
|
||||
|
||||
size_t pic_strlen(pic_str *);
|
||||
char pic_str_ref(pic_state *, pic_str *, size_t);
|
||||
|
|
4
number.c
4
number.c
|
@ -539,14 +539,14 @@ pic_number_number_to_string(pic_state *pic)
|
|||
|
||||
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 {
|
||||
char buf[snprintf(NULL, 0, "%a", f) + 1];
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
port.c
2
port.c
|
@ -101,7 +101,7 @@ pic_get_output_string(pic_state *pic, struct pic_port *port)
|
|||
buf[size] = 0;
|
||||
xfread(buf, size, 1, port->file);
|
||||
|
||||
return pic_str_new(pic, buf, size);
|
||||
return pic_make_str(pic, buf, size);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
4
read.c
4
read.c
|
@ -443,7 +443,7 @@ read_string(pic_state *pic, struct pic_port *port, const char *name)
|
|||
}
|
||||
buf[cnt] = '\0';
|
||||
|
||||
str = pic_str_new(pic, buf, cnt);
|
||||
str = pic_make_str(pic, buf, cnt);
|
||||
pic_free(pic, buf);
|
||||
return pic_obj_value(str);
|
||||
}
|
||||
|
@ -730,7 +730,7 @@ read_nullable(pic_state *pic, struct pic_port *port, int c)
|
|||
if (trie->proc == NULL) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
26
string.c
26
string.c
|
@ -10,7 +10,7 @@
|
|||
#include "picrin/port.h"
|
||||
|
||||
static pic_str *
|
||||
str_new_rope(pic_state *pic, xrope *rope)
|
||||
make_str_rope(pic_state *pic, xrope *rope)
|
||||
{
|
||||
pic_str *str;
|
||||
|
||||
|
@ -20,22 +20,22 @@ str_new_rope(pic_state *pic, xrope *rope)
|
|||
}
|
||||
|
||||
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) {
|
||||
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_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_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;
|
||||
char buf[len + 1];
|
||||
|
@ -45,7 +45,7 @@ pic_str_new_fill(pic_state *pic, size_t len, char fill)
|
|||
}
|
||||
buf[i] = '\0';
|
||||
|
||||
return pic_str_new(pic, buf, len);
|
||||
return pic_make_str(pic, buf, len);
|
||||
}
|
||||
|
||||
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);
|
||||
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));
|
||||
|
||||
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_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_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
|
||||
|
@ -258,7 +258,7 @@ pic_str_make_string(pic_state *pic)
|
|||
|
||||
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
|
||||
|
@ -377,7 +377,7 @@ pic_str_string_append(pic_state *pic)
|
|||
|
||||
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) {
|
||||
if (! pic_str_p(argv[i])) {
|
||||
pic_error(pic, "type error");
|
||||
|
@ -418,7 +418,7 @@ pic_str_list_to_string(pic_state *pic)
|
|||
|
||||
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_assert_type(pic, e, char);
|
||||
|
|
2
symbol.c
2
symbol.c
|
@ -135,7 +135,7 @@ pic_symbol_symbol_to_string(pic_state *pic)
|
|||
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
|
||||
|
|
8
system.c
8
system.c
|
@ -20,7 +20,7 @@ pic_system_cmdline(pic_state *pic)
|
|||
for (i = 0; i < pic->argc; ++i) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ pic_system_getenv(pic_state *pic)
|
|||
if (val == NULL)
|
||||
return pic_nil_value();
|
||||
else
|
||||
return pic_obj_value(pic_str_new_cstr(pic, val));
|
||||
return pic_obj_value(pic_make_str_cstr(pic, val));
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
@ -110,8 +110,8 @@ pic_system_getenvs(pic_state *pic)
|
|||
for (i = 0; (*envp)[i] != '='; ++i)
|
||||
;
|
||||
|
||||
key = pic_str_new(pic, *envp, i);
|
||||
val = pic_str_new_cstr(pic, getenv(pic_str_cstr(key)));
|
||||
key = pic_make_str(pic, *envp, i);
|
||||
val = pic_make_str_cstr(pic, getenv(pic_str_cstr(key)));
|
||||
|
||||
/* push */
|
||||
data = pic_acons(pic, pic_obj_value(key), pic_obj_value(val), data);
|
||||
|
|
Loading…
Reference in New Issue