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

Minor refactor in readEmAsmArgs. NFC #20054

Merged
merged 1 commit into from
Aug 18, 2023
Merged
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
16 changes: 7 additions & 9 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2887,19 +2887,17 @@ addToLibrary({
#endif
// Floats are always passed as doubles, and doubles and int64s take up 8
// bytes (two 32-bit slots) in memory, align reads to these:
buf += (ch != 105/*i*/) & buf;
buf += (ch != {{{ charCode('i') }}}) & buf;
readEmAsmArgsArray.push(
ch == {{{ charCode('i') }}} ? HEAP32[buf] :
#if MEMORY64
// Special case for pointers under wasm64 which we read as int53 Numbers.
if (ch == 112/*p*/) {
readEmAsmArgsArray.push(readI53FromI64(buf++ << 2));
} else
// Special case for pointers under wasm64 which we read as int53 Numbers.
ch == {{{ charCode('p') }}} ? {{{ makeGetValue('buf++ << 2', 0, '*') }}} :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a ? : nested in another - is there no need for ( ) to avoid ambiguity in parsing..?

Copy link
Collaborator Author

@sbc100 sbc100 Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the nesting works as we expect it to here.

$ cat test.js 
function f(n) {
  return n == 1 ? 'one' :
         n == 2 ? 'two' :
         n == 3 ? 'three' : NaN;
}

console.log(f(1));
console.log(f(2));
console.log(f(3));
$ node test.js 
one
two
three

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking, might just be confusing for me personally then... 😄 but seems fine in compiler output if it's unambiguous.

#endif
readEmAsmArgsArray.push(
ch == 105/*i*/ ? HEAP32[buf] :
#if WASM_BIGINT
(ch == 106/*j*/ ? HEAP64 : HEAPF64)[buf++ >> 1]
(ch == {{{ charCode('j') }}} ? HEAP64 : HEAPF64)[buf++ >> 1]
#else
HEAPF64[buf++ >> 1]
HEAPF64[buf++ >> 1]
#endif
);
++buf;
Expand Down
1 change: 1 addition & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,7 @@ def test_inlinejs4(self):
''', 'false', assert_returncode=NON_ZERO)

def test_em_asm(self):
self.maybe_closure()
self.do_core_test('test_em_asm.cpp')

def test_em_asm_c(self):
Expand Down