define type in forth

main
Clyne 2 days ago
parent 3246deb437
commit ff4e488ca0
Signed by: clyne
GPG Key ID: 7BA5A2980566A649

@ -65,18 +65,20 @@
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 ;

@ -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[])
{

Loading…
Cancel
Save