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

Commit

Permalink
Merge branch 'string-symbol'
Browse files Browse the repository at this point in the history
  • Loading branch information
nyuichi committed Feb 7, 2016
2 parents e076a8f + fd248d3 commit b3d5b1e
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 217 deletions.
6 changes: 3 additions & 3 deletions contrib/20.r7rs/src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pic_system_cmdline(pic_state *pic)
for (i = 0; i < pic->argc; ++i) {
size_t ai = pic_gc_arena_preserve(pic);

v = pic_cons(pic, pic_obj_value(pic_make_str_cstr(pic, pic->argv[i])), v);
v = pic_cons(pic, pic_obj_value(pic_make_cstr(pic, pic->argv[i])), v);
pic_gc_arena_restore(pic, ai);
}

Expand Down Expand Up @@ -84,7 +84,7 @@ pic_system_getenv(pic_state *pic)
if (val == NULL)
return pic_nil_value();
else
return pic_obj_value(pic_make_str_cstr(pic, val));
return pic_obj_value(pic_make_cstr(pic, val));
}

static pic_value
Expand All @@ -108,7 +108,7 @@ pic_system_getenvs(pic_state *pic)
;

key = pic_make_str(pic, *envp, i);
val = pic_make_str_cstr(pic, getenv(pic_str_cstr(pic, key)));
val = pic_make_cstr(pic, getenv(pic_str_cstr(pic, key)));

/* push */
data = pic_acons(pic, pic_obj_value(key), pic_obj_value(val), data);
Expand Down
14 changes: 7 additions & 7 deletions contrib/30.readline/src/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pic_rl_readline(pic_state *pic)
result = readline(prompt);

if(result)
return pic_obj_value(pic_make_str_cstr(pic, result));
return pic_obj_value(pic_make_cstr(pic, result));
else
return pic_eof_object();
}
Expand Down Expand Up @@ -87,7 +87,7 @@ pic_rl_current_history(pic_state *pic)
{
pic_get_args(pic, "");

return pic_obj_value(pic_make_str_cstr(pic, current_history()->line));
return pic_obj_value(pic_make_cstr(pic, current_history()->line));
}

static pic_value
Expand All @@ -100,7 +100,7 @@ pic_rl_history_get(pic_state *pic)

e = history_get(i);

return e ? pic_obj_value(pic_make_str_cstr(pic, e->line))
return e ? pic_obj_value(pic_make_cstr(pic, e->line))
: pic_false_value();
}

Expand All @@ -114,7 +114,7 @@ pic_rl_remove_history(pic_state *pic)

e = remove_history(i);

return e ? pic_obj_value(pic_make_str_cstr(pic, e->line))
return e ? pic_obj_value(pic_make_cstr(pic, e->line))
: pic_false_value();
}

Expand Down Expand Up @@ -148,7 +148,7 @@ pic_rl_previous_history(pic_state *pic)

e = previous_history();

return e ? pic_obj_value(pic_make_str_cstr(pic, e->line))
return e ? pic_obj_value(pic_make_cstr(pic, e->line))
: pic_false_value();
}

Expand All @@ -161,7 +161,7 @@ pic_rl_next_history(pic_state *pic)

e = next_history();

return e ? pic_obj_value(pic_make_str_cstr(pic, e->line))
return e ? pic_obj_value(pic_make_cstr(pic, e->line))
: pic_false_value();
}

Expand Down Expand Up @@ -240,7 +240,7 @@ pic_rl_history_expand(pic_state *pic)
if(status == -1 || status == 2)
pic_errorf(pic, "%s\n", result);

return pic_obj_value(pic_make_str_cstr(pic, result));
return pic_obj_value(pic_make_cstr(pic, result));
}

void
Expand Down
4 changes: 2 additions & 2 deletions contrib/30.regexp/src/regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pic_regexp_regexp_split(pic_state *pic)
input += match.rm_eo;
}

pic_push(pic, pic_obj_value(pic_make_str_cstr(pic, input)), output);
pic_push(pic, pic_obj_value(pic_make_cstr(pic, input)), output);

