crystal 的语法受到 ruby 语言的启发,属于编译语言,具有静态类型检查功能,但一般不需要指定变量或方法参数的类型,可实现接近 c/c++ 的性能。它的类型由一个先进的全局类型推理算法来解决。

最新发布的版本包含错误修复和功能改进,涉及到编译器、代码生成、调试器、解析器、语义、语法、标准库、加密、网络、运行时和语法宏等方面,详情查看 release note。

部分亮点

系统调用(syscalls)

添加了一个实验性 api 来创建原生系统调用 (#10777)。目前仅支持 linux。这是支持 linuxio_uring接口以提高 io 性能的第一步。

如需定义系统调用,请打开一个模块并使用syscall.def_syscall宏。如以下示例所示,需要传入系统调用名称、返回类型及其参数。

require "syscall"

module mysyscalls
  syscall.def_syscall write, int32, fd : int32, buf : uint8*, count : libc::sizet
end

data = "hello!\n"
mysyscalls.write(1, data.to_unsafe, libc::sizet.new(data.size))

支持 128 位字面量

通过改进解析器,现在可以理解完整范围内的数字文字或 128 位整数 (#11571)。到目前为止,仅在 64 位值的范围内支持 128 位文字。

1_i128                                       # works in 1.2.2 and 1.3.0
170141183460469231731687303715884105727_i128 # fails in 1.2.2, works in 1.3.0
1_.1   # error: unexpected '_' in number
-0u64  # error: invalid negative value -0 for uint64
-0_u64 # error: invalid negative value -0 for uint64
1__2   # error: consecutive underscores in numbers aren't allowed
0x_2   # error: unexpected '_' in number
0_12   # error: octal constants should be prefixed with 0o
0e40   # => 0.0
0x     # error: numeric literal without digits

详细更新说明点此查看。

以上就是crystal最新发布v1.3.0语法相似ruby编译型编程语言的详细内容,更多关于crystal最新发布v1.3.0的资料请关注www.887551.com其它相关文章!