about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--config.nims5
-rw-r--r--nim.cfg1
-rw-r--r--src/bindings/constcharp.nim6
-rw-r--r--src/bindings/quickjs.nim19
-rw-r--r--src/js/module.nim5
-rw-r--r--src/local/client.nim11
6 files changed, 30 insertions, 17 deletions
diff --git a/config.nims b/config.nims
deleted file mode 100644
index 1dab2604..00000000
--- a/config.nims
+++ /dev/null
@@ -1,5 +0,0 @@
-switch("import", "utils/eprint")
-
-# workaround for clang 16
-when defined(clang):
-  switch("passC", "-Wno-error=incompatible-function-pointer-types")
diff --git a/nim.cfg b/nim.cfg
index 3e30ca88..203291bf 100644
--- a/nim.cfg
+++ b/nim.cfg
@@ -6,3 +6,4 @@
 --experimental:"overloadableEnums"
 --warning:Effect:off
 --mm:refc
+--import:"utils/eprint"
diff --git a/src/bindings/constcharp.nim b/src/bindings/constcharp.nim
new file mode 100644
index 00000000..057b8acb
--- /dev/null
+++ b/src/bindings/constcharp.nim
@@ -0,0 +1,6 @@
+type
+  cstringConstImpl {.importc: "const char*".} = cstring
+  cstringConst* = distinct cstringConstImpl
+
+proc `[]`*(s: cstringConst, i: int): char = cstring(s)[i]
+proc `$`*(s: cstringConst): string {.borrow.}
diff --git a/src/bindings/quickjs.nim b/src/bindings/quickjs.nim
index 65d6c679..d573a1dd 100644
--- a/src/bindings/quickjs.nim
+++ b/src/bindings/quickjs.nim
@@ -1,3 +1,5 @@
+import bindings/constcharp
+
 const qjsheader = "quickjs/quickjs.h"
 
 {.passC: "-Ilib/".}
@@ -65,9 +67,16 @@ else:
     JSValue(u: JSValueUnion(`ptr`: p), tag: t)
 
 type
-  JSRuntime* = ptr object
-  JSContext* = ptr object
-  JSModuleDef* = ptr object
+  JSRuntimeT {.importc: "JSRuntime", header: qjsheader,
+    incompleteStruct.} = object
+  JSContextT {.importc: "JSContext", header: qjsheader,
+    incompleteStruct.} = object
+  JSModuleDefT {.importc: "JSModuleDef", header: qjsheader,
+    incompleteStruct.} = object
+
+  JSRuntime* = ptr JSRuntimeT
+  JSContext* = ptr JSContextT
+  JSModuleDef* = ptr JSModuleDefT
   JSCFunction* = proc (ctx: JSContext, this_val: JSValue, argc: cint,
       argv: ptr UncheckedArray[JSValue]): JSValue {.cdecl.}
   JSCFunctionData* = proc (ctx: JSContext, this_val: JSValue, argc: cint, argv: ptr JSValue, magic: cint, func_data: ptr JSValue): JSValue {.cdecl.}
@@ -83,8 +92,8 @@ type
   JSClassGCMark* = proc (rt: JSRuntime, val: JSValue, mark_func: JS_MarkFunc) {.cdecl.}
   JS_MarkFunc* = proc (rt: JSRuntime, gp: ptr JSGCObjectHeader) {.cdecl.}
   JSModuleNormalizeFunc* = proc(ctx: JSContext, module_base_name,
-    module_name: cstring, opaque: pointer): cstring {.cdecl.}
-  JSModuleLoaderFunc* = proc(ctx: JSContext, module_name: cstring,
+    module_name: cstringConst, opaque: pointer): cstring {.cdecl.}
+  JSModuleLoaderFunc* = proc(ctx: JSContext, module_name: cstringConst,
     opaque: pointer): JSModuleDef {.cdecl.}
   JSJobFunc* = proc (ctx: JSContext, argc: cint, argv: ptr JSValue): JSValue {.cdecl.}
   JSGCObjectHeader* {.importc, header: qjsheader.} = object
diff --git a/src/js/module.nim b/src/js/module.nim
index bae146a7..70755ebd 100644
--- a/src/js/module.nim
+++ b/src/js/module.nim
@@ -1,3 +1,4 @@
+import bindings/constcharp
 import bindings/quickjs
 import js/javascript
 import js/tojs
@@ -23,6 +24,6 @@ proc finishLoadModule*(ctx: JSContext, f: string, name: cstring): JSModuleDef =
   result = cast[JSModuleDef](JS_VALUE_GET_PTR(funcVal))
   JS_FreeValue(ctx, funcVal)
 
-proc normalizeModuleName*(ctx: JSContext, base_name: cstring, name: cstring,
+proc normalizeModuleName*(ctx: JSContext, base_name, name: cstringConst,
     opaque: pointer): cstring {.cdecl.} =
-  return js_strdup(ctx, name)
+  return js_strdup(ctx, cstring(name))
diff --git a/src/local/client.nim b/src/local/client.nim
index 752012a3..4dc29f24 100644
--- a/src/local/client.nim
+++ b/src/local/client.nim
@@ -1,4 +1,3 @@
-import cstrutils
 import nativesockets
 import net
 import options
@@ -14,6 +13,7 @@ when defined(posix):
 
 import std/exitprocs
 
+import bindings/constcharp
 import bindings/quickjs
 import config/config
 import display/lineedit
@@ -442,13 +442,14 @@ proc headlessLoop(client: Client) =
     client.loader.unregistered.setLen(0)
     client.acceptBuffers()
 
-proc clientLoadJSModule(ctx: JSContext, module_name: cstring,
+proc clientLoadJSModule(ctx: JSContext, module_name: cstringConst,
     opaque: pointer): JSModuleDef {.cdecl.} =
   let global = JS_GetGlobalObject(ctx)
   JS_FreeValue(ctx, global)
   var x: Option[URL]
-  if module_name.startsWith("/") or module_name.startsWith("./") or
-      module_name.startsWith("../"):
+  if module_name[0] == '/' or module_name[0] == '.' and
+      (module_name[1] == '/' or
+      module_name[1] == '.' and module_name[2] == '/'):
     let cur = getCurrentDir()
     x = parseURL($module_name, parseURL("file://" & cur & "/"))
   else:
@@ -458,7 +459,7 @@ proc clientLoadJSModule(ctx: JSContext, module_name: cstring,
     return nil
   try:
     let f = readFile($x.get.path)
-    return finishLoadModule(ctx, f, module_name)
+    return finishLoadModule(ctx, f, cstring(module_name))
   except IOError:
     JS_ThrowTypeError(ctx, "Failed to open file %s", module_name)
     return nil