From 01340068276810b3e7515bee1da6289812aab0ec Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 4 Dec 2014 12:54:19 -0500 Subject: [PATCH] Fixed a bug in create --- source/onward.c | 4 +++- source/onward.ft | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/onward.c b/source/onward.c index eb88095..3b67f6f 100755 --- a/source/onward.c +++ b/source/onward.c @@ -209,7 +209,9 @@ defcode("create", create, &exec, 0u) { char* name = (char*)onward_aspop(); /* Copy the name to a more permanent location */ size_t str_size = strlen(name) + 1; - size_t new_size = str_size + (sizeof(value_t) - (str_size % sizeof(value_t))); + size_t new_size = (str_size % sizeof(value_t)) + ? ((str_size + (sizeof(value_t) - 1)) & ~sizeof(value_t)) + : str_size; name = memcpy((void*)here, name, str_size); here += new_size; /* Start populating the word definition */ diff --git a/source/onward.ft b/source/onward.ft index aa4a58d..98951dc 100644 --- a/source/onward.ft +++ b/source/onward.ft @@ -17,7 +17,7 @@ CELLSZ + \ Add offset to get to the flags field dup @ \ Fetch the current value F_IMMEDIATE | ! \ Set the immediate bit -; immediate +; immediate \ Use the immediate word to make the immediate word immediate :D : [compile] immediate word find , @@ -31,6 +31,17 @@ ' lit , , \ Compile the top item on the stack as a literal ; +: allot here @ dup rot + here swap ! ; + +: cells CELLSZ * ; + +: variable + 1 cells allot + word create + [compile] literal + 0 , +; + : const word create [compile] literal 0 , ; : dump word find dumpw ; @@ -114,6 +125,7 @@ \ Comment Words \ ----------------------------------------------------------------------------- : # [compile] \ ; + : #! [compile] \ ; : ( immediate -- 2.55.0