Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions forth/dict.zf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

( 'words' generates a list of all define words )

: name dup @ 31 & swap next dup next rot tell @ ;
: words latest @ begin name br dup 0 = until cr drop ;
: name dup @ 31 & swap next dup next rot tell ;
: words latest @ dup begin name br @ - dup dup 0 = until cr drop drop ;

: prim? ( w -- bool ) @ 32 & ;
: a->xt ( w -- xt ) dup dup @ 31 & swap next next + swap prim? if @ fi ;
: xt->a ( xt -- w ) latest @ begin dup a->xt 2 pick = if swap drop exit fi next @ dup 0 = until swap drop ;
Expand Down
1 change: 0 additions & 1 deletion src/linux/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ int main(int argc, char **argv)
argv += optind;

zf_ctx *ctx = malloc(sizeof(zf_ctx));
printf("%p\n", (void *)ctx);

/* Initialize zforth */

Expand Down
15 changes: 8 additions & 7 deletions src/zforth/zforth.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ static const char *op_name(zf_ctx *ctx, zf_addr addr)

while(TRACE(ctx) && w) {
zf_addr xt, p = w;
zf_cell d, link, op2;
zf_cell d, size, op2;
int lenflags;

p += dict_get_cell(ctx, p, &d);
lenflags = d;
p += dict_get_cell(ctx, p, &link);
p += dict_get_cell(ctx, p, &size);
xt = p + ZF_FLAG_LEN(lenflags);
dict_get_cell(ctx, xt, &op2);

Expand All @@ -130,7 +130,7 @@ static const char *op_name(zf_ctx *ctx, zf_addr addr)
return name;
}

w = link;
w -= size;
}
return "?";
}
Expand Down Expand Up @@ -398,7 +398,8 @@ static void create(zf_ctx *ctx, const char *name, int flags)
trace(ctx, "\n=== create '%s'", name);
here_prev = HERE(ctx);
dict_add_cell(ctx, (strlen(name)) | flags);
dict_add_cell(ctx, LATEST(ctx));
zf_addr size = here_prev - LATEST(ctx);
dict_add_cell(ctx, size);
dict_add_str(ctx, name);
LATEST(ctx) = here_prev;
trace(ctx, "\n===");
Expand All @@ -415,11 +416,11 @@ static int find_word(zf_ctx *ctx, const char *name, zf_addr *word, zf_addr *code
size_t namelen = strlen(name);

while(w) {
zf_cell link, d;
zf_cell size, d;
zf_addr p = w;
size_t len;
p += dict_get_cell(ctx, p, &d);
p += dict_get_cell(ctx, p, &link);
p += dict_get_cell(ctx, p, &size);
len = ZF_FLAG_LEN((int)d);
if(len == namelen) {
const char *name2 = (const char *)&ctx->dict[p];
Expand All @@ -429,7 +430,7 @@ static int find_word(zf_ctx *ctx, const char *name, zf_addr *word, zf_addr *code
return 1;
}
}
w = link;
w -= size;
}

return 0;
Expand Down