Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(asys) Add libuv wrappers #306

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,6 @@ if(BUILD_TESTING)
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/threads.hl
)

#####################
# uvsample.hl

add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample.hl
COMMAND ${HAXE_COMPILER}
-hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample.hl
-cp ${CMAKE_SOURCE_DIR}/other/uvsample -main UVSample
)
add_custom_target(uvsample.hl ALL
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample.hl
)

#####################
# hello.c

Expand Down Expand Up @@ -231,29 +219,6 @@ if(BUILD_TESTING)
libhl
)

#####################
# uvsample.c

add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample/uvsample.c
COMMAND ${HAXE_COMPILER}
-hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample/uvsample.c
-cp ${CMAKE_SOURCE_DIR}/other/uvsample -main UVSample
)
add_executable(uvsample
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample/uvsample.c
)
set_target_properties(uvsample
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample
)
target_include_directories(uvsample
PRIVATE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample
)
target_link_libraries(uvsample
libhl
uv.hdll
)

#####################
# Tests

Expand All @@ -263,18 +228,12 @@ if(BUILD_TESTING)
add_test(NAME threads.hl
COMMAND hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/threads.hl
)
add_test(NAME uvsample.hl
COMMAND hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample.hl
)
add_test(NAME hello
COMMAND hello
)
add_test(NAME threads
COMMAND threads
)
add_test(NAME uvsample
COMMAND uvsample
)
add_test(NAME version
COMMAND hl --version
)
Expand Down
58 changes: 58 additions & 0 deletions libs/uv/apiparse/Parse.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import sys.io.File;

using StringTools;

class Parse {
public static function main():Void {
function getFunctions(path:String):Array<String> {
return File.getContent(path).split("\n").filter(line -> line.startsWith(".. c:function:: "));
}
var fsRE = ~/\.\. c:function:: int uv_fs_([^\(]+)\(uv_loop_t\* loop, uv_fs_t\* req, (([a-z\*\[\]_ 0-9]+, )+)uv_fs_cb cb\)/;
var wrap = [];
var haxe = [];
for (f in getFunctions("fs.rst")) {
if (!fsRE.match(f)) continue;
var name = fsRE.matched(1);
// skip functions that are not in 1.8.0
// could parse ".. versionadded" but this is simpler
if ([
"opendir",
"closedir",
"readdir",
"copyfile",
"lchown"
].indexOf(name) != -1) continue;
var signature = fsRE.matched(2);
signature = signature.substr(0, signature.length - 2); // remove last comma
var ffi = [];
var haxeArgs = [];
var wrapArgs = [ for (arg in signature.split(", ")) {
var argSplit = arg.split(" ");
var argName = argSplit.pop();
var argType = argSplit.join(" ");
var isArr = argName.endsWith("[]");
if (isArr) argType += "*";
var modArgs = (switch (argType) {
case "uv_file": ["_FILE", "file:UVFile"];
case "uv_dir_t*": ["_DIR", "dir:UVDir"];
case "const uv_buf_t*" if (isArr): ["_ARR", "_:hl.NativeArray<UVBuf>"];
case "uv_uid_t" | "uv_gid_t": ["_I32", "_:Int"]; // might be system specific?

case "int" | "unsigned int": ["_I32", "_:Int"];
case "int64_t" | "size_t": ["_I64", "_:hl.I64"];
case "double": ["_F64", "_:Float"];
case "const char*": ["_BYTES", "_:hl.Bytes"];

case _: throw argType;
});
ffi.push(modArgs[0]);
haxeArgs.push(modArgs.length > 1 ? modArgs[1] : "_:Dynamic");
argType;
} ];
wrap.push('UV_WRAP${wrapArgs.length}(fs_$name, ${wrapArgs.join(", ")}, ${ffi.join(" ")});');
haxe.push('@:hlNative("uv", "w_fs_$name") public static function fs_$name(loop:UVLoop, ${haxeArgs.join(", ")}, cb:UVError->Void):Void {}');
}
Sys.println(wrap.join("\n"));
Sys.println(haxe.join("\n"));
}
}
Loading