Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'c89-porting'
Browse files Browse the repository at this point in the history
  • Loading branch information
nyuichi committed Jan 26, 2015
2 parents 343d2e5 + 1e8f498 commit 684cbc5
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 194 deletions.
4 changes: 2 additions & 2 deletions contrib/03.callcc/callcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion contrib/03.file/src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
11 changes: 6 additions & 5 deletions extlib/benz/include/picrin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion extlib/benz/include/picrin/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions extlib/benz/include/picrin/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions extlib/benz/include/picrin/irep.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions extlib/benz/include/picrin/pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 11 additions & 3 deletions extlib/benz/include/picrin/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
76 changes: 38 additions & 38 deletions extlib/benz/include/picrin/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -272,7 +272,7 @@ pic_nil_value()
return v;
}

static inline pic_value
PIC_INLINE pic_value
pic_true_value()
{
pic_value v;
Expand All @@ -281,7 +281,7 @@ pic_true_value()
return v;
}

static inline pic_value
PIC_INLINE pic_value
pic_false_value()
{
pic_value v;
Expand All @@ -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;
Expand All @@ -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)) {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -402,7 +402,7 @@ pic_char_value(char c)

#endif

static inline pic_value
PIC_INLINE pic_value
pic_undef_value()
{
pic_value v;
Expand All @@ -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
Expand All @@ -423,21 +423,21 @@ 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;
}

#else

static inline bool
PIC_INLINE bool
pic_eq_p(pic_value x, pic_value y)
{
if (pic_type(x) != pic_type(y))
Expand All @@ -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))
Expand Down

0 comments on commit 684cbc5

Please sign in to comment.