From 218112f13cfa352ef86a92498aa77196e4a52ca8 Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Wed, 6 Jan 2021 01:13:10 +0900 Subject: [PATCH] minor fix --- bootstrap.fs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/bootstrap.fs b/bootstrap.fs index aa25f96..73ceaf5 100644 --- a/bootstrap.fs +++ b/bootstrap.fs @@ -1723,8 +1723,8 @@ switch-to-4th-stage \ limit start do ... loop -123 constant do-mark -457 constant leave-mark +1 constant do-mark +2 constant leave-mark create do-stack 16 cells allot drop variable do-sp @@ -1920,6 +1920,28 @@ codegen-target @ s" i386-linux" str= [if] next ;asm +( === File I/O === ) + +5 constant SYS_OPEN +6 constant SYS_CLOSE + +: fam-to-mode ( fam -- u ) + case + R/O of 0x00 endof + W/O of 0x01 endof + R/W of 0x02 endof + FILE-IO-ERROR throw + endcase +; + +: (open-file) ( c-addr fam -- obj f ) + fam-to-mode swap SYS_OPEN syscall2 dup 0>= +; + +: (close-file) ( obj -- f) + SYS_CLOSE syscall1 0>= +; + [else] \ i386-linux codegen-target @ s" no-codegen" str= <> [if] @@ -1927,4 +1949,30 @@ codegen-target @ s" no-codegen" str= <> [if] abort [then] [then] +( === open/close === ) + + +-62 s" CLOSE-FILE" def-error CLOSE-FILE-ERROR +-69 s" OPEN-FILE" def-error OPEN-FILE-ERROR + +: open-file ( c-addr fam -- file e ) + 2dup (open-file) if + file% %allot + tuck file>obj ! + tuck file>fam ! + tuck file>name ! + success + else + OPEN-FILE-ERROR throw + then +; + +: close-file ( file -- e ) + file>obj (close-file) unless + CLOSE-FILE-ERROR throw + then +; + +s" bootstrap.fs" R/O open-file + ." Ready" cr