diff --git a/examples/wayland/_linux.q b/examples/wayland/_linux.q new file mode 100644 index 0000000..cf44a3e --- /dev/null +++ b/examples/wayland/_linux.q @@ -0,0 +1,36 @@ +import c +import fs +import mem + +createShm(state *wayland.State) -> error { + path := c.string("wl_shm") + fd, err := fs.memfd_create(path.ptr, 0) + delete(path) + + if err != 0 { + return err + } + + state.shm_fd = fd + width := 1280 + height := 720 + state.shm_size = width * height * 4 + err := fs.ftruncate(state.shm_fd, state.shm_size) + + if err != 0 { + return err + } + + state.shm_data = mem.mmap(0, state.shm_size, mem.read|mem.write, mem.shared, state.shm_fd, 0) + return 0 +} + +deleteShm(state *wayland.State) { + if state.shm_data != 0 { + mem.munmap(state.shm_data, state.shm_size) + } + + if state.shm_fd != 0 { + fs.close(state.shm_fd) + } +} \ No newline at end of file diff --git a/examples/wayland/_mac.q b/examples/wayland/_mac.q new file mode 100644 index 0000000..25d3bc6 --- /dev/null +++ b/examples/wayland/_mac.q @@ -0,0 +1,5 @@ +createShm(_state *wayland.State) -> error { + return -1 +} + +deleteShm(_state *wayland.State) {} \ No newline at end of file diff --git a/examples/wayland/_windows.q b/examples/wayland/_windows.q new file mode 100644 index 0000000..25d3bc6 --- /dev/null +++ b/examples/wayland/_windows.q @@ -0,0 +1,5 @@ +createShm(_state *wayland.State) -> error { + return -1 +} + +deleteShm(_state *wayland.State) {} \ No newline at end of file diff --git a/examples/wayland/wayland.q b/examples/wayland/wayland.q index 57a128a..434e964 100644 --- a/examples/wayland/wayland.q +++ b/examples/wayland/wayland.q @@ -25,6 +25,7 @@ main() { io.write(err) } + deleteShm(state) delete(state) delete(buffer) net.close(socket) @@ -74,6 +75,12 @@ communicate(state *wayland.State, buffer string) -> error { return err } + err := createShm(state) + + if err != 0 { + return err + } + return 0 } diff --git a/lib/fs/_linux_arm.q b/lib/fs/_linux_arm.q index 90da053..ebf91a3 100644 --- a/lib/fs/_linux_arm.q +++ b/lib/fs/_linux_arm.q @@ -2,4 +2,6 @@ const { _openat = 56 _close = 57 _fstat = 80 + _ftruncate = 46 + _memfd_create = 279 } \ No newline at end of file diff --git a/lib/fs/_linux_x86.q b/lib/fs/_linux_x86.q index f5a8e8b..02ac37c 100644 --- a/lib/fs/_linux_x86.q +++ b/lib/fs/_linux_x86.q @@ -2,4 +2,6 @@ const { _openat = 257 _close = 3 _fstat = 5 + _ftruncate = 77 + _memfd_create = 319 } \ No newline at end of file diff --git a/lib/fs/fs_linux.q b/lib/fs/fs_linux.q index eba8b5f..c20b39f 100644 --- a/lib/fs/fs_linux.q +++ b/lib/fs/fs_linux.q @@ -34,4 +34,18 @@ size(fd int) -> (uint, error) { close(fd !int) -> error { return syscall(_close, fd) +} + +memfd_create(path *byte, flags uint) -> (!int, error) { + fd := syscall(_memfd_create, path, flags) + + if fd < 0 { + return 0, fd + } + + return fd, 0 +} + +ftruncate(fd int, length uint) -> error { + return syscall(_ftruncate, fd, length) } \ No newline at end of file diff --git a/lib/fs/fs_mac.q b/lib/fs/fs_mac.q index 5daae93..12c4be3 100644 --- a/lib/fs/fs_mac.q +++ b/lib/fs/fs_mac.q @@ -34,4 +34,12 @@ size(fd int) -> (uint, error) { close(fd !int) -> error { return syscall(_close, fd) +} + +memfd_create(_path *byte, _flags uint) -> (!int, error) { + return 0, -1 +} + +ftruncate(_fd int, _length uint) -> error { + return -1 } \ No newline at end of file diff --git a/lib/fs/fs_windows.q b/lib/fs/fs_windows.q index 4069599..fc170bc 100644 --- a/lib/fs/fs_windows.q +++ b/lib/fs/fs_windows.q @@ -42,6 +42,14 @@ close(fd !int) -> error { return -1 } +memfd_create(_path *byte, _flags uint) -> (!int, error) { + return 0, -1 +} + +ftruncate(_fd int, _length uint) -> error { + return -1 +} + extern { kernel32 { CloseHandle(handle int) -> (success bool) diff --git a/lib/mem/_linux.q b/lib/mem/_linux.q index c135c3f..d27ee8f 100644 --- a/lib/mem/_linux.q +++ b/lib/mem/_linux.q @@ -1,6 +1,7 @@ const { read = 0x1 write = 0x2 - private = 0x02 + shared = 0x1 + private = 0x2 anonymous = 0x20 } \ No newline at end of file diff --git a/lib/wayland/State.q b/lib/wayland/State.q index ccd5f6c..84814be 100644 --- a/lib/wayland/State.q +++ b/lib/wayland/State.q @@ -10,6 +10,10 @@ State { wl_compositor_name uint32 wl_shm_name uint32 xdg_wm_base_name uint32 + + shm_fd !int + shm_size uint + shm_data *byte } newId(state *State) -> uint32 { diff --git a/src/core/compileStoreField.go b/src/core/compileStoreField.go index 76acc03..2a50158 100644 --- a/src/core/compileStoreField.go +++ b/src/core/compileStoreField.go @@ -37,6 +37,12 @@ func (f *Function) compileStoreField(node *ast.Assign) error { return err } + _, isResource := rightValue.Type().(*types.Resource) + + if isResource { + f.Block().Unidentify(rightValue) + } + if node.Expression.Token.Kind != token.Assign { leftValue, err := f.evaluateRight(left)