Skip to content

Commit

Permalink
Split UNDEFINED into UNINITIALIZED and UNSPECIFIED.
Browse files Browse the repository at this point in the history
  • Loading branch information
kbob committed May 17, 2010
1 parent cd7423f commit c2131f1
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 86 deletions.
20 changes: 10 additions & 10 deletions eval.c
Expand Up @@ -140,7 +140,7 @@ extern cv_t c_apply_proc(obj_t cont, obj_t values)
return ((cont_proc_t)procedure_code(operator))(cont, values);
else {
// N.B., call proc after all other allocations.
obj_t new_values = CONS(UNDEFINED_OBJ, saved_values);
obj_t new_values = CONS(make_uninitialized(), saved_values);
pair_set_car_nc(new_values, apply_proc(operator, arg_list));
return cv(next, new_values);
}
Expand All @@ -167,7 +167,7 @@ extern cv_t c_apply_proc(obj_t cont, obj_t values)
env_bind(new_env, formal, BT_LEXICAL, M_MUTABLE, actual);
}
// Push a value for c_eval_seq to discard.
obj_t new_values = CONS(UNDEFINED_OBJ, saved_values);
obj_t new_values = CONS(make_uninitialized(), saved_values);
return cv(make_cont4(c_eval_seq, next, new_env, body), new_values);
}
}
Expand All @@ -188,7 +188,7 @@ static cv_t c_eval_operator(obj_t cont, obj_t values)
} else {
// N.B., call proc after all other allocations.
obj_t arg_list = application_operands(appl);
obj_t new_values = CONS(UNDEFINED_OBJ, CDR(values));
obj_t new_values = CONS(make_uninitialized(), CDR(values));
pair_set_car(new_values, apply_proc(operator, arg_list));
return cv(cont_cont(cont), new_values);
}
Expand Down Expand Up @@ -274,7 +274,7 @@ static cv_t default_handler(obj_t cont, obj_t values)
}
}
obj_t who_p = FALSE_OBJ;
obj_t irr_p = UNDEFINED_OBJ;
obj_t irr_p = make_uninitialized();
for (i = 0; i < size; i++) {
obj_t p = vector_ref(parts, i);
obj_t rtd = record_rtd(p);
Expand All @@ -288,20 +288,20 @@ static cv_t default_handler(obj_t cont, obj_t values)
else if (rtd == irritants)
irr_p = record_get_field(p, 0);
}
if (who_p != FALSE_OBJ && irr_p != UNDEFINED_OBJ) {
if (who_p != FALSE_OBJ && !is_uninitialized(irr_p)) {
ofprintf(stderr, "%*s %O\n", psnl, psn, CONS(who_p, irr_p));
psn = "";
} else if (who_p != FALSE_OBJ) {
ofprintf(stderr, "%*s %O\n", psnl, psn, who_p);
psn = "";
} else if (irr_p != UNDEFINED_OBJ) {
} else if (!is_uninitialized(irr_p)) {
ofprintf(stderr, "%*s %O\n", psnl, psn, irr_p);
psn = "";
}
if (*psn)
fprintf(stderr, "%s: unknown exception\n", psn);
ofprintf(stderr, "\n");
return cv(EMPTY_LIST, CONS(UNDEFINED_OBJ, EMPTY_LIST));
return cv(EMPTY_LIST, CONS(make_uninitialized(), EMPTY_LIST));
}

