diff options
Diffstat (limited to 'source/base')
| -rwxr-xr-x | source/base/base.h | 16 | ||||
| -rwxr-xr-x | source/base/base_include.h | 2 | ||||
| -rw-r--r-- | source/base/base_io.h | 29 | ||||
| -rw-r--r-- | source/base/base_os.h | 10 | ||||
| -rw-r--r-- | source/base/base_string.h | 15 | ||||
| -rw-r--r-- | source/base/base_test.h | 2 |
6 files changed, 49 insertions, 25 deletions
diff --git a/source/base/base.h b/source/base/base.h index ef23391..cf2a15f 100755 --- a/source/base/base.h +++ b/source/base/base.h | |||
| @@ -52,22 +52,22 @@ typedef uint32_t u32; | |||
| 52 | typedef uint16_t u16; | 52 | typedef uint16_t u16; |
| 53 | typedef uint8_t u8; | 53 | typedef uint8_t u8; |
| 54 | 54 | ||
| 55 | typedef int8_t i8; | 55 | typedef int8_t s8; |
| 56 | typedef int16_t i16; | 56 | typedef int16_t s16; |
| 57 | typedef int32_t i32; | 57 | typedef int32_t s32; |
| 58 | typedef int64_t i64; | 58 | typedef int64_t s64; |
| 59 | 59 | ||
| 60 | typedef float f32; | 60 | typedef float f32; |
| 61 | typedef double f64; | 61 | typedef double f64; |
| 62 | 62 | ||
| 63 | typedef i32 b32; | 63 | typedef s32 b32; |
| 64 | typedef i16 b16; | 64 | typedef s16 b16; |
| 65 | typedef u8 b8; | 65 | typedef u8 b8; |
| 66 | 66 | ||
| 67 | typedef uintptr_t umm; | 67 | typedef uintptr_t umm; |
| 68 | typedef intptr_t smm; | 68 | typedef intptr_t smm; |
| 69 | 69 | ||
| 70 | #define TRUE (0 == 0) | 70 | #define TRUE (1 == 1) |
| 71 | #define FALSE (0 != 0) | 71 | #define FALSE (1 != 1) |
| 72 | 72 | ||
| 73 | #endif | 73 | #endif |
diff --git a/source/base/base_include.h b/source/base/base_include.h index 40ae5ea..07856d0 100755 --- a/source/base/base_include.h +++ b/source/base/base_include.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include <dirent.h> | 4 | #include <dirent.h> |
| 5 | #include <sys/mman.h> | 5 | #include <sys/mman.h> |
| 6 | #include <sys/stat.h> | 6 | #include <sys/stat.h> |
| 7 | #include <sys/syscall.h> | ||
| 7 | #include <fcntl.h> | 8 | #include <fcntl.h> |
| 8 | #include <stdint.h> | 9 | #include <stdint.h> |
| 9 | #include <stddef.h> | 10 | #include <stddef.h> |
| @@ -16,6 +17,7 @@ | |||
| 16 | #include "base_stack.h" | 17 | #include "base_stack.h" |
| 17 | #include "base_test.h" | 18 | #include "base_test.h" |
| 18 | #include "base_string.h" | 19 | #include "base_string.h" |
| 20 | #include "base_io.h" | ||
| 19 | #include "base_os.h" | 21 | #include "base_os.h" |
| 20 | 22 | ||
| 21 | #ifdef BASE_UNITY | 23 | #ifdef BASE_UNITY |
diff --git a/source/base/base_io.h b/source/base/base_io.h index ece4d7c..85fedc7 100644 --- a/source/base/base_io.h +++ b/source/base/base_io.h | |||
| @@ -1,11 +1,38 @@ | |||
| 1 | #ifndef BASE_IO_H | 1 | #ifndef BASE_IO_H |
| 2 | #define BASE_IO_H | 2 | #define BASE_IO_H |
| 3 | 3 | ||
| 4 | #define STDIN_FD 0 | ||
| 5 | #define STDOUT_FD 1 | ||
| 6 | #define STDERR_FD 2 | ||
| 7 | |||
| 8 | internal s64 | ||
| 9 | os_write(s32 fd, void const *buf, u64 count) | ||
| 10 | { | ||
| 11 | return syscall(SYS_write, fd, buf, count); | ||
| 12 | } | ||
| 13 | |||
| 14 | internal s64 | ||
| 15 | os_read(s32 fd, void *buf, u64 count) | ||
| 16 | { | ||
| 17 | return syscall(SYS_read, fd, buf, count); | ||
| 18 | } | ||
| 19 | |||
| 4 | internal void | 20 | internal void |
| 5 | input_read() | 21 | print_s8(string8 s) |
| 6 | { | 22 | { |
| 23 | os_write(STDOUT_FILENO, s.data, s.size); | ||
| 24 | } | ||
| 7 | 25 | ||
| 26 | internal void | ||
| 27 | print(const char *str) | ||
| 28 | { | ||
| 29 | s32 len = 0; | ||
| 30 | while (str[len]) len++; | ||
| 31 | os_write(STDOUT_FILENO, str, len); | ||
| 8 | 32 | ||
| 9 | } | 33 | } |
| 10 | 34 | ||
| 35 | #define Os_read(buffer, buffer_count) | ||
| 36 | |||
| 37 | |||
| 11 | #endif /* BASE_IO_H */ | 38 | #endif /* BASE_IO_H */ |
diff --git a/source/base/base_os.h b/source/base/base_os.h index 23587c6..abe8628 100644 --- a/source/base/base_os.h +++ b/source/base/base_os.h | |||
| @@ -1,21 +1,13 @@ | |||
| 1 | #ifndef BASE_OS_H | 1 | #ifndef BASE_OS_H |
| 2 | #define BASE_OS_H | 2 | #define BASE_OS_H |
| 3 | 3 | ||
| 4 | internal void | ||
| 5 | print(const char *str) | ||
| 6 | { | ||
| 7 | i32 len = 0; | ||
| 8 | while (str[len]) len++; | ||
| 9 | write(STDOUT_FILENO, str, len); | ||
| 10 | } | ||
| 11 | |||
| 12 | internal string8 | 4 | internal string8 |
| 13 | load_file(const char *path) | 5 | load_file(const char *path) |
| 14 | { | 6 | { |
| 15 | string8 result = {0}; | 7 | string8 result = {0}; |
| 16 | struct stat sbuf = {0}; | 8 | struct stat sbuf = {0}; |
| 17 | 9 | ||
| 18 | i32 file = open(path, O_RDONLY); | 10 | s32 file = open(path, O_RDONLY); |
| 19 | if(file == -1) return result; | 11 | if(file == -1) return result; |
| 20 | 12 | ||
| 21 | if(fstat(file, &sbuf) == -1) | 13 | if(fstat(file, &sbuf) == -1) |
diff --git a/source/base/base_string.h b/source/base/base_string.h index 189b38a..4e0d923 100644 --- a/source/base/base_string.h +++ b/source/base/base_string.h | |||
| @@ -1,13 +1,18 @@ | |||
| 1 | #ifndef BASE_STRING_H | 1 | #ifndef BASE_STRING_H |
| 2 | #define BASE_STRING_H | 2 | #define BASE_STRING_H |
| 3 | 3 | ||
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | #define StringLit(string) \ | 4 | #define StringLit(string) \ |
| 7 | (string8){ .data = (u8 *)(string), .size = (sizeof(string) - 1) } | 5 | (string8){ .data = (u8 *)(string), .size = (sizeof(string) - 1) } |
| 8 | 6 | ||
| 9 | #define PushString(arena, size) \ | 7 | #define PushString(arena, size) \ |
| 10 | (string8){ (u8 *)PushArray((arena), u8, (size)), (u64)(size) } | 8 | ({ \ |
| 9 | string8 *result = PushStruct((arena), string8); \ | ||
| 10 | result->data = PushArray((arena), u8, (size)); \ | ||
| 11 | result->size = (u64)(size); \ | ||
| 12 | result; \ | ||
| 13 | }) | ||
| 14 | |||
| 15 | #define String8Cast(literal, literal_count) ( string8 ){( u8 * )( literal ),( u64 )( literal_count ) } | ||
| 11 | 16 | ||
| 12 | #define StringFmt "%.*s" | 17 | #define StringFmt "%.*s" |
| 13 | #define ULongFmt "%lu" | 18 | #define ULongFmt "%lu" |
| @@ -50,10 +55,8 @@ string8_append_char(string8 *buf, u8 c) | |||
| 50 | read_only global_variable | 55 | read_only global_variable |
| 51 | string8 nil_string = | 56 | string8 nil_string = |
| 52 | { | 57 | { |
| 53 | |||
| 54 | .data = NULL, | 58 | .data = NULL, |
| 55 | .size = 0, | 59 | .size = 0, |
| 56 | |||
| 57 | }; | 60 | }; |
| 58 | 61 | ||
| 59 | #endif /* BASE_STRING_H */ | 62 | #endif /* BASE_STRING_H */ |
diff --git a/source/base/base_test.h b/source/base/base_test.h index 412797b..7619cfb 100644 --- a/source/base/base_test.h +++ b/source/base/base_test.h | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #define LEN(s) (sizeof(s) - 1) | 9 | #define LEN(s) (sizeof(s) - 1) |
| 10 | 10 | ||
| 11 | internal void | 11 | internal void |
| 12 | write_int(i32 num) | 12 | write_int(s32 num) |
| 13 | { | 13 | { |
| 14 | 14 | ||
| 15 | if (num < 0) | 15 | if (num < 0) |