return pic_reverse(pic, output);
}
Expand All @@ -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_str(pic, NULL, 0);
pic_str *txt, *output = pic_make_lit(pic, "");

pic_get_args(pic, "ozs", &reg, &input, &txt);

Expand Down
10 changes: 5 additions & 5 deletions extlib/benz/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ pic_get_backtrace(pic_state *pic)
pic_callinfo *ci;
pic_str *trace;

trace = pic_make_str(pic, NULL, 0);
trace = pic_make_lit(pic, "");

for (ci = pic->ci; ci != pic->cibase; --ci) {
struct pic_proc *proc = pic_proc_ptr(ci->fp[0]);

trace = pic_str_cat(pic, trace, pic_make_str_cstr(pic, " at "));
trace = pic_str_cat(pic, trace, pic_make_str_cstr(pic, "(anonymous lambda)"));
trace = pic_str_cat(pic, trace, pic_make_lit(pic, " at "));
trace = pic_str_cat(pic, trace, pic_make_lit(pic, "(anonymous lambda)"));

if (pic_proc_func_p(proc)) {
trace = pic_str_cat(pic, trace, pic_make_str_cstr(pic, " (native function)\n"));
trace = pic_str_cat(pic, trace, pic_make_lit(pic, " (native function)\n"));
} else if (pic_proc_irep_p(proc)) {
trace = pic_str_cat(pic, trace, pic_make_str_cstr(pic, " (unknown location)\n")); /* TODO */
trace = pic_str_cat(pic, trace, pic_make_lit(pic, " (unknown location)\n")); /* TODO */
}
}

Expand Down
17 changes: 8 additions & 9 deletions extlib/benz/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,29 @@ void
pic_warnf(pic_state *pic, const char *fmt, ...)
{
va_list ap;
pic_value err_line;
pic_str *err;

va_start(ap, fmt);
err_line = pic_xvformat(pic, fmt, ap);
err = pic_vformat(pic, fmt, ap);
va_end(ap);

xfprintf(pic, pic_stderr(pic)->file, "warn: %s\n", pic_str_cstr(pic, pic_str_ptr(pic_car(pic, err_line))));
xfprintf(pic, pic_stderr(pic)->file, "warn: %s\n", pic_str_cstr(pic, err));
}

void
pic_errorf(pic_state *pic, const char *fmt, ...)
{
va_list ap;
pic_value err_line, irrs;
const char *msg;
pic_str *err;

va_start(ap, fmt);
err_line = pic_xvformat(pic, fmt, ap);
err = pic_vformat(pic, fmt, ap);
va_end(ap);

msg = pic_str_cstr(pic, pic_str_ptr(pic_car(pic, err_line)));
irrs = pic_cdr(pic, err_line);
msg = pic_str_cstr(pic, err);

pic_error(pic, msg, irrs);
pic_error(pic, msg, pic_nil_value());
}

pic_value
Expand Down Expand Up @@ -101,7 +100,7 @@ pic_make_error(pic_state *pic, pic_sym *type, const char *msg, pic_value irrs)

e = (struct pic_error *)pic_obj_alloc(pic, sizeof(struct pic_error), PIC_TT_ERROR);
e->type = type;
e->msg = pic_make_str_cstr(pic, msg);
e->msg = pic_make_cstr(pic, msg);
e->irrs = irrs;
e->stack = stack;

Expand Down
16 changes: 7 additions & 9 deletions extlib/benz/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ analyzer_scope_destroy(pic_state *pic, analyze_scope *scope)
}

static bool
search_scope(analyze_scope *scope, pic_sym *sym)
search_scope(pic_state *pic, analyze_scope *scope, pic_sym *sym)
{
return kh_get(a, &scope->args, sym) != kh_end(&scope->args) || kh_get(a, &scope->locals, sym) != kh_end(&scope->locals) || scope->depth == 0;
}
Expand All @@ -128,7 +128,7 @@ find_var(pic_state *pic, analyze_scope *scope, pic_sym *sym)
int depth = 0, ret;

