-
Notifications
You must be signed in to change notification settings - Fork 454
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
Add stdio.write import for writing a sequence of bytes to stdout #121
Conversation
(module | ||
(import $write "stdio" "write" (param i32 i32)) | ||
|
||
(memory 4096 4096 (segment 0 "hello, world!\0D\0A\00")) |
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.
In C/C++ code compiled to wasm, strings don't contain the "\0D", because stdout is in "text" mode, which ordinarily means that the C library translates newline into carriage-return-line-feed on Windows. However in wasm's case, the C library won't know that it's running on Windows, so it won't know that it has to do this. I think it's best if stdio.write handles this itself so that wasm programs don't have to worry about it.
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.
That would make it unusable for binary data.
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.
The alternative is to be unusable for text strings in C/C++. How about a separate function for binary data?
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.
write
is a base primitive for writing whatever to stdout. if you want to print text, your stdlib would do any transforms like \n
-> \r\n
on windows.
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.
How should the stdlib detect that is is on Windows?
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.
What I'm actually concerned about here is that there's wasm code with a \r\n
in it, which I find very concerning. I assumed you put it there because of Windows; if not, then can we just remove the \r
?
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.
IIUC this is meant to test that \r
is unchanged. I strongly believe that fwrite
shouldn't change the bits it's given, so the test should exist in some form. Are you suggesting the form be changed?
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.
Would you mind making a separate test for binary output then? I saw this test as the "hello world" test that would be used as an example of what wasm code looks like. I don't want to risk anyone thinking that wasm code needs a \r
to print hello world.
As you say, a separate test for binary output could test \0
and other interesting characters.
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.
"write" for binary data, "print" for text?
On Fri, Oct 9, 2015 at 12:34 PM, Dan Gohman notifications@github.com
wrote:
In ml-proto/test/stdio_write.wast
#121 (comment):@@ -0,0 +1,14 @@
+(module
- (import $write "stdio" "write" (param i32 i32))
- (memory 4096 4096 (segment 0 "hello, world!\0D\0A\00"))
Would you mind making a separate test for binary output then? I saw this
test as the "hello world" test that would be used as an example of what
wasm code looks like. I don't want to risk anyone thinking that wasm code
needs a \r to print hello world.As you say, a separate test for binary output could test \0 and other
interesting characters.—
Reply to this email directly or view it on GitHub
https://github.com/WebAssembly/spec/pull/121/files#r41669560.
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.
I think separate test files is fine.
Welp. Looks like windows ocaml is doing line normalization. I probably need to find another way to write raw bytes to stdout.
|
I added the line set_binary_mode_out stdout true; And it seems to work, but I don't know if it does on linux. |
Switched to print_bytes, that might disable newline conversion. Or it might not, since |
I don't think It's just like in the C or C++ stdlibs: newline conversion is a property of the stream, not the source. And |
Nope, I don't have access to Windows at work :-) I'll come up with a fix on my Windows machine. |
Yeah, Your suggested pattern-match doesn't seem like it type-checks, at least as written. I'm not actually sure why, as it looks correct to me.
Should I just update the PR without using the pattern-match, or do you not want to merge without it? The pattern-match does seem like the right way to do this. |
Ah, sorry, I keep forgetting that OCaml separates list items by semicolons. That should fix it. |
…rmalized. Iterate using Int64 (since the offset and count are Int64)
OK, I've revised it so that it works correctly on Windows now. Had some confusion over the fact that to disable newline normalization, you do |
lgtm |
@@ -1,9 +1,50 @@ | |||
open Source | |||
open Eval |
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.
From a readthrough, the only use of the Eval module in this file is the Eval.memory_for_module. Can this open be removed?
Closing, there doesn't seem to be a strong need |
…bly#121) Included in this PR: - Detailed core formal spec additions aiming to fully implement: + the "informal formal" core spec laid out by Andreas @rossberg here: WebAssembly/exception-handling#87 (comment) and + the core spec outlined in the [proposal overview](https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md), while removing the mention of "events" everywhere but in the binary format , + prose for the above in: syntax, validation, execution, binary format, text format, and the appendix, as well as an example for throw contexts. - Travis-ci build status icon to `README.md`. The contents of this PR get built and deployed on my fork's github page successfully, using [the howto instructions](https://github.com/WebAssembly/proposals/blob/master/howto.md#setting-up-travis-and-github-page). Not included in this PR: - Neither the new values representing unresolved throw contexts, nor the additional rules for the execution contexts, which we discussed in WebAssembly#87, are added here. I plan to add these separately. - No JS API/Web API changes. Side comments: - In [document/core/text/types.rst](https://ioannad.github.io/exception-handling/core/text/types.html#text-refedtype): I'm not sure whether `refedtype ::= ... | event ⇒ exnref` should have `event` there or something else (perhaps `exception`?) However, since currently the only events are exceptions, this is probably not really an issue. - The "informal formal spec" defines the administrative instruction which represents an exception package as `exnref`, i.e., the same name as the type. I called this administrative instruction `ref.exn` instead for two reasons; to match the style of `ref.null` and `ref.extern`, and to avoid ambiguity in the discussions. - I removed multi-value mentions from `README.md` because multi-value is now part of the main spec. For the same reason I didn't add "multi-value" to the list of included proposals at the top of the core spec landing page.
Fix expected result type in relaxed dot product tests
No description provided.