query_next :: ctx => {
while true {
if !ctx.stack {
+ if !ctx.d do break;
+
// If the stack is empty, populate with a node
ctx.top_level_node += 1;
if ctx.top_level_node >= ctx.d.nodes.length do break;
as_float :: (v: Value) -> ? f64 {
return v.data.Number?.Float;
}
+
+ as_bool :: (v: Value) -> ? bool {
+ return v.data.Boolean;
+ }
}
#inject Document {
dir_remove :: fs.__dir_remove
dir_rename :: fs.__file_rename
+chdir :: fs.__chdir
+getcwd :: fs.__getcwd
+
list_directory :: (path: str) -> Iterator(DirectoryEntry) {
Context :: struct {
dir: Directory;
__dir_read :: (dir: DirectoryData, out_entry: &os.DirectoryEntry) -> bool ---
__dir_create :: (path: str) -> bool ---
__dir_remove :: (path: str) -> bool ---
+ __dir_cwd :: (pathbuf: [] u8) -> i32 ---
+ __dir_chdir :: (path: cstr) -> bool ---
}
}
__dir_create :: __dir_create
__dir_remove :: __dir_remove
+__chdir :: (path: str) -> bool {
+ #persist buf: [1024] u8;
+ memory.copy(~~buf, path.data, math.min(1023, path.length));
+
+ return __dir_chdir(~~ buf);
+}
+
+__getcwd :: () -> str {
+ #persist buf: [1024] u8;
+ length := __dir_cwd(.{ ~~buf, 1024 });
+ if length < 0 {
+ return "";
+ }
+
+ return buf[0 .. length];
+}
+
__file_stream_vtable := io.Stream_Vtable.{
seek = (use fs: &os.File, to: i32, whence: io.SeekFrom) -> io.Error {
now := __file_seek(data, to, whence);
return removed;
}
+
+
+#if !#defined(runtime.vars.WASIX) {
+ __chdir :: (path: str) => false
+ __getcwd :: () => ""
+}
\ No newline at end of file
tty_set :: (state: &TTY) -> Errno ---
getcwd :: (path: [&] u8, pathlen: &u32) -> Errno ---
- chdir :: (path: cstr) -> Errno ---
+ chdir :: (path: str) -> Errno ---
thread_spawn_v2 :: (args: rawptr, tid: &u32) -> Errno ---
thread_sleep :: (duration: Timestamp) -> Errno ---
wasi.tty_set(&state);
return true;
+}
+
+__chdir :: (path: str) -> bool {
+ return wasi.chdir(path) == .Success;
+}
+
+__getcwd :: () -> str {
+ #persist buf: [1024] u8;
+ len := 1024;
+ if wasi.getcwd(~~buf, &len) == .Success {
+ return buf[0 .. len];
+ }
+
+ return "";
}
\ No newline at end of file
ONYX_FUNC(__dir_close)
ONYX_FUNC(__dir_create)
ONYX_FUNC(__dir_remove)
+ ONYX_FUNC(__dir_cwd)
+ ONYX_FUNC(__dir_chdir)
ONYX_FUNC(__spawn_thread)
ONYX_FUNC(__kill_thread)
return NULL;
#endif
}
+
+ONYX_DEF(__dir_cwd, (WASM_I32, WASM_I32), (WASM_I32)) {
+#if defined(_BH_LINUX) || defined(_BH_DARWIN)
+ char *dir = getcwd(ONYX_PTR(params->data[0].of.i32), params->data[1].of.i32);
+ if (!dir) {
+ results->data[0] = WASM_I32_VAL(-1);
+ return NULL;
+ }
+
+ results->data[0] = WASM_I32_VAL( strlen(dir) );
+ return NULL;
+#endif
+
+#if defined(_BH_WINDOWS)
+ int length = GetCurrentDirectory(params->data[1].of.i32, ONYX_PTR(params->data[0].of.i32));
+ if (length == 0 || length > params->data[1].of.i32) {
+ results->data[0] = WASM_I32_VAL(-1);
+ return NULL;
+ }
+
+ results->data[0] = WASM_I32_VAL( length );
+ return NULL;
+#endif
+}
+
+ONYX_DEF(__dir_chdir, (WASM_I32), (WASM_I32)) {
+#if defined(_BH_LINUX) || defined(_BH_DARWIN)
+ int result = chdir(ONYX_PTR(params->data[0].of.i32));
+ results->data[0] = WASM_I32_VAL(result ? 0 : 1);
+ return NULL;
+#endif
+
+#if defined(_BH_WINDOWS)
+ int result = SetCurrentDirectory(ONYX_PTR(params->data[0].of.i32));
+ results->data[0] = WASM_I32_VAL(result ? 1 : 0);
+ return NULL;
+#endif
+}
+
GB_DLL_IMPORT void WINAPI WakeByAddressSingle(void * Address);
GB_DLL_IMPORT BOOL WINAPI WaitOnAddress(volatile void * Address, void * compareAddress, size_t addressSize, DWORD milliseconds);
+GB_DLL_IMPORT DWORD GetCurrentDirectory(DWORD nBufferLength, char *lpBuffer);
+GB_DLL_IMPORT BOOL SetCurrentDirectory(char *lpPathName);