-
Notifications
You must be signed in to change notification settings - Fork 67
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
Support JS String Builtins #539
Comments
We could easily add this to Jco, as you have described. Will keep this open to track. Are there toolchains that would be able to utilize this feature already? |
moonbit supports this: https://www.moonbitlang.com/blog/js-string-builtins This is the artificial: ;; jco transpile palindrome.wat --imported-string-constants "_"
(core module
(type (;0;) (func (param externref) (result i32)))
(type (;1;) (func (param externref i32) (result i32)))
(type (;2;) (func (param (ref extern)) (result (ref extern))))
(type (;3;) (func (param i32)))
(type (;4;) (func))
(import "wasm:js-string" "length" (func (;0;) (type 0)))
(import "wasm:js-string" "charCodeAt" (func (;1;) (type 1)))
(import "_" "true" (global (;0;) (ref extern)))
(import "_" "false" (global (;1;) (ref extern)))
(memory (;0;) 1)
(export "palindrome" (func 2))
(start 3)
(func (;2;) (type 2) (param (ref extern)) (result (ref extern))
(local i32 i32 i32)
local.get 0
call 0
local.tee 1
i32.const 2
i32.div_s
local.set 2
i32.const 0
loop (type 3) (param i32) ;; label = @1
local.tee 3
local.get 2
i32.lt_s
if ;; label = @2
local.get 0
local.get 3
call 1
local.get 0
local.get 1
local.get 3
i32.sub
i32.const 1
i32.sub
call 1
i32.ne
if ;; label = @3
global.get 1
return
end
local.get 3
i32.const 1
i32.add
br 1 (;@1;)
end
end
global.get 0
)
(func (;3;) (type 4))
) |
Note you could also experiment with this today using Jco's custom instantiation mode. I think one of the hardest questions will just be what string builtin import name to use. |
I hope
jco
transpile can implement JS String Builtins Proposal.This helps to significantly reduce the size of browsers by reducing string-related functions and constant conversions.
The specific logic is to determine whether
(import "wasm:js-string" ...)
exists in core module.If it exists, then add
builtins: ['js-string']
toinstantiateCore
function.Another logic is to add the
--imported-string-constants
option.When
--imported-string-constants STATIC_STRING
is entered, theimportedStringConstants: "STATIC_STRING"
parameter will be added to theinstantiateCore
functionThe text was updated successfully, but these errors were encountered: