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

Feature request: Build for WebAssembly #105

Open
Machine-Jonte opened this issue Mar 27, 2023 · 3 comments
Open

Feature request: Build for WebAssembly #105

Machine-Jonte opened this issue Mar 27, 2023 · 3 comments
Labels

Comments

@Machine-Jonte
Copy link

Hi,
Wonder if this scheme interpreter works compiling and running in native wasm (target "wasm32-unknown-unknown")?

@cipriancraciun
Copy link
Member

I wouldn't say it's impossible to make it work, because there are a lot of "features" that gate varyous pieces of code.

However I doubt it would work without some serious effort.

(I think the main issue would be the fact that it uses the standard allocator for memory management.)


Could you detail perhaps your intended use-case?

@Machine-Jonte
Copy link
Author

Yes, and thanks for the blazingly fast response! I will look into it a bit and post here if I make some progress.

@cipriancraciun
Copy link
Member

If you want to give it a try, you can take a look at the extensive set of features, and start adding them incrementally until something breaks, or until you get what you need:

vonuvoli-scheme/Cargo.toml

Lines 115 to 708 in b7f8d69

[features]
default = [
"vonuvoli_release",
]
vonuvoli_release = [
"vonuvoli_defaults",
"vonuvoli_values_all",
"vonuvoli_builtins_all",
"vonuvoli_tools_all",
"vonuvoli_terminal",
"vonuvoli_transcript_ansi_enabled",
"vonuvoli_transcript_code_hashes",
"vonuvoli_abort_on_panic",
"vonuvoli_lints_all",
]
vonuvoli_debug_for_binaries = [
"vonuvoli_debug_level_6",
"vonuvoli_trace_enabled_all",
"vonuvoli_trace_error_all",
"vonuvoli_abort_on_panic",
"vonuvoli_lints_warnings",
]
vonuvoli_debug_for_tests = [
"vonuvoli_debug_level_6",
"vonuvoli_trace_enabled_all",
"vonuvoli_trace_error_all",
"vonuvoli_transcript_compact",
"vonuvoli_transcript_ansi_always",
"vonuvoli_lints_warnings",
]
vonuvoli_defaults = [
"vonuvoli_compiler",
"vonuvoli_optimizer",
"vonuvoli_evaluator",
"vonuvoli_new_immutable",
"vonuvoli_port_output_display_flush",
"vonuvoli_port_output_newline_flush",
"vonuvoli_backtrace",
"vonuvoli_transcript",
"vonuvoli_parser",
"vonuvoli_tests",
"vonuvoli_hash",
"vonuvoli_eqord",
"vonuvoli_fmt_display",
"vonuvoli_fmt_debug",
]
vonuvoli_debug_level_0 = []
vonuvoli_debug_level_1 = [
"vonuvoli_debug_level_0",
"vonuvoli_compiler",
"vonuvoli_optimizer",
"vonuvoli_evaluator",
"vonuvoli_parser",
"vonuvoli_tests",
]
vonuvoli_debug_level_2 = [
"vonuvoli_debug_level_1",
"vonuvoli_defaults",
]
vonuvoli_debug_level_3 = [
"vonuvoli_debug_level_2",
"vonuvoli_values_all",
]
vonuvoli_debug_level_4 = [
"vonuvoli_debug_level_3",
"vonuvoli_builtins_all",
]
vonuvoli_debug_level_5 = [
"vonuvoli_debug_level_4",
"vonuvoli_tools_all",
]
vonuvoli_debug_level_6 = [
"vonuvoli_debug_level_5",
"vonuvoli_terminal",
"vonuvoli_transcript_ansi_enabled",
"vonuvoli_transcript_code_hashes",
"vonuvoli_backtrace_sources",
"vonuvoli_documentation",
"vonuvoli_documentation_variances",
"vonuvoli_documentation_sources",
]
vonuvoli_new_immutable = []
vonuvoli_port_output_write_flush = []
vonuvoli_port_output_display_flush = []
vonuvoli_port_output_newline_flush = []
vonuvoli_compiler = [
"vonuvoli_expressions",
]
vonuvoli_optimizer = [
"vonuvoli_expressions_optimizer",
]
vonuvoli_evaluator = [
"vonuvoli_expressions",
]
vonuvoli_expressions = []
vonuvoli_expressions_optimizer = [
"vonuvoli_expressions",
]
vonuvoli_trace_enabled_all = [
"vonuvoli_compiler_trace_enabled",
"vonuvoli_optimizer_trace_enabled",
"vonuvoli_evaluator_trace_enabled",
"vonuvoli_parser_trace_enabled",
]
vonuvoli_trace_error_all = [
"vonuvoli_compiler_trace_error",
"vonuvoli_optimizer_trace_error",
"vonuvoli_evaluator_trace_error",
"vonuvoli_parser_trace_error",
]
vonuvoli_compiler_trace_enabled = []
vonuvoli_compiler_trace_error = [
"vonuvoli_compiler_trace_enabled",
]
vonuvoli_optimizer_trace_enabled = []
vonuvoli_optimizer_trace_error = [
"vonuvoli_optimizer_trace_enabled",
]
vonuvoli_evaluator_trace_enabled = []
vonuvoli_evaluator_trace_error = [
"vonuvoli_evaluator_trace_enabled",
]
vonuvoli_parser_trace_enabled = []
vonuvoli_parser_trace_error = [
"vonuvoli_parser_trace_enabled",
]
vonuvoli_backtrace = [
"backtrace",
"rustc-demangle",
]
vonuvoli_backtrace_sources = []
vonuvoli_terminal = [
"ansi_term",
"atty",
]
vonuvoli_transcript_compact = []
vonuvoli_transcript_ansi_enabled = []
vonuvoli_transcript_ansi_always = []
vonuvoli_transcript_code_hashes = [
"blake3",
]
vonuvoli_transcript = []
vonuvoli_parser = []
vonuvoli_tests = [
"vonuvoli_compiler",
"vonuvoli_optimizer",
"vonuvoli_evaluator",
"vonuvoli_parser",
"vonuvoli_transcript",
"vonuvoli_eqord",
]
vonuvoli_documentation = [
"vonuvoli_parser",
"vonuvoli_values_string",
]
vonuvoli_documentation_variances = []
vonuvoli_documentation_sources = []
vonuvoli_panic_on_failed = []
vonuvoli_abort_on_panic = []
vonuvoli_hash = []
vonuvoli_eqord = []
vonuvoli_fmt_display = []
vonuvoli_fmt_debug = []
vonuvoli_lints_all = [
"vonuvoli_lints_warnings",
"vonuvoli_lints_issue_tracking",
]
vonuvoli_lints_warnings = []
vonuvoli_lints_issue_tracking = []
vonuvoli_values_all = [
"vonuvoli_values_string",
"vonuvoli_values_bytes",
"vonuvoli_values_array",
"vonuvoli_values_values",
"vonuvoli_values_error",
"vonuvoli_values_keyword",
"vonuvoli_values_unique",
"vonuvoli_values_contexts",
"vonuvoli_values_opaque",
"vonuvoli_values_lambda",
"vonuvoli_values_extended",
"vonuvoli_values_native",
"vonuvoli_values_mutable",
#! "vonuvoli_values_pair_drop_iterative",
]
vonuvoli_values_string = []
vonuvoli_values_bytes = []
vonuvoli_values_array = []
vonuvoli_values_values = []
vonuvoli_values_error = []
vonuvoli_values_keyword = []
vonuvoli_values_unique = []
vonuvoli_values_contexts = []
vonuvoli_values_opaque = []
vonuvoli_values_lambda = []
vonuvoli_values_extended = []
vonuvoli_values_native = []
vonuvoli_values_mutable = []
vonuvoli_values_pair_drop_iterative = []
vonuvoli_builtins_all = [
"vonuvoli_builtins_comparisons",
"vonuvoli_builtins_parameters",
"vonuvoli_builtins_promises",
"vonuvoli_builtins_records",
"vonuvoli_builtins_regex",
"vonuvoli_builtins_ports",
"vonuvoli_builtins_ports_input_value",
"vonuvoli_builtins_ports_output_value",
"vonuvoli_builtins_ports_descriptors",
"vonuvoli_builtins_ports_temporary",
"vonuvoli_builtins_filesystem",
"vonuvoli_builtins_filesystem_temporary",
"vonuvoli_builtins_processes",
"vonuvoli_builtins_transcript",
"vonuvoli_builtins_crypto",
"vonuvoli_builtins_random",
"vonuvoli_builtins_encoding",
"vonuvoli_builtins_cache",
"vonuvoli_builtins_serde",
"vonuvoli_builtins_hashes",
"vonuvoli_builtins_hashes_siphash",
"vonuvoli_builtins_hashes_highwayhash",
"vonuvoli_builtins_hashes_xxh3",
"vonuvoli_builtins_hashes_seahash",
"vonuvoli_builtins_hashes_blake2",
"vonuvoli_builtins_hashes_blake3",
]
vonuvoli_builtins_comparisons = [
"vonuvoli_eqord",
]
vonuvoli_builtins_parameters = []
vonuvoli_builtins_promises = []
vonuvoli_builtins_records = [
"vonuvoli_values_extended",
]
vonuvoli_builtins_regex = [
"regex",
]
vonuvoli_builtins_ports = []
vonuvoli_builtins_ports_input_value = []
vonuvoli_builtins_ports_output_value = [
"vonuvoli_fmt_display",
]
vonuvoli_builtins_ports_descriptors = []
vonuvoli_builtins_ports_temporary = [
"vonuvoli_values_values",
"vonuvoli_values_opaque",
"tempfile",
]
vonuvoli_builtins_filesystem = [
"vonuvoli_values_opaque",
]
vonuvoli_builtins_filesystem_temporary = [
"vonuvoli_values_values",
"vonuvoli_values_opaque",
"tempfile",
]
vonuvoli_builtins_processes = [
"vonuvoli_builtins_ports",
]
vonuvoli_builtins_transcript = [
"vonuvoli_values_string",
"vonuvoli_transcript",
]
vonuvoli_builtins_crypto = [
"vonuvoli_values_native",
"vonuvoli_values_bytes",
"ring",
"digest",
"sha1",
"sha2",
"sha3",
"md-5",
"blake2",
"blake3",
]
vonuvoli_builtins_random = [
"vonuvoli_values_native",
"rand",
]
vonuvoli_builtins_encoding = [
"vonuvoli_values_native",
"vonuvoli_values_string",
"vonuvoli_values_bytes",
"data-encoding",
]
vonuvoli_builtins_cache = [
"vonuvoli_values_opaque",
"vonuvoli_hash",
"lmdb-zero",
"blake3",
]
vonuvoli_builtins_serde = [
"serde",
"serde_derive",
"serde_bytes",
"bincode",
]
vonuvoli_builtins_hashes = [
"vonuvoli_hash",
"lazy_static",
]
vonuvoli_builtins_hashes_siphash = [
"vonuvoli_builtins_hashes",
"siphasher",
"lazy_static",
"rand",
]
vonuvoli_builtins_hashes_highwayhash = [
"vonuvoli_builtins_hashes",
"highway",
"lazy_static",
"rand",
]
vonuvoli_builtins_hashes_xxh3 = [
"vonuvoli_builtins_hashes",
"twox-hash",
"lazy_static",
"rand",
]
vonuvoli_builtins_hashes_seahash = [
"vonuvoli_builtins_hashes",
"seahash",
"lazy_static",
"rand",
]
vonuvoli_builtins_hashes_blake2 = [
"vonuvoli_builtins_hashes",
"vonuvoli_values_bytes",
"blake2",
"lazy_static",
"rand",
]
vonuvoli_builtins_hashes_blake3 = [
"vonuvoli_builtins_hashes",
"vonuvoli_values_bytes",
"blake3",
"lazy_static",
"rand",
]
vonuvoli_tools_common = [
"vonuvoli_transcript",
]
vonuvoli_tools_all = [
"vonuvoli_tools_interpreter",
"vonuvoli_tools_compiler",
"vonuvoli_tools_tester",
"vonuvoli_tools_bencher",
"vonuvoli_tools_reports",
"vonuvoli_tools_documentation",
]
vonuvoli_tools_interpreter = [
"vonuvoli_tools_common",
"vonuvoli_evaluator",
"vonuvoli_compiler",
"vonuvoli_optimizer",
"vonuvoli_parser",
]
vonuvoli_tools_compiler = [
"vonuvoli_tools_common",
"vonuvoli_compiler",
"vonuvoli_optimizer",
"vonuvoli_parser",
]
vonuvoli_tools_tester = [
"vonuvoli_tools_common",
"vonuvoli_tests",
]
vonuvoli_tools_bencher = [
"vonuvoli_tools_common",
"vonuvoli_tests",
]
vonuvoli_tools_reports = [
"vonuvoli_tools_common",
"vonuvoli_eqord",
"vonuvoli_hash",
]
vonuvoli_tools_documentation = [
"vonuvoli_tools_common",
"vonuvoli_documentation",
"vonuvoli_values_all",
"serde_json",
"pulldown-cmark",
"cpio",
"regex",
"lazy_static",
]
vonuvoli_tools_interpreter_binary = [
"vonuvoli_tools_interpreter",
"vonuvoli_tools_common_binary",
]
vonuvoli_tools_compiler_binary = [
"vonuvoli_tools_compiler",
"vonuvoli_tools_common_binary",
]
vonuvoli_tools_tester_binary = [
"vonuvoli_tools_tester",
"vonuvoli_tools_common_binary",
]
vonuvoli_tools_bencher_binary = [
"vonuvoli_tools_bencher",
"vonuvoli_tools_common_binary",
]
vonuvoli_tools_reports_binary = [
"vonuvoli_tools_reports",
"vonuvoli_tools_common_binary",
]
vonuvoli_tools_documentation_binary = [
"vonuvoli_tools_documentation",
"vonuvoli_tools_common_binary",
"vonuvoli_documentation_sources",
]
vonuvoli_tools_common_binary = [
"vonuvoli_tools_common",
"vonuvoli_fmt_display",
"vonuvoli_fmt_debug",
"vonuvoli_transcript",
"vonuvoli_transcript_ansi_enabled",
"vonuvoli_trace_error_all",
"vonuvoli_backtrace",
"vonuvoli_backtrace_sources",
]
vonuvoli_features_all = [
"vonuvoli_features_all_macros",
"vonuvoli_features_all_individual",
"vonuvoli_features_all_configurations",
]
vonuvoli_features_all_macros = [
"vonuvoli_release",
"vonuvoli_debug_for_binaries",
"vonuvoli_debug_for_tests",
"vonuvoli_debug_level_0",
"vonuvoli_debug_level_1",
"vonuvoli_debug_level_2",
"vonuvoli_debug_level_3",
"vonuvoli_debug_level_4",
"vonuvoli_debug_level_5",
"vonuvoli_debug_level_6",
"vonuvoli_defaults",
"vonuvoli_values_all",
"vonuvoli_builtins_all",
"vonuvoli_tools_all",
"vonuvoli_trace_enabled_all",
"vonuvoli_trace_error_all",
"vonuvoli_lints_all",
]
vonuvoli_features_all_individual = [
"vonuvoli_values_string",
"vonuvoli_values_bytes",
"vonuvoli_values_array",
"vonuvoli_values_values",
"vonuvoli_values_error",
"vonuvoli_values_keyword",
"vonuvoli_values_unique",
"vonuvoli_values_contexts",
"vonuvoli_values_opaque",
"vonuvoli_values_lambda",
"vonuvoli_values_extended",
"vonuvoli_values_native",
"vonuvoli_values_mutable",
"vonuvoli_values_pair_drop_iterative",
"vonuvoli_builtins_comparisons",
"vonuvoli_builtins_parameters",
"vonuvoli_builtins_promises",
"vonuvoli_builtins_records",
"vonuvoli_builtins_regex",
"vonuvoli_builtins_ports",
"vonuvoli_builtins_ports_input_value",
"vonuvoli_builtins_ports_output_value",
"vonuvoli_builtins_ports_descriptors",
"vonuvoli_builtins_ports_temporary",
"vonuvoli_builtins_filesystem",
"vonuvoli_builtins_filesystem_temporary",
"vonuvoli_builtins_processes",
"vonuvoli_builtins_transcript",
"vonuvoli_builtins_crypto",
"vonuvoli_builtins_random",
"vonuvoli_builtins_encoding",
"vonuvoli_builtins_cache",
"vonuvoli_builtins_serde",
"vonuvoli_builtins_hashes",
"vonuvoli_builtins_hashes_siphash",
"vonuvoli_builtins_hashes_highwayhash",
"vonuvoli_builtins_hashes_xxh3",
"vonuvoli_builtins_hashes_seahash",
"vonuvoli_builtins_hashes_blake2",
"vonuvoli_builtins_hashes_blake3",
"vonuvoli_tools_common",
"vonuvoli_tools_interpreter",
"vonuvoli_tools_compiler",
"vonuvoli_tools_tester",
"vonuvoli_tools_bencher",
"vonuvoli_tools_reports",
"vonuvoli_tools_documentation",
"vonuvoli_parser",
"vonuvoli_tests",
"vonuvoli_transcript",
"vonuvoli_transcript_ansi_enabled",
"vonuvoli_transcript_code_hashes",
"vonuvoli_terminal",
"vonuvoli_backtrace",
"vonuvoli_backtrace_sources",
"vonuvoli_compiler",
"vonuvoli_optimizer",
"vonuvoli_evaluator",
"vonuvoli_expressions",
"vonuvoli_expressions_optimizer",
"vonuvoli_compiler_trace_enabled",
"vonuvoli_optimizer_trace_enabled",
"vonuvoli_evaluator_trace_enabled",
"vonuvoli_parser_trace_enabled",
"vonuvoli_hash",
"vonuvoli_eqord",
"vonuvoli_fmt_display",
"vonuvoli_fmt_debug",
"vonuvoli_documentation",
"vonuvoli_documentation_sources",
"vonuvoli_documentation_variances",
]
vonuvoli_features_all_configurations = [
"vonuvoli_new_immutable",
"vonuvoli_port_output_write_flush",
"vonuvoli_port_output_display_flush",
"vonuvoli_port_output_newline_flush",
"vonuvoli_transcript_compact",
"vonuvoli_transcript_ansi_always",
"vonuvoli_compiler_trace_error",
"vonuvoli_optimizer_trace_error",
"vonuvoli_evaluator_trace_error",
"vonuvoli_parser_trace_error",
"vonuvoli_panic_on_failed",
"vonuvoli_abort_on_panic",
"vonuvoli_lints_warnings",
"vonuvoli_lints_issue_tracking",
]

