remove typedefs of struct pic_string and struct pic_blob

This commit is contained in:
Yuichi Nishiwaki 2016-02-15 00:20:49 +09:00
parent 780df6275b
commit a92e70a610
23 changed files with 85 additions and 87 deletions

View File

@ -1,9 +1,9 @@
#include "picrin.h"
void
pic_str_set(pic_state *pic, pic_str *str, int i, char c)
pic_str_set(pic_state *pic, struct pic_string *str, int i, char c)
{
pic_str *x, *y, *z, *tmp;
struct pic_string *x, *y, *z, *tmp;
char buf[1];
if (pic_str_len(str) <= i) {
@ -26,7 +26,7 @@ pic_str_set(pic_state *pic, pic_str *str, int i, char c)
static pic_value
pic_str_string_set(pic_state *pic)
{
pic_str *str;
struct pic_string *str;
char c;
int k;
@ -39,7 +39,7 @@ pic_str_string_set(pic_state *pic)
static pic_value
pic_str_string_copy_ip(pic_state *pic)
{
pic_str *to, *from;
struct pic_string *to, *from;
int n, at, start, end;
n = pic_get_args(pic, "sis|ii", &to, &at, &from, &start, &end);
@ -63,7 +63,7 @@ pic_str_string_copy_ip(pic_state *pic)
static pic_value
pic_str_string_fill_ip(pic_state *pic)
{
pic_str *str;
struct pic_string *str;
char c;
int n, start, end;

View File

@ -105,7 +105,7 @@ pic_system_getenvs(pic_state *pic)
}
for (envp = picrin_envp; *envp; ++envp) {
pic_str *key, *val;
struct pic_string *key, *val;
int i;
for (i = 0; (*envp)[i] != '='; ++i)

View File

@ -82,7 +82,7 @@ pic_regexp_regexp_match(pic_state *pic)
const char *input;
regmatch_t match[100];
pic_value matches, positions;
pic_str *str;
struct pic_string *str;
int i, offset;
pic_get_args(pic, "oz", &reg, &input);
@ -157,7 +157,7 @@ pic_regexp_regexp_replace(pic_state *pic)
pic_value reg;
const char *input;
regmatch_t match;
pic_str *txt, *output = pic_make_lit(pic, "");
struct pic_string *txt, *output = pic_make_lit(pic, "");
pic_get_args(pic, "ozs", &reg, &input, &txt);

View File

@ -30,7 +30,7 @@ pic_blob_bytevector(pic_state *pic)
{
pic_value *argv;
int argc, i;
pic_blob *blob;
struct pic_blob *blob;
unsigned char *data;
pic_get_args(pic, "*", &argc, &argv);
@ -55,7 +55,7 @@ pic_blob_bytevector(pic_state *pic)
static pic_value
pic_blob_make_bytevector(pic_state *pic)
{
pic_blob *blob;
struct pic_blob *blob;
int k, i, b = 0;
pic_get_args(pic, "i|i", &k, &b);
@ -110,7 +110,7 @@ pic_blob_bytevector_u8_set(pic_state *pic)
static pic_value
pic_blob_bytevector_copy_i(pic_state *pic)
{
pic_blob *to, *from;
struct pic_blob *to, *from;
int n, at, start, end;
n = pic_get_args(pic, "bib|ii", &to, &at, &from, &start, &end);
@ -141,7 +141,7 @@ pic_blob_bytevector_copy_i(pic_state *pic)
static pic_value
pic_blob_bytevector_copy(pic_state *pic)
{
pic_blob *from, *to;
struct pic_blob *from, *to;
int n, start, end, i = 0;
n = pic_get_args(pic, "b|ii", &from, &start, &end);
@ -170,7 +170,7 @@ pic_blob_bytevector_append(pic_state *pic)
{
int argc, i, j, len;
pic_value *argv;
pic_blob *blob;
struct pic_blob *blob;
pic_get_args(pic, "*", &argc, &argv);
@ -196,7 +196,7 @@ pic_blob_bytevector_append(pic_state *pic)
static pic_value
pic_blob_list_to_bytevector(pic_state *pic)
{
pic_blob *blob;
struct pic_blob *blob;
unsigned char *data;
pic_value list, e, it;
@ -220,7 +220,7 @@ pic_blob_list_to_bytevector(pic_state *pic)
static pic_value
pic_blob_bytevector_to_list(pic_state *pic)
{
pic_blob *blob;
struct pic_blob *blob;
pic_value list;
int n, start, end, i;

View File

@ -54,7 +54,7 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, int depth, khash_t(m)
return pic_str_cmp(pic, pic_str_ptr(x), pic_str_ptr(y)) == 0;
}
case PIC_TT_BLOB: {
pic_blob *blob1, *blob2;
struct pic_blob *blob1, *blob2;
int i;
blob1 = pic_blob_ptr(x);

View File

@ -4,12 +4,12 @@
#include "picrin.h"
pic_str *
struct pic_string *
pic_get_backtrace(pic_state *pic)
{
size_t ai = pic_gc_arena_preserve(pic);
pic_callinfo *ci;
pic_str *trace;
struct pic_string *trace;
trace = pic_make_lit(pic, "");

View File

@ -21,7 +21,7 @@ void
pic_warnf(pic_state *pic, const char *fmt, ...)
{
va_list ap;
pic_str *err;
struct pic_string *err;
va_start(ap, fmt);
err = pic_vformat(pic, fmt, ap);
@ -35,7 +35,7 @@ pic_errorf(pic_state *pic, const char *fmt, ...)
{
va_list ap;
const char *msg;
pic_str *err;
struct pic_string *err;
va_start(ap, fmt);
err = pic_vformat(pic, fmt, ap);
@ -94,7 +94,7 @@ struct pic_error *
pic_make_error(pic_state *pic, pic_sym *type, const char *msg, pic_value irrs)
{
struct pic_error *e;
pic_str *stack;
struct pic_string *stack;
stack = pic_get_backtrace(pic);

View File

@ -47,7 +47,7 @@ typedef void *(*pic_allocf)(void *, void *, size_t);
#include "picrin/read.h"
#include "picrin/gc.h"
KHASH_DECLARE(s, pic_str *, pic_sym *)
KHASH_DECLARE(s, struct pic_string *, pic_sym *)
typedef struct pic_checkpoint {
PIC_OBJECT_HEADER
@ -247,19 +247,19 @@ void pic_weak_del(pic_state *, struct pic_weak *, void *);
bool pic_weak_has(pic_state *, struct pic_weak *, void *);
/* symbol */
pic_sym *pic_intern(pic_state *, pic_str *);
pic_sym *pic_intern(pic_state *, struct pic_string *);
#define pic_intern_str(pic,s,i) pic_intern(pic, pic_make_str(pic, (s), (i)))
#define pic_intern_cstr(pic,s) pic_intern(pic, pic_make_cstr(pic, (s)))
#define pic_intern_lit(pic,lit) pic_intern(pic, pic_make_lit(pic, lit))
const char *pic_symbol_name(pic_state *, pic_sym *);
/* string */
int pic_str_len(pic_str *);
char pic_str_ref(pic_state *, pic_str *, int);
pic_str *pic_str_cat(pic_state *, pic_str *, pic_str *);
pic_str *pic_str_sub(pic_state *, pic_str *, int, int);
int pic_str_cmp(pic_state *, pic_str *, pic_str *);
int pic_str_hash(pic_state *, pic_str *);
int pic_str_len(struct pic_string *);
char pic_str_ref(pic_state *, struct pic_string *, int);
struct pic_string *pic_str_cat(pic_state *, struct pic_string *, struct pic_string *);
struct pic_string *pic_str_sub(pic_state *, struct pic_string *, int, int);
int pic_str_cmp(pic_state *, struct pic_string *, struct pic_string *);
int pic_str_hash(pic_state *, struct pic_string *);
#include "picrin/blob.h"
#include "picrin/cont.h"
@ -313,7 +313,7 @@ struct pic_proc *pic_make_var(pic_state *, pic_value, struct pic_proc *);
(pic->prev_lib = NULL)))
void pic_warnf(pic_state *, const char *, ...);
pic_str *pic_get_backtrace(pic_state *);
struct pic_string *pic_get_backtrace(pic_state *);
void pic_print_backtrace(pic_state *, xFILE *);
struct pic_port *pic_stdin(pic_state *);

View File

@ -12,9 +12,9 @@ extern "C" {
struct pic_error {
PIC_OBJECT_HEADER
pic_sym *type;
pic_str *msg;
struct pic_string *msg;
pic_value irrs;
pic_str *stack;
struct pic_string *stack;
};
#define pic_error_p(v) (pic_type(v) == PIC_TT_ERROR)

View File

@ -15,13 +15,13 @@ struct pic_env {
PIC_OBJECT_HEADER
khash_t(env) map;
struct pic_env *up;
pic_str *prefix;
struct pic_string *prefix;
};
#define pic_env_p(v) (pic_type(v) == PIC_TT_ENV)
#define pic_env_ptr(v) ((struct pic_env *)pic_ptr(v))
struct pic_env *pic_make_topenv(pic_state *, pic_str *);
struct pic_env *pic_make_topenv(pic_state *, struct pic_string *);
struct pic_env *pic_make_env(pic_state *, struct pic_env *);
pic_sym *pic_add_identifier(pic_state *, pic_id *, struct pic_env *);

View File

@ -19,14 +19,14 @@ void pic_rope_decref(pic_state *, struct pic_rope *);
#define pic_str_ptr(o) ((struct pic_string *)pic_ptr(o))
pic_str *pic_make_str(pic_state *, const char *, int);
struct pic_string *pic_make_str(pic_state *, const char *, int);
#define pic_make_cstr(pic, cstr) pic_make_str(pic, (cstr), strlen(cstr))
#define pic_make_lit(pic, lit) pic_make_str(pic, "" lit, -((int)sizeof lit - 1))
const char *pic_str_cstr(pic_state *, pic_str *);
const char *pic_str_cstr(pic_state *, struct pic_string *);
pic_str *pic_format(pic_state *, const char *, ...);
pic_str *pic_vformat(pic_state *, const char *, va_list);
struct pic_string *pic_format(pic_state *, const char *, ...);
struct pic_string *pic_vformat(pic_state *, const char *, va_list);
#if defined(__cplusplus)
}

View File

@ -13,7 +13,7 @@ struct pic_id {
union {
struct pic_symbol {
PIC_OBJECT_HEADER
pic_str *str;
struct pic_string *str;
} sym;
struct {
PIC_OBJECT_HEADER

View File

@ -202,9 +202,7 @@ struct pic_env;
typedef struct pic_symbol pic_sym;
typedef struct pic_id pic_id;
typedef struct pic_pair pic_pair;
typedef struct pic_string pic_str;
typedef struct pic_vector pic_vec;
typedef struct pic_blob pic_blob;
#define pic_obj_p(v) (pic_vtype(v) == PIC_VTYPE_HEAP)
#define pic_obj_ptr(v) ((struct pic_object *)pic_ptr(v))

View File

@ -9,7 +9,7 @@ make_library_env(pic_state *pic, pic_value name)
{
struct pic_env *env;
pic_value dir, it;
pic_str *prefix = NULL;
struct pic_string *prefix = NULL;
pic_for_each (dir, name, it) {
if (prefix == NULL) {

View File

@ -21,7 +21,7 @@ pic_make_env(pic_state *pic, struct pic_env *up)
}
struct pic_env *
pic_make_topenv(pic_state *pic, pic_str *prefix)
pic_make_topenv(pic_state *pic, struct pic_string *prefix)
{
struct pic_env *env;
@ -37,7 +37,7 @@ pic_add_identifier(pic_state *pic, pic_id *id, struct pic_env *env)
{
const char *name;
pic_sym *uid;
pic_str *str;
struct pic_string *str;
name = pic_identifier_name(pic, id);

View File

@ -218,7 +218,7 @@ pic_number_number_to_string(pic_state *pic)
double f;
bool e;
int radix = 10;
pic_str *str;
struct pic_string *str;
pic_get_args(pic, "F|i", &f, &e, &radix);

View File

@ -546,7 +546,7 @@ static pic_value
pic_port_get_output_bytevector(pic_state *pic)
{
struct pic_port *port = pic_stdout(pic);
pic_blob *blob;
struct pic_blob *blob;
struct strfile *s;
pic_get_args(pic, "|p", &port);
@ -646,7 +646,7 @@ pic_port_char_ready_p(pic_state *pic)
static pic_value
pic_port_read_string(pic_state *pic){
struct pic_port *port = pic_stdin(pic), *buf;
pic_str *str;
struct pic_string *str;
int k, i;
int c;
pic_value res = pic_eof_object();
@ -725,7 +725,7 @@ static pic_value
pic_port_read_blob(pic_state *pic)
{
struct pic_port *port = pic_stdin(pic);
pic_blob *blob;
struct pic_blob *blob;
int k, i;
pic_get_args(pic, "i|p", &k, &port);

View File

@ -19,10 +19,10 @@
* F double *, bool * float with exactness
* c char * char
* z char ** c string
* s pic_str ** string object
* m pic_sym ** symbol
* v pic_vec ** vector object
* b pic_blob ** bytevector object
* s struct pic_str ** string object
* b struct pic_blob ** bytevector object
* l struct pic_proc ** lambda object
* p struct pic_port ** port object
* d struct pic_dict ** dictionary object
@ -146,10 +146,10 @@ pic_get_args(pic_state *pic, const char *format, ...)
#define PTR_CASE(c, type, ctype) \
VAL_CASE(c, type, ctype, pic_## type ##_ptr(v))
PTR_CASE('s', str, pic_str *)
PTR_CASE('m', sym, pic_sym *)
PTR_CASE('v', vec, pic_vec *)
PTR_CASE('b', blob, pic_blob *)
PTR_CASE('s', str, struct pic_string *)
PTR_CASE('b', blob, struct pic_blob *)
PTR_CASE('l', proc, struct pic_proc *)
PTR_CASE('p', port, struct pic_port *)
PTR_CASE('d', dict, struct pic_dict *)

View File

@ -419,7 +419,7 @@ read_string(pic_state *pic, struct pic_port *port, int c)
{
char *buf;
int size, cnt;
pic_str *str;
struct pic_string *str;
size = 256;
buf = pic_malloc(pic, size);
@ -499,7 +499,7 @@ read_blob(pic_state *pic, struct pic_port *port, int c)
int nbits, n;
int len, i;
unsigned char *dat;
pic_blob *blob;
struct pic_blob *blob;
nbits = 0;

View File

@ -93,12 +93,12 @@ pic_make_rope(pic_state *pic, struct pic_chunk *c)
return x;
}
static pic_str *
static struct pic_string *
pic_make_string(pic_state *pic, struct pic_rope *rope)
{
pic_str *str;
struct pic_string *str;
str = (pic_str *)pic_obj_alloc(pic, sizeof(pic_str), PIC_TT_STRING);
str = (struct pic_string *)pic_obj_alloc(pic, sizeof(struct pic_string), PIC_TT_STRING);
str->rope = rope; /* delegate ownership */
return str;
}
@ -236,7 +236,7 @@ rope_cstr(pic_state *pic, struct pic_rope *x)
return c->str;
}
pic_str *
struct pic_string *
pic_make_str(pic_state *pic, const char *str, int len)
{
struct pic_chunk *c;
@ -253,13 +253,13 @@ pic_make_str(pic_state *pic, const char *str, int len)
}
int
pic_str_len(pic_str *str)
pic_str_len(struct pic_string *str)
{
return rope_len(str->rope);
}
char
pic_str_ref(pic_state *pic, pic_str *str, int i)
pic_str_ref(pic_state *pic, struct pic_string *str, int i)
{
int c;
@ -270,26 +270,26 @@ pic_str_ref(pic_state *pic, pic_str *str, int i)
return (char)c;
}
pic_str *
pic_str_cat(pic_state *pic, pic_str *a, pic_str *b)
struct pic_string *
pic_str_cat(pic_state *pic, struct pic_string *a, struct pic_string *b)
{
return pic_make_string(pic, rope_cat(pic, a->rope, b->rope));
}
pic_str *
pic_str_sub(pic_state *pic, pic_str *str, int s, int e)
struct pic_string *
pic_str_sub(pic_state *pic, struct pic_string *str, int s, int e)
{
return pic_make_string(pic, rope_sub(pic, str->rope, s, e));
}
int
pic_str_cmp(pic_state *pic, pic_str *str1, pic_str *str2)
pic_str_cmp(pic_state *pic, struct pic_string *str1, struct pic_string *str2)
{
return strcmp(pic_str_cstr(pic, str1), pic_str_cstr(pic, str2));
}
int
pic_str_hash(pic_state *pic, pic_str *str)
pic_str_hash(pic_state *pic, struct pic_string *str)
{
const char *s;
int h = 0;
@ -302,7 +302,7 @@ pic_str_hash(pic_state *pic, pic_str *str)
}
const char *
pic_str_cstr(pic_state *pic, pic_str *str)
pic_str_cstr(pic_state *pic, struct pic_string *str)
{
return rope_cstr(pic, str->rope);
}
@ -373,11 +373,11 @@ pic_vfformat(pic_state *pic, xFILE *file, const char *fmt, va_list ap)
return;
}
pic_str *
struct pic_string *
pic_vformat(pic_state *pic, const char *fmt, va_list ap)
{
struct pic_port *port;
pic_str *str;
struct pic_string *str;
port = pic_open_output_string(pic);
@ -388,11 +388,11 @@ pic_vformat(pic_state *pic, const char *fmt, va_list ap)
return str;
}
pic_str *
struct pic_string *
pic_format(pic_state *pic, const char *fmt, ...)
{
va_list ap;
pic_str *str;
struct pic_string *str;
va_start(ap, fmt);
str = pic_vformat(pic, fmt, ap);
@ -416,7 +416,7 @@ pic_str_string(pic_state *pic)
{
int argc, i;
pic_value *argv;
pic_str *str;
struct pic_string *str;
char *buf;
pic_get_args(pic, "*", &argc, &argv);
@ -456,7 +456,7 @@ pic_str_make_string(pic_state *pic)
static pic_value
pic_str_string_length(pic_state *pic)
{
pic_str *str;
struct pic_string *str;
pic_get_args(pic, "s", &str);
@ -466,7 +466,7 @@ pic_str_string_length(pic_state *pic)
static pic_value
pic_str_string_ref(pic_state *pic)
{
pic_str *str;
struct pic_string *str;
int k;
pic_get_args(pic, "si", &str, &k);
@ -507,7 +507,7 @@ DEFINE_STRING_CMP(ge, >=)
static pic_value
pic_str_string_copy(pic_state *pic)
{
pic_str *str;
struct pic_string *str;
int n, start, end, len;
n = pic_get_args(pic, "s|ii", &str, &start, &end);
@ -532,7 +532,7 @@ pic_str_string_append(pic_state *pic)
{
int argc, i;
pic_value *argv;
pic_str *str;
struct pic_string *str;
pic_get_args(pic, "*", &argc, &argv);
@ -552,7 +552,7 @@ pic_str_string_map(pic_state *pic)
struct pic_proc *proc;
pic_value *argv, vals, val;
int argc, i, len, j;
pic_str *str;
struct pic_string *str;
char *buf;
pic_get_args(pic, "l*", &proc, &argc, &argv);
@ -632,7 +632,7 @@ pic_str_string_for_each(pic_state *pic)
static pic_value
pic_str_list_to_string(pic_state *pic)
{
pic_str *str;
struct pic_string *str;
pic_value list, e, it;
int i;
char *buf;
@ -667,7 +667,7 @@ pic_str_list_to_string(pic_state *pic)
static pic_value
pic_str_string_to_list(pic_state *pic)
{
pic_str *str;
struct pic_string *str;
pic_value list;
int n, start, end, i;

View File

@ -7,10 +7,10 @@
#define kh_pic_str_hash(a) (pic_str_hash(pic, (a)))
#define kh_pic_str_cmp(a, b) (pic_str_cmp(pic, (a), (b)) == 0)
KHASH_DEFINE(s, pic_str *, pic_sym *, kh_pic_str_hash, kh_pic_str_cmp)
KHASH_DEFINE(s, struct pic_string *, pic_sym *, kh_pic_str_hash, kh_pic_str_cmp)
pic_sym *
pic_intern(pic_state *pic, pic_str *str)
pic_intern(pic_state *pic, struct pic_string *str)
{
khash_t(s) *h = &pic->oblist;
pic_sym *sym;
@ -102,7 +102,7 @@ pic_symbol_symbol_to_string(pic_state *pic)
static pic_value
pic_symbol_string_to_symbol(pic_state *pic)
{
pic_str *str;
struct pic_string *str;
pic_get_args(pic, "s", &str);

View File

@ -323,7 +323,7 @@ pic_vec_vector_to_string(pic_state *pic)
pic_vec *vec;
char *buf;
int n, start, end, i;
pic_str *str;
struct pic_string *str;
n = pic_get_args(pic, "v|ii", &vec, &start, &end);
@ -355,7 +355,7 @@ pic_vec_vector_to_string(pic_state *pic)
static pic_value
pic_vec_string_to_vector(pic_state *pic)
{
pic_str *str;
struct pic_string *str;
int n, start, end, i;
pic_vec *vec;

View File

@ -47,7 +47,7 @@ writer_control_destroy(struct writer_control *p)
}
static void
write_blob(pic_state *pic, pic_blob *blob, xFILE *file)
write_blob(pic_state *pic, struct pic_blob *blob, xFILE *file)
{
int i;
@ -82,7 +82,7 @@ write_char(pic_state *pic, char c, xFILE *file, int mode)
}
static void
write_str(pic_state *pic, pic_str *str, xFILE *file, int mode)
write_str(pic_state *pic, struct pic_string *str, xFILE *file, int mode)
{
int i;
const char *cstr = pic_str_cstr(pic, str);
@ -433,7 +433,7 @@ pic_printf(pic_state *pic, const char *fmt, ...)
{
xFILE *file = pic_stdout(pic)->file;
va_list ap;
pic_str *str;
struct pic_string *str;
va_start(ap, fmt);