| author | |
| committer | |
| log | 7828456b30829e68a959f74e86d02e737d590cc2 |
| tree | 783c37c7937a7895207180d59a25556956d853aa |
| parent | 592210a1739dfe3fe506260c11b8b5e5d8a5a715 |
later we'll add a full featured allocator instead of this5 files changed, 6 insertions(+), 52 deletions(-)
CMakeLists.txt-1| ... | @@ -140,7 +140,6 @@ set(ZIG_STD_SRC | ... | @@ -140,7 +140,6 @@ set(ZIG_STD_SRC |
| 140 | "${CMAKE_SOURCE_DIR}/std/syscall.zig" | 140 | "${CMAKE_SOURCE_DIR}/std/syscall.zig" |
| 141 | "${CMAKE_SOURCE_DIR}/std/errno.zig" | 141 | "${CMAKE_SOURCE_DIR}/std/errno.zig" |
| 142 | "${CMAKE_SOURCE_DIR}/std/rand.zig" | 142 | "${CMAKE_SOURCE_DIR}/std/rand.zig" |
| 143 | "${CMAKE_SOURCE_DIR}/std/mem.zig" | ||
| 144 | "${CMAKE_SOURCE_DIR}/std/math.zig" | 143 | "${CMAKE_SOURCE_DIR}/std/math.zig" |
| 145 | ) | 144 | ) |
| 146 | 145 |
doc/targets.md-6| ... | @@ -12,10 +12,4 @@ Write the target-specific code in std.zig. | ... | @@ -12,10 +12,4 @@ Write the target-specific code in std.zig. |
| 12 | 12 | ||
| 13 | Update the C integer types to be the correct size for the target. | 13 | Update the C integer types to be the correct size for the target. |
| 14 | 14 | ||
| 15 | Add the conditional compilation code for the page size global. It is hardcoded | ||
| 16 | for each target. | ||
| 17 | |||
| 18 | Make sure that parseh sends the correct command line parameters to libclang for | ||
| 19 | the given target. | ||
| 20 | |||
| 21 | Make sure that `c_long_double` codegens the correct floating point value. | 15 | Make sure that `c_long_double` codegens the correct floating point value. |
std/mem.zig deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | import "syscall.zig"; | ||
| 2 | import "std.zig"; | ||
| 3 | import "errno.zig"; | ||
| 4 | |||
| 5 | pub fn malloc(bytes: isize) -> ?&u8 { | ||
| 6 | if (bytes > 4096) { | ||
| 7 | %%stderr.printf("TODO alloc sizes > 4096B\n"); | ||
| 8 | return null; | ||
| 9 | } | ||
| 10 | |||
| 11 | const result = mmap(isize(0), 4096, MMAP_PROT_READ|MMAP_PROT_WRITE, MMAP_MAP_ANON|MMAP_MAP_SHARED, -1, 0); | ||
| 12 | |||
| 13 | if (-4096 < result && result <= 0) { | ||
| 14 | null | ||
| 15 | } else { | ||
| 16 | (&u8)(result) | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | pub fn free(ptr: &u8) { | ||
| 21 | munmap(isize(ptr), 4096); | ||
| 22 | } | ||
std/syscall.zig+6-4| ... | @@ -250,12 +250,14 @@ fn i386_syscall6(number: isize, arg1: isize, arg2: isize, arg3: isize, arg4: isi | ... | @@ -250,12 +250,14 @@ fn i386_syscall6(number: isize, arg1: isize, arg2: isize, arg3: isize, arg4: isi |
| 250 | [arg6] "{ebp}" (arg6)) | 250 | [arg6] "{ebp}" (arg6)) |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | pub fn mmap(address: isize, length: isize, prot: isize, flags: isize, fd: isize, offset: isize) -> isize { | 253 | pub fn mmap(address: ?&u8, length: isize, prot: isize, flags: isize, fd: isize, offset: isize) -> isize { |
| 254 | syscall6(SYS_mmap, address, length, prot, flags, fd, offset) | 254 | // TODO ability to cast maybe pointer to isize |
| 255 | const addr = if (const unwrapped ?= address) isize(unwrapped) else 0; | ||
| 256 | syscall6(SYS_mmap, addr, length, prot, flags, fd, offset) | ||
| 255 | } | 257 | } |
| 256 | 258 | ||
| 257 | pub fn munmap(address: isize, length: isize) -> isize { | 259 | pub fn munmap(address: &u8, length: isize) -> isize { |
| 258 | syscall2(SYS_munmap, address, length) | 260 | syscall2(SYS_munmap, isize(address), length) |
| 259 | } | 261 | } |
| 260 | 262 | ||
| 261 | pub fn read(fd: isize, buf: &u8, count: isize) -> isize { | 263 | pub fn read(fd: isize, buf: &u8, count: isize) -> isize { |
test/run_tests.cpp-19| ... | @@ -1023,25 +1023,6 @@ pub fn main(args: [][]u8) -> %void { | ... | @@ -1023,25 +1023,6 @@ pub fn main(args: [][]u8) -> %void { |
| 1023 | } | 1023 | } |
| 1024 | )SOURCE", "OK\n"); | 1024 | )SOURCE", "OK\n"); |
| 1025 | 1025 | ||
| 1026 | add_simple_case("malloc and free", R"SOURCE( | ||
| 1027 | import "mem.zig"; | ||
| 1028 | import "std.zig"; | ||
| 1029 | |||
| 1030 | pub fn main(args: [][]u8) -> %void { | ||
| 1031 | var ptr = malloc(1) ?? unreachable{}; | ||
| 1032 | |||
| 1033 | *ptr = 6; | ||
| 1034 | |||
| 1035 | if (*ptr != 6) { | ||
| 1036 | %%stdout.printf("BAD\n"); | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | free(ptr); | ||
| 1040 | |||
| 1041 | %%stdout.printf("OK\n"); | ||
| 1042 | } | ||
| 1043 | )SOURCE", "OK\n"); | ||
| 1044 | |||
| 1045 | add_simple_case("store member function in variable", R"SOURCE( | 1026 | add_simple_case("store member function in variable", R"SOURCE( |
| 1046 | import "std.zig"; | 1027 | import "std.zig"; |
| 1047 | struct Foo { | 1028 | struct Foo { |