]> code.bitgloo.com Git - clyne/sforth.git/commitdiff
define type in forth
authorClyne Sullivan <clyne@bitgloo.com>
Thu, 19 Dec 2024 22:29:23 +0000 (17:29 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Thu, 19 Dec 2024 22:29:23 +0000 (17:29 -0500)
core.fth
main.cpp

index 8d4789b6a1b2bde235c1f2083fe21d73055fc15d..768f195b46878926245a5ba221490e0fed508c8f 100644 (file)
--- a/core.fth
+++ b/core.fth
             dup cell+ allot
             rot here swap !
             swap postpone literal postpone literal then ; immediate
-: ."       postpone s" state @ if postpone type else type then ; immediate
+: type      ?dup if 0 do dup c@ emit 1+ loop then drop ;
+: ."        postpone s" state @ if postpone type else type then ; immediate
 
 : (         begin [char] ) key = until ; immediate
 
 : execute   [ here 3 cells + ] literal ! [ ' _jmp , 0 , ] ;
 
-: move     dup 0 <= if drop 2drop exit then
-           >r 2dup < r> swap if
-           1- 0 swap do over i + c@ over i + c! -1 +loop
-           else
-           0 do over i + c@ over i + c! loop
-           then 2drop ;
-: fill     -rot begin dup 0 > while
-           >r 2dup c! char+ r> 1- repeat
-           2drop drop ;
+: move      dup 0 <= if drop 2drop exit then
+            >r 2dup < r> swap if
+            1- 0 swap do over i + c@ over i + c! -1 +loop
+            else
+            0 do over i + c@ over i + c! loop
+            then 2drop ;
+: fill      -rot begin dup 0 > while
+            >r 2dup c! char+ r> 1- repeat
+            2drop drop ;
+
index ec2e02c289e99e9b448aa6f9981b5f5985b08fb8..e51f702a0901813c387a7190bb482001d5dc2d0a 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -40,17 +40,12 @@ constinit static sforth::native_word<"U.", [](auto) {
 constinit static sforth::native_word<"EMIT", [](auto) {
     std::cout << static_cast<char>(forth.pop());
 }, &udot> emit;
-constinit static sforth::native_word<"TYPE", [](auto) {
-    const unsigned u = forth.pop();
-    const auto caddr = reinterpret_cast<const char *>(forth.pop());
-    std::cout << std::string_view{caddr, u};
-}, &emit> type;
 constinit static sforth::native_word<"INCLUDE", [](auto) {
     const auto w = forth.parse();
     std::string s {w.begin(), w.end()};
     std::ifstream file {s};
     parse_stream(forth, file);
-}, &type> incl;
+}, &emit> incl;
 
 int main(int argc, const char *argv[])
 {