From 9be13d26ced58dda77cac4c71cbf0476c065c56e Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Mon, 4 Jan 2021 16:14:14 +0900 Subject: [PATCH] Add input stream stack --- bootstrap.fs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bootstrap.fs b/bootstrap.fs index 577c234..12aeed8 100644 --- a/bootstrap.fs +++ b/bootstrap.fs @@ -1429,3 +1429,29 @@ W/O stdout_ file>fam c! \ do nothing :noname drop success ; stdout_ file>flush ! + +( === Input Stream === ) + +\ input stream stack +struct + cell% field input>next + cell% field input>file + cell% field input>lineno +end-struct input% + +variable input-streams +0 input-streams ! + +: push-input-stream ( file -- ) + input% %allot \ addr + swap over input>file ! + 0 over input>lineno ! + input-streams @ over input>next ! + input-streams ! +; + +: pop-input-stream ( -- ) + input-streams @ input-streams ! +; + +stdin_ push-input-stream