Merge branch 'c89-porting'

This commit is contained in:
Yuichi Nishiwaki 2015-01-26 12:25:03 +09:00
commit 684cbc54d4
13 changed files with 203 additions and 194 deletions

View File

@ -161,7 +161,7 @@ native_stack_extend(pic_state *pic, struct pic_cont *cont)
restore_cont(pic, cont);
}
pic_noreturn static void
PIC_NORETURN static void
restore_cont(pic_state *pic, struct pic_cont *cont)
{
char v;
@ -203,7 +203,7 @@ restore_cont(pic_state *pic, struct pic_cont *cont)
longjmp(tmp->jmp, 1);
}
pic_noreturn static pic_value
PIC_NORETURN static pic_value
cont_call(pic_state *pic)
{
struct pic_proc *proc;

View File

@ -6,7 +6,7 @@
#include "picrin/port.h"
#include "picrin/error.h"
pic_noreturn static void
PIC_NORETURN static void
file_error(pic_state *pic, const char *msg)
{
pic_throw(pic, pic->sFILE, msg, pic_nil_value());

View File

@ -42,13 +42,14 @@ extern "C" {
#include <math.h>
#include <ctype.h>
#include "picrin/config.h"
#include "picrin/util.h"
#include "picrin/xvect.h"
#include "picrin/xhash.h"
#include "picrin/xfile.h"
#include "picrin/xrope.h"
#include "picrin/config.h"
#include "picrin/util.h"
#include "picrin/value.h"
typedef struct pic_code pic_code;
@ -219,15 +220,15 @@ void pic_import(pic_state *, pic_value);
void pic_import_library(pic_state *, struct pic_lib *);
void pic_export(pic_state *, pic_sym *);
pic_noreturn void pic_panic(pic_state *, const char *);
pic_noreturn void pic_errorf(pic_state *, const char *, ...);
PIC_NORETURN void pic_panic(pic_state *, const char *);
PIC_NORETURN void pic_errorf(pic_state *, const char *, ...);
void pic_warnf(pic_state *, const char *, ...);
const char *pic_errmsg(pic_state *);
pic_str *pic_get_backtrace(pic_state *);
void pic_print_backtrace(pic_state *);
/* obsoleted */
static inline void pic_warn(pic_state *pic, const char *msg)
PIC_INLINE void pic_warn(pic_state *pic, const char *msg)
{
pic_warnf(pic, msg);
}

View File

@ -25,7 +25,7 @@ struct pic_data {
#define pic_data_p(o) (pic_type(o) == PIC_TT_DATA)
#define pic_data_ptr(o) ((struct pic_data *)pic_ptr(o))
static inline bool pic_data_type_p(const pic_value obj, const pic_data_type *type) {
PIC_INLINE bool pic_data_type_p(const pic_value obj, const pic_data_type *type) {
return pic_data_p(obj) && pic_data_ptr(obj)->type == type;
}

View File

@ -51,9 +51,9 @@ void pic_push_try(pic_state *, struct pic_escape *);
void pic_pop_try(pic_state *);
pic_value pic_raise_continuable(pic_state *, pic_value);
pic_noreturn void pic_raise(pic_state *, pic_value);
pic_noreturn void pic_throw(pic_state *, pic_sym *, const char *, pic_list);
pic_noreturn void pic_error(pic_state *, const char *, pic_list);
PIC_NORETURN void pic_raise(pic_state *, pic_value);
PIC_NORETURN void pic_throw(pic_state *, pic_sym *, const char *, pic_list);
PIC_NORETURN void pic_error(pic_state *, const char *, pic_list);
#if defined(__cplusplus)
}

View File

@ -75,7 +75,7 @@ struct pic_irep {
pic_value pic_analyze(pic_state *, pic_value);
struct pic_irep *pic_codegen(pic_state *, pic_value);
static inline void
PIC_INLINE void
pic_dump_code(pic_code c)
{
printf("[%2d] ", c.insn);
@ -191,7 +191,7 @@ pic_dump_code(pic_code c)
}
}
static inline void
PIC_INLINE void
pic_dump_irep(struct pic_irep *irep)
{
unsigned i;

View File

@ -18,7 +18,7 @@ struct pic_pair {
#define pic_pair_p(v) (pic_type(v) == PIC_TT_PAIR)
#define pic_pair_ptr(o) ((struct pic_pair *)pic_ptr(o))
static inline pic_value
PIC_INLINE pic_value
pic_car(pic_state *pic, pic_value obj)
{
struct pic_pair *pair;
@ -31,7 +31,7 @@ pic_car(pic_state *pic, pic_value obj)
return pair->car;
}
static inline pic_value
PIC_INLINE pic_value
pic_cdr(pic_state *pic, pic_value obj)
{
struct pic_pair *pair;

View File

@ -11,11 +11,19 @@ extern "C" {
#if __STDC_VERSION__ >= 201112L
# include <stdnoreturn.h>
# define pic_noreturn noreturn
# define PIC_NORETURN noreturn
#elif __GNUC__ || __clang__
# define pic_noreturn __attribute__((noreturn))
# define PIC_NORETURN __attribute__((noreturn))
#else
# define pic_noreturn
# define PIC_NORETURN
#endif
#if __STDC_VERSION__ >= 199901L
# define PIC_INLINE static inline
#elif __GNUC__ || __clang__
# define PIC_INLINE static __attribute__((unused))
#else
# define PIC_INLINE static
#endif
#define PIC_FALLTHROUGH ((void)0)

View File

@ -153,32 +153,32 @@ typedef struct pic_blob pic_blob;
#define pic_test(v) (! pic_false_p(v))
static inline enum pic_tt pic_type(pic_value);
static inline const char *pic_type_repr(enum pic_tt);
PIC_INLINE enum pic_tt pic_type(pic_value);
PIC_INLINE const char *pic_type_repr(enum pic_tt);
#define pic_assert_type(pic, v, type) \
if (! pic_##type##_p(v)) { \
pic_errorf(pic, "expected " #type ", but got ~s", v); \
}
static inline bool pic_valid_int(double);
PIC_INLINE bool pic_valid_int(double);
static inline pic_value pic_nil_value();
static inline pic_value pic_true_value();
static inline pic_value pic_false_value();
static inline pic_value pic_bool_value(bool);
static inline pic_value pic_undef_value();
static inline pic_value pic_obj_value(void *);
static inline pic_value pic_float_value(double);
static inline pic_value pic_int_value(int);
static inline pic_value pic_size_value(size_t);
static inline pic_value pic_char_value(char c);
static inline pic_value pic_none_value();
PIC_INLINE pic_value pic_nil_value();
PIC_INLINE pic_value pic_true_value();
PIC_INLINE pic_value pic_false_value();
PIC_INLINE pic_value pic_bool_value(bool);
PIC_INLINE pic_value pic_undef_value();
PIC_INLINE pic_value pic_obj_value(void *);
PIC_INLINE pic_value pic_float_value(double);
PIC_INLINE pic_value pic_int_value(int);
PIC_INLINE pic_value pic_size_value(size_t);
PIC_INLINE pic_value pic_char_value(char c);
PIC_INLINE pic_value pic_none_value();
static inline bool pic_eq_p(pic_value, pic_value);
static inline bool pic_eqv_p(pic_value, pic_value);
PIC_INLINE bool pic_eq_p(pic_value, pic_value);
PIC_INLINE bool pic_eqv_p(pic_value, pic_value);
static inline enum pic_tt
PIC_INLINE enum pic_tt
pic_type(pic_value v)
{
switch (pic_vtype(v)) {
@ -205,7 +205,7 @@ pic_type(pic_value v)
PIC_UNREACHABLE();
}
static inline const char *
PIC_INLINE const char *
pic_type_repr(enum pic_tt tt)
{
switch (tt) {
@ -257,13 +257,13 @@ pic_type_repr(enum pic_tt tt)
PIC_UNREACHABLE();
}
static inline bool
PIC_INLINE bool
pic_valid_int(double v)
{
return INT_MIN <= v && v <= INT_MAX;
}
static inline pic_value
PIC_INLINE pic_value
pic_nil_value()
{
pic_value v;
@ -272,7 +272,7 @@ pic_nil_value()
return v;
}
static inline pic_value
PIC_INLINE pic_value
pic_true_value()
{
pic_value v;
@ -281,7 +281,7 @@ pic_true_value()
return v;
}
static inline pic_value
PIC_INLINE pic_value
pic_false_value()
{
pic_value v;
@ -290,7 +290,7 @@ pic_false_value()
return v;
}
static inline pic_value
PIC_INLINE pic_value
pic_bool_value(bool b)
{
pic_value v;
@ -299,7 +299,7 @@ pic_bool_value(bool b)
return v;
}
static inline pic_value
PIC_INLINE pic_value
pic_size_value(size_t s)
{
if (sizeof(unsigned) < sizeof(size_t)) {
@ -312,7 +312,7 @@ pic_size_value(size_t s)
#if PIC_NAN_BOXING
static inline pic_value
PIC_INLINE pic_value
pic_obj_value(void *ptr)
{
pic_value v;
@ -322,7 +322,7 @@ pic_obj_value(void *ptr)
return v;
}
static inline pic_value
PIC_INLINE pic_value
pic_float_value(double f)
{
union { double f; uint64_t i; } u;
@ -335,7 +335,7 @@ pic_float_value(double f)
}
}
static inline pic_value
PIC_INLINE pic_value
pic_int_value(int i)
{
union { int i; unsigned u; } u;
@ -348,7 +348,7 @@ pic_int_value(int i)
return v;
}
static inline pic_value
PIC_INLINE pic_value
pic_char_value(char c)
{
pic_value v;
@ -360,7 +360,7 @@ pic_char_value(char c)
#else
static inline pic_value
PIC_INLINE pic_value
pic_obj_value(void *ptr)
{
pic_value v;
@ -370,7 +370,7 @@ pic_obj_value(void *ptr)
return v;
}
static inline pic_value
PIC_INLINE pic_value
pic_float_value(double f)
{
pic_value v;
@ -380,7 +380,7 @@ pic_float_value(double f)
return v;
}
static inline pic_value
PIC_INLINE pic_value
pic_int_value(int i)
{
pic_value v;
@ -390,7 +390,7 @@ pic_int_value(int i)
return v;
}
static inline pic_value
PIC_INLINE pic_value
pic_char_value(char c)
{
pic_value v;
@ -402,7 +402,7 @@ pic_char_value(char c)
#endif
static inline pic_value
PIC_INLINE pic_value
pic_undef_value()
{
pic_value v;
@ -411,7 +411,7 @@ pic_undef_value()
return v;
}
static inline pic_value
PIC_INLINE pic_value
pic_none_value()
{
#if PIC_NONE_IS_FALSE
@ -423,13 +423,13 @@ pic_none_value()
#if PIC_NAN_BOXING
static inline bool
PIC_INLINE bool
pic_eq_p(pic_value x, pic_value y)
{
return x == y;
}
static inline bool
PIC_INLINE bool
pic_eqv_p(pic_value x, pic_value y)
{
return x == y;
@ -437,7 +437,7 @@ pic_eqv_p(pic_value x, pic_value y)
#else
static inline bool
PIC_INLINE bool
pic_eq_p(pic_value x, pic_value y)
{
if (pic_type(x) != pic_type(y))
@ -453,7 +453,7 @@ pic_eq_p(pic_value x, pic_value y)
}
}
static inline bool
PIC_INLINE bool
pic_eqv_p(pic_value x, pic_value y)
{
if (pic_type(x) != pic_type(y))

View File

@ -20,47 +20,47 @@ typedef struct {
} xFILE;
/* generic file constructor */
static inline xFILE *xfunopen(void *cookie, int (*read)(void *, char *, int), int (*write)(void *, const char *, int), long (*seek)(void *, long, int), int (*flush)(void *), int (*close)(void *));
PIC_INLINE xFILE *xfunopen(void *cookie, int (*read)(void *, char *, int), int (*write)(void *, const char *, int), long (*seek)(void *, long, int), int (*flush)(void *), int (*close)(void *));
/* resource aquisition */
static inline xFILE *xfpopen(FILE *);
static inline xFILE *xmopen();
static inline xFILE *xfopen(const char *, const char *);
static inline int xfclose(xFILE *);
PIC_INLINE xFILE *xfpopen(FILE *);
PIC_INLINE xFILE *xmopen();
PIC_INLINE xFILE *xfopen(const char *, const char *);
PIC_INLINE int xfclose(xFILE *);
/* buffer management */
static inline int xfflush(xFILE *);
PIC_INLINE int xfflush(xFILE *);
/* direct IO with buffering */
static inline size_t xfread(void *, size_t, size_t, xFILE *);
static inline size_t xfwrite(const void *, size_t, size_t, xFILE *);
PIC_INLINE size_t xfread(void *, size_t, size_t, xFILE *);
PIC_INLINE size_t xfwrite(const void *, size_t, size_t, xFILE *);
/* indicator positioning */
static inline long xfseek(xFILE *, long offset, int whence);
static inline long xftell(xFILE *);
static inline void xrewind(xFILE *);
PIC_INLINE long xfseek(xFILE *, long offset, int whence);
PIC_INLINE long xftell(xFILE *);
PIC_INLINE void xrewind(xFILE *);
/* stream status */
static inline void xclearerr(xFILE *);
static inline int xfeof(xFILE *);
static inline int xferror(xFILE *);
PIC_INLINE void xclearerr(xFILE *);
PIC_INLINE int xfeof(xFILE *);
PIC_INLINE int xferror(xFILE *);
/* character IO */
static inline int xfgetc(xFILE *);
static inline char *xfgets(char *, int, xFILE *);
static inline int xfputc(int, xFILE *);
static inline int xfputs(const char *, xFILE *);
static inline int xgetc(xFILE *);
static inline int xgetchar(void);
static inline int xputc(int, xFILE *);
static inline int xputchar(int);
static inline int xputs(const char *);
static inline int xungetc(int, xFILE *);
PIC_INLINE int xfgetc(xFILE *);
PIC_INLINE char *xfgets(char *, int, xFILE *);
PIC_INLINE int xfputc(int, xFILE *);
PIC_INLINE int xfputs(const char *, xFILE *);
PIC_INLINE int xgetc(xFILE *);
PIC_INLINE int xgetchar(void);
PIC_INLINE int xputc(int, xFILE *);
PIC_INLINE int xputchar(int);
PIC_INLINE int xputs(const char *);
PIC_INLINE int xungetc(int, xFILE *);
/* formatted I/O */
static inline int xprintf(const char *, ...);
static inline int xfprintf(xFILE *, const char *, ...);
static inline int xvfprintf(xFILE *, const char *, va_list);
PIC_INLINE int xprintf(const char *, ...);
PIC_INLINE int xfprintf(xFILE *, const char *, ...);
PIC_INLINE int xvfprintf(xFILE *, const char *, va_list);
/* standard I/O */
#define xstdin (xstdin_())
@ -73,7 +73,7 @@ static inline int xvfprintf(xFILE *, const char *, va_list);
#define XF_EOF 1
#define XF_ERR 2
static inline xFILE *
PIC_INLINE xFILE *
xfunopen(void *cookie, int (*read)(void *, char *, int), int (*write)(void *, const char *, int), long (*seek)(void *, long, int), int (*flush)(void *), int (*close)(void *))
{
xFILE *file;
@ -99,7 +99,7 @@ xfunopen(void *cookie, int (*read)(void *, char *, int), int (*write)(void *, co
* Derieved xFILE Classes
*/
static inline int
PIC_INLINE int
xf_file_read(void *cookie, char *ptr, int size)
{
FILE *file = cookie;
@ -115,7 +115,7 @@ xf_file_read(void *cookie, char *ptr, int size)
return r;
}
static inline int
PIC_INLINE int
xf_file_write(void *cookie, const char *ptr, int size)
{
FILE *file = cookie;
@ -128,25 +128,25 @@ xf_file_write(void *cookie, const char *ptr, int size)
return r;
}
static inline long
PIC_INLINE long
xf_file_seek(void *cookie, long pos, int whence)
{
return fseek(cookie, pos, whence);
}
static inline int
PIC_INLINE int
xf_file_flush(void *cookie)
{
return fflush(cookie);
}
static inline int
PIC_INLINE int
xf_file_close(void *cookie)
{
return fclose(cookie);
}
static inline xFILE *
PIC_INLINE xFILE *
xfpopen(FILE *fp)
{
xFILE *file;
@ -161,7 +161,7 @@ xfpopen(FILE *fp)
#define XF_FILE_VTABLE xf_file_read, xf_file_write, xf_file_seek, xf_file_flush, xf_file_close
static inline xFILE *
PIC_INLINE xFILE *
xstdin_()
{
static xFILE x = { -1, 0, { NULL, XF_FILE_VTABLE } };
@ -172,7 +172,7 @@ xstdin_()
return &x;
}
static inline xFILE *
PIC_INLINE xFILE *
xstdout_()
{
static xFILE x = { -1, 0, { NULL, XF_FILE_VTABLE } };
@ -183,7 +183,7 @@ xstdout_()
return &x;
}
static inline xFILE *
PIC_INLINE xFILE *
xstderr_()
{
static xFILE x = { -1, 0, { NULL, XF_FILE_VTABLE } };
@ -199,7 +199,7 @@ struct xf_membuf {
long pos, end, capa;
};
static inline int
PIC_INLINE int
xf_mem_read(void *cookie, char *ptr, int size)
{
struct xf_membuf *mem;
@ -213,7 +213,7 @@ xf_mem_read(void *cookie, char *ptr, int size)
return size;
}
static inline int
PIC_INLINE int
xf_mem_write(void *cookie, const char *ptr, int size)
{
struct xf_membuf *mem;
@ -231,7 +231,7 @@ xf_mem_write(void *cookie, const char *ptr, int size)
return size;
}
static inline long
PIC_INLINE long
xf_mem_seek(void *cookie, long pos, int whence)
{
struct xf_membuf *mem;
@ -253,7 +253,7 @@ xf_mem_seek(void *cookie, long pos, int whence)
return mem->pos;
}
static inline int
PIC_INLINE int
xf_mem_flush(void *cookie)
{
(void)cookie;
@ -261,7 +261,7 @@ xf_mem_flush(void *cookie)
return 0;
}
static inline int
PIC_INLINE int
xf_mem_close(void *cookie)
{
struct xf_membuf *mem;
@ -272,7 +272,7 @@ xf_mem_close(void *cookie)
return 0;
}
static inline xFILE *
PIC_INLINE xFILE *
xmopen()
{
struct xf_membuf *mem;
@ -288,7 +288,7 @@ xmopen()
#undef XF_FILE_VTABLE
static inline xFILE *
PIC_INLINE xFILE *
xfopen(const char *filename, const char *mode)
{
FILE *fp;
@ -307,7 +307,7 @@ xfopen(const char *filename, const char *mode)
return file;
}
static inline int
PIC_INLINE int
xfclose(xFILE *file)
{
int r;
@ -321,13 +321,13 @@ xfclose(xFILE *file)
return 0;
}
static inline int
PIC_INLINE int
xfflush(xFILE *file)
{
return file->vtable.flush(file->vtable.cookie);
}
static inline size_t
PIC_INLINE size_t
xfread(void *ptr, size_t block, size_t nitems, xFILE *file)
{
char *dst = (char *)ptr;
@ -362,7 +362,7 @@ xfread(void *ptr, size_t block, size_t nitems, xFILE *file)
return i;
}
static inline size_t
PIC_INLINE size_t
xfwrite(const void *ptr, size_t block, size_t nitems, xFILE *file)
{
char *dst = (char *)ptr;
@ -386,44 +386,44 @@ xfwrite(const void *ptr, size_t block, size_t nitems, xFILE *file)
return i;
}
static inline long
PIC_INLINE long
xfseek(xFILE *file, long offset, int whence)
{
file->ungot = -1;
return file->vtable.seek(file->vtable.cookie, offset, whence);
}
static inline long
PIC_INLINE long
xftell(xFILE *file)
{
return xfseek(file, 0, SEEK_CUR);
}
static inline void
PIC_INLINE void
xrewind(xFILE *file)
{
xfseek(file, 0, SEEK_SET);
}
static inline void
PIC_INLINE void
xclearerr(xFILE *file)
{
file->flags = 0;
}
static inline int
PIC_INLINE int
xfeof(xFILE *file)
{
return file->flags & XF_EOF;
}
static inline int
PIC_INLINE int
xferror(xFILE *file)
{
return file->flags & XF_ERR;
}
static inline int
PIC_INLINE int
xfgetc(xFILE *file)
{
char buf[1];
@ -437,13 +437,13 @@ xfgetc(xFILE *file)
return buf[0];
}
static inline int
PIC_INLINE int
xgetc(xFILE *file)
{
return xfgetc(file);
}
static inline char *
PIC_INLINE char *
xfgets(char *str, int size, xFILE *file)
{
int c = EOF, i;
@ -465,7 +465,7 @@ xfgets(char *str, int size, xFILE *file)
return str;
}
static inline int
PIC_INLINE int
xungetc(int c, xFILE *file)
{
file->ungot = c;
@ -475,13 +475,13 @@ xungetc(int c, xFILE *file)
return c;
}
static inline int
PIC_INLINE int
xgetchar(void)
{
return xfgetc(xstdin);
}
static inline int
PIC_INLINE int
xfputc(int c, xFILE *file)
{
char buf[1];
@ -495,19 +495,19 @@ xfputc(int c, xFILE *file)
return buf[0];
}
static inline int
PIC_INLINE int
xputc(int c, xFILE *file)
{
return xfputc(c, file);
}
static inline int
PIC_INLINE int
xputchar(int c)
{
return xfputc(c, xstdout);
}
static inline int
PIC_INLINE int
xfputs(const char *str, xFILE *file)
{
size_t len;
@ -521,13 +521,13 @@ xfputs(const char *str, xFILE *file)
return 0;
}
static inline int
PIC_INLINE int
xputs(const char *s)
{
return xfputs(s, xstdout);
}
static inline int
PIC_INLINE int
xprintf(const char *fmt, ...)
{
va_list ap;
@ -539,7 +539,7 @@ xprintf(const char *fmt, ...)
return n;
}
static inline int
PIC_INLINE int
xfprintf(xFILE *stream, const char *fmt, ...)
{
va_list ap;
@ -551,7 +551,7 @@ xfprintf(xFILE *stream, const char *fmt, ...)
return n;
}
static inline int
PIC_INLINE int
xvfprintf(xFILE *stream, const char *fmt, va_list ap)
{
va_list ap2;

View File

@ -50,32 +50,32 @@ typedef struct xhash {
*/
/* string map */
static inline void xh_init_str(xhash *x, size_t width);
static inline xh_entry *xh_get_str(xhash *x, const char *key);
static inline xh_entry *xh_put_str(xhash *x, const char *key, void *);
static inline void xh_del_str(xhash *x, const char *key);
PIC_INLINE void xh_init_str(xhash *x, size_t width);
PIC_INLINE xh_entry *xh_get_str(xhash *x, const char *key);
PIC_INLINE xh_entry *xh_put_str(xhash *x, const char *key, void *);
PIC_INLINE void xh_del_str(xhash *x, const char *key);
/* object map */
static inline void xh_init_ptr(xhash *x, size_t width);
static inline xh_entry *xh_get_ptr(xhash *x, const void *key);
static inline xh_entry *xh_put_ptr(xhash *x, const void *key, void *);
static inline void xh_del_ptr(xhash *x, const void *key);
PIC_INLINE void xh_init_ptr(xhash *x, size_t width);
PIC_INLINE xh_entry *xh_get_ptr(xhash *x, const void *key);
PIC_INLINE xh_entry *xh_put_ptr(xhash *x, const void *key, void *);
PIC_INLINE void xh_del_ptr(xhash *x, const void *key);
/* int map */
static inline void xh_init_int(xhash *x, size_t width);
static inline xh_entry *xh_get_int(xhash *x, int key);
static inline xh_entry *xh_put_int(xhash *x, int key, void *);
static inline void xh_del_int(xhash *x, int key);
PIC_INLINE void xh_init_int(xhash *x, size_t width);
PIC_INLINE xh_entry *xh_get_int(xhash *x, int key);
PIC_INLINE xh_entry *xh_put_int(xhash *x, int key, void *);
PIC_INLINE void xh_del_int(xhash *x, int key);
static inline size_t xh_size(xhash *x);
static inline void xh_clear(xhash *x);
static inline void xh_destroy(xhash *x);
PIC_INLINE size_t xh_size(xhash *x);
PIC_INLINE void xh_clear(xhash *x);
PIC_INLINE void xh_destroy(xhash *x);
static inline xh_entry *xh_begin(xhash *x);
static inline xh_entry *xh_next(xh_entry *e);
PIC_INLINE xh_entry *xh_begin(xhash *x);
PIC_INLINE xh_entry *xh_next(xh_entry *e);
static inline void
PIC_INLINE void
xh_bucket_realloc(xhash *x, size_t newsize)
{
x->size = newsize;
@ -83,7 +83,7 @@ xh_bucket_realloc(xhash *x, size_t newsize)
memset(x->buckets, 0, (x->size + 1) * sizeof(xh_entry *));
}
static inline void
PIC_INLINE void
xh_init_(xhash *x, size_t kwidth, size_t vwidth, xh_hashf hashf, xh_equalf equalf, void *data)
{
x->size = 0;
@ -102,7 +102,7 @@ xh_init_(xhash *x, size_t kwidth, size_t vwidth, xh_hashf hashf, xh_equalf equal
xh_bucket_realloc(x, XHASH_INIT_SIZE);
}
static inline xh_entry *
PIC_INLINE xh_entry *
xh_get_(xhash *x, const void *key)
{
int hash;
@ -118,7 +118,7 @@ xh_get_(xhash *x, const void *key)
return e;
}
static inline void
PIC_INLINE void
xh_resize_(xhash *x, size_t newsize)
{
xhash y;
@ -145,7 +145,7 @@ xh_resize_(xhash *x, size_t newsize)
memcpy(x, &y, sizeof(xhash));
}
static inline xh_entry *
PIC_INLINE xh_entry *
xh_put_(xhash *x, const void *key, void *val)
{
int hash;
@ -186,7 +186,7 @@ xh_put_(xhash *x, const void *key, void *val)
return x->buckets[idx] = e;
}
static inline void
PIC_INLINE void
xh_del_(xhash *x, const void *key)
{
int hash;
@ -235,13 +235,13 @@ xh_del_(xhash *x, const void *key)
x->count--;
}
static inline size_t
PIC_INLINE size_t
xh_size(xhash *x)
{
return x->count;
}
static inline void
PIC_INLINE void
xh_clear(xhash *x)
{
size_t i;
@ -261,7 +261,7 @@ xh_clear(xhash *x)
x->count = 0;
}
static inline void
PIC_INLINE void
xh_destroy(xhash *x)
{
xh_clear(x);
@ -270,7 +270,7 @@ xh_destroy(xhash *x)
/* string map */
static inline int
PIC_INLINE int
xh_str_hash(const void *key, void *data)
{
const char *str = *(const char **)key;
@ -284,7 +284,7 @@ xh_str_hash(const void *key, void *data)
return hash;
}
static inline int
PIC_INLINE int
xh_str_equal(const void *key1, const void *key2, void *data)
{
(void)data;
@ -292,25 +292,25 @@ xh_str_equal(const void *key1, const void *key2, void *data)
return strcmp(*(const char **)key1, *(const char **)key2) == 0;
}
static inline void
PIC_INLINE void
xh_init_str(xhash *x, size_t width)
{
xh_init_(x, sizeof(const char *), width, xh_str_hash, xh_str_equal, NULL);
}
static inline xh_entry *
PIC_INLINE xh_entry *
xh_get_str(xhash *x, const char *key)
{
return xh_get_(x, &key);
}
static inline xh_entry *
PIC_INLINE xh_entry *
xh_put_str(xhash *x, const char *key, void *val)
{
return xh_put_(x, &key, val);
}
static inline void
PIC_INLINE void
xh_del_str(xhash *x, const char *key)
{
xh_del_(x, &key);
@ -318,7 +318,7 @@ xh_del_str(xhash *x, const char *key)
/* object map */
static inline int
PIC_INLINE int
xh_ptr_hash(const void *key, void *data)
{
(void)data;
@ -326,7 +326,7 @@ xh_ptr_hash(const void *key, void *data)
return (int)(size_t)*(const void **)key;
}
static inline int
PIC_INLINE int
xh_ptr_equal(const void *key1, const void *key2, void *data)
{
(void) data;
@ -334,25 +334,25 @@ xh_ptr_equal(const void *key1, const void *key2, void *data)
return *(const void **)key1 == *(const void **)key2;
}
static inline void
PIC_INLINE void
xh_init_ptr(xhash *x, size_t width)
{
xh_init_(x, sizeof(const void *), width, xh_ptr_hash, xh_ptr_equal, NULL);
}
static inline xh_entry *
PIC_INLINE xh_entry *
xh_get_ptr(xhash *x, const void *key)
{
return xh_get_(x, &key);
}
static inline xh_entry *
PIC_INLINE xh_entry *
xh_put_ptr(xhash *x, const void *key, void *val)
{
return xh_put_(x, &key, val);
}
static inline void
PIC_INLINE void
xh_del_ptr(xhash *x, const void *key)
{
xh_del_(x, &key);
@ -360,7 +360,7 @@ xh_del_ptr(xhash *x, const void *key)
/* int map */
static inline int
PIC_INLINE int
xh_int_hash(const void *key, void *data)
{
(void)data;
@ -368,7 +368,7 @@ xh_int_hash(const void *key, void *data)
return *(int *)key;
}
static inline int
PIC_INLINE int
xh_int_equal(const void *key1, const void *key2, void *data)
{
(void)data;
@ -376,25 +376,25 @@ xh_int_equal(const void *key1, const void *key2, void *data)
return *(int *)key1 == *(int *)key2;
}
static inline void
PIC_INLINE void
xh_init_int(xhash *x, size_t width)
{
xh_init_(x, sizeof(int), width, xh_int_hash, xh_int_equal, NULL);
}
static inline xh_entry *
PIC_INLINE xh_entry *
xh_get_int(xhash *x, int key)
{
return xh_get_(x, &key);
}
static inline xh_entry *
PIC_INLINE xh_entry *
xh_put_int(xhash *x, int key, void *val)
{
return xh_put_(x, &key, val);
}
static inline void
PIC_INLINE void
xh_del_int(xhash *x, int key)
{
xh_del_(x, &key);
@ -402,13 +402,13 @@ xh_del_int(xhash *x, int key)
/** iteration */
static inline xh_entry *
PIC_INLINE xh_entry *
xh_begin(xhash *x)
{
return x->head;
}
static inline xh_entry *
PIC_INLINE xh_entry *
xh_next(xh_entry *e)
{
return e->bw;

View File

@ -20,19 +20,19 @@ typedef struct xrope xrope;
#define xr_new(cstr) xr_new_cstr(cstr, strlen(cstr))
#define xr_new_lit(cstr) xr_new_cstr(cstr, sizeof(cstr) - 1)
static inline xrope *xr_new_cstr(const char *, size_t);
static inline xrope *xr_new_imbed(const char *, size_t);
static inline xrope *xr_new_move(const char *, size_t);
static inline xrope *xr_new_copy(const char *, size_t);
PIC_INLINE xrope *xr_new_cstr(const char *, size_t);
PIC_INLINE xrope *xr_new_imbed(const char *, size_t);
PIC_INLINE xrope *xr_new_move(const char *, size_t);
PIC_INLINE xrope *xr_new_copy(const char *, size_t);
static inline void XROPE_INCREF(xrope *);
static inline void XROPE_DECREF(xrope *);
PIC_INLINE void XROPE_INCREF(xrope *);
PIC_INLINE void XROPE_DECREF(xrope *);
static inline size_t xr_len(xrope *);
static inline char xr_at(xrope *, size_t);
static inline xrope *xr_cat(xrope *, xrope *);
static inline xrope *xr_sub(xrope *, size_t, size_t);
static inline const char *xr_cstr(xrope *); /* returns NULL-terminated string */
PIC_INLINE size_t xr_len(xrope *);
PIC_INLINE char xr_at(xrope *, size_t);
PIC_INLINE xrope *xr_cat(xrope *, xrope *);
PIC_INLINE xrope *xr_sub(xrope *, size_t, size_t);
PIC_INLINE const char *xr_cstr(xrope *); /* returns NULL-terminated string */
/* impl */
@ -65,12 +65,12 @@ struct xrope {
struct xrope *left, *right;
};
static inline void
PIC_INLINE void
XROPE_INCREF(xrope *x) {
x->refcnt++;
}
static inline void
PIC_INLINE void
XROPE_DECREF(xrope *x) {
if (! --x->refcnt) {
if (x->chunk) {
@ -84,7 +84,7 @@ XROPE_DECREF(xrope *x) {
}
}
static inline xrope *
PIC_INLINE xrope *
xr_new_cstr(const char *cstr, size_t len)
{
xr_chunk *c;
@ -108,7 +108,7 @@ xr_new_cstr(const char *cstr, size_t len)
return x;
}
static inline xrope *
PIC_INLINE xrope *
xr_new_imbed(const char *str, size_t len)
{
xr_chunk *c;
@ -132,7 +132,7 @@ xr_new_imbed(const char *str, size_t len)
return x;
}
static inline xrope *
PIC_INLINE xrope *
xr_new_move(const char *cstr, size_t len)
{
xr_chunk *c;
@ -156,7 +156,7 @@ xr_new_move(const char *cstr, size_t len)
return x;
}
static inline xrope *
PIC_INLINE xrope *
xr_new_copy(const char *str, size_t len)
{
char *buf;
@ -185,13 +185,13 @@ xr_new_copy(const char *str, size_t len)
return x;
}
static inline size_t
PIC_INLINE size_t
xr_len(xrope *x)
{
return x->weight;
}
static inline char
PIC_INLINE char
xr_at(xrope *x, size_t i)
{
if (x->weight <= i) {
@ -205,7 +205,7 @@ xr_at(xrope *x, size_t i)
: xr_at(x->right, i - x->left->weight);
}
static inline xrope *
PIC_INLINE xrope *
xr_cat(xrope *x, xrope *y)
{
xrope *z;
@ -224,7 +224,7 @@ xr_cat(xrope *x, xrope *y)
return z;
}
static inline struct xrope *
PIC_INLINE struct xrope *
xr_sub(xrope *x, size_t i, size_t j)
{
assert(i <= j);
@ -271,7 +271,7 @@ xr_sub(xrope *x, size_t i, size_t j)
}
}
static inline void
PIC_INLINE void
xr_fold(xrope *x, xr_chunk *c, size_t offset)
{
if (x->chunk) {
@ -294,7 +294,7 @@ xr_fold(xrope *x, xr_chunk *c, size_t offset)
XR_CHUNK_INCREF(c);
}
static inline const char *
PIC_INLINE const char *
xr_cstr(xrope *x)
{
xr_chunk *c;

View File

@ -16,7 +16,7 @@
static pic_value read(pic_state *pic, struct pic_port *port, int c);
static pic_value read_nullable(pic_state *pic, struct pic_port *port, int c);
pic_noreturn static void
PIC_NORETURN static void
read_error(pic_state *pic, const char *msg)
{
pic_throw(pic, pic->sREAD, msg, pic_nil_value());