1 Star 2 Fork 0

PLOC / 凸语言

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

The Tu Programming Language

文档手册:筹备中

GitHub code size in bytes GitHub release (latest by date including pre-releases) GitHub top language

logo

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相关内置库代码

demo

gif

env & install

linux: 环境安装

$ git clone https://github.com/tu-lang/tu.git
$ cd tu
$ sudo make install

compiler&asmer&linker测试

更多语法测试用例在/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

@动态写法

更多用例请看/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
}

License

Copyright @2016-2024 The tu-lang author. All rights reserved.

空文件

简介

tu-lang 是一种动态类型编译型的通用编程语言, 已实现自举 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/ploc-org/tulang.git
git@gitee.com:ploc-org/tulang.git
ploc-org
tulang
凸语言
main

搜索帮助