onyxlang 简单试用

发布时间 2024-01-09 09:37:28作者: 荣锋亮

以前简单说过onyxlang 是一个基于webassembly 的新编程语言,以下是一个简单试用

安装

sh <(curl https://get.onyxlang.io -sSfL)

效果

注意安装完成之后需要配置环境变量(有提示)
包含的cli

 
Onyx toolchain version v0.1.8
Built on Wed Nov 29 01:49:11 2023
Runtime: wasmer
 
The toolchain for the Onyx programming language, created by Brendan Hansen.
 
Usage:
    onyx <subcommand>
 
Subcommands:
    help      Shows this help message. Use "onyx help <subcommand>".
    build     Compiles an Onyx program into an executable.
    run       Compiles and runs an Onyx program, all at once.
    check     Checks syntax and types of an Onyx program.
    package   Package manager
    version   Prints version information

使用

  • vs code 编辑器支持

以前也简单说过onyxlang包含了包管理,编辑器支持,比如我使用vs code 的

  • 简单代码
    app.onyx
 
use core { printf }
 
main :: () {
    // Inferred variable type
    x := 10;
 
    // Function with entirely inferred types.
    change_value :: x => x + 10;
 
    // Onyx figures out the types of `change_value` when you call it.
    printf("The value is {}.\n", change_value(x));
}
  • 构建
onyx build -V -r wasi -DWASIX -o site.wasm  app.onyx

  • 运行
    可以直接使用onyx 或者使用,wasmer runtime
    onyx 模式
 
onyx run app.onyx

wasmer runtime

 
wasmer site.wasm

说明

以上是一个简单的试用,实际上onyx 目前来看还是很强大的,而且支持c-ffi 进行c 库调用

参考资料

https://onyxlang.io/
https://github.com/onyx-lang/onyx
https://wasmer.io/
https://docs.onyxlang.io/book/Overview.html
https://github.com/wasmerio/wasmer