configurable none value
This commit is contained in:
parent
e067ab64c9
commit
33cbf5ff6a
|
@ -10,6 +10,9 @@
|
|||
/* enable readline module */
|
||||
#define PIC_ENABLE_READLINE 1
|
||||
|
||||
/* treat false value as none */
|
||||
#define PIC_NONE_IS_FALSE 1
|
||||
|
||||
/* initial memory size (to be dynamically extended if necessary) */
|
||||
#define PIC_ARENA_SIZE 100
|
||||
#define PIC_HEAP_PAGE_SIZE (10000)
|
||||
|
|
|
@ -143,6 +143,7 @@ pic_value pic_float_value(double);
|
|||
pic_value pic_int_value(int);
|
||||
pic_value pic_symbol_value(pic_sym);
|
||||
pic_value pic_char_value(char c);
|
||||
pic_value pic_none_value();
|
||||
|
||||
#define pic_float(v) ((v).u.f)
|
||||
#define pic_int(v) ((v).u.i)
|
||||
|
|
|
@ -76,7 +76,7 @@ pic_blob_bytevector_u8_set(pic_state *pic)
|
|||
pic_error(pic, "byte out of range");
|
||||
|
||||
bv->data[k] = v;
|
||||
return pic_false_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -8,6 +8,12 @@
|
|||
#include "picrin/macro.h"
|
||||
#include "xhash/xhash.h"
|
||||
|
||||
#if PIC_NONE_IS_FALSE
|
||||
# define OP_PUSHNONE OP_PUSHFALSE
|
||||
#else
|
||||
# error enable PIC_NONE_IS_FALSE
|
||||
#endif
|
||||
|
||||
#define FALLTHROUGH ((void)0)
|
||||
|
||||
typedef struct codegen_scope {
|
||||
|
@ -272,7 +278,7 @@ codegen(codegen_state *state, pic_value obj, bool tailpos)
|
|||
irep->code[irep->clen].insn = OP_GSET;
|
||||
irep->code[irep->clen].u.i = idx;
|
||||
irep->clen++;
|
||||
irep->code[irep->clen].insn = OP_PUSHFALSE;
|
||||
irep->code[irep->clen].insn = OP_PUSHNONE;
|
||||
irep->clen++;
|
||||
break;
|
||||
}
|
||||
|
@ -283,7 +289,7 @@ codegen(codegen_state *state, pic_value obj, bool tailpos)
|
|||
irep->code[irep->clen].u.r.depth = 0;
|
||||
irep->code[irep->clen].u.r.idx = idx;
|
||||
irep->clen++;
|
||||
irep->code[irep->clen].insn = OP_PUSHFALSE;
|
||||
irep->code[irep->clen].insn = OP_PUSHNONE;
|
||||
irep->clen++;
|
||||
break;
|
||||
}
|
||||
|
@ -312,7 +318,7 @@ codegen(codegen_state *state, pic_value obj, bool tailpos)
|
|||
int s,t;
|
||||
pic_value if_true, if_false;
|
||||
|
||||
if_false = pic_false_value();
|
||||
if_false = pic_none_value();
|
||||
switch (pic_length(pic, obj)) {
|
||||
default:
|
||||
pic_error(pic, "syntax error");
|
||||
|
@ -400,7 +406,7 @@ codegen(codegen_state *state, pic_value obj, bool tailpos)
|
|||
break;
|
||||
}
|
||||
|
||||
irep->code[irep->clen].insn = OP_PUSHFALSE;
|
||||
irep->code[irep->clen].insn = OP_PUSHNONE;
|
||||
irep->clen++;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ pic_file_delete(pic_state *pic)
|
|||
if (remove(fname) != 0) {
|
||||
pic_error(pic, "file cannot be deleted");
|
||||
}
|
||||
return pic_true_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
10
src/macro.c
10
src/macro.c
|
@ -297,7 +297,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
}
|
||||
pic_in_library(pic, prev->name);
|
||||
|
||||
return pic_false_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
case PIC_STX_IMPORT: {
|
||||
struct pic_lib *lib;
|
||||
|
@ -339,7 +339,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
xh_next(lib->exports, &it);
|
||||
}
|
||||
}
|
||||
return pic_false_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
case PIC_STX_EXPORT: {
|
||||
for (v = pic_cdr(pic, expr); ! pic_nil_p(v); v = pic_cdr(pic, v)) {
|
||||
|
@ -350,7 +350,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
/* TODO: warn if symbol is shadowed by local variable */
|
||||
pic_export(pic, pic_sym(spec));
|
||||
}
|
||||
return pic_false_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
case PIC_STX_DEFSYNTAX: {
|
||||
pic_value var, val;
|
||||
|
@ -380,7 +380,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
pic_defsyntax(pic, pic_symbol_name(pic, pic_sym(var)), pic_proc_ptr(v), senv);
|
||||
|
||||
pic_gc_arena_restore(pic, ai);
|
||||
return pic_false_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
case PIC_STX_DEFMACRO: {
|
||||
pic_value var, val;
|
||||
|
@ -422,7 +422,7 @@ macroexpand(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
|||
pic_defmacro(pic, pic_symbol_name(pic, pic_sym(var)), pic_proc_ptr(v));
|
||||
|
||||
pic_gc_arena_restore(pic, ai);
|
||||
return pic_false_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
case PIC_STX_MACRO: {
|
||||
if (pic_syntax(car)->senv == NULL) { /* legacy macro */
|
||||
|
|
|
@ -237,7 +237,7 @@ pic_pair_set_car(pic_state *pic)
|
|||
pic_error(pic, "pair expected");
|
||||
|
||||
pic_pair_ptr(v)->car = w;
|
||||
return pic_true_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
@ -251,7 +251,7 @@ pic_pair_set_cdr(pic_state *pic)
|
|||
pic_error(pic, "pair expected");
|
||||
|
||||
pic_pair_ptr(v)->cdr = w;
|
||||
return pic_true_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -263,14 +263,14 @@ pic_port_write(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "o", &v);
|
||||
write(pic, v);
|
||||
return pic_false_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_port_newline(pic_state *pic)
|
||||
{
|
||||
puts("");
|
||||
return pic_false_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
@ -318,7 +318,7 @@ pic_port_close_port(pic_state *pic)
|
|||
}
|
||||
port->status = PIC_PORT_CLOSE;
|
||||
|
||||
return pic_false_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -82,7 +82,7 @@ pic_str_string_set(pic_state *pic)
|
|||
pic_get_args(pic, "sic", &str, &len, &k, &c);
|
||||
|
||||
str[k] = c;
|
||||
return pic_false_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
|
||||
#define DEFINE_STRING_CMP(name, op) \
|
||||
|
|
10
src/value.c
10
src/value.c
|
@ -208,6 +208,16 @@ pic_undef_value()
|
|||
return v;
|
||||
}
|
||||
|
||||
pic_value
|
||||
pic_none_value()
|
||||
{
|
||||
#if PIC_NONE_IS_FALSE
|
||||
return pic_false_value();
|
||||
#else
|
||||
# error enable PIC_NONE_IS_FALSE
|
||||
#endif
|
||||
}
|
||||
|
||||
#if PIC_NAN_BOXING
|
||||
|
||||
bool
|
||||
|
|
|
@ -11,7 +11,7 @@ pic_vec_new(pic_state *pic, size_t len)
|
|||
vec->len = len;
|
||||
vec->data = (pic_value *)pic_alloc(pic, sizeof(pic_value) * len);
|
||||
for (i = 0; i < len; ++i) {
|
||||
vec->data[i] = pic_false_value();
|
||||
vec->data[i] = pic_none_value();
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ pic_vec_extend_ip(pic_state *pic, struct pic_vector *vec, int size)
|
|||
vec->len = size;
|
||||
vec->data = (pic_value *)pic_realloc(pic, vec->data, sizeof(pic_value) * size);
|
||||
for (i = len; i < size; ++i) {
|
||||
vec->data[i] = pic_false_value();
|
||||
vec->data[i] = pic_none_value();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ pic_vec_vector_set(pic_state *pic)
|
|||
pic_error(pic, "vector-set!: index out of range");
|
||||
}
|
||||
v->data[k] = o;
|
||||
return pic_false_value();
|
||||
return pic_none_value();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue