Files
hakorune/docs/guides/language-guide.md
Selfhosting Dev af11c6855b 🚀 Start Phase 15.3: Nyash compiler MVP implementation
Major milestone:
- Set up apps/selfhost-compiler/ directory structure
- Implement basic Nyash compiler in Nyash (CompilerBox)
- Stage-1: Basic arithmetic parser (int/string/+/-/*/括弧/return)
- JSON v0 output compatible with --ny-parser-pipe
- Runner integration with NYASH_USE_NY_COMPILER=1 flag
- Comprehensive smoke tests for PHI/Bridge/Stage-2

Technical updates:
- Updated CLAUDE.md with Phase 15.3 status and MIR14 details
- Statement separation policy: newline-based with minimal ASI
- Fixed runaway ny-parser-pipe processes (CPU 94.9%)
- Clarified MIR14 as canonical instruction set (not 13/18)
- LoopForm strategy: PHI auto-generation during reverse lowering

Collaborative development:
- ChatGPT5 implementing compiler skeleton
- Codex provided LoopForm PHI generation guidance
- Claude maintaining documentation and coordination

🎉 セルフホスティングの歴史的一歩!自分自身をコンパイルする日が近いにゃ!

Co-Authored-By: ChatGPT <noreply@openai.com>
2025-09-15 01:21:37 +09:00

59 lines
2.2 KiB
Markdown

# Nyash Language Guide
Start here to learn Nyash language basics and find deeper references.
- Syntax Cheat Sheet: quick-reference/syntax-cheatsheet.md
- Full Language Reference (2025): reference/language/LANGUAGE_REFERENCE_2025.md
- Phase 12.7 Grammar (peek / ternary / sugar):
- Overview: development/roadmap/phases/phase-12.7/grammar-specs/README.md
- Tokens & Grammar: development/roadmap/phases/phase-12.7/ancp-specs/ANCP-Token-Specification-v1.md
- Sugar transformations (?., ??, |> ...): tools/nyfmt/NYFMT_POC_ROADMAP.md
Common Constructs
- Ternary operator: `cond ? then : else` (Phase 12.7); lowered to If-expression
- Peek expression: `peek value { lit => expr, else => expr }`
- Null-coalesce: `x ?? y``peek x { null => y, else => x }`
- Safe access: `a?.b``peek a { null => null, else => a.b }`
Minimal Examples
- Ternary
```nyash
static box Main {
main(args) {
local a = 3
local b = 5
// Nested ternary is supported
local v = (a < b) ? ((b < 0) ? 40 : 50) : 60
return v
}
}
```
- Peek as expression block (last expression is the value)
```nyash
static box Main {
main(args) {
local d = "1"
// Each arm can be a block; the last expression becomes the value
local dv = peek d {
"0" => { print("found zero") 0 }
"1" => { print("found one") 1 }
else => { print("other") 0 }
}
return dv
}
}
```
must_use Notes
- Peek arms are expressions. When using a block arm `{ ... }`, the last expression is the resulting value; statements without a final expression yield no usable value.
- Ternary is an expression; ensure both branches are type-compatible at MIR level (e.g., both yield integer or both yield string handle in current phase).
When you need the implementation details
- Tokenizer: src/tokenizer.rs
- Parser: src/parser/expressions.rs, src/parser/statements.rs
- Lowering to MIR: src/mir/builder/**
Statement Separation (Semicolons)
- Newline separates statements by default; semicolons are optional.
- Use semicolons only when placing multiple statements on one line.
- Minimal ASI rules: newline does not end a statement when the line ends with an operator/dot/comma, or while inside grouping.