From f3bcf32a12d6bab167810359dfbae55c56e4e1c1 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sun, 3 Jan 2021 19:34:03 -0800 Subject: [PATCH] More posix. --- ueforth/common/boot.fs | 2 +- ueforth/common/core.h | 2 +- ueforth/posix/posix.fs | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index 5e677f1..5726511 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -144,7 +144,7 @@ variable hld : sign ( n -- ) 0< if 45 hold then ; : #> ( w -- b u ) drop hld @ pad over - ; : str ( n -- b u ) dup >r abs <# #s r> sign #> ; -: hex ( -- ) 16 base ! ; +: hex ( -- ) 16 base ! ; : octal ( -- ) 8 base ! ; : decimal ( -- ) 10 base ! ; : u. ( u -- ) <# #s #> type space ; : . ( w -- ) base @ 10 xor if u. exit then str type space ; diff --git a/ueforth/common/core.h b/ueforth/common/core.h index f5f9aa4..5f7a597 100644 --- a/ueforth/common/core.h +++ b/ueforth/common/core.h @@ -90,7 +90,7 @@ static cell_t *eval1(cell_t *sp, cell_t *call) { *++sp = n; } } else { - //fwrite((void *) name, 1, len, stderr); + //write(2, (void *) name, len); *++sp = -1; *call = g_sys.tthrow; } diff --git a/ueforth/posix/posix.fs b/ueforth/posix/posix.fs index 62b0b7d..4877a39 100644 --- a/ueforth/posix/posix.fs +++ b/ueforth/posix/posix.fs @@ -25,6 +25,8 @@ z" wait" 1 sysfunc wait z" waitpid" 3 sysfunc waitpid z" mmap" 6 sysfunc mmap z" munmap" 2 sysfunc munmap +z" unlink" 1 sysfunc unlink +z" rename" 2 sysfunc rename ( Errno ) z" __errno_location" 0 sysfunc __errno_location @@ -48,6 +50,14 @@ z" __errno_location" 0 sysfunc __errno_location $10 constant MAP_FIXED $20 constant MAP_ANONYMOUS +( open ) +0 constant O_RDONLY +1 constant O_WRONLY +2 constant O_RDWR +$100 constant O_CREAT +$200 constant O_TRUNC +$2000 constant O_APPEND + ( Terminal handling ) : n. ( n -- ) base @ swap decimal <# #s #> type base ! ; : esc 27 emit ; @@ -74,6 +84,7 @@ $20 constant MAP_ANONYMOUS ( I/O Error Helpers ) : 0ior ( n -- n ior ) dup 0= if errno else 0 then ; +: 0z ( a n -- z ) here >r $place r> ; +: open-file ( a n fam -- fh ior ) >r s>z r> 0777 open 0r s>z r> O_CREAT or 0777 open 0z unlink 0z -rot s>z swap rename 0r write r> = 0ior ; +