提交 84fe5863 编写于 作者: G github-actions[bot]

deploy: b57b736a

上级
# 代码风格(仅参考)
为了便于调试,不同的模块可以在 config 包增加 Trace 开关,然后针对每个返回 err 的地方输出日志。
比如 `config.EnableTrace_loader` 标注 loader 模块:
```go
logger.Trace(&config.EnableTrace_loader, "import "+manifest.MainPkg)
if _, err := p.Import(manifest.MainPkg); err != nil {
logger.Tracef(&config.EnableTrace_loader, "err: %v", err)
return nil, err
}
```
# 凹语言™项目目标
本项目的发起人(柴树杉、丁尔男、史斌)均是Gopher,在开发实践中,因为不同的原因,先后萌生了发展一门新语言的想法,Go 语言克制的风格是我们对于编程语言审美的最大公约数,因此选择它作为初始的蓝本。不必讳言:本项目启动时大量借鉴了 Go 的设计思想和具体实现——这是在有限投入下不得不作出的折衷,我们希望随着项目的发展,积累更多原创的设计,为自主创新的大潮贡献一点力量。
纵观编程界,没有哪门被广泛使用的通用语言诞生于KPI制度之下。本项目作为个人业余项目,不存在明确的指标,从成果分类的角度,我们希望在第一阶段完成以下目标:
- 确定凹语言™语法规则
- 实现可用的凹语言™编译器
- 使用凹语言™创建一个网页应用
---
## 凹语言™特性——预期
凹语言™包含两套相互等价的语法:凹语法与 WaGo 语法,这里“等价”的含义是:二者可生成相同的AST并无损的互相转换。使用凹语法编写的源文件后缀为 `.wa`,使用 WaGo 语法编写的源文件后缀为 `.wa.go`。WaGo 语法是 Go 语法的真子集,换句话说:一个合法的 WaGo 包必然是合法的 Go 包。
网页应用是我们很重视的目标场景,这与 Go 语言把服务端作为主战场截然不同,WaGo 裁减掉的部分多半与此相关:
* WaGo 没有 `go` 关键字,不支持goroutine/并发
* WaGo 没有 `chan` 关键字,不支持与之相关的管道操作
* WaGo 没有全局GC——但**可能**会提供自动RC以尽可能简化内存管理
* WaGo 没有内置标准库——即使有,规模也极其有限
WaGo 的数据类型如下表:
|字符串(string)|数组(array)|切片(slice)|复数(complex)|哈希表(map)|结构体(struct)|
|:-:|:-:|:-:|:-:|:-:|:-:|
|有|有|有|可能有|可能有|有|
WaGo 的其他特性如下表:
|多返回值|方法|方法值|接口|闭包|反射|
|:-:|:-:|:-:|:-:|:-:|:-:|
|有|有|可能无|有|可能有|可能有|
> 各特性的实现可能性从高到底排列为:有 > 可能无 > 可能有 > 无
通过以上描述,大致可以勾勒出 WaGo 的轮廓。凹语法在AST层面与 WaGo 等价的同时,最显著的变化是增加了中文关键字。对于凹语法将来的发展,我们持开放态度。
---
## 凹编译器实现——路线
凹编译器的工作过程如下图所示:
```mermaid
graph LR
wa_ext(.wa);
wago_ext(.wa.go);
wa_ast(Wa AST);
c_cpp(C/C++);
llir(LLVM IR);
wasm(WASM);
wa_ext --> wa_ast;
wago_ext --> wa_ast;
wa_ast --> c_cpp;
wa_ast --> llir;
wa_ast --> wasm;
```
凹编译器支持 C/C++、LLVM IR、WASM 等多种输出以满足不同的目标场景。当前阶段的主要任务:
- 创建编译器框架
- 确定前中后端模块间的接口
- 设计能满足语法特性基线的运行时模型
每种后端的进度互相独立,但显然目标代码越底层,需要考虑的细节也越多,因此在落地语法特性时,采用先高级目标后低级目标的顺序有利于问题的逐步降解。
各后端可能的应用场景:
- C/C++:凹语言™与 C/C++ 混合开发
- LLVM IR:直接编译为Native Code
- WASM:直接编译为WebAssembly模块
当任一后端模块覆盖“可用最小集”,我们将尝试开发一些简单的网页示例,待选的方向有交互式图形图像、在线编译等。
---
2022.7.23
\ No newline at end of file
<!--
// 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang
-->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400" width="400" height="400" fill="none">
<path fill-rule="evenodd" clip-rule="evenodd" d="M50 70C50 58.9543 58.9543 50 70 50H130C141.046 50 150 58.9543 150 70V74V130V150H250V130V74V70C250 58.9543 258.954 50 270 50H330C341.046 50 350 58.9543 350 70V94V130V330C350 341.046 341.046 350 330 350H70C58.9543 350 50 341.046 50 330V130V94V70Z" fill="blue" />
<circle cx="100" cy="100" r="5" stroke="black" stroke-width="0" fill="white">
<animate attributeName="r" values="0;5;5;0" dur="1s" repeatCount="1" />
</circle>
<circle cx="300" cy="100" r="5" stroke="black" stroke-width="0" fill="white">
<animate attributeName="r" values="0;5;5;0" dur="1s" repeatCount="1" />
</circle>
<path d="M200 230L234 264L268 230M200 230L166 264L132 230" stroke="white" stroke-width="8" stroke-linecap="round" stroke-dasharray="0,0,0,192">
<animate attributeType="XML" attributeName="stroke-dasharray" values="0,0,0,192;0,96,96,0; 192,0,0,0" keyTimes="0; 0.5;1" fill="freeze" dur="1.5s" repeatCount="1" />
</path>
</svg>
\ No newline at end of file
<!--
// 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang
-->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400" width="400" height="400" fill="none">
<path fill-rule="evenodd" clip-rule="evenodd" d="M50 70C50 58.9543 58.9543 50 70 50H130C141.046 50 150 58.9543 150 70V74V130V150H250V130V74V70C250 58.9543 258.954 50 270 50H330C341.046 50 350 58.9543 350 70V94V130V330C350 341.046 341.046 350 330 350H70C58.9543 350 50 341.046 50 330V130V94V70Z" fill="LightSeaGreen" />
<circle cx="100" cy="100" r="5" stroke="black" stroke-width="0" fill="white">
<animate attributeName="r" values="0;5;5;0" dur="1s" repeatCount="1" />
</circle>
<circle cx="300" cy="100" r="5" stroke="black" stroke-width="0" fill="white">
<animate attributeName="r" values="0;5;5;0" dur="1s" repeatCount="1" />
</circle>
<path d="M200 230L234 264L268 230M200 230L166 264L132 230" stroke="white" stroke-width="8" stroke-linecap="round" stroke-dasharray="0,0,0,192">
<animate attributeType="XML" attributeName="stroke-dasharray" values="0,0,0,192;0,96,96,0; 192,0,0,0" keyTimes="0; 0.5;1" fill="freeze" dur="1.5s" repeatCount="1" />
</path>
</svg>
\ No newline at end of file
<!--
// 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang
-->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400" width="400" height="400" fill="none">
<path fill-rule="evenodd" clip-rule="evenodd" d="M50 70C50 58.9543 58.9543 50 70 50H130C141.046 50 150 58.9543 150 70V74V130V150H250V130V74V70C250 58.9543 258.954 50 270 50H330C341.046 50 350 58.9543 350 70V94V130V330C350 341.046 341.046 350 330 350H70C58.9543 350 50 341.046 50 330V130V94V70Z" fill="LightSeaGreen">
<animateMotion path="M 0 0 v 30 Z" dur="0.8s" repeatCount="indefinite" />
</path>
<path stroke="none" fill="white" d="M100,100 m-5,-5 h10 v10 h-10">
<animateMotion path="M 0 0 v 30 Z" dur="0.8s" repeatCount="indefinite" />
</path>
<path stroke="none" fill="white" d="M400,100 m-100,0 m-5,-5 h10 v10 h-10">
<animateMotion path="M 0 0 v 30 Z" dur="0.8s" repeatCount="indefinite" />
</path>
<path stroke="white" fill="none" stroke-width="8" stroke-linecap="round" d="M200,230 l34,34 l34,-34 M200,230 l-34,34 l-34,-34">
<animateMotion path="M 0 0 v 30 Z" dur="0.8s" repeatCount="indefinite" />
</path>
</svg>
<!--
// 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang
-->
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 400 400" width="400" height="400"
style="border: 0px solid red"
>
<path
stroke="none" fill="LightSeaGreen"
d="M60,50 h90 v100 h100 v-100 h90 l10,10 v280 l-10,10 h-280 l-10,-10 v-280"
/>
<path
stroke="none" fill="white"
d="M100,100 m-5,-5 h10 v10 h-10"
/>
<path
stroke="none" fill="white"
d="M400,100 m-100,0 m-5,-5 h10 v10 h-10"
/>
<path
stroke="white" fill="none" stroke-width="8" stroke-linecap="round"
d="M200,230 l34,34 l34,-34 M200,230 l-34,34 l-34,-34"
/>
</svg>
<!--
// 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang
-->
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 400 400" width="400" height="400"
style="border: 0px solid red"
>
<path
stroke="none" fill="blue"
d="M60,50 h90 v100 h100 v-100 h90 l10,10 v280 l-10,10 h-280 l-10,-10 v-280"
/>
<path
stroke="none" fill="white"
d="M100,100 m-5,-5 h10 v10 h-10"
/>
<path
stroke="none" fill="white"
d="M400,100 m-100,0 m-5,-5 h10 v10 h-10"
/>
<path
stroke="white" fill="none" stroke-width="8" stroke-linecap="round"
d="M200,230 l34,34 l34,-34 M200,230 l-34,34 l-34,-34"
/>
</svg>
<!--
// 版权 @2019 凹语言 作者。保留所有权利。
// https://github.com/wa-lang
-->
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 400 400" width="400" height="400"
style="border: 0px solid red"
>
<path
stroke="none" fill="blue"
d="M50,50 h100 v100 h100 v-100 h100 v300 h-300"
/>
<path
stroke="none" fill="white"
d="M100,100 m-5,-5 h10 v10 h-10"
/>
<path
stroke="none" fill="white"
d="M400,100 m-100,0 m-5,-5 h10 v10 h-10"
/>
<path
stroke="white" fill="none" stroke-width="8" stroke-linecap="round"
d="M200,230 l34,34 l34,-34 M200,230 l-34,34 l-34,-34"
/>
</svg>
+---+ +---+
| o | | o |
| +----+ |
| |
| \/\/ |
| |
+------------+
+---+ +---+
| o | | o |
| +----+ |
| |
| 1024 |
| |
+------------+
https://wa-lang.org
文件已添加
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册