From c293b184d84a8f16ee55675439d8b03ef4ceb809 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 30 Jan 2015 15:10:48 -0500 Subject: [PATCH] Added some basic string handling words --- source/onward.c | 6 ++++-- source/onward.ft | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/source/onward.c b/source/onward.c index 5f1a235..a4ae923 100755 --- a/source/onward.c +++ b/source/onward.c @@ -351,12 +351,14 @@ defcode("-!", sub_store, &add_store, 0u) { /** Fetch a byte from the given location */ defcode("b@", byte_fetch, &sub_store, 0u) { -// onward_aspush( (value_t)*((char*)onward_aspop()) ); + onward_aspush( (value_t)*((char*)onward_aspop()) ); } /** Store a byte in an address at the given location */ defcode("b!", byte_store, &byte_fetch, 0u) { -// *((char*)onward_aspop()) = (char)onward_aspop(); + char val = (char)onward_aspop(); + char* addr = (char*)onward_aspop(); + *(addr) = val; } /** Copy a block of memory to a new location */ diff --git a/source/onward.ft b/source/onward.ft index 98951dc..b21b43e 100644 --- a/source/onward.ft +++ b/source/onward.ft @@ -44,8 +44,6 @@ : const word create [compile] literal 0 , ; -: dump word find dumpw ; - \ Stack Manipulation Words \ ----------------------------------------------------------------------------- : nip swap drop ; @@ -144,3 +142,39 @@ drop \ drop the depth counter ; +\ String Words +\ ----------------------------------------------------------------------------- +: s" immediate + here @ + here @ + begin + \ while ( key != '"' ) + key dup 34 <> while + over swap b! + 1 + + repeat + drop + dup 0 b! + here over align ! + drop +; + +: emit+ + dup b@ dup if + emit 1 + + else + drop + then +; + +: semit + begin + dup b@ dup while + emit + 1 + + repeat + drop +; + +: sput semit 10 emit ; + -- 2.51.0