static cv_t c_exception_returned(obj_t cont, obj_t values)
Expand Down Expand Up @@ -388,8 +388,8 @@ extern obj_t core_eval_cont(volatile obj_t cont,
collect_garbage();
cont = cont_root;
values = values_root;
cont_root = UNDEFINED_OBJ;
values_root = UNDEFINED_OBJ;
cont_root = make_uninitialized();
values_root = make_uninitialized();
break;

case LT_NO_EXCEPTION:
Expand All @@ -414,7 +414,7 @@ extern obj_t core_eval_cont(volatile obj_t cont,
#endif
}
deregister_lowex_handler(handle_lowex);
eval_dyn_env = make_undefined();
eval_dyn_env = make_uninitialized();
EVAL_LOG("END values=%O", values);
assert(is_null(CDR(values)));
return CAR(values);
Expand Down
9 changes: 6 additions & 3 deletions heap.c
Expand Up @@ -13,7 +13,8 @@
#include "obj_eof.h"
#include "obj_fixnum.h"
#include "obj_null.h"
#include "obj_undefined.h"
#include "obj_uninit.h"
#include "obj_unspec.h"
#include "roots.h"

#if DEBUG_HEAP
Expand Down Expand Up @@ -339,8 +340,10 @@ const wchar_t *obj_type_name(const obj_t obj)
return L"forward";
if (is_null(obj))
return L"null";
if (is_undefined(obj))
return L"undefined";
if (is_uninitialized(obj))
return L"uninitialized";
if (is_unspecified(obj))
return L"unspecified";
if (is_eof(obj))
return L"eof-object";
if (is_read_action(obj))
Expand Down
13 changes: 7 additions & 6 deletions mem.h
Expand Up @@ -47,12 +47,13 @@
* See read.c.
*
* 0001 1110 - Special constant.
* 0000 0001 1110 - nil (the empty list)
* 0001 0001 1110 - undefined
* 0010 0001 1110 - missing arg
* 0011 0001 1110 - end of file
* 0100 0001 1110 - mem ops primitive (see below)
* 0101 0001 1110 - end of args
* 0000 0001 1110 - the empty list (nil)
* 0001 0001 1110 - unspecified
* 0010 0001 1110 - uninitialized
* 0011 0001 1110 - missing arg
* 0100 0001 1110 - end of file
* 0101 0001 1110 - mem ops primitive (see below)
* 0110 0001 1110 - end of args
*
* - "Forwarding" pointers are used by the garbage collector, and
* are never seen by the mutator. While a heap region is being
Expand Down
11 changes: 6 additions & 5 deletions obj.h
Expand Up @@ -44,11 +44,12 @@
#define SPECIAL_OBJ(n) ((obj_t)((n) << SPECIAL_SHIFT | SPECIAL_TAG))

#define EMPTY_LIST (SPECIAL_OBJ(0))
#define UNDEFINED_OBJ (SPECIAL_OBJ(1))
#define END_OF_FILE (SPECIAL_OBJ(2))
#define MISSING_ARG (SPECIAL_OBJ(3))
#define MEM_OPS_PRIMITIVE (SPECIAL_OBJ(4))
#define END_OF_ARGS (SPECIAL_OBJ(5))
#define UNINITIALIZED_OBJ (SPECIAL_OBJ(1))
#define UNSPECIFIED_OBJ (SPECIAL_OBJ(2))
#define END_OF_FILE (SPECIAL_OBJ(3))
#define MISSING_ARG (SPECIAL_OBJ(4))
#define MEM_OPS_PRIMITIVE (SPECIAL_OBJ(5))
#define END_OF_ARGS (SPECIAL_OBJ(6))

#define OBJ_TYPE_PREDICATE(type) \
static inline bool is_##type(obj_t obj) \
Expand Down
18 changes: 14 additions & 4 deletions obj_proc.c
Expand Up @@ -2,6 +2,8 @@

#include <assert.h>

#include "obj_uninit.h"

static size_t proc_size_op(const heap_object_t *hobj)
{
return sizeof (proc_obj_t);
Expand Down Expand Up @@ -75,7 +77,11 @@ obj_t make_procedure(obj_t body, obj_t arglist, obj_t env)
CHECK_OBJ(body);
CHECK_OBJ(arglist);
CHECK_OBJ(env);
return make_proc(PF_ARGS_EVALUATED, body, UNDEFINED_OBJ, arglist, env);
return make_proc(PF_ARGS_EVALUATED,
body,
make_uninitialized(),
arglist,
env);
}

obj_t make_C_procedure(C_procedure_t code,
Expand All @@ -92,15 +98,19 @@ obj_t make_raw_procedure(cont_proc_t code, obj_t name, obj_t env)
{
CHECK_OBJ(env);
proc_flags_t flags = PF_COMPILED_C | PF_RAW | PF_ARGS_EVALUATED;
return make_proc(flags, (obj_t)code, name, UNDEFINED_OBJ, env);
return make_proc(flags, (obj_t)code, name, make_uninitialized(), env);
}

obj_t make_special_form_procedure(obj_t body, obj_t env)
{
CHECK_OBJ(body);
CHECK_OBJ(env);
proc_flags_t flags = 0;
return make_proc(flags, body, UNDEFINED_OBJ, UNDEFINED_OBJ, env);
return make_proc(flags,
body,
make_uninitialized(),
make_uninitialized(),
env);
}

obj_t make_C_special_form_procedure(C_procedure_t code,
Expand All @@ -117,5 +127,5 @@ obj_t make_raw_special_form_procedure(cont_proc_t code, obj_t name, obj_t env)
{
CHECK_OBJ(env);
proc_flags_t flags = PF_COMPILED_C | PF_RAW;
return make_proc(flags, (obj_t)code, name, UNDEFINED_OBJ, env);
return make_proc(flags, (obj_t)code, name, make_uninitialized(), env);
}
6 changes: 3 additions & 3 deletions obj_symbol.c
Expand Up @@ -9,7 +9,7 @@
#include "obj_null.h"
#include "obj_pair.h"
#include "obj_string.h"
#include "obj_undefined.h"
#include "obj_uninit.h"
#include "roots.h"

mem_ops_t symbol_ops;
Expand Down Expand Up @@ -72,15 +72,15 @@ obj_t make_symbol_from_C_str(const wchar_t *C_name)

obj_t make_anonymous_symbol(void)
{
return alloc_symbol(UNDEFINED_OBJ);
return alloc_symbol(make_uninitialized());
}

obj_t symbol_name(obj_t symbol)
{
CHECK_OBJ(symbol);
CHECK(is_symbol(symbol), "must be symbol", symbol);
obj_t name = fixvec1_get_ptr(symbol, 0);
if (is_undefined(name)) {
if (is_uninitialized(name)) {
size_t max_len = 12;
ssize_t name_len;
wchar_t name_buf[max_len];
Expand Down
18 changes: 0 additions & 18 deletions obj_undefined.h

This file was deleted.

18 changes: 18 additions & 0 deletions obj_uninit.h
@@ -0,0 +1,18 @@
#ifndef OBJ_UNINIT_INCLUDED
#define OBJ_UNINIT_INCLUDED

#include "obj.h"

#define UNINITIALIZED_REPR L"#<uninitialized>"

static inline obj_t make_uninitialized(void)
{
return UNINITIALIZED_OBJ;
}

static inline bool is_uninitialized(obj_t obj)
{
return obj == UNINITIALIZED_OBJ;
}

#endif /* !OBJ_UNINIT_INCLUDED */
18 changes: 18 additions & 0 deletions obj_unspec.h
@@ -0,0 +1,18 @@
#ifndef OBJ_UNSPEC_INCLUDED
#define OBJ_UNSPEC_INCLUDED

#include "obj.h"

#define UNSPECIFIED_REPR L"#<unspecified>"

static inline obj_t make_unspecified(void)
{
return UNSPECIFIED_OBJ;
}

static inline bool is_unspecified(obj_t obj)
{
return obj == UNSPECIFIED_OBJ;
}

#endif /* !OBJ_UNSPEC_INCLUDED */
4 changes: 3 additions & 1 deletion prim_ctrl.c
Expand Up @@ -61,7 +61,9 @@ DEFINE_RAW_PROC(L"call-with-current-continuation")(obj_t cont, obj_t values)
obj_t saved_values = cont5_arg2(cont);
obj_t closure = CONS((obj_t)cont_cont(cont),
saved_values);
obj_t escape = make_raw_procedure(escape_callcc, UNDEFINED_OBJ, closure);
obj_t escape = make_raw_procedure(escape_callcc,
make_unspecified(),
closure);
return cv(make_cont5(c_apply_proc,
cont_cont(cont),
cont_env(cont),
Expand Down
6 changes: 3 additions & 3 deletions prim_defn.c
@@ -1,7 +1,7 @@
#include "env.h"
#include "list.h"
#include "prim.h"
#include "obj_undefined.h"
#include "obj_unspec.h"
#include "test.h"
#include "types.h"

Expand All @@ -10,7 +10,7 @@ static cv_t c_continue_define(obj_t cont, obj_t values)
assert(is_cont5(cont));
EVAL_LOG("var=%O values=%O", cont5_arg1(cont), values);
/* N.B., allocate new values before mutating environment. */
obj_t new_values = CONS(UNDEFINED_OBJ, cont5_arg2(cont));
obj_t new_values = CONS(make_unspecified(), cont5_arg2(cont));
obj_t ret = cont_cont(cont);
env_bind(cont_env(cont),
cont5_arg1(cont),
Expand Down Expand Up @@ -39,4 +39,4 @@ DEFINE_SPECIAL_FORM(L"define")(obj_t cont, obj_t values)
}

TEST_EVAL(L"(define v0 3) v0", L"3");
TEST_EVAL(L"(define v5 1)", UNDEFINED_REPR);
TEST_EVAL(L"(define v5 1)", UNSPECIFIED_REPR);
10 changes: 5 additions & 5 deletions prim_expr.c
Expand Up @@ -76,7 +76,7 @@ static cv_t c_continue_if(obj_t cont, obj_t values)
return cv(make_cont4(c_eval, cont_cont(cont), env, consequent),
CDR(values));
} else if (is_null(CDDDR(form)))
return cv(cont_cont(cont), CONS(UNDEFINED_OBJ, CDR(values)));
return cv(cont_cont(cont), CONS(make_unspecified(), CDR(values)));
else {
obj_t alternate = CADDDR(form);
return cv(make_cont4(c_eval, cont_cont(cont), env, alternate),
Expand All @@ -101,15 +101,15 @@ DEFINE_SPECIAL_FORM(L"if")(obj_t cont, obj_t values)
TEST_EVAL(L"(if (= 0 0) 1 2)", L"1");
TEST_EVAL(L"(if (= 0 1) 1 2)", L"2");
TEST_EVAL(L"(if (= 0 0) 1)", L"1");
TEST_EVAL(L"(if (= 0 1) 1)", UNDEFINED_REPR);
TEST_EVAL(L"(if (= 0 1) 1)", UNSPECIFIED_REPR);

/* from r6rs */
TEST_EVAL(L"(if (> 3 2) 'yes 'no)", L"yes");
TEST_EVAL(L"(if (> 2 3) 'yes 'no)", L"no");
TEST_EVAL(L"(if (> 3 2)\n"
L" (- 3 2)\n"
L" (+ 3 2))", L"1");
TEST_EVAL(L"(if #f #f)", UNDEFINED_REPR);
TEST_EVAL(L"(if #f #f)", UNSPECIFIED_REPR);

static cv_t c_continue_set(obj_t cont, obj_t values)
{
Expand All @@ -120,7 +120,7 @@ static cv_t c_continue_set(obj_t cont, obj_t values)
obj_t bdg = env_lookup(env, var);
EVAL_LOG("var=%O value=%O", var, value);
/* N.B., allocate values list before mutating environment. */
obj_t new_values = CONS(UNDEFINED_OBJ, cont5_arg2(cont));
obj_t new_values = CONS(make_unspecified(), cont5_arg2(cont));
obj_t ret = cont_cont(cont);
binding_set_value(bdg, value);
return cv(ret, new_values);
Expand All @@ -144,7 +144,7 @@ DEFINE_SPECIAL_FORM(L"set!")(obj_t cont, obj_t values)
}

TEST_EVAL(L"(define v1 '()) (set! v1 4) v1", L"4");
TEST_EVAL(L"(define v2 '()) (set! v2 4)", UNDEFINED_REPR);
TEST_EVAL(L"(define v2 '()) (set! v2 4)", UNSPECIFIED_REPR);
TEST_EVAL(L"((lambda (x) (set! x #t) x) #f)", L"#t");

/* from r6rs */
Expand Down
8 changes: 4 additions & 4 deletions prim_io.c
Expand Up @@ -76,7 +76,7 @@ static obj_t make_readline_port(void)
FALSE_OBJ,
FALSE_OBJ,
FALSE_OBJ,
make_undefined(),
make_uninitialized(),
FALSE_OBJ);
}

Expand Down Expand Up @@ -164,13 +164,13 @@ static obj_t make_text_file_input_port(int fd, bool close)
FALSE_OBJ, /* write proc */
FALSE_OBJ, /* seek proc */
file_close_proc,
make_undefined(), /* text buffer */
make_uninitialized(), /* text buffer */
binary_buffer); /* binary buffer */
}

static obj_t current_stdin(void)
{
if (is_undefined(standard_input)) {
if (is_uninitialized(standard_input)) {
int ifd = fileno(stdin), ofd = fileno(stdout);
if (isatty(ifd) && isatty(ofd))
standard_input = make_readline_port();
Expand Down Expand Up @@ -260,7 +260,7 @@ DEFINE_EXTERN_RAW_PROC(c_peek_char, L"peek-char")(obj_t cont, obj_t values)
EVAL_LOG("values=%O port=%O", values, port);
CHECK(is_port(port), "must be port");
obj_t rbuf = port_text_buffer(port);
if (!is_undefined(rbuf)) {
if (!is_uninitialized(rbuf)) {
if (is_eof(rbuf))
return cv(cont_cont(cont), CONS(rbuf, saved_values));
size_t rpos = port_text_pos(port);
Expand Down

0 comments on commit c2131f1

Please sign in to comment.