Last active
January 19, 2024 15:28
-
-
Save headius/7f0003d1965b0ed528961f4b94d60162 to your computer and use it in GitHub Desktop.
Attempting to use Chicory (JVM WASM runtime) to run Prism (C-based Ruby language parser)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%w[runtime wasm wasi].each {|pkg| require "/Users/headius/.m2/repository/com/dylibso/chicory/#{pkg}/0.0.3/#{pkg}-0.0.3.jar"} | |
module Chicory | |
%w[ | |
runtime.Module | |
runtime.HostImports | |
runtime.wasi.WasiOptions | |
runtime.wasi.WasiPreview1 | |
wasm.types.Value].each do |cls| | |
java_import "com.dylibso.chicory.#{cls}" | |
end | |
module_function def load_and_export(wasm_path, export) | |
wasi = Chicory::WasiPreview1.new(Chicory::WasiOptions.builder.with_stdout(java.lang.System.err).build) | |
imports = Chicory::HostImports.new(wasi.to_host_functions) | |
instance = Chicory::Module.build(java.io.File.new(wasm_path)).instantiate(imports) | |
instance.get_export(export) | |
end | |
end | |
parse = Chicory.load_and_export "./prism.wasm", "pm_serialize_parse" | |
# need args buffer, source, length, options | |
parse.apply(Chicory::Value.i32(1), Chicory::Value.i32(2), Chicory::Value.i32(3), Chicory::Value.i32(4)) | |
# need args buffer, source, length, options | |
parse.apply() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[] chicory $ jruby prism_chicory.rb | |
Jan 19, 2024 8:52:05 AM com.dylibso.chicory.runtime.wasi.WasiPreview1 <init> | |
WARNING: Use of WASIP1 is experimental and will only work for the simplest of use cases. | |
Jan 19, 2024 8:52:05 AM com.dylibso.chicory.runtime.Module mapHostImports | |
WARNING: Could not find host function for import number: 2 named: wasi_snapshot_preview1.environ_get | |
Jan 19, 2024 8:52:05 AM com.dylibso.chicory.runtime.Module mapHostImports | |
WARNING: Could not find host function for import number: 13 named: wasi_snapshot_preview1.fd_filestat_get | |
Jan 19, 2024 8:52:05 AM com.dylibso.chicory.runtime.Machine printStackTrace | |
SEVERE: Trapped. Stacktrace: | |
Jan 19, 2024 8:52:05 AM com.dylibso.chicory.runtime.Machine printStackTrace | |
SEVERE: pm_serialize_parse[288] | |
pc=33 locals=[0@i32, 130208@i32] | |
Unhandled Java exception: com.dylibso.chicory.runtime.exceptions.WASMRuntimeException: An underlying Java exception occurred | |
com.dylibso.chicory.runtime.exceptions.WASMRuntimeException: An underlying Java exception occurred | |
eval at com/dylibso/chicory/runtime/Machine.java:1928 | |
call at com/dylibso/chicory/runtime/Machine.java:45 | |
lambda$getExport$0 at com/dylibso/chicory/runtime/Instance.java:60 | |
invoke0 at jdk/internal/reflect/NativeMethodAccessorImpl.java:-2 | |
invoke at jdk/internal/reflect/NativeMethodAccessorImpl.java:77 | |
invoke at jdk/internal/reflect/DelegatingMethodAccessorImpl.java:43 | |
invoke at java/lang/reflect/Method.java:568 | |
invokeDirectWithExceptionHandling at org/jruby/javasupport/JavaMethod.java:285 | |
invokeDirect at org/jruby/javasupport/JavaMethod.java:152 | |
invokeOther23:apply at prism_chicory.rb:20 | |
<main> at prism_chicory.rb:20 | |
run at prism_chicory.rb:-1 | |
invokeWithArguments at java/lang/invoke/MethodHandle.java:732 | |
runScript at org/jruby/Ruby.java:1286 | |
runNormally at org/jruby/Ruby.java:1203 | |
runNormally at org/jruby/Ruby.java:1185 | |
runNormally at org/jruby/Ruby.java:1221 | |
runFromMain at org/jruby/Ruby.java:999 | |
doRunFromMain at org/jruby/Main.java:398 | |
internalRun at org/jruby/Main.java:282 | |
run at org/jruby/Main.java:227 | |
main at org/jruby/Main.java:199 | |
Caused by: | |
java.lang.RuntimeException: Type error when extracting args. | |
extractArgsForParams at com/dylibso/chicory/runtime/Machine.java:2037 | |
eval at com/dylibso/chicory/runtime/Machine.java:940 | |
call at com/dylibso/chicory/runtime/Machine.java:45 | |
lambda$getExport$0 at com/dylibso/chicory/runtime/Instance.java:60 | |
invoke0 at jdk/internal/reflect/NativeMethodAccessorImpl.java:-2 | |
invoke at jdk/internal/reflect/NativeMethodAccessorImpl.java:77 | |
invoke at jdk/internal/reflect/DelegatingMethodAccessorImpl.java:43 | |
invoke at java/lang/reflect/Method.java:568 | |
invokeDirectWithExceptionHandling at org/jruby/javasupport/JavaMethod.java:285 | |
invokeDirect at org/jruby/javasupport/JavaMethod.java:152 | |
call at org/jruby/java/invokers/InstanceMethodInvoker.java:24 | |
call at org/jruby/java/invokers/InstanceMethodInvoker.java:29 | |
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:456 | |
call at org/jruby/runtime/callsite/CachingCallSite.java:195 | |
invokeOther23:apply at prism_chicory.rb:20 | |
RUBY$script at prism_chicory.rb:20 | |
run at prism_chicory.rb:-1 | |
invokeWithArguments at java/lang/invoke/MethodHandle.java:732 | |
load at org/jruby/ir/Compiler.java:114 | |
runScript at org/jruby/Ruby.java:1286 | |
runNormally at org/jruby/Ruby.java:1203 | |
runNormally at org/jruby/Ruby.java:1185 | |
runNormally at org/jruby/Ruby.java:1221 | |
runFromMain at org/jruby/Ruby.java:999 | |
doRunFromMain at org/jruby/Main.java:398 | |
internalRun at org/jruby/Main.java:282 | |
run at org/jruby/Main.java:227 | |
main at org/jruby/Main.java:199 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment