diff --git a/CMakeLists.txt b/CMakeLists.txt index 6feb456fae20eb325b67cc866c2e8298cb413637..efe9802f2d5b15235ad76aa87b64d1ba6eb9747d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,7 +140,6 @@ set(ZIG_STD_SRC "${CMAKE_SOURCE_DIR}/std/syscall.zig" "${CMAKE_SOURCE_DIR}/std/errno.zig" "${CMAKE_SOURCE_DIR}/std/rand.zig" - "${CMAKE_SOURCE_DIR}/std/mem.zig" "${CMAKE_SOURCE_DIR}/std/math.zig" ) diff --git a/doc/targets.md b/doc/targets.md index de465959c9e72f6e9d9b7ebf11f3a9102a8db91c..fe1e388bb04f33a23610219c344b829041c10897 100644 --- a/doc/targets.md +++ b/doc/targets.md @@ -12,10 +12,4 @@ Write the target-specific code in std.zig. Update the C integer types to be the correct size for the target. -Add the conditional compilation code for the page size global. It is hardcoded -for each target. - -Make sure that parseh sends the correct command line parameters to libclang for -the given target. - Make sure that `c_long_double` codegens the correct floating point value. diff --git a/std/mem.zig b/std/mem.zig deleted file mode 100644 index a10a6c95692a5628b5d7c64bc401660b90b01b0e..0000000000000000000000000000000000000000 --- a/std/mem.zig +++ /dev/null @@ -1,22 +0,0 @@ -import "syscall.zig"; -import "std.zig"; -import "errno.zig"; - -pub fn malloc(bytes: isize) -> ?&u8 { - if (bytes > 4096) { - %%stderr.printf("TODO alloc sizes > 4096B\n"); - return null; - } - - const result = mmap(isize(0), 4096, MMAP_PROT_READ|MMAP_PROT_WRITE, MMAP_MAP_ANON|MMAP_MAP_SHARED, -1, 0); - - if (-4096 < result && result <= 0) { - null - } else { - (&u8)(result) - } -} - -pub fn free(ptr: &u8) { - munmap(isize(ptr), 4096); -} diff --git a/std/syscall.zig b/std/syscall.zig index 669fb2b8c074033f2899b6bc5e98964f08ae6059..00a44832e3f4029a765311ccaa0ebdddf7e0af2c 100644 --- a/std/syscall.zig +++ b/std/syscall.zig @@ -250,12 +250,14 @@ fn i386_syscall6(number: isize, arg1: isize, arg2: isize, arg3: isize, arg4: isi [arg6] "{ebp}" (arg6)) } -pub fn mmap(address: isize, length: isize, prot: isize, flags: isize, fd: isize, offset: isize) -> isize { - syscall6(SYS_mmap, address, length, prot, flags, fd, offset) +pub fn mmap(address: ?&u8, length: isize, prot: isize, flags: isize, fd: isize, offset: isize) -> isize { + // TODO ability to cast maybe pointer to isize + const addr = if (const unwrapped ?= address) isize(unwrapped) else 0; + syscall6(SYS_mmap, addr, length, prot, flags, fd, offset) } -pub fn munmap(address: isize, length: isize) -> isize { - syscall2(SYS_munmap, address, length) +pub fn munmap(address: &u8, length: isize) -> isize { + syscall2(SYS_munmap, isize(address), length) } pub fn read(fd: isize, buf: &u8, count: isize) -> isize { diff --git a/test/run_tests.cpp b/test/run_tests.cpp index b372473eec07009effd22b8b826203525b5f336a..e7d696a34cc4b2f74aa2c186090a63b740e8aa3e 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -1023,25 +1023,6 @@ pub fn main(args: [][]u8) -> %void { } )SOURCE", "OK\n"); - add_simple_case("malloc and free", R"SOURCE( -import "mem.zig"; -import "std.zig"; - -pub fn main(args: [][]u8) -> %void { - var ptr = malloc(1) ?? unreachable{}; - - *ptr = 6; - - if (*ptr != 6) { - %%stdout.printf("BAD\n"); - } - - free(ptr); - - %%stdout.printf("OK\n"); -} - )SOURCE", "OK\n"); - add_simple_case("store member function in variable", R"SOURCE( import "std.zig"; struct Foo {