Resort more.
This commit is contained in:
@ -272,21 +272,23 @@ e: check-float-opcodes
|
|||||||
;e
|
;e
|
||||||
|
|
||||||
e: check-files
|
e: check-files
|
||||||
out: file-size
|
out: NON-BLOCK
|
||||||
out: resize-file
|
out: FILE-SIZE
|
||||||
out: reposition-file
|
out: RESIZE-FILE
|
||||||
out: file-position
|
out: REPOSITION-FILE
|
||||||
out: write-file
|
out: FILE-POSITION
|
||||||
out: read-file
|
out: READ-FILE
|
||||||
out: rename-file
|
out: WRITE-FILE
|
||||||
out: delete-file
|
out: RENAME-FILE
|
||||||
out: flush-file
|
out: DELETE-FILE
|
||||||
out: close-file
|
out: CREATE-FILE
|
||||||
out: create-file
|
out: OPEN-FILE
|
||||||
out: open-file
|
out: FLUSH-FILE
|
||||||
out: r/w
|
out: CLOSE-FILE
|
||||||
out: w/o
|
out: BIN
|
||||||
out: r/o
|
out: R/W
|
||||||
|
out: W/O
|
||||||
|
out: R/O
|
||||||
;e
|
;e
|
||||||
|
|
||||||
e: check-blocks
|
e: check-blocks
|
||||||
@ -476,7 +478,6 @@ e: test-posix-forth-namespace
|
|||||||
out: #!
|
out: #!
|
||||||
out: ms-ticks
|
out: ms-ticks
|
||||||
out: ms
|
out: ms
|
||||||
out: non-block
|
|
||||||
check-files
|
check-files
|
||||||
out: default-key
|
out: default-key
|
||||||
out: default-type
|
out: default-type
|
||||||
@ -541,22 +542,7 @@ e: check-esp32-basics2
|
|||||||
out: setsockopt
|
out: setsockopt
|
||||||
out: MDNS.begin
|
out: MDNS.begin
|
||||||
out: dacWrite
|
out: dacWrite
|
||||||
out: NON-BLOCK
|
check-files
|
||||||
out: FILE-SIZE
|
|
||||||
out: RESIZE-FILE
|
|
||||||
out: REPOSITION-FILE
|
|
||||||
out: FILE-POSITION
|
|
||||||
out: READ-FILE
|
|
||||||
out: WRITE-FILE
|
|
||||||
out: DELETE-FILE
|
|
||||||
out: CREATE-FILE
|
|
||||||
out: OPEN-FILE
|
|
||||||
out: FLUSH-FILE
|
|
||||||
out: CLOSE-FILE
|
|
||||||
out: BIN
|
|
||||||
out: W/O
|
|
||||||
out: R/W
|
|
||||||
out: R/O
|
|
||||||
out: TERMINATE
|
out: TERMINATE
|
||||||
out: MS-TICKS
|
out: MS-TICKS
|
||||||
out: pulseIn
|
out: pulseIn
|
||||||
|
|||||||
@ -93,8 +93,8 @@ static cell_t ResizeFile(cell_t fd, cell_t size);
|
|||||||
|
|
||||||
#define REQUIRED_FILES_SUPPORT \
|
#define REQUIRED_FILES_SUPPORT \
|
||||||
X("R/O", R_O, PUSH O_RDONLY) \
|
X("R/O", R_O, PUSH O_RDONLY) \
|
||||||
X("R/W", R_W, PUSH O_RDWR) \
|
|
||||||
X("W/O", W_O, PUSH O_WRONLY) \
|
X("W/O", W_O, PUSH O_WRONLY) \
|
||||||
|
X("R/W", R_W, PUSH O_RDWR) \
|
||||||
Y(BIN, ) \
|
Y(BIN, ) \
|
||||||
X("CLOSE-FILE", CLOSE_FILE, tos = close(tos); tos = tos ? errno : 0) \
|
X("CLOSE-FILE", CLOSE_FILE, tos = close(tos); tos = tos ? errno : 0) \
|
||||||
X("FLUSH-FILE", FLUSH_FILE, fsync(tos); /* fsync has no impl and returns ENOSYS :-( */ tos = 0) \
|
X("FLUSH-FILE", FLUSH_FILE, fsync(tos); /* fsync has no impl and returns ENOSYS :-( */ tos = 0) \
|
||||||
@ -107,6 +107,7 @@ static cell_t ResizeFile(cell_t fd, cell_t size);
|
|||||||
X("DELETE-FILE", DELETE_FILE, cell_t len = n0; DROP; \
|
X("DELETE-FILE", DELETE_FILE, cell_t len = n0; DROP; \
|
||||||
memcpy(filename, a0, len); filename[len] = 0; \
|
memcpy(filename, a0, len); filename[len] = 0; \
|
||||||
n0 = unlink(filename); n0 = n0 ? errno : 0) \
|
n0 = unlink(filename); n0 = n0 ? errno : 0) \
|
||||||
|
X("RENAME-FILE", RENAME_FILE, NIPn(3); /* unimplemented */ n0 = 1) \
|
||||||
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; \
|
||||||
|
|||||||
@ -156,29 +156,29 @@ z" fcntl" 3 sysfunc fcntl
|
|||||||
forth definitions posix
|
forth definitions posix
|
||||||
|
|
||||||
( Generic Files )
|
( Generic Files )
|
||||||
O_RDONLY constant r/o
|
O_RDONLY constant R/O
|
||||||
O_WRONLY constant w/o
|
O_WRONLY constant W/O
|
||||||
O_RDWR constant r/w
|
O_RDWR constant R/W
|
||||||
|
: BIN ( fh -- fh ) ;
|
||||||
|
|
||||||
: open-file ( a n fam -- fh ior ) >r s>z r> 0777 open sign-extend d0<ior ;
|
: CLOSE-FILE ( fh -- ior ) close sign-extend ;
|
||||||
: create-file ( a n fam -- fh ior )
|
: FLUSH-FILE ( fh -- ior ) fsync sign-extend ;
|
||||||
|
: OPEN-FILE ( a n fam -- fh ior ) >r s>z r> 0777 open sign-extend d0<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 ;
|
||||||
: close-file ( fh -- ior ) close sign-extend ;
|
: DELETE-FILE ( a n -- ior ) s>z unlink sign-extend ;
|
||||||
: flush-file ( fh -- ior ) fsync sign-extend ;
|
: RENAME-FILE ( a n a n -- ior ) s>z -rot s>z swap rename sign-extend ;
|
||||||
: delete-file ( a n -- ior ) s>z unlink sign-extend ;
|
: WRITE-FILE ( a n fh -- ior ) -rot dup >r write r> = 0= ;
|
||||||
: rename-file ( a n a n -- ior ) s>z -rot s>z swap rename sign-extend ;
|
: 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 ;
|
||||||
: write-file ( a n fh -- ior ) -rot dup >r write r> = 0= ;
|
: REPOSITION-FILE ( n fh -- ior ) swap SEEK_SET lseek 0< ;
|
||||||
: file-position ( fh -- n ior ) 0 SEEK_CUR lseek d0<ior ;
|
: RESIZE-FILE ( n fh -- ior ) swap ftruncate 0< ;
|
||||||
: reposition-file ( n fh -- ior ) swap SEEK_SET lseek 0< ;
|
: FILE-SIZE ( fh -- n ior )
|
||||||
: resize-file ( n fh -- ior ) swap ftruncate 0< ;
|
|
||||||
: 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
|
||||||
SEEK_SET lseek drop r> d0<ior ;
|
SEEK_SET lseek drop r> d0<ior ;
|
||||||
|
|
||||||
( Non-standard )
|
( Non-standard )
|
||||||
: non-block ( fh -- ior ) F_SETFL FNDELAY fcntl ;
|
: NON-BLOCK ( fh -- ior ) F_SETFL FNDELAY fcntl ;
|
||||||
|
|
||||||
( Other Utils )
|
( Other Utils )
|
||||||
: ms ( n -- ) 1000 * usleep drop ;
|
: ms ( n -- ) 1000 * usleep drop ;
|
||||||
|
|||||||
@ -149,33 +149,35 @@ $80 constant FILE_ATTRIBUTE_NORMAL
|
|||||||
forth definitions windows
|
forth definitions windows
|
||||||
|
|
||||||
( Generic Files )
|
( Generic Files )
|
||||||
$80000000 constant r/o ( GENERIC_READ )
|
$80000000 constant R/O ( GENERIC_READ )
|
||||||
$40000000 constant w/o ( GENERIC_WRITE )
|
$40000000 constant W/O ( GENERIC_WRITE )
|
||||||
r/o w/o or constant r/w
|
R/O W/O or constant R/W
|
||||||
: open-file ( a n fam -- fh ior )
|
: BIN ( fh -- fh ) ;
|
||||||
|
: CLOSE-FILE ( fh -- ior ) CloseHandle 0=ior ;
|
||||||
|
: FLUSH-FILE ( fh -- ior ) FlushFileBuffers 0=ior ;
|
||||||
|
: OPEN-FILE ( a n fam -- fh ior )
|
||||||
>r s>z r> FILE_SHARE_READ FILE_SHARE_WRITE or NULL
|
>r s>z r> FILE_SHARE_READ FILE_SHARE_WRITE or NULL
|
||||||
OPEN_EXISTING FILE_ATTRIBUTE_NORMAL NULL CreateFileA d0<ior ;
|
OPEN_EXISTING FILE_ATTRIBUTE_NORMAL NULL CreateFileA d0<ior ;
|
||||||
: create-file ( a n fam -- fh ior )
|
: CREATE-FILE ( a n fam -- fh ior )
|
||||||
>r s>z r> FILE_SHARE_READ FILE_SHARE_WRITE or NULL
|
>r s>z r> FILE_SHARE_READ FILE_SHARE_WRITE or NULL
|
||||||
CREATE_ALWAYS FILE_ATTRIBUTE_NORMAL NULL CreateFileA d0<ior ;
|
CREATE_ALWAYS FILE_ATTRIBUTE_NORMAL NULL CreateFileA d0<ior ;
|
||||||
: close-file ( fh -- ior ) CloseHandle 0=ior ;
|
: DELETE-FILE ( a n -- ior ) s>z DeleteFileA 0=ior ;
|
||||||
: flush-file ( fh -- ior ) FlushFileBuffers 0=ior ;
|
: RENAME-FILE ( a n a n -- ior ) s>z -rot s>z swap MoveFileA 0=ior ;
|
||||||
: delete-file ( a n -- ior ) s>z DeleteFileA 0=ior ;
|
: WRITE-FILE ( a n fh -- ior )
|
||||||
: rename-file ( a n a n -- ior ) s>z -rot s>z swap MoveFileA 0=ior ;
|
|
||||||
: read-file ( a n fh -- n ior ) -rot 0 >r rp@ NULL ReadFile r> swap 0=ior ;
|
|
||||||
: write-file ( a n fh -- ior )
|
|
||||||
-rot dup >r 0 >r rp@ NULL WriteFile
|
-rot dup >r 0 >r rp@ NULL WriteFile
|
||||||
if r> r> <> else rdrop rdrop GetLastError then ;
|
if r> r> <> else rdrop rdrop GetLastError then ;
|
||||||
: file-position ( fh -- n ior )
|
: READ-FILE ( a n fh -- n ior ) -rot 0 >r rp@ NULL ReadFile r> swap 0=ior ;
|
||||||
|
: FILE-POSITION ( fh -- n ior )
|
||||||
0 NULL FILE_CURRENT SetFilePointer dup invalid?ior ;
|
0 NULL FILE_CURRENT SetFilePointer dup invalid?ior ;
|
||||||
: reposition-file ( n fh -- ior )
|
: REPOSITION-FILE ( n fh -- ior )
|
||||||
swap NULL FILE_BEGIN SetFilePointer invalid?ior ;
|
swap NULL FILE_BEGIN SetFilePointer invalid?ior ;
|
||||||
: resize-file ( n fh -- ior )
|
: RESIZE-FILE ( n fh -- ior )
|
||||||
dup file-position dup if drop 2drop 1 ior exit else drop then >r
|
dup file-position dup if drop 2drop 1 ior exit else drop then >r
|
||||||
dup -rot reposition-file if rdrop drop 1 ior exit then
|
dup -rot reposition-file if rdrop drop 1 ior exit then
|
||||||
dup SetEndOfFile 0= if rdrop drop 1 ior exit then
|
dup SetEndOfFile 0= if rdrop drop 1 ior exit then
|
||||||
r> swap reposition-file ;
|
r> swap reposition-file ;
|
||||||
: file-size ( fh -- n ior ) NULL GetFileSize dup invalid?ior ;
|
: FILE-SIZE ( fh -- n ior ) NULL GetFileSize dup invalid?ior ;
|
||||||
|
: NON-BLOCK ( fh -- ior ) 1 throw ; ( IMPLEMENT! )
|
||||||
|
|
||||||
( Other Utils )
|
( Other Utils )
|
||||||
: ms ( n -- ) Sleep ;
|
: ms ( n -- ) Sleep ;
|
||||||
|
|||||||
Reference in New Issue
Block a user