summaryrefslogtreecommitdiff
path: root/source/base
diff options
context:
space:
mode:
Diffstat (limited to 'source/base')
-rwxr-xr-xsource/base/base.h16
-rwxr-xr-xsource/base/base_include.h2
-rw-r--r--source/base/base_io.h29
-rw-r--r--source/base/base_os.h10
-rw-r--r--source/base/base_string.h15
-rw-r--r--source/base/base_test.h2
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;
52typedef uint16_t u16; 52typedef uint16_t u16;
53typedef uint8_t u8; 53typedef uint8_t u8;
54 54
55typedef int8_t i8; 55typedef int8_t s8;
56typedef int16_t i16; 56typedef int16_t s16;
57typedef int32_t i32; 57typedef int32_t s32;
58typedef int64_t i64; 58typedef int64_t s64;
59 59
60typedef float f32; 60typedef float f32;
61typedef double f64; 61typedef double f64;
62 62
63typedef i32 b32; 63typedef s32 b32;
64typedef i16 b16; 64typedef s16 b16;
65typedef u8 b8; 65typedef u8 b8;
66 66
67typedef uintptr_t umm; 67typedef uintptr_t umm;
68typedef intptr_t smm; 68typedef 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
8internal s64
9os_write(s32 fd, void const *buf, u64 count)
10{
11 return syscall(SYS_write, fd, buf, count);
12}
13
14internal s64
15os_read(s32 fd, void *buf, u64 count)
16{
17 return syscall(SYS_read, fd, buf, count);
18}
19
4internal void 20internal void
5input_read() 21print_s8(string8 s)
6{ 22{
23 os_write(STDOUT_FILENO, s.data, s.size);
24}
7 25
26internal void
27print(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
4internal void
5print(const char *str)
6{
7 i32 len = 0;
8 while (str[len]) len++;
9 write(STDOUT_FILENO, str, len);
10}
11
12internal string8 4internal string8
13load_file(const char *path) 5load_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)
50read_only global_variable 55read_only global_variable
51string8 nil_string = 56string8 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
11internal void 11internal void
12write_int(i32 num) 12write_int(s32 num)
13{ 13{
14 14
15 if (num < 0) 15 if (num < 0)