- ✨ 语法简单,易学易用
- ⚡ 语法高效,编译速度快
- 📦 内存占用小
- 🎃 跨平台编译
- 🎈 国际化支持 (英,中文)
- Windows
- Linux Ubuntu
- MacOS
fn main() {
print("Hello, World!")
}
main()
use 'chinese'
遍历 变量 在 范围(2) {
输出(变量, "hi")
尝试 {
输出(变量位置, "hi")
} 捕获 {
输出("报错:", error)
}
}
0 hi 报错: ReferenceError(type="ReferenceError", message="Variable 变量位置 not defined", line=7, column=15) 1 hi 报错: ReferenceError(type="ReferenceError", message="Variable 变量位置 not defined", line=7, column=15) 2 hi 报错: ReferenceError(type="ReferenceError", message="Variable 变量位置 not defined", line=7, column=15)
a = 1024
a += 2
a -= 4
a *= 8
a **= 12
a /= 16
b = a + 1
fn add(a, b) {
return a + b
}
fn main() {
print("Hello, World!")
return add(1, 2)
}
if val > 10 {
print("val > 10")
} elif val < 10 {
print("val < 10")
} else {
print("val = 10")
}
if condition {
print("condition")
}
if n + 1 != 0 && n {
print("n & (n + 1) != 0")
}
for i in range(0, 10) {
print(i)
}
n = 0
while n < 10 {
print(n)
n += 1
}
arr = [1, 2, 3, 4, 5]
for i in arr {
...
}
for i in ["hello", "world"] {
print(i)
}
for i in range(1,10,2) {
try {
print(id)
} catch {
print("a", error, "b")
}
}
$ kylin test.ky a ReferenceError(message="Variable id not defined", type="ReferenceError", line=3, column=22) b a ReferenceError(message="Variable id not defined", type="ReferenceError", line=3, column=22) b a ReferenceError(message="Variable id not defined", type="ReferenceError", line=3, column=22) b a ReferenceError(message="Variable id not defined", type="ReferenceError", line=3, column=22) b a ReferenceError(message="Variable id not defined", type="ReferenceError", line=3, column=22) b a ReferenceError(message="Variable id not defined", type="ReferenceError", line=3, column=22) b
kylin main.ky
.ky 后缀可省略
kylin server
fn
函数if
条件判断else
条件判断for
循环in
循环while
循环return
返回true
真false
假null
空try
异常截获catch
异常截获break
跳出循环continue
跳过本次循环import
导入use
国际化导入语言包
print
打印input
输入str
字符串int
整数float
浮点数bool
布尔值array
数组range
范围len
长度sum
求和max
最大值min
最小值abs
绝对值all
全部为真any
任意为真join
连接字符串split
分割字符串type
类型time
时间 (ms)sleep
阻塞等待 (ms)timenano
CPU 时间 (ns)read
读取文件write
写入文件shell
执行 shell 命令exit
退出程序
- Lexer 编译 AST 语法树
- 词法分析器使用递归下降进行语法分析
- 动态解释器
- 编译器使用 Golang SSA 进行编译
n = 0
val = 2345
t = time()
while n < 9999999 {
n += 1
val **= 1289
val = n * 999
}
print(time() - t, "ms")
- C (GCC)
891.9ms
- Golang
1012.5ms
- NodeJS
1170.0ms
- Kylin Go
1751.2ms
- Python
4681.8ms
n = 0
while n < 1000000 {
n += 1
print('hello world')
}
- C (GCC)
0.9 MB
- Golang
3.2 MB
- Kylin Go
8 MB
- Node
10 MB
- Python
14MB
- Kylin JVM
84MB
- C ❌
- Golang ❌
- Kylin Go ❌
- NodeJS ❌
- Python ❌
- Kylin JVM ✔
C 语言
#include <stdio.h>
int main() {
int n = 0;
while (n < 1000000) {
n++;
printf("hello world\n");
}
return 0;
}
Golang
package main
import "fmt"
func main() {
n := 0
for n < 1000000 {
n++
fmt.Println("hello world")
}
}
Kylin Go
n = 0
while n < 1000000 {
n += 1
print('hello world')
}
Kylin JVM
var n = 0
while n < 1000000 {
n = <n + 1>
out('hello world')
}
NodeJS
let n = 0;
while (n < 1000000) {
n++;
console.log('hello world');
}
Python
n = 0
while n < 1000000:
n += 1
print('hello world')