From 68bcacf3ecad24ed03536fc9674af6aa54a810d9 Mon Sep 17 00:00:00 2001 From: Zoe Stafford <36511192+Z-snails@users.noreply.github.com> Date: Fri, 22 Apr 2022 15:45:52 +0100 Subject: [PATCH] [base] add missing node ffi functions (#2427) --- libs/base/Data/Buffer.idr | 3 +++ libs/base/System/Directory.idr | 3 +++ support/js/support_system_directory.js | 32 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/libs/base/Data/Buffer.idr b/libs/base/Data/Buffer.idr index 2e8f1157a..557c43453 100644 --- a/libs/base/Data/Buffer.idr +++ b/libs/base/Data/Buffer.idr @@ -117,6 +117,7 @@ getBits32 buf offset = primIO (prim__getBits32 buf offset) %foreign "scheme:blodwen-buffer-setbits64" + "node:lambda:(buf,offset,value)=>buf.writeBigUInt64LE(value, offset)" prim__setBits64 : Buffer -> Int -> Bits64 -> PrimIO () export %inline @@ -125,6 +126,7 @@ setBits64 buf offset val = primIO (prim__setBits64 buf offset val) %foreign "scheme:blodwen-buffer-getbits64" + "node:lambda:(buf,offset)=>buf.readBigUInt64LE(offset)" prim__getBits64 : Buffer -> (offset : Int) -> PrimIO Bits64 export %inline @@ -194,6 +196,7 @@ getDouble buf offset export %foreign "scheme:blodwen-stringbytelen" "C:strlen, libc 6" + "javascript:lambda:(string)=>new TextEncoder().encode(string).length" stringByteLength : String -> Int %foreign "scheme:blodwen-buffer-setstring" diff --git a/libs/base/System/Directory.idr b/libs/base/System/Directory.idr index cf610557e..a2ef7c2ab 100644 --- a/libs/base/System/Directory.idr +++ b/libs/base/System/Directory.idr @@ -38,9 +38,11 @@ prim__changeDir : String -> PrimIO Int prim__createDir : String -> PrimIO Int %foreign supportC "idris2_openDir" + supportNode "openDir" prim__openDir : String -> PrimIO DirPtr %foreign supportC "idris2_closeDir" + supportNode "closeDir" prim__closeDir : DirPtr -> PrimIO () %foreign supportC "idris2_removeDir" @@ -48,6 +50,7 @@ prim__closeDir : DirPtr -> PrimIO () prim__removeDir : String -> PrimIO () %foreign supportC "idris2_nextDirEntry" + supportNode "dirEntry" prim__dirEntry : DirPtr -> PrimIO (Ptr String) ||| Data structure for managing the pointer to a directory. diff --git a/support/js/support_system_directory.js b/support/js/support_system_directory.js index 168bf88a5..225eab5a1 100644 --- a/support/js/support_system_directory.js +++ b/support/js/support_system_directory.js @@ -29,3 +29,35 @@ function support_system_directory_removeDir(d){ return 1 } } + +function support_system_directory_openDir(d) { + try{ + return support_system_directory_fs.opendirSync(d) + }catch(e){ + process.__lasterr = e + return null + } +} + +function support_system_directory_closeDir(d) { + try{ + d.closeSync() + }catch(e){ + process.__lasterr = e + return null + } +} + +function support_system_directory_dirEntry(d) { + try{ + const dir = d.readSync() + if (dir == null) { + return null + } else { + return dir.name + } + }catch(e){ + process.__lasterr = e + return null + } +}