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
- 动态类型 int float string bool null array map closure object
- 原生类型 pointer i8 u8 i16 u16 i32 u32 i64 i64 f32 f64 struct
- func,goto,class,mem
- return,type,use,if,continue,break
- while,for|range for,loop,match
- async await
更多用例请看/tests
use fmt
class Http {
request
}
Http::closure(){
return fn(){
return ["arr1","arr2",3,4]
}
}
fn factory(){
a = ["1",2,"some string word"] // array
b = {1:2,"sdfds":3,"a":a} // map
return a,b
}
fn main(){
a = "this is a string" // string
b,c = 1000,200.33 // number
fmt.println(a,b,c)
a,b = factory()
fmt.print(a[0],a[1],a[2])
fmt.print(b["a"],b["sdfds"])
obj = new Http() // object
obj.request = {"method":"POST"}
cfunc = obj.closure() // member
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
use runtime
Null<i64> = 0
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
}
fn main(){}
async(无栈协程)
use fmt
use runtime
use os
mem ReadStream: async {
i32 bytes
i32 readn
i32 fd
}
ReadStream::poll(){
if this.readn != this.bytes {
this.readn += 1
return runtime.PollPending
}
match this.fd {
1 : return runtime.PollReady , "hello "
2 : return runtime.PollReady , "world"
_ : os.die("")
}
}
async read(){
fut<ReadStream> = new ReadStream { fd: 1, bytes: 5 }
buf += fut.await
fut2<ReadStream> = new ReadStream { fd: 2, bytes: 5 }
buf += fut2.await
return buf
}
fn main(){
body = runtime.block(read())
fmt.println(body)
}
Copyright @2016-2024 The tu-lang author. All rights reserved.
tu's People
tu's Issues
How to debug tu binary
Exciting project!
I just built a simple hello.tu.
use fmt
func main() {
fmt.println("Hello World")
}
then run tu build hello.tu
I got the a.out
file
My question is how to debug the a.out
.
more specifically,
- how to add a breakpoint
- how to watch local variable
- etc
Thanks.
怎么方便接入其他语言的生态
作者想法非常好,我也是想要动态语言+静态语言的组合。之前是看到dart,不过还是有虚拟机。
作者有没有考虑怎么和已有生态结合,重新造轮子代价太大。另外凸语言有没有一个切入点,打造一个杀手级应用。
在Windows用mingw编译应该如何修改Makefile文件?
MINGW64 /d/softinstall/tulang/tu
$ mingw32-make
environment: line 1: tu: command not found
rm: cannot remove 'a.tu.s': No such file or directory
environment: line 1: tu: command not found
D:\msys64\mingw64\bin\ar.exe: *.o: Invalid argument
mv: cannot stat '*.o': No such file or directory
install liba to /usr/local/lib/colib success
合作交流
作者可否加微信交流一下?想进行合作交流!
https://work.weixin.qq.com/u/vc8a6d0ffea1ff8bc1?v=4.1.6.125550
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.