sonolus-go

module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT

README

sonolus-go

全 Go 语言实现的 Sonolus 引擎编译工具链。

将 Go 源代码子集编译为 Sonolus 可加载的 EngineData(EngineConfiguration + EnginePlayData / EngineWatchData / EnginePreviewData / EngineTutorialData), 支持四种模式完整打包与本地开发服务器。

安装

GitHub Releases 下载预编译二进制,无需 Go 环境。

或从源码编译(需 Go 1.25+,依赖自动拉取):

git clone https://github.com/WindowsSov8forUs/sonolus-go.git
cd sonolus-go
go build ./cmd/sonolus-go/
开发
go build ./...    # 编译
go test ./...     # 测试
go vet ./...      # 静态分析

架构

Go源文件 (.go)
  │
  ▼ compiler/frontend     ← go/parser + go/types 类型检查 + AST 追踪 → IR
  │
  ▼ compiler/ir/optimize  ← CFG/SSA 优化器 (~40 个 pass: SCCP/LICM/CSE/...)
  │
  ▼ compiler/ir/finalize  ← 寄存器分配 + 指令扁平化
  │
  ▼ compiler/snode        ← 运行时节点树 (SNode) + 去重 + 序列化
  │
  ▼ compiler/{play,watch,preview,tutorial} + compiler/modecompile
  │                       ← 四模式装配 + 回调 body 合成
  │
  ▼ compiler/build        ← EngineData 包装 + ROM
  │
  ▼ compiler/pack         ← sonolus-pack 源树输出
  │
  ▼ cmd/sonolus-go        ← CLI: build / serve / host / pack / level

命令行

# 编译单一模式
sonolus-go build -m play ./engine/

# 编译全部四种模式
sonolus-go build -m all ./engine/

# 本地开发服务器 (带热编译,自动编译四种模式)
sonolus-go serve ./engine/

# 生产模式打包 + 服务
sonolus-go host ./engine/ -author "YourName"

详见 快速入门CLI 参考

参照项目

  • sonolus.js — 引擎 DSL 标准库(TypeScript 运行时)
  • sonolus.js-compiler — JS → 引擎节点编译器(结构参照)
  • sonolus.py — Python 实现 / 性能目标(45k LOC,最完整)

许可

MIT

Directories

Path Synopsis
cmd
sonolus-go command
sonolus-go is the Go implementation of the sonolus engine compiler.
sonolus-go is the Go implementation of the sonolus engine compiler.
internal
compiler/build
Package build packages compiled engine data into the on-disk Sonolus file layout: each datum is gzip-compressed, mirroring sonolus.py's package_data / PackagedEngine.write.
Package build packages compiled engine data into the on-disk Sonolus file layout: each datum is gzip-compressed, mirroring sonolus.py's package_data / PackagedEngine.write.
compiler/engine
Package engine is the top-level integration layer: it compiles a Go-authored engine description end-to-end into Sonolus EngineData.
Package engine is the top-level integration layer: it compiles a Go-authored engine description end-to-end into Sonolus EngineData.
compiler/frontend
Package frontend is the frontend compilation stage.
Package frontend is the frontend compilation stage.
compiler/ir
Package ir is the compiler's mid-level intermediate representation: a statement-level CFG of BasicBlocks holding IR nodes.
Package ir is the compiler's mid-level intermediate representation: a statement-level CFG of BasicBlocks holding IR nodes.
compiler/ir/optimize
Package optimize holds CFG optimization passes, ported from sonolus.py's sonolus/backend/optimize.
Package optimize holds CFG optimization passes, ported from sonolus.py's sonolus/backend/optimize.
compiler/level
Package level compiles and packages Sonolus levels (charts).
Package level compiles and packages Sonolus levels (charts).
compiler/modecompile
Package modecompile contains shared compilation helpers used by the play, watch, and preview mode packages.
Package modecompile contains shared compilation helpers used by the play, watch, and preview mode packages.
compiler/pack
Package pack provides the adapter layer between sonolus-go's compiler output and sonolus-pack-go's source tree input.
Package pack provides the adapter layer between sonolus-go's compiler output and sonolus-pack-go's source tree input.
compiler/play
Package play compiles and assembles Play-mode engine data.
Package play compiles and assembles Play-mode engine data.
compiler/preview
Package preview compiles and assembles Preview-mode engine data.
Package preview compiles and assembles Preview-mode engine data.
compiler/snode
Package snode defines the final SNode representation — the output layer of the compiler pipeline.
Package snode defines the final SNode representation — the output layer of the compiler pipeline.
compiler/tutorial
Package tutorial compiles and assembles Tutorial-mode engine data.
Package tutorial compiles and assembles Tutorial-mode engine data.
compiler/watch
Package watch compiles and assembles Watch-mode engine data.
Package watch compiles and assembles Watch-mode engine data.
Package sonolus provides the type declarations and runtime function stubs for Sonolus engine DSL.
Package sonolus provides the type declarations and runtime function stubs for Sonolus engine DSL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL