Add mkdir, cd, and more, refactor.
This commit is contained in:
4
Makefile
4
Makefile
@ -248,9 +248,9 @@ $(GEN)/windows_boot.h: tools/source_to_string.js $(WINDOWS_BOOT) | $(GEN)
|
|||||||
$< -win boot $(VERSION) $(REVISION) $(WINDOWS_BOOT) >$@
|
$< -win boot $(VERSION) $(REVISION) $(WINDOWS_BOOT) >$@
|
||||||
|
|
||||||
ESP32_BOOT = $(COMMON_PHASE1) \
|
ESP32_BOOT = $(COMMON_PHASE1) \
|
||||||
esp32/allocation.fs \
|
esp32/allocation.fs esp32/bindings.fs \
|
||||||
$(COMMON_PHASE2) $(COMMON_FILETOOLS) \
|
$(COMMON_PHASE2) $(COMMON_FILETOOLS) \
|
||||||
esp32/bindings.fs esp32/platform.fs \
|
esp32/platform.fs \
|
||||||
posix/httpd.fs posix/web_interface.fs esp32/web_interface.fs \
|
posix/httpd.fs posix/web_interface.fs esp32/web_interface.fs \
|
||||||
esp32/registers.fs esp32/timers.fs \
|
esp32/registers.fs esp32/timers.fs \
|
||||||
esp32/bterm.fs posix/telnetd.fs \
|
esp32/bterm.fs posix/telnetd.fs \
|
||||||
|
|||||||
@ -53,6 +53,16 @@ forth definitions internals
|
|||||||
again
|
again
|
||||||
;
|
;
|
||||||
|
|
||||||
|
DEFINED? read-dir [IF]
|
||||||
|
: ls ( "path" -- )
|
||||||
|
bl parse open-dir throw { dh } begin
|
||||||
|
dh read-dir dup 0= if
|
||||||
|
2drop dh close-dir throw exit
|
||||||
|
then type cr
|
||||||
|
again
|
||||||
|
;
|
||||||
|
[THEN]
|
||||||
|
|
||||||
internals definitions
|
internals definitions
|
||||||
( Leave some room for growth of starting system. )
|
( Leave some room for growth of starting system. )
|
||||||
0 value saving-base
|
0 value saving-base
|
||||||
|
|||||||
@ -307,6 +307,17 @@ e: check-float-opcodes
|
|||||||
out: FSQRT
|
out: FSQRT
|
||||||
;e
|
;e
|
||||||
|
|
||||||
|
e: check-files-dir
|
||||||
|
out: READ-DIR
|
||||||
|
out: CLOSE-DIR
|
||||||
|
out: OPEN-DIR
|
||||||
|
;e
|
||||||
|
|
||||||
|
e: check-files-dir-reverse
|
||||||
|
out: OPEN-DIR
|
||||||
|
out: CLOSE-DIR
|
||||||
|
;e
|
||||||
|
|
||||||
e: check-files
|
e: check-files
|
||||||
out: NON-BLOCK
|
out: NON-BLOCK
|
||||||
out: FILE-SIZE
|
out: FILE-SIZE
|
||||||
@ -409,6 +420,12 @@ e: check-snapshots
|
|||||||
out: remember
|
out: remember
|
||||||
out: restore
|
out: restore
|
||||||
out: save
|
out: save
|
||||||
|
;e
|
||||||
|
|
||||||
|
e: check-fileops
|
||||||
|
DEFINED? open-dir [IF]
|
||||||
|
out: ls
|
||||||
|
[THEN]
|
||||||
out: cat
|
out: cat
|
||||||
out: touch
|
out: touch
|
||||||
out: rm
|
out: rm
|
||||||
@ -479,6 +496,7 @@ e: check-filetools
|
|||||||
check-blocks
|
check-blocks
|
||||||
check-imports
|
check-imports
|
||||||
check-snapshots
|
check-snapshots
|
||||||
|
check-fileops
|
||||||
out: streams
|
out: streams
|
||||||
out: ms
|
out: ms
|
||||||
check-tasks
|
check-tasks
|
||||||
@ -568,8 +586,13 @@ e: test-posix-forth-namespace
|
|||||||
out: termios
|
out: termios
|
||||||
check-allocation
|
check-allocation
|
||||||
out: ok
|
out: ok
|
||||||
|
out: pwd
|
||||||
|
out: rmdir
|
||||||
|
out: mkdir
|
||||||
|
out: cd
|
||||||
out: ms-ticks
|
out: ms-ticks
|
||||||
out: ms
|
out: ms
|
||||||
|
check-files-dir
|
||||||
check-files
|
check-files
|
||||||
out: default-key
|
out: default-key
|
||||||
out: default-type
|
out: default-type
|
||||||
@ -586,6 +609,10 @@ e: test-esp32-forth-voclist
|
|||||||
internals ' ansi voclist-from
|
internals ' ansi voclist-from
|
||||||
out: ansi
|
out: ansi
|
||||||
out: registers
|
out: registers
|
||||||
|
out: ansi
|
||||||
|
out: editor
|
||||||
|
out: streams
|
||||||
|
out: tasks
|
||||||
out: oled
|
out: oled
|
||||||
out: bluetooth
|
out: bluetooth
|
||||||
out: rtos
|
out: rtos
|
||||||
@ -601,10 +628,6 @@ e: test-esp32-forth-voclist
|
|||||||
out: WiFi
|
out: WiFi
|
||||||
out: Wire
|
out: Wire
|
||||||
out: ESP
|
out: ESP
|
||||||
out: ansi
|
|
||||||
out: editor
|
|
||||||
out: streams
|
|
||||||
out: tasks
|
|
||||||
out: structures
|
out: structures
|
||||||
out: internalized
|
out: internalized
|
||||||
out: internals
|
out: internals
|
||||||
@ -637,10 +660,30 @@ e: check-esp32-builtins
|
|||||||
out: MS-TICKS
|
out: MS-TICKS
|
||||||
out: TERMINATE
|
out: TERMINATE
|
||||||
check-files-reverse
|
check-files-reverse
|
||||||
|
check-files-dir-reverse
|
||||||
out: dacWrite
|
out: dacWrite
|
||||||
out: MDNS.begin
|
out: MDNS.begin
|
||||||
;e
|
;e
|
||||||
|
|
||||||
|
e: check-esp32-bindings
|
||||||
|
out: oled
|
||||||
|
out: bluetooth
|
||||||
|
out: rtos
|
||||||
|
out: rmt
|
||||||
|
out: interrupts
|
||||||
|
out: sockets
|
||||||
|
out: Serial
|
||||||
|
out: ledc
|
||||||
|
out: SPIFFS
|
||||||
|
out: spi_flash
|
||||||
|
out: SD_MMC
|
||||||
|
out: SD
|
||||||
|
out: WiFi
|
||||||
|
out: Wire
|
||||||
|
out: ESP
|
||||||
|
out: read-dir
|
||||||
|
;e
|
||||||
|
|
||||||
e: test-esp32-forth-namespace
|
e: test-esp32-forth-namespace
|
||||||
' forth list-from
|
' forth list-from
|
||||||
out: FORTH
|
out: FORTH
|
||||||
@ -657,23 +700,9 @@ e: test-esp32-forth-namespace
|
|||||||
out: web-interface
|
out: web-interface
|
||||||
out: httpd
|
out: httpd
|
||||||
check-esp32-platform
|
check-esp32-platform
|
||||||
out: oled
|
|
||||||
out: bluetooth
|
|
||||||
out: rtos
|
|
||||||
out: rmt
|
|
||||||
out: interrupts
|
|
||||||
out: sockets
|
|
||||||
out: Serial
|
|
||||||
out: ledc
|
|
||||||
out: SPIFFS
|
|
||||||
out: spi_flash
|
|
||||||
out: SD_MMC
|
|
||||||
out: SD
|
|
||||||
out: WiFi
|
|
||||||
out: Wire
|
|
||||||
out: ESP
|
|
||||||
check-filetools
|
check-filetools
|
||||||
check-phase2
|
check-phase2
|
||||||
|
check-esp32-bindings
|
||||||
check-allocation
|
check-allocation
|
||||||
check-phase1
|
check-phase1
|
||||||
check-esp32-builtins
|
check-esp32-builtins
|
||||||
|
|||||||
@ -14,12 +14,14 @@
|
|||||||
|
|
||||||
( Migrate various words to separate vocabularies, and constants )
|
( Migrate various words to separate vocabularies, and constants )
|
||||||
|
|
||||||
|
forth definitions internals
|
||||||
|
: read-dir ( dh -- a n ) dup if errno else 0 then ;
|
||||||
|
forth definitions
|
||||||
|
|
||||||
vocabulary ESP ESP definitions
|
vocabulary ESP ESP definitions
|
||||||
transfer ESP-builtins
|
transfer ESP-builtins
|
||||||
only forth definitions
|
only forth definitions
|
||||||
|
|
||||||
forth definitions
|
|
||||||
|
|
||||||
vocabulary Wire Wire definitions
|
vocabulary Wire Wire definitions
|
||||||
transfer wire-builtins
|
transfer wire-builtins
|
||||||
forth definitions
|
forth definitions
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#ifndef SIM_PRINT_ONLY
|
#ifndef SIM_PRINT_ONLY
|
||||||
|
|
||||||
|
# include <dirent.h>
|
||||||
# include <errno.h>
|
# include <errno.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
@ -128,7 +129,7 @@ static cell_t ResizeFile(cell_t fd, cell_t size);
|
|||||||
X("RENAME-FILE", RENAME_FILE, \
|
X("RENAME-FILE", RENAME_FILE, \
|
||||||
cell_t len = n0; DROP; memcpy(filename, a0, len); filename[len] = 0; DROP; \
|
cell_t len = n0; DROP; memcpy(filename, a0, len); filename[len] = 0; DROP; \
|
||||||
cell_t len2 = n0; DROP; memcpy(filename2, a0, len2); filename2[len2] = 0; \
|
cell_t len2 = n0; DROP; memcpy(filename2, a0, len2); filename2[len2] = 0; \
|
||||||
n0 = rename(filename, filename2); n0 = n0 ? errno : 0) \
|
n0 = rename(filename2, filename); n0 = n0 ? errno : 0) \
|
||||||
X("WRITE-FILE", WRITE_FILE, cell_t fd = n0; DROP; cell_t len = n0; DROP; \
|
X("WRITE-FILE", WRITE_FILE, cell_t fd = n0; DROP; cell_t len = n0; DROP; \
|
||||||
n0 = write(fd, a0, len); n0 = n0 != len ? errno : 0) \
|
n0 = write(fd, a0, len); n0 = n0 != len ? errno : 0) \
|
||||||
X("READ-FILE", READ_FILE, cell_t fd = n0; DROP; cell_t len = n0; DROP; \
|
X("READ-FILE", READ_FILE, cell_t fd = n0; DROP; cell_t len = n0; DROP; \
|
||||||
@ -141,7 +142,11 @@ static cell_t ResizeFile(cell_t fd, cell_t size);
|
|||||||
X("FILE-SIZE", FILE_SIZE, struct stat st; w = fstat(n0, &st); \
|
X("FILE-SIZE", FILE_SIZE, struct stat st; w = fstat(n0, &st); \
|
||||||
n0 = (cell_t) st.st_size; PUSH w < 0 ? errno : 0) \
|
n0 = (cell_t) st.st_size; PUSH w < 0 ? errno : 0) \
|
||||||
X("NON-BLOCK", NON_BLOCK, n0 = fcntl(n0, F_SETFL, O_NONBLOCK); \
|
X("NON-BLOCK", NON_BLOCK, n0 = fcntl(n0, F_SETFL, O_NONBLOCK); \
|
||||||
n0 = n0 < 0 ? errno : 0)
|
n0 = n0 < 0 ? errno : 0) \
|
||||||
|
X("OPEN-DIR", OPEN_DIR, memcpy(filename, a1, n0); filename[n0] = 0; \
|
||||||
|
n1 = (cell_t) opendir(filename); n0 = n1 ? 0 : errno) \
|
||||||
|
X("CLOSE-DIR", CLOSE_DIR, n0 = closedir((DIR *) n0); n0 = n0 ? errno : 0) \
|
||||||
|
YV(internals, READDIR, SET readdir((DIR *) n0)->d_name)
|
||||||
|
|
||||||
#ifndef ENABLE_LEDC_SUPPORT
|
#ifndef ENABLE_LEDC_SUPPORT
|
||||||
# define OPTIONAL_LEDC_SUPPORT
|
# define OPTIONAL_LEDC_SUPPORT
|
||||||
|
|||||||
@ -58,8 +58,10 @@ z" usleep" 1 sysfunc usleep
|
|||||||
z" signal" 2 sysfunc signal
|
z" signal" 2 sysfunc signal
|
||||||
|
|
||||||
( Directories )
|
( Directories )
|
||||||
|
z" chdir" 1 sysfunc chdir
|
||||||
z" mkdir" 2 sysfunc mkdir
|
z" mkdir" 2 sysfunc mkdir
|
||||||
z" rmdir" 1 sysfunc rmdir
|
z" rmdir" 1 sysfunc rmdir
|
||||||
|
z" getwd" 1 sysfunc getwd
|
||||||
z" opendir" 1 sysfunc opendir
|
z" opendir" 1 sysfunc opendir
|
||||||
z" closedir" 1 sysfunc closedir
|
z" closedir" 1 sysfunc closedir
|
||||||
z" readdir" 1 sysfunc readdir
|
z" readdir" 1 sysfunc readdir
|
||||||
@ -114,7 +116,10 @@ only posix definitions
|
|||||||
' posix-bye is bye
|
' posix-bye is bye
|
||||||
|
|
||||||
( I/O Error Helpers )
|
( I/O Error Helpers )
|
||||||
: d0<ior ( n -- n ior ) dup 0< if errno else 0 then ;
|
: 0<ior ( n -- ior ) 0< if errno else 0 then ;
|
||||||
|
: 0=ior ( n -- ior ) 0= if errno else 0 then ;
|
||||||
|
: d0<ior ( n -- n ior ) dup 0<ior ;
|
||||||
|
: d0=ior ( n -- n ior ) dup 0=ior ;
|
||||||
|
|
||||||
( errno.h )
|
( errno.h )
|
||||||
11 constant EAGAIN
|
11 constant EAGAIN
|
||||||
@ -164,18 +169,18 @@ O_WRONLY constant W/O
|
|||||||
O_RDWR constant R/W
|
O_RDWR constant R/W
|
||||||
: BIN ( fh -- fh ) ;
|
: BIN ( fh -- fh ) ;
|
||||||
|
|
||||||
: CLOSE-FILE ( fh -- ior ) close sign-extend ;
|
: CLOSE-FILE ( fh -- ior ) close 0<ior ;
|
||||||
: FLUSH-FILE ( fh -- ior ) fsync sign-extend ;
|
: FLUSH-FILE ( fh -- ior ) fsync 0<ior ;
|
||||||
: OPEN-FILE ( a n fam -- fh ior ) >r s>z r> 0777 open sign-extend d0<ior ;
|
: OPEN-FILE ( a n fam -- fh ior ) >r s>z r> 0777 open sign-extend d0<ior ;
|
||||||
: CREATE-FILE ( a n fam -- fh ior )
|
: CREATE-FILE ( a n fam -- fh ior )
|
||||||
>r s>z r> O_CREAT or 0777 open sign-extend d0<ior ;
|
>r s>z r> O_CREAT or 0777 open sign-extend d0<ior ;
|
||||||
: DELETE-FILE ( a n -- ior ) s>z unlink sign-extend ;
|
: DELETE-FILE ( a n -- ior ) s>z unlink 0<ior ;
|
||||||
: RENAME-FILE ( a n a n -- ior ) s>z -rot s>z swap rename sign-extend ;
|
: RENAME-FILE ( a n a n -- ior ) s>z -rot s>z swap rename 0<ior ;
|
||||||
: WRITE-FILE ( a n fh -- ior ) -rot dup >r write r> = 0= ;
|
: WRITE-FILE ( a n fh -- ior ) -rot dup >r write r> = 0=ior ;
|
||||||
: READ-FILE ( a n fh -- n ior ) -rot read d0<ior ;
|
: READ-FILE ( a n fh -- n ior ) -rot read d0<ior ;
|
||||||
: FILE-POSITION ( fh -- n ior ) 0 SEEK_CUR lseek d0<ior ;
|
: FILE-POSITION ( fh -- n ior ) 0 SEEK_CUR lseek d0<ior ;
|
||||||
: REPOSITION-FILE ( n fh -- ior ) swap SEEK_SET lseek 0< ;
|
: REPOSITION-FILE ( n fh -- ior ) swap SEEK_SET lseek 0<ior ;
|
||||||
: RESIZE-FILE ( n fh -- ior ) swap ftruncate 0< ;
|
: RESIZE-FILE ( n fh -- ior ) swap ftruncate 0<ior ;
|
||||||
: FILE-SIZE ( fh -- n ior )
|
: FILE-SIZE ( fh -- n ior )
|
||||||
dup 0 SEEK_CUR lseek >r
|
dup 0 SEEK_CUR lseek >r
|
||||||
dup 0 SEEK_END lseek r> swap >r
|
dup 0 SEEK_END lseek r> swap >r
|
||||||
@ -183,12 +188,23 @@ O_RDWR constant R/W
|
|||||||
( Non-standard )
|
( Non-standard )
|
||||||
: NON-BLOCK ( fh -- ior ) F_SETFL FNDELAY fcntl ;
|
: NON-BLOCK ( fh -- ior ) F_SETFL FNDELAY fcntl ;
|
||||||
|
|
||||||
|
( Directories )
|
||||||
|
: OPEN-DIR ( a n -- dh ior ) s>z opendir d0=ior ;
|
||||||
|
: CLOSE-DIR ( dh -- ior ) closedir 0<ior ;
|
||||||
|
: READ-DIR ( dh -- a n ) readdir dup if .d_name z>s else 0 then ;
|
||||||
|
|
||||||
( Other Utils )
|
( Other Utils )
|
||||||
: ms ( n -- ) 1000 * usleep drop ;
|
: ms ( n -- ) 1000 * usleep drop ;
|
||||||
: ms-ticks ( -- n )
|
: ms-ticks ( -- n )
|
||||||
0 >r 0 >r CLOCK_MONOTONIC_RAW rp@ cell - clock_gettime throw
|
0 >r 0 >r CLOCK_MONOTONIC_RAW rp@ cell - clock_gettime throw
|
||||||
r> 1000000 / r> 1000 * + ;
|
r> 1000000 / r> 1000 * + ;
|
||||||
|
|
||||||
|
( Shell ops )
|
||||||
|
: cd ( "path" -- ) bl parse s>z chdir throw ;
|
||||||
|
: mkdir ( "path" -- ) bl parse s>z 0777 mkdir throw ;
|
||||||
|
: rmdir ( "path" -- ) bl parse s>z rmdir throw ;
|
||||||
|
: pwd here getwd z>s type cr ;
|
||||||
|
|
||||||
forth
|
forth
|
||||||
|
|
||||||
( Setup entry )
|
( Setup entry )
|
||||||
|
|||||||
Reference in New Issue
Block a user