Code Monkey home page Code Monkey logo

tu's Introduction

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's People

Contributors

brewlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tu's Issues

在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

怎么方便接入其他语言的生态

作者想法非常好,我也是想要动态语言+静态语言的组合。之前是看到dart,不过还是有虚拟机。
作者有没有考虑怎么和已有生态结合,重新造轮子代价太大。另外凸语言有没有一个切入点,打造一个杀手级应用。

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.