From b2c60e43f2198c8d42237be5bc03a91c90aa2b37 Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Tue, 5 Jan 2021 07:01:53 +0900 Subject: [PATCH] rewrite existing parsers --- bootstrap.fs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/bootstrap.fs b/bootstrap.fs index 5d4b082..df040fc 100644 --- a/bootstrap.fs +++ b/bootstrap.fs @@ -1492,4 +1492,70 @@ variable inputstreams stdin_ push-inputstream +\ Rewrite existing functions that reads input using inputstream. + +: key ( -- c ) + inputstreams @ input>file @ key-file +; + +: word ( -- c-addr ) + inputstreams @ input>file @ + \ skip leading spaces + 0 + begin + drop + dup key-file \ ( file c ) + dup bl <> over '\n' <> and + until + word-buffer tuck c! + 1+ + begin + \ ( file p ) + over key-file + dup bl = over '\n' = or if + drop + 0 swap c! \ store \0 + drop + word-buffer exit + then + over c! + 1+ + again +; + +: ' ( "name" -- xt ) word find >cfa ; + +: : ( "name -- ) + align + here latest , &latest ! + word dup strlen + smudge-bit or c, + strcpy, + align + docol , + ] +; + +: ; ( -- ) + align + compile exit + latest cell + dup c@ + smudge-bit invert and swap c! + [compile] [ +; immediate + +: create ( "name" -- ) + align + here latest , &latest ! + word dup strlen c, strcpy, + align + docol , + compile lit + here 3 cells + , + compile nop + compile exit +; + +: char ( "ccc" -- c ) word c@ ; + ." Ready" cr