From c4745240f68839843909b6a4d8624f15f58fa7c1 Mon Sep 17 00:00:00 2001 From: kitty Date: Sun, 8 Mar 2026 19:41:56 +1100 Subject: port strlen, argc, argv, environ from jonesforth --- jefs.fs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'jefs.fs') diff --git a/jefs.fs b/jefs.fs index d3e4331..8dd4a8e 100644 --- a/jefs.fs +++ b/jefs.fs @@ -71,8 +71,8 @@ hex : ret, c3 c, ; decimal : ." [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 -\ todo s>z z>s : s>z ( a u -- zstr ) here @ -rot cmove, 0 c, ; +: strlen ( zstr -- len ) dup begin dup c@ 0<> while 1+ repeat swap - ; \ creates a word called _ (so don't create an actual word called that!!!) \ maybe it could be an empty string but that might require some rewriting @@ -353,6 +353,12 @@ make line-buffer line-buffer-length allot : include ( "path" -- ) parse included ; \ }}} +\ ARGS {{{ +: argc rs0 @ @ ; +: argv ( n -- a u ) 1+ cells rs0 @ + @ dup strlen ; \ segfaults if n>=argc +: environ argc 2 + cells rs0 @ + ; +\ }}} + \ TERMINAL CONTROL {{{ 60 constant termios# make termios termios# allot -- cgit v1.2.3