4 个版本
使用旧的 Rust 2015
0.2.2 | 2018 年 12 月 28 日 |
---|---|
0.2.1 | 2018 年 12 月 28 日 |
0.2.0 | 2018 年 12 月 28 日 |
0.1.0 | 2018 年 12 月 12 日 |
#900 在 编程语言
235KB
6K SLoC
tin

tin
是一种新的静态结构化编程语言。其主要目的是嵌入到其他程序中(例如 Lua),但设计得易于编译(最初为 JIT)。
tin
是您创建应用程序插件所需的工具。使用 tin
,您可以轻松构建类型安全的插件 API。
尽管 tin 的化学符号是 Sn
,但 tin
文件传统上使用 .tn
扩展名,因为它更容易记忆。
目前,该语言仍在开发中。最小可行产品(MVP)将是一个名为 tin
的 Rust 库和可执行文件,包括 JIT 编译器和基本的类型推断。
示例
tin
完全面向表达式;没有类型本身。为了定义类型,您为该类型提供一个示例值。这与基于原型的类型系统非常相似,但没有任何继承支持。
/* Defines the Int type by giving an example value */
Int = 0i64;
/* Similarly for String */
String = "";
/* A Person is anything that has both a name of type String and an age of type Int
* The definintion is identical to: { name: "", age: 0i64 }
*/
Person = { name: String, age: Int };
一切要么是表达式,要么是变量定义。例如,没有函数;只有可以分配给变量的 lambda 表达式
getAge = |person: Person|: Int { person.age };
tin
支持结构化多态类型推断
getAge = |person| { person.age };
main = || {
getAge({age: 3}); /* → returns 3 */
getAge({age: "Hello"}); /* → returns "Hello" */
getAge({name: "Hello"}) /* compile time error */
};
tin
有几个内置类型
/* An unsigned 8-bit integer */
U8 = 0u8;
/* An unsigned 16-bit integer */
U16 = 0u16;
/* An unsigned 32-bit integer */
U32 = 0u32;
/* An unsigned 64-bit integer */
U64 = 0u64;
/* A signed 8-bit integer */
I8 = 0i8;
/* A signed 16-bit integer */
I16 = 0i16;
/* A signed 32-bit integer */
I32 = 0i32;
/* A signed 64-bit integer */
I64 = 0i64;
/* A 32 bit floating point number */
F32 = 0.0f32;
/* A 64 bit floating point number */
F64 = 0.0f64;
/* An UTF-8 string */
String = "";
/* A tuple */
ExampleTuple = (String, I8, I8);
/* A record */
ExampleRecord = { name: String, x: I8, y: I8 };
/* A lambda */
ExampleLambda = |tuple: ExampleTuple, record: ExampleRecord, int: I8|: I8 { int };
依赖关系
~15–25MB
~376K SLoC