bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
14.9k stars 1.24k forks source link

improve/document examples in `wasmtime/cranelift/jit/` #4839

Open adsick opened 1 year ago

adsick commented 1 year ago

Hi, I just came from https://github.com/bytecodealliance/cranelift-jit-demo which is nice, documented and pretty straightforward (although has some todo comments left there 3-4 years ago)

Improvement

Add more examples of different complexity (basic to medium and maybe some complex ones), document them with explanations of what's what (like it is done in cranelift-jit-demo)

Implementation

Think of some simple examples and use-cases that incorporate jit, it could be something like compiled regex or other type of state machine pattern, then add examples commenting every jit and cranelift-specific step to avoid confusion and provide guidance.

Show how to define functions, work with data, leave useful notes to external resources (at least to Wikipedia).

Benefit

Newcomers like me will be able to understand what is going on there and how they can use cranelift jit to build their own blazingly fast & feature packed language.

p.s. now I'm trying to explore cranelift-jit-demo and it is looking good so far, I like it.

jameysharp commented 1 year ago

I had considered hooking up my experimental regex compiler (https://github.com/jameysharp/pikevm) to cranelift-jit for fun, but I hadn't really thought about making it be useful documentation. Thanks for the suggestion!

I'm curious: what project do you want to use a JIT compiler in?

One way you can help is by keeping notes on things that you find confusing or surprising about Cranelift as you work on your project. We can help turn those notes into better documentation, or even better, fix Cranelift to be easier to use.

Also, I encourage you to join the #cranelift stream at https://bytecodealliance.zulipchat.com/. There are a bunch of people hanging out there who can help answer questions.

adsick commented 1 year ago

Thanks for the response!

what project do you want to use a JIT compiler in?

Probably building a programming language of my own (at least trying my best) but for now just learning more stuff from it to become a bit more experienced. The reason I want JIT compiled language is that I like prototyping and iteration, but interpreted languages are not as fast to be useful in areas like gamedev or heavy simulations so I'm going to use JIT. In the past I've tried Julia programming language and found that is really nice but the problem is that it has GC so gamedev is basically no go (also it is a math-oriented functional language so some things are not so convenient as in e.g. Rust where you have "normal" mutability)

btw currently I'm working on a note-taking app called mem, it can be used to create notes, todos, readlists, dictionaries... but notably it will allow for creating "QA" cards so you can save questions you (or someone else) have to answer later.

Also, I encourage you to join the #cranelift stream at https://bytecodealliance.zulipchat.com/

thanks for that suggestion, not exactly sure if I'm gonna be there, but if I need some help I know where to go.