For example start with the minimum of vonuvoli_evaluator, vonuvoli_parser and vonuvoli_compiler. Then you can start adding vonuvoli_values_* and vonuvoli_builtins_* until it breaks.

Most likely you'll have to write a custom main, see the tools_interpreter.rs snippet below:

let expressions = match parse_script (&source, None) {
Ok (expressions) =>
expressions,
Err (error) => {
trace_error! (transcript, 0x4b546a75 => "failed parsing script!" => (), error = &error);
error.backtrace_report (tracer_error! (transcript, 0xfcb837f6));
succeed! (1);
},
};
let expressions = match compile_script (&context, &expressions, None) {
Ok (expression) =>
expression,
Err (error) => {
trace_error! (transcript, 0xeaf9b7f2 => "failed compiling script!" => (), error = &error);
error.backtrace_report (tracer_error! (transcript, 0x0a87f029));
succeed! (1);
},
};
let expressions = match optimize_script (expressions, None) {
Ok (expression) =>
expression,
Err (error) => {
trace_error! (transcript, 0x89f48a5b => "failed optimizing script!" => (), error = &error);
error.backtrace_report (tracer_error! (transcript, 0x5e46732f));
succeed! (1);
},
};
match evaluate_script (expressions.into_iter (), Some (&context), parameters.as_ref (), None) {
Ok (()) =>
succeed! (0),
Err (error) =>
match *error.internals_ref () {
ErrorInternals::Exit (code, _) =>
succeed! (code),
#[ cfg ( feature = "vonuvoli_builtins_processes" ) ]
ErrorInternals::Exec (ref configuration) =>
match Process::exec (configuration) {
Ok (_) =>
unreachable_0! (0x765f3997, github_issue_new),
Err (error) => {
trace_error! (transcript, 0x9d5d1d35 => "failed executing!" => (), error = &error);
error.backtrace_report (tracer_error! (transcript, 0xd2bda446));
succeed! (1);
},
},
_ => {
trace_error! (transcript, 0xe74be5c8 => "failed evaluating script!" => (), error = &error);
error.backtrace_report (tracer_error! (transcript, 0x5c04a150));
succeed! (1);
}
},
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants