#embeddable #jit #jit-compiler #structural-typing #language

bin+lib tin

tin: 一种静态结构化嵌入式编程语言

1 个不稳定版本

0.3.0 2019年1月7日
0.0.6 2016年6月12日
0.0.5 2016年5月21日
0.0.2 2016年2月10日

#jit-compiler 中排名 4

Download history 13/week @ 2023-10-29 2/week @ 2023-11-05 10/week @ 2023-11-12 4/week @ 2023-11-19 22/week @ 2023-11-26 3/week @ 2023-12-03 1/week @ 2023-12-10 8/week @ 2023-12-17 14/week @ 2023-12-24 1/week @ 2023-12-31 3/week @ 2024-01-07 7/week @ 2024-01-14 7/week @ 2024-01-21 13/week @ 2024-01-28 1/week @ 2024-02-04 31/week @ 2024-02-11

每月下载量 56

MIT 许可证

335KB
9K SLoC

tin CircleCI codecov

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 */
ExampleU8 = 0u8;
/* An unsigned 16-bit integer */
ExampleU16 = 0u16;
/* An unsigned 32-bit integer */
ExampleU32 = 0u32;
/* An unsigned 64-bit integer */
ExampleU64 = 0u64;

/* A signed 8-bit integer */
ExampleI8 = 0i8;
/* A signed 16-bit integer */
ExampleI16 = 0i16;
/* A signed 32-bit integer */
ExampleI32 = 0i32;
/* A signed 64-bit integer */
ExampleI64 = 0i64;

/* A 32 bit floating point number */
ExampleF32 = 0.0f32;
/* A 64 bit floating point number */
ExampleF64 = 0.0f64;

/* An UTF-8 string */
ExampleString = "";

/* A symbol value */
ExampleSymbol = :foo;

/* 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 };

依赖项

~17MB
~330K SLoC