while (scope) {
if (search_scope(scope, sym)) {
if (search_scope(pic, scope, sym)) {
if (depth > 0) {
kh_put(a, &scope->captures, sym, &ret); /* capture! */
}
Expand All @@ -145,13 +145,15 @@ define_var(pic_state *pic, analyze_scope *scope, pic_sym *sym)
{
int ret;

if (search_scope(scope, sym)) {
if (scope->depth > 0 || (pic_reg_has(pic, pic->globals, sym) && ! pic_invalid_p(pic_box_ptr(pic_reg_ref(pic, pic->globals, sym))->value))) {
if (search_scope(pic, scope, sym)) {
if (scope->depth > 0 || pic_reg_has(pic, pic->globals, sym)) {
pic_warnf(pic, "redefining variable: ~s", pic_obj_value(sym));
}
return;
}

pic_reg_set(pic, pic->globals, sym, pic_invalid_value());

kh_put(a, &scope->locals, sym, &ret);
}

Expand Down Expand Up @@ -514,15 +516,11 @@ index_local(codegen_context *cxt, pic_sym *sym)
static int
index_global(pic_state *pic, codegen_context *cxt, pic_sym *name)
{
extern struct pic_box *pic_vm_gref_slot(pic_state *, pic_sym *);
int pidx;
struct pic_box *slot;

slot = pic_vm_gref_slot(pic, name);

check_pool_size(pic, cxt);
pidx = (int)cxt->plen++;
cxt->pool[pidx] = (struct pic_object *)(slot);
cxt->pool[pidx] = (struct pic_object *)name;

return pidx;
}
Expand Down
11 changes: 2 additions & 9 deletions extlib/benz/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ struct pic_object {
struct pic_port port;
struct pic_error err;
struct pic_lib lib;
struct pic_box box;
struct pic_checkpoint cp;
} u;
};
Expand Down Expand Up @@ -385,6 +384,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
break;
}
case PIC_TT_SYMBOL: {
LOOP(obj->u.sym.str);
break;
}
case PIC_TT_REG: {
Expand All @@ -394,12 +394,6 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
pic->heap->regs = reg;
break;
}
case PIC_TT_BOX: {
if (pic_obj_p(obj->u.box.value)) {
LOOP(pic_obj_ptr(obj->u.box.value));
}
break;
}
case PIC_TT_CP: {
if (obj->u.cp.prev) {
gc_mark_object(pic, (struct pic_object *)obj->u.cp.prev);
Expand Down Expand Up @@ -566,7 +560,7 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
break;
}
case PIC_TT_SYMBOL: {
pic_free(pic, (void *)obj->u.sym.cstr);
/* TODO: remove this symbol's entry from pic->syms immediately */
break;
}
case PIC_TT_REG: {
Expand All @@ -588,7 +582,6 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
case PIC_TT_LIB:
case PIC_TT_RECORD:
case PIC_TT_CP:
case PIC_TT_BOX:
break;

case PIC_TT_NIL:
Expand Down
3 changes: 1 addition & 2 deletions extlib/benz/include/picrin.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef struct pic_state pic_state;
#include "picrin/read.h"
#include "picrin/gc.h"

KHASH_DECLARE(s, const char *, pic_sym *)
KHASH_DECLARE(s, pic_str *, pic_sym *)

typedef struct pic_checkpoint {
PIC_OBJECT_HEADER
Expand Down Expand Up @@ -251,7 +251,6 @@ pic_value pic_fdisplay(pic_state *, pic_value, xFILE *);
#include "picrin/symbol.h"
#include "picrin/vector.h"
#include "picrin/reg.h"
#include "picrin/box.h"

#if defined(__cplusplus)
}
Expand Down
34 changes: 0 additions & 34 deletions extlib/benz/include/picrin/box.h

This file was deleted.

0 comments on commit b3d5b1e

Please sign in to comment.