feat: connect source compilation and VM execution
Verify databases and deploy Aster VM / verify-and-deploy (push) Successful in 7m56s
Verify databases and deploy Aster VM / verify-and-deploy (push) Successful in 7m56s
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
# 可执行 Endor 示例
|
||||
|
||||
这些 UTF-8 文件由 compiler 和 CLI 集成测试直接使用;运行只在指定远端环境进行,本地不运行。
|
||||
|
||||
| 文件 | 输入模式与预期结果 |
|
||||
| --- | --- |
|
||||
| [hello.endor](hello.endor) | run;main 返回“你好,Endor 🌱” |
|
||||
| [calls.endor](calls.endor) | run;前向函数引用、参数和 let,返回“函数调用已接通” |
|
||||
| [shadowing.endor](shadowing.endor) | run;参数遮蔽全局函数名并传递函数值,返回“局部名称优先” |
|
||||
| [number.endor](number.endor) | run;返回无损负十进制常量 -123456789012345678901234567890.00100 |
|
||||
| [literal.endor](literal.endor) | eval;返回“表达式 → 字节码 → VM” |
|
||||
|
||||
```sh
|
||||
cli run crates/compiler/examples/hello.endor
|
||||
cli run crates/compiler/examples/calls.endor
|
||||
cli run crates/compiler/examples/shadowing.endor
|
||||
cli run crates/compiler/examples/number.endor
|
||||
cli eval crates/compiler/examples/literal.endor
|
||||
```
|
||||
|
||||
run 默认调用无参数 main,可用 --entry name 选择另一个无参数入口;eval 解析一个完整表达式,二者都支持 - 读取 stdin 到 EOF。类型名称暂只保留语法,Callable 不要求预先注册语言类。例子不依赖 print 或其他默认标准库。编译器尚无算术运行语义;前端 basic.endor 含算术,只是解析示例,不能混作可执行示例。规则见 [编译契约](../../../docs/runtime/compiler.md),返回 [compiler](../README.md)。
|
||||
@@ -0,0 +1,13 @@
|
||||
// The callee is declared after main. Parameters, locals and calls use wordcode.
|
||||
function main(): String {
|
||||
let message = echo("函数调用已接通")
|
||||
return relay(message)
|
||||
}
|
||||
|
||||
function relay(value: String): String {
|
||||
return echo(value)
|
||||
}
|
||||
|
||||
function echo(value: String): String {
|
||||
return value
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// cli run crates/compiler/examples/hello.endor → 你好,Endor 🌱
|
||||
function main(): String {
|
||||
return "你好,Endor 🌱"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// cli eval crates/compiler/examples/literal.endor
|
||||
"表达式 → 字节码 → VM"
|
||||
@@ -0,0 +1,5 @@
|
||||
// Signed decimal constants retain all digits; no f64 conversion or arithmetic.
|
||||
function main(): Number {
|
||||
let value = -123456789012345678901234567890.00100
|
||||
return value
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// A parameter can shadow a module function, and functions are ordinary values.
|
||||
function echo(value: String): String {
|
||||
return value
|
||||
}
|
||||
|
||||
function invoke(echo: Callable, value: String): String {
|
||||
let chosen = echo
|
||||
return chosen(value)
|
||||
}
|
||||
|
||||
function main(): String {
|
||||
return invoke(echo, "局部名称优先")
|
||||
}
|
||||
Reference in New Issue
Block a user