-
Notifications
You must be signed in to change notification settings - Fork 382
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
[ node ] Add missing FFI functions for node #3500
Conversation
The C functions for getting errno and file errno are different so I don't imagine we can use the same NodeJS implementation for both. |
I can move it to a separate function to make the semantics match. On node the whole Note that in the RefC/Scheme backends Lines 43 to 56 in e341368
|
Meaning that the result in Idris code won't be the same as if you were calling the same function depending on if you use the C or NodeJS backends? That's not great (and not documented in the Idris code that I can tell, though that's not on you to do in this PR).
Nope, I was calling out the fact that |
- adds missing cases and fixes fallback values - fix sign of getErrno
I had the sign wrong on the previous commit. It looks like the exception objects have a negative error number in the error field and I fixed the sign and I think we have parity for For Which brings me to another question. Before this PR, if you run the
But baseLibraryTests : IO TestPool
baseLibraryTests = testsInDir "base" "Base library" {requirements = [Chez, Node]} Are these tests supposed to run on node? |
So I said "faked" in that support doesn't see C errno and is making its own global that emulates errno. I didn't know how valid the numbers were at that point, but it appears that the number that it pulls off the exception matches C error codes. Windows is a bit weird there - it's possible that it's weird in scheme/C too. I'll have to check. (I don't yet know if those numbers are a windows thing or a node+windows thing.) |
Yeah, for main : IO ()
main = do
Left err <- readFile "xxxx" | Right _ => putStrLn "exists?"
putStrLn "ENOENT is \{show !(getErrno)}"
Left err <- createDir "build" | Right _ => putStrLn "can create?"
putStrLn "EEXIST is \{show !(getErrno)}" which gave:
|
Ideally all of base would be tested on NodeJS, but since it has been an ongoing project to implement some of the primitives needed by base they are not run automatically (intentionally). NodeJS is nevertheless required in order to run the base tests because some of the tests do explicitly test NodeJS, like this one: https://github.com/idris-lang/Idris2/blob/main//tests/base/system_time001/run#L5..L6 |
I'm tempted to be okay with that -- to feel that consistency between backends on the same system is more important than consistency between platforms. I wish Windows implemented a faithful Thanks for not only adding to the NodeJS primitive surface area but also adding the missing cases that had sat as a TODO for a long time! |
Tangentially, I do think a reasonable test case could be written that expected different results for Windows vs. Unix, but I would merge this without that too. |
The 0 error numbers are not ideal, but I think a test that they're equal to 0 will simply verify that something is broken. I've added documentation to I've removed my And I've added a test that checks if file errors are getting translated correctly (in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Description
The
openDir
FFI is implemented for the node backend, but it does not compile due to a reference toprim__getErrno
. I've addedprim__getErrno
for node, following the pattern used for file errors.In addition to this, I've implemented three
System.Term
FFI functions. As in the non-windowsC
backend,prim__setupTerm
is a no-op.prim__getTermCols
andprim__getTermLines
return the number of columns and lines, respectively.Finally, I put in a no-op for
prim__flush
on node. I didn't see a flush in the node api. This is used forstdout
in the REPL and on the file handle in ide mode. The REPL in node appears to flush output characters automatically. I haven't ported IDE mode yet.These all came up when building an Idris compiler that runs in javascript. If IDE mode and scheme eval are commented out, these changes are sufficient to build and run on JS.