refractor code, seperate instructions from keywords

This commit is contained in:
MCorange
2023-03-22 14:58:11 +02:00
parent 42492ce521
commit 93e308c0b0
12 changed files with 282 additions and 240 deletions

19
include/fs.mcl Normal file
View File

@@ -0,0 +1,19 @@
macro FS_O_APPEND 1024 end // append to existing file
macro FS_O_ASYNC 8192 end // use signal-driven IO
macro FS_O_CLOEXEC 524288 end // use close-on-exec (avoid race conditions and lock contentions)
macro FS_O_CREAT 64 end // create file if it doesnt exist
macro FS_O_DIRECT 16384 end // bypass cache (slower)
macro FS_O_DIRECTORY 65536 end // fail if pathname isnt a directory
macro FS_O_DSYNC 4096 end // ensure output is sent to hardware and metadata written before return
macro FS_O_EXCL 128 end // ensure creation of file
macro FS_O_LARGEFILE 0 end // allows use of file sizes represented by off64_t
macro FS_O_NOATIME 262144 end // do not increment access time upon open
macro FS_O_NOCTTY 256 end // if pathname is a terminal device, dont become controlling terminal
macro FS_O_NOFOLLOW 131072 end // fail if pathname is symbolic link
macro FS_O_NONBLOCK 2048 end // if possible, open file with non-blocking IO
macro FS_O_NDELAY 2048 end // same as O_NONBLOCK
macro FS_O_PATH 2097152 end // open descriptor for obtaining permissions and status of a file but does not allow read/write operations
macro FS_O_SYNC 1052672 end // wait for IO to complete before returning
macro FS_O_TMPFILE 4259840 end // create an unnamed, unreachable (via any other open call) temporary file
macro FS_O_TRUNC 512 end // if file exists, ovewrite it (careful!)

View File

@@ -1,5 +1,16 @@
macro NULL 0 end
macro false 0 end
macro true 1 end
macro div divmod drop end
macro mod divmod swap drop end
macro mod divmod swap drop end
macro / div end
macro % mod end
macro 2dup over over end
macro 2drop drop drop end
macro sizeof(u64) 8 end
macro sizeof(u32) 4 end
macro sizeof(u16) 2 end
macro sizeof(u8) 1 end

View File

@@ -1,21 +1,29 @@
include "linux.mcl"
// Write to a file descriptor using the SYS_write syscall
// args: [str_size, str_ptr, fd]
// @arg str_size: Int
// @arg str_ptr: Ptr
// @arg fd: Int
// args: [buff_size, buff_ptr, fd]
// @arg buff_size: Int - number of bytes to write
// @arg buff_ptr: Ptr - pointer to the buffer to write
// @arg fd: Int - file descriptor
// @ret Int
macro write
SYS_write syscall3
end
// Write to a file descriptor using the SYS_write syscall
// args: [buff_size, buff_ptr, fd]
// @arg buff_size: Int - number of bytes to write
// @arg buff_ptr: Ptr - pointer to the buffer to write
// @arg fd: Int - file descriptor
// @ret Int
macro read
SYS_read syscall3
end
// Print a string to STDOUT
// args: [str_size, str_ptr]
// @arg str_size: Int
// @arg str_ptr: Ptr
// @arg buff_size: Int - number of bytes to write
// @arg buff_ptr: Ptr - pointer to the buffer to write
// @ret NULL
macro puts
STDOUT write drop
@@ -23,8 +31,8 @@ end
// Print a string to STDERR
// args: [str_size, str_ptr]
// @arg str_size: Int
// @arg str_ptr: Ptr
// @arg buff_size: Int - number of bytes to write
// @arg buff_ptr: Ptr - pointer to the buffer to write
// @ret NULL
macro eputs
STDOUT write drop

27
include/mem.mcl Normal file
View File

@@ -0,0 +1,27 @@
macro load8 @8 end
macro store8 !8 end
macro load64
7 + 0
8 shl over !8 + swap 1 - swap
8 shl over !8 + swap 1 - swap
8 shl over !8 + swap 1 - swap
8 shl over !8 + swap 1 - swap
8 shl over !8 + swap 1 - swap
8 shl over !8 + swap 1 - swap
8 shl over !8 + swap 1 - swap
8 shl over !8 + swap drop
end
macro store64
2dup 255 band @8 shr swap 1 + swap
2dup 255 band @8 shr swap 1 + swap
2dup 255 band @8 shr swap 1 + swap
2dup 255 band @8 shr swap 1 + swap
2dup 255 band @8 shr swap 1 + swap
2dup 255 band @8 shr swap 1 + swap
2dup 255 band @8 shr swap 1 + swap
2dup 255 band @8 shr swap 2drop
end

5
include/std.mcl Normal file
View File

@@ -0,0 +1,5 @@
include "linux.mcl"
include "io.mcl"
include "util.mcl"
include "int.mcl"
include "fs.mcl"