From 54738d3c71c181a50e7d6556491d2d4190fbdeb8 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Thu, 11 Dec 2025 10:32:52 -0600 Subject: [PATCH 1/8] Wave 1 of spec tests --- .../compact_imports.wast | 24 ---- .../imports-compact.wast | 132 ++++++++++++++++++ 2 files changed, 132 insertions(+), 24 deletions(-) delete mode 100644 test/core/compact-import-section/compact_imports.wast create mode 100644 test/core/compact-import-section/imports-compact.wast diff --git a/test/core/compact-import-section/compact_imports.wast b/test/core/compact-import-section/compact_imports.wast deleted file mode 100644 index 133942a2b..000000000 --- a/test/core/compact-import-section/compact_imports.wast +++ /dev/null @@ -1,24 +0,0 @@ -(module - (func (export "func->11") (result i32) (i32.const 11)) - (func (export "func->22") (result f32) (f32.const 22)) - (global (export "global->1") i32 (i32.const 55)) - (global (export "global->20") i32 (i32.const 44)) -) -(register "test") - -(module - (import "test" - (item "func->11" (func $f11 (result i32))) - (item "func->22" (func $f22 (result f32))) - ) - - (func (export "sum") (result i32) - (local i32) - - call $f11 - (i32.trunc_f32_s (call $f22)) - i32.add - ) -) - -(assert_return (invoke "sum") (i32.const 33)) diff --git a/test/core/compact-import-section/imports-compact.wast b/test/core/compact-import-section/imports-compact.wast new file mode 100644 index 000000000..ab1d36e9f --- /dev/null +++ b/test/core/compact-import-section/imports-compact.wast @@ -0,0 +1,132 @@ +;; Auxiliary module to import from + +(module + (func (export "func->11i") (result i32) (i32.const 11)) + (func (export "func->22f") (result f32) (f32.const 22)) + (global (export "global->1") i32 (i32.const 1)) + (global (export "global->20") i32 (i32.const 20)) + (global (export "global->300") i32 (i32.const 300)) + (global (export "global->4000") i32 (i32.const 4000)) +) +(register "test") + + +;; Basic behavior + +(module + (import "test" + (item "func->11i" (func (result i32))) + (item "func->22f" (func (result f32))) + ) + (import "test" + (item "global->1") + (item "global->20") + (item "global->300") + (item "global->4000") + (global i32) + ) + + (global i32 (i32.const 50000)) + + (func (export "sum1") (result i32) + (local i32) + + call 0 + (i32.trunc_f32_s (call 1)) + i32.add + ) + (func (export "sum2") (result i32) + (local i32) + + global.get 0 + global.get 1 + global.get 2 + global.get 3 + i32.add + i32.add + i32.add + ) + + ;; Tests that indices were tracked correctly + (func (export "sum3") (result i32) + call 2 ;; sum1 + call 3 ;; sum2 + i32.add + + global.get 4 + i32.add + ) +) + +(assert_return (invoke "sum1") (i32.const 33)) +(assert_return (invoke "sum2") (i32.const 4321)) +(assert_return (invoke "sum3") (i32.const 54354)) + +(module (import "test" (item "func->11i" (func (result i32))))) +(assert_unlinkable + (module (import "unknown" (item "func->11i" (func (result i32))))) + "unknown import" +) +(assert_unlinkable + (module (import "test" (item "unknown" (func (result i32))))) + "unknown import" +) +(assert_unlinkable + (module (import "test" (item "func->11i" (func (result i32))) (item "unknown" (func (result i32))))) + "unknown import" +) + +(module (import "test" (item "func->11i") (func (result i32)))) +(assert_unlinkable + (module (import "unknown" (item "func->11i") (func (result i32)))) + "unknown import" +) +(assert_unlinkable + (module (import "test" (item "unknown") (func (result i32)))) + "unknown import" +) +(assert_unlinkable + (module (import "test" (item "func->11i") (item "unknown") (func (result i32)))) + "unknown import" +) + +(assert_unlinkable + (module (import "test" (item "func->11i" (func)))) + "incompatible import type" +) +(assert_unlinkable + (module (import "test" (item "func->11i" (func (result i32))) (item "func->22f" (func)))) + "incompatible import type" +) + +(assert_unlinkable + (module (import "test" (item "func->11i") (item "func->22f") (func (result i32)))) + "incompatible import type" +) + + +;; Identifiers + +(module + (import "test" "func->11i" (func $f11i (result i32))) + (import "test" + (item "global->1" (global $g1 i32)) + (item "global->20" (global $g20 i32)) + ) + ;; Shared-type form does not allow identifiers + + (func (export "sum") (result i32) + call $f11i + global.get $g1 + global.get $g20 + i32.add + i32.add + ) +) + +(assert_return (invoke "sum") (i32.const 32)) + +(assert_malformed + (module quote "(import \"test\" (item \"foo\") (func $foo))") + "identifier not allowed" +) From f9c5e91ae4ec96ecec983579bd168dbce556cd88 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Thu, 11 Dec 2025 10:58:00 -0600 Subject: [PATCH 2/8] Remove unnecessary "unknown" import tests --- test/core/compact-import-section/imports-compact.wast | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/core/compact-import-section/imports-compact.wast b/test/core/compact-import-section/imports-compact.wast index ab1d36e9f..43422356b 100644 --- a/test/core/compact-import-section/imports-compact.wast +++ b/test/core/compact-import-section/imports-compact.wast @@ -63,10 +63,6 @@ (assert_return (invoke "sum3") (i32.const 54354)) (module (import "test" (item "func->11i" (func (result i32))))) -(assert_unlinkable - (module (import "unknown" (item "func->11i" (func (result i32))))) - "unknown import" -) (assert_unlinkable (module (import "test" (item "unknown" (func (result i32))))) "unknown import" @@ -77,10 +73,6 @@ ) (module (import "test" (item "func->11i") (func (result i32)))) -(assert_unlinkable - (module (import "unknown" (item "func->11i") (func (result i32)))) - "unknown import" -) (assert_unlinkable (module (import "test" (item "unknown") (func (result i32)))) "unknown import" From 710ced3249088069c9782a90d0df5a170ea60f3d Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Thu, 11 Dec 2025 15:54:23 -0600 Subject: [PATCH 3/8] Initial binary tests --- .../binary-compact-imports.wast | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 test/core/compact-import-section/binary-compact-imports.wast diff --git a/test/core/compact-import-section/binary-compact-imports.wast b/test/core/compact-import-section/binary-compact-imports.wast new file mode 100644 index 000000000..4130d3520 --- /dev/null +++ b/test/core/compact-import-section/binary-compact-imports.wast @@ -0,0 +1,97 @@ +;; Auxiliary modules to import +(module + (func (export "b") (result i32) (i32.const 0x0f)) + (func (export "c") (result i32) (i32.const 0xf0)) +) +(register "a") +(module + (func (export "") (result i32) (i32.const 0xab)) +) +(register "") + +;; Valid compact encodings +(module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\02\0d" ;; Import section + "\01" ;; 1 group + "\01a" ;; "a" + "\00\7f" ;; "" + 0x7f (compact encoding) + "\02" ;; 2 items + "\01b" "\00\00" ;; "b" (func (type 0)) + "\01c" "\00\00" ;; "c" (func (type 0)) +) +(module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\02\0b" ;; Import section + "\01" ;; 1 group + "\01a" ;; "a" + "\00\7e" ;; "" + 0x7e (compact encoding) + "\00\00" ;; (func (type 0)) + "\02" ;; 2 items + "\01b" ;; "b" + "\01c" ;; "c" +) + +;; Overly-long empty name encodings are valid +(module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\02\0d" ;; Import section + "\01" ;; 1 group + "\01a" ;; "a" + "\80\80\80\00\7f" ;; "" (long encoding) + 0x7f + "\02" ;; 2 items + "\01b" "\00\00" ;; "b" (func (type 0)) + "\01c" "\00\00" ;; "c" (func (type 0)) +) +(module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\02\0b" ;; Import section + "\01" ;; 1 group + "\01a" ;; "a" + "\80\80\80\00\7e" ;; "" (long encoding) + 0x7e + "\00\00" ;; (func (type 0)) + "\02" ;; 2 items + "\01b" ;; "b" + "\01c" ;; "c" +) + +;; Discriminator is not to be interpreted as LEB128 +(assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\02\0d" ;; Import section + "\01" ;; 1 group + "\01a" ;; "a" + "\00\ff\80\80\00" ;; "" + 0x7f (long encoding) + "\02" ;; 2 items + "\01b" "\00\00" ;; "b" (func (type 0)) + "\01c" "\00\00" ;; "c" (func (type 0)) + ) +) +(assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\02\0b" ;; Import section + "\01" ;; 1 group + "\01a" ;; "a" + "\00\fe\80\80\00" ;; "" + 0x7e (long encoding) + "\00\00" ;; (func (type 0)) + "\02" ;; 2 items + "\01b" ;; "b" + "\01c" ;; "c" + ) +) + +;; Empty names are still valid if not followed by a discriminator +(module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\02\05\01" ;; Import section: one group + "\00\00\00\00" ;; (import "" "" (func (type 0)) +) From 01f999a0be0d5a8c35bab933ed6cf08fde3bb7ab Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Thu, 11 Dec 2025 15:55:53 -0600 Subject: [PATCH 4/8] Fix missing messages in assert_malformed --- test/core/compact-import-section/binary-compact-imports.wast | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/core/compact-import-section/binary-compact-imports.wast b/test/core/compact-import-section/binary-compact-imports.wast index 4130d3520..7937bd110 100644 --- a/test/core/compact-import-section/binary-compact-imports.wast +++ b/test/core/compact-import-section/binary-compact-imports.wast @@ -72,6 +72,7 @@ "\01b" "\00\00" ;; "b" (func (type 0)) "\01c" "\00\00" ;; "c" (func (type 0)) ) + "malformed import kind" ) (assert_malformed (module binary @@ -86,6 +87,7 @@ "\01b" ;; "b" "\01c" ;; "c" ) + "malformed import kind" ) ;; Empty names are still valid if not followed by a discriminator From e7e2a64f0c5aba05251b44ff667a079763fd49c2 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Thu, 11 Dec 2025 16:10:06 -0600 Subject: [PATCH 5/8] Fix up byte counts, etc. --- .../binary-compact-imports.wast | 56 +++++++++++++++---- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/test/core/compact-import-section/binary-compact-imports.wast b/test/core/compact-import-section/binary-compact-imports.wast index 7937bd110..802557c9f 100644 --- a/test/core/compact-import-section/binary-compact-imports.wast +++ b/test/core/compact-import-section/binary-compact-imports.wast @@ -13,10 +13,10 @@ (module binary "\00asm" "\01\00\00\00" "\01\04\01\60\00\00" ;; Type section: (type (func)) - "\02\0d" ;; Import section + "\02\0e" ;; Import section "\01" ;; 1 group "\01a" ;; "a" - "\00\7f" ;; "" + 0x7f (compact encoding) + "\00" "\7f" ;; "" + 0x7f (compact encoding) "\02" ;; 2 items "\01b" "\00\00" ;; "b" (func (type 0)) "\01c" "\00\00" ;; "c" (func (type 0)) @@ -24,10 +24,10 @@ (module binary "\00asm" "\01\00\00\00" "\01\04\01\60\00\00" ;; Type section: (type (func)) - "\02\0b" ;; Import section + "\02\11" ;; Import section "\01" ;; 1 group "\01a" ;; "a" - "\00\7e" ;; "" + 0x7e (compact encoding) + "\00" "\7e" ;; "" + 0x7e (compact encoding) "\00\00" ;; (func (type 0)) "\02" ;; 2 items "\01b" ;; "b" @@ -38,10 +38,10 @@ (module binary "\00asm" "\01\00\00\00" "\01\04\01\60\00\00" ;; Type section: (type (func)) - "\02\0d" ;; Import section + "\02\11" ;; Import section "\01" ;; 1 group "\01a" ;; "a" - "\80\80\80\00\7f" ;; "" (long encoding) + 0x7f + "\80\80\80\00" "\7f" ;; "" (long encoding) + 0x7f "\02" ;; 2 items "\01b" "\00\00" ;; "b" (func (type 0)) "\01c" "\00\00" ;; "c" (func (type 0)) @@ -49,22 +49,53 @@ (module binary "\00asm" "\01\00\00\00" "\01\04\01\60\00\00" ;; Type section: (type (func)) - "\02\0b" ;; Import section + "\02\0f" ;; Import section "\01" ;; 1 group "\01a" ;; "a" - "\80\80\80\00\7e" ;; "" (long encoding) + 0x7e + "\80\80\80\00" "\7e" ;; "" (long encoding) + 0x7e "\00\00" ;; (func (type 0)) "\02" ;; 2 items "\01b" ;; "b" "\01c" ;; "c" ) +;; Discriminator is not valid except after empty names +(assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\02\12" ;; Import section + "\01" ;; 1 group + "\01a" ;; "a" + "\01b" "\7f" ;; "b" + 0x7f + "\02" ;; 2 items + "\01b" "\00\00" ;; "b" (func (type 0)) + "\01c" "\00\00" ;; "c" (func (type 0)) + ) + "malformed import kind" +) +(assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\02\10" ;; Import section + "\01" ;; 1 group + "\01a" ;; "a" + "\01b" "\7e" ;; "" + 0x7e (long encoding) + "\00\00" ;; (func (type 0)) + "\02" ;; 2 items + "\01b" ;; "b" + "\01c" ;; "c" + ) + "malformed import kind" +) + ;; Discriminator is not to be interpreted as LEB128 (assert_malformed (module binary "\00asm" "\01\00\00\00" "\01\04\01\60\00\00" ;; Type section: (type (func)) - "\02\0d" ;; Import section + "\02\11" ;; Import section "\01" ;; 1 group "\01a" ;; "a" "\00\ff\80\80\00" ;; "" + 0x7f (long encoding) @@ -78,7 +109,7 @@ (module binary "\00asm" "\01\00\00\00" "\01\04\01\60\00\00" ;; Type section: (type (func)) - "\02\0b" ;; Import section + "\02\0f" ;; Import section "\01" ;; 1 group "\01a" ;; "a" "\00\fe\80\80\00" ;; "" + 0x7e (long encoding) @@ -94,6 +125,7 @@ (module binary "\00asm" "\01\00\00\00" "\01\04\01\60\00\00" ;; Type section: (type (func)) - "\02\05\01" ;; Import section: one group - "\00\00\00\00" ;; (import "" "" (func (type 0)) + "\02\05" ;; Import section + "\01" ;; 1 group + "\00\00\00\00" ;; "" "" (func (type 0)) ) From 9afdecd9b78d7356fbf831b674f6b43a0352925e Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Thu, 11 Dec 2025 16:14:15 -0600 Subject: [PATCH 6/8] Fix type signatures --- .../binary-compact-imports.wast | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/core/compact-import-section/binary-compact-imports.wast b/test/core/compact-import-section/binary-compact-imports.wast index 802557c9f..e788a6597 100644 --- a/test/core/compact-import-section/binary-compact-imports.wast +++ b/test/core/compact-import-section/binary-compact-imports.wast @@ -12,7 +12,7 @@ ;; Valid compact encodings (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\0e" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -23,7 +23,7 @@ ) (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\11" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -37,7 +37,7 @@ ;; Overly-long empty name encodings are valid (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\11" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -48,7 +48,7 @@ ) (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\0f" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -63,7 +63,7 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\12" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -77,7 +77,7 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\10" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -94,7 +94,7 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\11" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -108,7 +108,7 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\0f" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -124,7 +124,7 @@ ;; Empty names are still valid if not followed by a discriminator (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\00" ;; Type section: (type (func)) + "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\05" ;; Import section "\01" ;; 1 group "\00\00\00\00" ;; "" "" (func (type 0)) From 927ed61e1dea2a3af94c37633bf809c163c530ce Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Thu, 11 Dec 2025 16:15:20 -0600 Subject: [PATCH 7/8] Fix more fixatiously --- .../binary-compact-imports.wast | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/core/compact-import-section/binary-compact-imports.wast b/test/core/compact-import-section/binary-compact-imports.wast index e788a6597..b0e863132 100644 --- a/test/core/compact-import-section/binary-compact-imports.wast +++ b/test/core/compact-import-section/binary-compact-imports.wast @@ -12,7 +12,7 @@ ;; Valid compact encodings (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\0e" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -23,7 +23,7 @@ ) (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\11" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -37,7 +37,7 @@ ;; Overly-long empty name encodings are valid (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\11" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -48,7 +48,7 @@ ) (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\0f" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -63,7 +63,7 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\12" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -77,7 +77,7 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\10" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -94,7 +94,7 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\11" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -108,7 +108,7 @@ (assert_malformed (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\0f" ;; Import section "\01" ;; 1 group "\01a" ;; "a" @@ -124,7 +124,7 @@ ;; Empty names are still valid if not followed by a discriminator (module binary "\00asm" "\01\00\00\00" - "\01\04\01\60\00\01\7f" ;; Type section: (type (func (result i32))) + "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\05" ;; Import section "\01" ;; 1 group "\00\00\00\00" ;; "" "" (func (type 0)) From 9c2be08aa438c0eb1b7fa2f10699a8debc58b661 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Thu, 11 Dec 2025 16:31:26 -0600 Subject: [PATCH 8/8] More robust binary tests --- .../binary-compact-imports.wast | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/test/core/compact-import-section/binary-compact-imports.wast b/test/core/compact-import-section/binary-compact-imports.wast index b0e863132..bf5d9e021 100644 --- a/test/core/compact-import-section/binary-compact-imports.wast +++ b/test/core/compact-import-section/binary-compact-imports.wast @@ -1,4 +1,5 @@ ;; Auxiliary modules to import + (module (func (export "b") (result i32) (i32.const 0x0f)) (func (export "c") (result i32) (i32.const 0xf0)) @@ -9,7 +10,9 @@ ) (register "") + ;; Valid compact encodings + (module binary "\00asm" "\01\00\00\00" "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) @@ -20,11 +23,23 @@ "\02" ;; 2 items "\01b" "\00\00" ;; "b" (func (type 0)) "\01c" "\00\00" ;; "c" (func (type 0)) + "\03\02" "\01" ;; Function section, 1 func + "\00" ;; func 2: type 0 + "\07\08" "\01" ;; Export section, 1 export + "\04test" "\00\02" ;; "test" func 2 + "\0a\09" "\01" ;; Code section, 1 func + "\07" "\00" ;; len, 0 locals + "\10\00" ;; call 0 + "\10\01" ;; call 1 + "\6a" ;; i32.add + "\0b" ;; end ) +(assert_return (invoke "test") (i32.const 0xff)) + (module binary "\00asm" "\01\00\00\00" "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) - "\02\11" ;; Import section + "\02\0c" ;; Import section "\01" ;; 1 group "\01a" ;; "a" "\00" "\7e" ;; "" + 0x7e (compact encoding) @@ -32,9 +47,22 @@ "\02" ;; 2 items "\01b" ;; "b" "\01c" ;; "c" + "\03\02" "\01" ;; Function section, 1 func + "\00" ;; func 2: type 0 + "\07\08" "\01" ;; Export section, 1 export + "\04test" "\00\02" ;; "test" func 2 + "\0a\09" "\01" ;; Code section, 1 func + "\07" "\00" ;; len, 0 locals + "\10\00" ;; call 0 + "\10\01" ;; call 1 + "\6a" ;; i32.add + "\0b" ;; end ) +(assert_return (invoke "test") (i32.const 0xff)) + ;; Overly-long empty name encodings are valid + (module binary "\00asm" "\01\00\00\00" "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) @@ -59,7 +87,9 @@ "\01c" ;; "c" ) + ;; Discriminator is not valid except after empty names + (assert_malformed (module binary "\00asm" "\01\00\00\00" @@ -90,7 +120,9 @@ "malformed import kind" ) + ;; Discriminator is not to be interpreted as LEB128 + (assert_malformed (module binary "\00asm" "\01\00\00\00" @@ -121,11 +153,22 @@ "malformed import kind" ) + ;; Empty names are still valid if not followed by a discriminator + (module binary "\00asm" "\01\00\00\00" "\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32))) "\02\05" ;; Import section "\01" ;; 1 group "\00\00\00\00" ;; "" "" (func (type 0)) + "\03\02" "\01" ;; Function section, 1 func + "\00" ;; func 1: type 0 + "\07\08" "\01" ;; Export section, 1 export + "\04test" "\00\01" ;; "test" func 1 + "\0a\06" "\01" ;; Code section, 1 func + "\04" "\00" ;; len, 0 locals + "\10\00" ;; call 0 + "\0b" ;; end ) +(assert_return (invoke "test") (i32.const 0xab))