13 ms·
The Onyx Programming Language
- tines 3y agoAnyone have any experience with Onyx that would care to comment?
- kemitchell 3y agoClearly Wasmer wants to do WebAssembly. But for a whole new, general-purpose programming language, what's the case for that target, versus, say, LLVM intermediate representation?
- brendanfh 3y agoOnyx is entirely independent from Wasmer. It is a separate project developed by me, over the past 3 years. It does however use Wasmer for running on Windows, MacOS, and optionally on Linux. 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.
- digdugdirk 3y agoVery cool project! If I wanted to try it out in a repl based environment (maybe like a jupyter notebook?) where/how would you recommend I get started?
- brendanfh 3y agoOnyx does not really support a REPL environment at the moment because of the way it is compiled. Its execution cannot be paused in the same way as Python or JS. If you want to give it a try without committing to installing anything, I would recommend the Onyx Playground at https://try.onyxlang.io https://try.onyxlang.io
- digdugdirk 3y agoCould you please explain a bit about what you mean by how it's compiled? My immediate thought when I saw this was dreaming of a tiny modern lisp repl that I could store in the cloud and run on any computer. Even pointing to somewhere in the code that I could start poking around would be great.
- brendanfh 3y agoThe issue right now is how all WebAssembly modules in general are executed. WASM modules currently must contain everything need to run them when they are built. There is no way to dynamically define a new function or variable after they have been built, which would be required for an Onyx REPL to work. 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.
- andsoitis 3y ago> A data-oriented, expressive, and modern programming language What problems does this uniquely solve that other languages & environments don't?
- cogman10 3y agoIt looks to be a nicer C ultimately. It looks like it fits pretty squarely in the "if you want to do C level programming but you'd also like nice lambdas, sum types, and type inference"
- celrod 3y agoAnd only need it to compile to webassembly.
- cogman10 3y agoOh, I missed that part. That's quiet the design choice.
- CollinEMac 3y agoYeah but we have a lot of languages that do that now. Some of them are even mentioned on Onyx's homepage.
- bwanab 3y agoExactly. Three things that should be on the front page of any new language: 1) examples of syntax (check), 2) quick start instructions (check), 3) short description of motivation/rationale including what other languages were considered and why do they fall short?
- evanjrowley 3y agoNotably, this is the description on GitHub[0]: >A modern language for WebAssembly. [0] https://github.com/onyx-lang/onyx https://github.com/onyx-lang/onyx
- bunderbunder 3y ago
- moss2 3y ago> Onyx is strictly type-checked. However, the type-inference systems in Onyx usually allow you to omit types. > > x := 10 I... Why is this a feature in every new language? Can't we have a language that is more verbose and explicit, not less? I'd love it if named parameters were mandatory, not optional. (Named parameters is when you name parameters/arguments you pass on to functions, like you can do in python and groovy: `foobar(arg1: 123, arg2: 'hello')`) Most of my problems I run into is due to implicit behaviour that no one bothers to explain. In Onyx here, having type-inference means I now how to remember that x := 10 means x will be a signed 32-bit integer instead of, you know, the code that I'm writing remembering it for me. And I'm just guessing here. Maybe x is a double. Or unsigned since its initial value isn't negative. Or maybe it was signed 32-bit integer but the Onyx developers changed it to 128-bit long long for version 666.0.0. The point is I have to look this stuff up or remember it instead of, you know, it being right there. I don't even know what you gain by doing this. Less code is less messy but also hides a lot of information from you. Hiding information should be something an IDE does, not the language itself. Thank you for reading my rant.
- Joker_vD 3y agoReasonably, x in this case would be generic/polymorphic (just as 10 is a generic/polymorphic constant) with its type bounded by the equivalent of Num trait. Haskell (and to some extent Go) gets it right. Also reasonably, each source file should start with declaring the version of a language it was written in, so that e.g. Onyx 666.0 changing its default integer width wouldn't affect the code in the file with "///OnyxVer=665.0" at the top of it. Now that is a feature I would like every new language to have.
- giraffe_lady 3y agoThe other side of "why do I have to remember this when I could write it" is "why do I have to write it when the compiler already knows it?" I love complete inferred type systems, using one has completely changed how I think about types and what I expect from a programming language. I feel ill every time I have to use go or typescript. Like I am teaching the compiler how to compile. This is not my job, it's a waste of time and energy, it should already know. Things like rescript and ocaml are where my attention is going for typed languages in the future.
- IshKebab 3y agoLooks neat. Some obvious basic questions that I imagine most people would wonder: 1. Is it value based (C++, Rust, Go, TCL) or reference based (basically everything else). 2. How is memory freed? GC? 3. If GC how do you deal with the fact that Wasm GC is still in progress? 4. What about concurrency? Is it single threaded? 5. How does error handling work? 6. Does it support modern type features - Option<>, sum types, etc. 7. It's imperative, does that mean things that should be expressions (e.g. if/else) are statements?
- norir 3y ago8. What does blazingly-fast build times mean quantitatively? How does it scale with project size?
- brendanfh 3y agoThe largest project I have in Onyx is currently around 30000 lines (not all that large I know). That project on my Intel i7-1165G7 laptop compiles in about 80ms. 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.
- titzer 3y agoThat's impressively fast. Well done!
- brendanfh 3y agoThose are all great questions. I will add to the docs to explain more details later, but for now: 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.
- rishav_sharan 3y ago> Fast Compilation Onyx's compiler is written entirely in C and features incredibly fast compilation. The web-server for this website was compiled in 47 milliseconds. Ok, that got my attention. Its refreshing to see a new language which doesn't takes 10 seconds to build a Hello world example. Couple of questions; 1. The Windows installation is a bit tedious. Any plan to support Scoop for installing Onyx? 2. Given that gamedev seems to be a focus, with the raylib integration, how is the performance compared to something like c. Will a comparable onyx program get me to at least 50%+ of the performance of c? I haven't used webassembly much so I am curious how this works out. I was just thinking of creating a new project to try out Raylib 5. So your post has perfect timing for me! Best of luck to your language. Looks lovely in the online playground. Now going to set it up on my device
- koube 3y agonit: seamless not seemless. Actually TIL seemless is actually a word but it's a synonym for unseemly.
- deleted 3y ago[deleted]
- ivanjermakov 3y agoI have irrational anger towards := assignment operator, probably because of Pascal course in high school. Interesting if anyone else have such stories regarding language syntax and features.
- deleted 3y ago[deleted]
- topikk 3y agoI also have this irrational anger, but as a result of PL/SQL. It's also an objectively hideous operator that is inconvenient to type.
- _lvbh 3y agoComing from Go, I got used to :=. I would’ve preferred if it defaulted to const though
- cutemonster 3y agoComing from Pascal, I like := :-)
- CooCooCaCha 3y agoIt bugs me too. Mainly because I don't see anything wrong with "=", plus it's shorter and more intuitive.
- brendanfh 3y agoThe example in the blog post could have been written a little bit better, but in Onyx ":=" is actually a combination of two operations: defining a new variable with ':', and assigning the value with '='. If the type can be inferred on the right hand-side of the assignment, you can leave out the type between the ':' and the '=' and it effectively becomes a single operator. An alternative way to write that could have been 'input: str = "111 110 121 120";'. To assign in Onyx, you only have to use '='.
- xigoi 3y ago
- royjacobs 3y agoHow optimized is the generated code? One of the benefits of using LLVM is the amazing set of optimization passes, after all. Will Onyx have to reimplement a lot of these optimizations?
- brendanfh 3y agoThe compiler does not have many optimizations currently implemented. Currently, the compilers just uses constant folding and generally reducing unneeded operations if possible. There are plans to do function inlining and better tree-shaking, but those are a ways out. 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.
- ipsum2 3y agoNot to be confused with Onnx, a popular language for machine learning models, that is also commonly used with WebAssembly. Even the logo looks similar. https://onnx.ai/ https://onnx.ai/ https://cloudblogs.microsoft.com/opensource/2021/09/02/onnx-runtime-web-running-your-machine-learning-model-in-browser/ https://cloudblogs.microsoft.com/opensource/2021/09/02/onnx-...
- FireInsight 3y agoNot to be confused with Fedora Onyx, the budgie version of atomic Fedora. https://fedoraproject.org/onyx/ https://fedoraproject.org/onyx/
- tripdout 3y agoNot to be confused with Onyx, the son of rappers Playboi Carti and Iggy Azalea.
- ketralnis 3y agoNot to be confused with Onix https://bulbapedia.bulbagarden.net/wiki/Onix_(Pokémon) https://bulbapedia.bulbagarden.net/wiki/Onix_(Pokémon)
- JoshStrobl 3y agoFunny to see Onyx be mentioned in the wild! :D
- mike_hock 3y agoNot to be confused with Onyx the clothing store.
- cutemonster 3y agoNot to be confused with Onyx the gemstone. Or the other way around
- egberts1 3y agoNot to be confused with Onex Hacking Tool. https://github.com/MasterScott/onex https://github.com/MasterScott/onex
- phukit 3y agoWhy does every language designer feel compelled to invent unique syntax? We need a common syntax for all new languages. Only internals differ. This arbitrary combination of :: { () : core std f fmt -> is just annoying.
- bnchrch 3y agoI'm in no way against a new language! Love programming languages, particularly ones that push boundaries and challenge assumptions! (Great work on that front btw Onyx Team) But! When I see powered by WebAssembly. I can't see a good reason to choosing a unique language when any language in theory can target WASM/WASI. In other words Javascript/Python is looking at your lunch and is very hungry.
- orangea 3y agoWhen I see "powered by WebAssembly", I take it as a sign that the language is going to be designed around WebAssembly's VM interface rather than the implicit standard of the C memory model and POSIX-like API which basically all popular programming languages are designed for. Even languages like Python have the concepts of stdin/stdout/stderr, a filesystem, threads, and a single globally accessible heap baked into their design. It would take a lot of work to amend Python's design to be able to easily use features that are somewhat unique to WebAssembly like the various things a .wasm file can import or export. As it stands, languages like Python can be run on WASM, but they use inelegant hacks in order to be able to replicate the execution environment features that their interpreters require such as malloc, and usually it is assumed that the target will be WASI. A language that is designed for WASM from the ground up would make it so that WASM can be used to its fullest potential as a lightweight execution environment that makes extremely minimal assumptions about what interfaces are going to be provided to the program.
- brendanfh 3y agoThat is exactly the way that I see it too. 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.
- CyberDildonics 3y agoI'm not sure a specific compilation target that is meant to be as simple and generic as possible makes a new language a good idea. New languages mean you start all over and wipe away decades of tools, knowledge, libraries, development environments, package managers, workflows and now people are in the wild west again. To justify that you have to have some enormous benefits.
- tbm57 3y agoThe most interesting part of this language to me is that it's streamlined for WASM compilation, and I think that should be put up front more than it is
- onyxlangfanboy 3y ago[flagged]
- kettlecorn 3y agoCan Onyx's compiler be compiled to Wasm to itself run in the browser? It's niche, but I've thought it'd be cool if there were a mini Wasm-based game building tool in the browser, but that requires a Wasm language with a compiler that can run in the browser.
- brendanfh 3y agoCurrently, it does not. But it is written in C with a reasonable separation between the OS things and the compiler things, so compiling with Emscripten should be possible without too much modification. 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.
- bobajeff 3y ago> When linking, I find the libraries on disk, load them, call a function in each dynamic library that returns a list of procedures that can be used when linking. This external linking enables Onyx to use any native C library, from Raylib and OpenGL, to PostgresQL and OpenSSL. This is really cool. I wonder if there is any overhead using native libraries from wasm like this. My intuition says it does similar to node-ffi and JNI but I hope it's not as bad.
- brendanfh 3y agoI haven't directly measured any throughput or latency numbers. I know it is relatively fast, but I know it is not as seamless as I would like. 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.
- crabmusket 3y agoI would really like if the language reference[1] had a "rationale" or "principles" section describing the decisions at a high level. At the moment it dives straight into the minutiae of syntax, built-in types, etc. The language marketing insists it is "data-oriented", even in the footer of every page. But I couldn't find any more detail on this. My favourite example of this is Austral, which has a detailed rationale[2] that justifies the choices made and the tradeoffs. It really helped me decide whether I was interested in the language. Odin, cited in the blog post, has a shallow rationale on its FAQ page[3], but seems to have had more time/maturity to document specific "data-oriented" features like built-in SoA[4]. [1] https://docs.onyxlang.io/book/Overview.html https://docs.onyxlang.io/book/Overview.html [2] https://austral-lang.org/spec/spec.html#rationale https://austral-lang.org/spec/spec.html#rationale [3] https://odin-lang.org/docs/faq/ https://odin-lang.org/docs/faq/ [4] https://odin-lang.org/docs/overview/#soa-data-types https://odin-lang.org/docs/overview/#soa-data-types
- brendanfh 3y agoThanks for the feedback! I agree my documentation is very lacking in that department. I hope in the next few days to have a page in the documentation that describes my rationale, and the tradeoffs made during development.
- DoesntMatter22 3y agoTo go along with that I really need a "Why should I use this" type of thing. Similar to what you are suggesting.
- ReleaseCandidat 3y agoRoc also is a great site on how to present a "new" language. Specially the sections that explain what they mean by being "fast", "friendly" and "functional". https://www.roc-lang.org/ https://www.roc-lang.org/
- dwenzek 3y agoThanks for these links! Austral rational documentation is indeed really interesting. My preference goes into another direction (notably toward expression-based languages), but it's refreshing to read well explained design decisions. The section about linear types is also a gem to this regard. I would even consider this as a reference source to introduce the motivations and principles behind the Rust type system and borrow checker. Only the syntax would have to be made a bit more rusty. [1] https://austral-lang.org/spec/spec.html#rationale-linear-types https://austral-lang.org/spec/spec.html#rationale-linear-typ...
- insanitybit 3y agoHow did you find the experience of compiling to wasm? Do you build an IR first at all or just ast -> wasm?
- brendanfh 3y agoI found it relatively easy. I planned a lot of things out of whiteboards and notebooks, but the actual code writing was mostly straight forward. For Onyx, I went straight from AST to WASM. The trickiest part was probably deciding how non-primitive things would be represented in WASM, like structures and tagged unions. But all of that came later after I had the basics down. I started with the simplest little compiler that could only compile binary operations on integers, and basic function calls. Then I expanded the compiler outward once I had the underlying data structures and code paths figured out.
- soulbadguy 3y agoWell it's Friday and i have some time to kill. Before i start, creating a language is hard and i am just making random comment on the internet. From the "why webassembly" section : > When making a programming language, you need to decide how your programs will actually be executed. In abstract maybe, and obviously some language features might make an interpreter or a compiler harder/easier to make. But in general and in practice the language semantic and the "execution mode" can be treated independently. Some of the languages mentioned even have multiple style of execution (AOT, JIT, interpretation , compilation etc...) > Onyx does not rely on libraries like LLVM to generate its code, because WASM is so simple to target. In term of correctness maybe. It will be interesting to see what happens as performance and more complex code pattern need to be supported. Most language evolve some type of high level representation between the AST and they target of choices for language specific transformation and error reporting (SIL,clangIR and HIR? not sure about that last one). >My strategy was to wrap libwasmer.a, the standalone library version of Wasmer, into my own custom WASM loader, to allow imported functions to be linked against native libraries Doesn't this both limit the portability and introduce potential security risk (and thus negating the whole point of wasm) ? I think the inter reaction with the outside world is what WASI and the other is trying to address.
- adiabatty 3y agoSince the guy who makes this is in the thread and I'm not the first to say stuff about the website… Seems cool but I was trying to read one of the examples on <https://onyxlang.io/ https://onyxlang.io/> and the carousel changed pages, throwing me off. Would you consider not using a(n auto-advancing) carousel with code examples? Not unrelated: <https://shouldiuseacarousel.com https://shouldiuseacarousel.com> (short answer: "no")
- deleted 3y ago[deleted]
- brendanfh 3y agoI totally agree the auto-advancing carousel was a bad idea. I wanted to add something with movement to the page, but that was definitely not the right idea. The carousel has been removed!
- solarkraft 3y agoIt seemed inevitable that a new language would choose WASM as a runtime. We get a bytecode runtime to rival JVM and CLR, but with a diversity of stake holders (no single vendor trying to push a language or enterprise offering), it's JITed even on Apple devices and on the damn web! Pretty amazing. What makes me excited about this: Getting to poke around, at runtime, my compiled .NET C# code using PowerShell (in Snoop) was pretty eye-opening to me. The "standard" interoperability between PowerShell (Core?) and .NET objects as well, of course. It feels great to have a common runtime making calling out to other languages so seamless. Yet it seems to me like it never reached the popularity it deserved, but maybe it will get another try, with a lot more enthusiasm (no more Oracle/MS brake-foot).
- pjmlp 3y agoExcept the detail that it is mostly driven by Google, given Chrome's market share.
- nolist_policy 3y agoWrong, Google drove NaCl for a long time (portable LLVM bytecode) but then Mozilla countered with asm.js which kickstarted and heavily influenced the development of Webassembly.
- pjmlp 3y agoWrong, because you are only focusing on what lead to WebAssembly 1.0, almost a decade ago, not what happened afterwards the Web turned into ChromeOS.
- pyrossh 3y agoNice name analogous to ruby. From wikipedia, Onyx - A banded variety of chalcedony, a cryptocrystalline form of quartz. Ruby - A clear, deep, red variety of corundum, valued as a precious stone.
- Alifatisk 3y agoIs Crystal also analogous to ruby?
- pyrossh 3y agoAhh yes. Totally forgot about crystal. Crystal - A solid whose atoms (or molecules) are arranged in a repeating pattern. Crystals are found naturally or can be made artificially. Someone should use Diamond for the next programming language, really like the wiki definition. Diamond - is a carbon crystal formed under heat and pressure.
- pyrossh 3y agoI've been trying to build a programming language targeting only wasm but never seem to get the time to work on it. Like the syntax, mainly the pipe operator |> A few questions, 1. Any plans to use binaryen to optimize the wasm output? 2. How is memory management handled? Are you going to use wasm-gc? 3. How does the C FFI work? Do you convert the WASM types to C types?
- ReleaseCandidat 3y ago> To navigate these limitations I came up with a way for any WebAssembly embedder, like Wasmer, to interact with native system components. ... I added a custom section to the WASM binaries output by Onyx that specifies which native libraries it wants to link against. So the main reasons for using WASM and all of it's advantages are lost. It's neither sandboxed nor self contained any more, but slower than using "native" compilation and still missing libraries (compared to JVM, CLR, Beam,...). Don't get mé wrong, I know about the advantages of WASM for the language implementor (although I'd use WASM GC), but as a user, but I don't know why I should use Onyx.
- spuz 3y agoI am getting network errors loading some paths on the onyxlang.io website. That's not a good advertisement for Wasmer.
- syrusakbary 3y agoOh no! Do you mind providing the paths where the errors occurs or the requests ids returned by Wasmer, so we can investigate further? Thanks!
- spuz 3y agoI think the requests that were failing were pretty random actually but I didn't get any response from the following. After a few minutes the request would timeout with an error NS_ERROR_NET_HTTP2_SENT_GOAWAY in shown Firefox. https://onyxlang.io/ https://onyxlang.io/ https://onyxlang.io/playground https://onyxlang.io/playground The second one is a 404 but I wasn't even seeing that earlier (this is linked from the first page of the docs). Currently, I don't have any issues but the problems I was having lasted at least a few hours which is why I mentioned it.
- syrusakbary 3y agoThanks a lot for the info, I'll relay to the team to investigate further
- WhereIsTheTruth 3y agoDoes it support hotreload? To me that's the piece that's missing in all these new languages Being able to hot patch code saves you from having to recompile everything and reload the state of your program, saves lot of time I was excited when Zig announced planning it, but it's been like 4 years now and they went radio silence unfortunatly
- brendanfh 3y agoThat is a planned feature because I really want that too! I believe it should be possible and not take years to develop, especially because Onyx does have its own WASM runtime that I can completely control how and when certain things happen, like pausing for a hot reload. This runtime is currently Linux only, but I should be able to address that relatively soon. I don't know if it would be possible with Wasmer as the runtime, without Wasmer making severe modifications to its code generation and runtime. Hot reload is a tricky problem, but I believe for the developer experience, it is worth trying.