93 karma · joined Dec 1, 2023 (3y ago) · 15 submissions
comment 2y ago · link · parent
You could definitely use Onyx to create a modern lisp interpreter that can run in the browser without any dependencies, but it might be worth porting an existing C project if that is your goal. I'm not gonna stop you from making something like that in Onyx tho; it would be very cool!
There is a however possibility for a REPL for Onyx to exist outside of the browser. This is because Onyx has another runtime it can use alongside WASM called OVMwasm. This runtime is entirely custom (you can see the source code in the 'interpreter' folder on the Onyx GitHub), so it could be modified to do non-standard things with WASM, like add new functions dynamically. That would take some work to achieve, but in theory should be possible.
comment 2y ago · link · parent
comment 2y ago · link · parent
comment 2y ago · link · parent
comment 2y ago · link · parent
Currently, for WASM to call any imported function, its arguments have to be formatted in a particular way that is specified by the wasm-c-api. Then it can invoke the imported function. Only after that can the arguments be translated back into the native calling convention in order to call the real native function. I don't know how that compares to node-ffi and JNI, but I imagine its not as slow.
I have a piece of documentation I need to write that will explain how calling native libraries works from Onyx, so that should be able to go into more detail.
comment 2y ago · link · parent
This is similar to what the Onyx Playground currently does. To do that I just POST your project files to a server, save everything to disk, run the compiler, delete everything, and send the resulting WASM file back to the browser, to be run in a WebWorker.
comment 2y ago · link · parent
While Onyx does have core library support for doing standard POSIX things like stdin/stdout/stderr, file operations, and networking, Onyx can be used in an entirely different environment without any of these things. In fact, the standard libraries are (almost) entirely separate from the compiler (i.e. the compiler makes no assumptions about what the standard library is), so if the standard library does not suite your use case for one reason or another, you can write your own. It will be a bit of work, but there would be nothing in your way.
comment 2y ago · link · parent
To assign in Onyx, you only have to use '='.
comment 2y ago · link · parent
The "nice" thing about WebAssembly is that the job of generating optimized machine-instructions is up to the WASM embedder, which Wasmer is doing very well right now. Onyx does have a second runtime that is currently only implemented for x86_64 Linux, that does have some more optimizations, but it does not compile to native code; just to an interpreted byte-code.
comment 2y ago · link · parent
There are currently no large Onyx projects that can really test how this number scales, but I would guess the growth is not linear. So for an off the cuff estimated, I would say a million line project could compile in about 4-5 seconds.
Also worth noting that the entire compiler is currently single-threaded. So that number could get much better.
comment 2y ago · link · parent
1. It is value based, like C. There is obviously passing by pointer, but you do that explcitly.
2/3. Memory is manually managed. To make this easier, like Zig and Odin, everything that allocates should take an allocator as a parameter. This allocator can be the general purpose heap allocator, or it can be an arena, ring buffer, or even tracked allocations that can be freed all at once. More details on that to follow in the documentation.
4. It does have multi-threading support, thanks to the atomics WASM proposal. The standard library currently has support for basic multi-threaded primitives like mutexes, semaphores, and condition variables. Note, there is currently not async/await or any kind of concurrent execution.
5/6. It does have modern type features like sum types. It has Optional(T) and Result(Ok, Err) out of the box. That is the preferred method of error handling.
7. It is mostly statement oriented, but there are features like Elixir's pipe operator (|>) and if/else (value if condition else otherwise) expressions.
comment 3y ago · link · parent
I started making Onyx because I simply wanted to create my own programming language for the fun of it. I choose WebAssembly as the target for my compiler because it was relatively easy to write my own full-stack solution, instead of relying on something like LLVM. That language evolved over the years until I had something I felt was worth sharing. When the Wasmer team reached out to see if I wanted to do a collaboration blog post, I said yes.
The main reason I didn't go with LLVM was simply because I wanted to write everything myself (for fun) and to have a super-fast compiler. LLVM is not the fastest backend, but it is understandable for all the optimizations that it does.