summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jefs.fs30
1 files changed, 27 insertions, 3 deletions
diff --git a/jefs.fs b/jefs.fs
index 944b146..42f32c4 100644
--- a/jefs.fs
+++ b/jefs.fs
@@ -2,7 +2,6 @@
\ things TODO:
\ better error handling
\ :noname
-\ asciiz strings (for syscalls)
\ DO LOOP
\ s\"
\ <builds does>
@@ -64,8 +63,9 @@ hex : ret, c3 c, ; decimal
\ }}}
\ TODO interpret mode strings?
-: s" 1 >in +! [ char " ] literal cparse branch >mark >r 2dup cmove, r> >resolve swap [compile] lit [compile] lit ; immediate
+: s" 1 >in +! [ char " ] literal cparse branch >mark >r 2dup cmove, nip r> dup >resolve 4 + [compile] lit [compile] lit ; immediate
: ." [compile] s" ' say compile, ; immediate \ lol this word breaks the highlighting, here have another "
+: z" 1 >in +! [ char " ] literal cparse branch >mark >r 2dup cmove, 0 c, nip r> dup >resolve 4 + [compile] lit drop ( 1+ [compile] lit ) ; immediate
\ ASSEMBLER {{{
\ https://wiki.osdev.org/X86-64_Instruction_Encoding
@@ -208,11 +208,35 @@ variable hld
: (evaluate) ( c-addr u -- ) 0 >in ! ( u ) #tib ! ( c-addr ) tib ! interpret ;
: evaluate ( c-addr u -- ) tib @ >r #tib @ >r >in @ >r (evaluate) r> >in ! r> #tib ! r> tib ! ;
+\ SYSCALL ERRORS {{{
+: errno ( rax -- ?val err|0 ) dup 0< if negate else 0 then ;
+: errno-flag ( rax -- err|0 ) dup 0< if negate else drop 0 then ;
+
+2 constant enoent
+9 constant ebadf
+13 constant eacces
+\ }}}
+
\ FILE I/O {{{
\ for syswrite see the top of the file
0 constant stdin
1 constant stdout
2 constant stderr
+
+: sysread ( u c-addr fd -- ) 0 syscall3 ;
+: sysopen ( mode flags filename -- ) 2 syscall3 ;
+: sysclose ( fd -- ) 3 syscall1 ;
+
+0 constant r/o
+1 constant w/o
+2 constant r/w
+
+\ TODO error handling (0< abs → errno i think)
+\ flags are zero on success
+: open-file ( mode zstr -- ?fd flag ) 0 -rot sysopen errno ;
+: close-file ( fd -- flag ) sysclose errno-flag ;
+: read-file ( c-addr u fd -- ?u flag ) >r swap r> sysread errno ;
\ }}}
-.free bye
+: t r/o z" test" open-file .s drop close-file .s drop ;
+t .free bye