代码拉取完成,页面将自动刷新
tu-lang(凸)是一种编程语言,旨在创造一种非常简单的零依赖、支持动态&&静态语法的编译型语言,全静态链接,目前已自举完成: compiler纯动态语法,asmer纯静态语法,linker动静混合语法
.
tu [options] file.tu
build *.tu 编译成汇编后进行链接生成二进制可执行文件
-s *.tu|dir 编译为tulang代码为linux-amd64汇编文件
-c *.s |dir 编译汇编为elf&pecoff跨平台可重定向cpu指令集文件
-o *.o |dir 链接elf&pecofff可重定向文件生成最终执行程序
-d 开启trace日志打印编译详细过程
-gcc 支持通过gcc链接生成最终可执行程序
-g 编译tu文件时带上debug段信息,支持栈回溯
-std 编译runtime&std相关内置库代码
linux
: 环境安装
$ git clone https://github.com/tu-lang/tu.git
$ cd tu
$ sudo make install
更多语法测试用例在/tests
目录下,包含了各种数据结构、运算、gc、demo测试
$ cd tu
$ sudo make install
$ make tests
更多用例请看/tests
use fmt
class Http {
request
fn handler(){
fmt.println("hello world!",this.request)
}
}
Http::closure(){
return fn(){
return ["arr1","arr2",3,4]
}
}
fn main(){
a = "this is a string" #string
a = 1000 # int
fmt.println(a,b)
a = ["1",2,"33",4,"some string word"] // array
fmt.print(a[0],a[1],a[2],a[3],a[4])
b = {"sdfds":"sdfsd",1:2,"sdfds":3,"a":a} // map
fmt.print(b["a"],b["sdfds"])
obj = new Http() # object
obj.request = {"method":"POST"}
obj.handler()
cfunc = obj.closure()
fmt.println(cfunc())
}
use fmt
use os
fn main(){
map = { "1":'a' , "hello":"world" , 3:5.11 , "arr": [ 0,1,2,3,4] }
for k,v : map {
if k == "arr" {
for v2 : v {}
}
fmt.println(k,v)
}
match map["hello"] {
map : os.die("not this one!")
999 : os.die("not this one!")
"hello" | "world": {
fmt.println("got it",map["hello"])
}
_ : {
os.die("not default")
}
}
}
更多用例请看/tests
enum {
Insert,
Update
Conflict,
}
mem Rbtree {
RbtreeNode* root
RbtreeNode* sentinel
u64 insert
}
mem RbtreeNode {
u64 key
u8 color
RbtreeNode* left
RbtreeNode* right
RbtreeNode* parent
runtime.Value* k
runtime.Value* v[Conflict]
}
Rbtree::find(hk<u64>){
node<RbtreeNode> = this.root
sentinel<RbtreeNode> = this.sentinel
while node != sentinel
{
if hk != node.key {
if hk < node.key {
node = node.left
}else{
node = node.right
}
continue
}
}
return Null
}
Copyright @2016-2024 The tu-lang author. All rights reserved.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型