feat: draft new spec#2
Open
Allianaab2m wants to merge 9 commits into
Open
Conversation
- 0011: rewrite error handling around `throws E` clause, `throw` expr, `?` propagation, and `try`/`catch`; drop built-in Result - 0008: add `throws E` clause to function types - 0009: clarify throws is a separate channel from the effect row - 0003/0005/0010: align examples with throws-based errors - rename 0010-typed-ir.md to 0012-typed-ir.md to resolve number clash
Specify the boundary where capability effects (0009) are resolved by the runtime. Platform functions are a language-defined interface; Emela declares them with `extern fn` (matching the interface) and holds no implementation, each backend provides a subset, and an executable that requires a platform function the target does not provide is rejected. Cross-reference from 0009 and list 0013 in the README drafts.
- 0001: define Never as the bottom type — no value, assignable to any expected type, and the type of throw/panic - 0011: note throws Never is equivalent to non-throwing, and require the entrypoint main's throws to be Never
Snapshot the in-progress generics draft and list it in the README drafts.
Specify the language primitives needed to write `to_string` in pure Emela:
- 0015: `if cond { } else { }` as an expression (else required, branches unify).
- 0016: `/` and `%` (Int truncates toward zero, `%` Int-only, division by zero
traps; Float `/` is real division).
- 0017: a `Char` type with `'x'` literals, `++` string concatenation, and the
pure conversions `Char.from_code` / `String.from_char` (language built-ins,
not platform functions). WASM `String.from_char` is ASCII-only for now.
Index them in the README.
Imported functions become callable by any suffix of their import path (bare, leaf-qualified, or fully qualified). Multiple imports may bind the same bare name; collisions are resolved at the use site, not at import time. Specifies the resolution rules R1–R6 and resolution precedence, and extends spec 0010.
Define the `|>` pipeline operator: `lhs |> f(a, b)` inserts the left operand as the first argument (`f(lhs, a, b)`), lowest precedence, left-associative, with a trailing `?` applied after insertion. It is a pure desugaring to a call, so the IR and backends are unchanged (Compilation Notes).
There was a problem hiding this comment.
Pull request overview
This PR refreshes and reorganizes the Emela language specification drafts to better match the direction of targeting WASM/WAMR, replacing older monolithic drafts with a newer, renumbered set of smaller specs.
Changes:
- Added a new sequence of draft specs (0000–0019) covering core semantics, effects/throws, modules/imports, typed IR, runtime/platform boundary, and new surface features (if-expression, division/remainder, qualified calls, pipeline operator).
- Removed older draft specs that are superseded by the new structure (e.g., prior minimal core, imports, function values, pipeline syntax, toolchain/package resolution, etc.).
- Updated
README.mdto reflect the new “Current Drafts” list.
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| specs/0019-pipeline-operator.md | Introduces the ` |
| specs/0018-qualified-imports-and-calls.md | Defines qualified import suffix resolution and disambiguation at call sites. |
| specs/0017-char-and-string-concatenation.md | Adds Char, char literals, ++, and minimal Char/String conversions plus backend notes. |
| specs/0016-integer-division-and-remainder.md | Specifies / and % semantics for Int/Float including trap behavior notes. |
| specs/0015-if-expression.md | Defines if as an expression with typing/effect rules and lowering notes. |
| specs/0014-generic-functions.md | Defines named generic functions, parametricity constraints, and monomorphization. |
| specs/0013-platform-functions-and-runtime-provision.md | Defines the platform-function boundary and runtime provisioning contract for effects. |
| specs/0013-generic-functions.md | Removes the older generic-functions draft (superseded by 0014). |
| specs/0012-typed-ir.md | Introduces typed IR requirements, examples, and core IR concepts. |
| specs/0012-toolchain-and-package-resolution.md | Removes the older toolchain/package-resolution draft (scope shifted by the reorg). |
| specs/0011-pipeline-syntax.md | Removes the older pipeline-syntax draft (superseded by 0019). |
| specs/0011-error-handling.md | Adds a new error-handling spec (throws/throw/?/try-catch/panic and lowering notes). |
| specs/0010-modules-imports-visibility.md | Adds a minimal modules/imports/visibility spec as the base for later import extensions. |
| specs/0010-function-values.md | Removes the older function-values draft (replaced by the new core structure). |
| specs/0009-type-annotations.md | Removes the older type-annotations draft (replaced by the new core structure). |
| specs/0009-effect-semantics.md | Adds the effect semantics baseline and built-in effect set; links to platform-function boundary. |
| specs/0008-imports.md | Removes the older imports draft (replaced by 0010 + 0018 direction). |
| specs/0008-function-types-with-effects.md | Defines function type shape including throws/uses clauses and examples. |
| specs/0007-generic-types.md | Removes the older generic-types draft (replaced by the new core structure). |
| specs/0007-array-and-strings.md | Adds an approved baseline spec for arrays/strings and their high-level semantics. |
| specs/0006-result-type.md | Removes the older result-type draft (error model shifted to throws/Option). |
| specs/0006-records.md | Adds a records spec draft with basic syntax and access examples. |
| specs/0005-enum-types.md | Removes the older enum-types draft (replaced by approved enum/match spec). |
| specs/0005-enum-and-match-expression.md | Adds an approved enum + match spec, including guards and IR lowering sketch. |
| specs/0004-struct-types.md | Removes the older struct-types draft (replaced by records + new core structure). |
| specs/0004-blocks-and-expression-semantics.md | Adds an approved baseline for blocks and expression-oriented semantics. |
| specs/0003-platform-capabilities.md | Removes the older platform-capabilities draft (replaced by effects + platform functions model). |
| specs/0003-function-definitions-and-calls.md | Adds core function/call semantics including evaluation order, recursion, and function values. |
| specs/0002-traits-and-operators.md | Removes the older traits/operators draft (explicitly deferred per design principles). |
| specs/0002-binding-and-mutation.md | Adds an approved baseline for immutable bindings and let. |
| specs/0001-effect-system.md | Removes the older effect-system draft (replaced by 0009 + 0013 direction). |
| specs/0001-core-values-and-types.md | Adds core values/types draft including heap-vs-primitive model and Never. |
| specs/0000-minimal-core-language.md | Removes the older minimal-core draft (replaced by the new spec set). |
| specs/0000-language-design-principles.md | Adds an approved high-level principles document framing the reorg. |
| README.md | Updates the “Current Drafts” list to match the new spec set. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,32 @@ | |||
| ## 0000: Language Design Principles | |||
|
|
|||
| State: Approved | |||
| @@ -0,0 +1,98 @@ | |||
| ## 0001: Core Values and Types | |||
|
|
|||
| State: Draft | |||
|
|
||
| ### String | ||
|
|
||
| 文字単位は `byte`. |
| ``` | ||
|
|
||
| ```text | ||
| fn loadUser(id: UserId) -> User effects { db } { |
| io.write_stderr : (String) -> Unit uses { io } | ||
| ``` | ||
|
|
||
| 将来,0017 の標準 capability に合わせて `clock.now`,`random.int`,`fs.read` 等を追加する(本仕様を supersede せず拡張する). |
|
|
||
| - **IR**: platform 関数の呼び出しは,通常の関数呼び出しとは区別された専用ノードとして typed IR に保持する(0012,effect 注釈を保つ). | ||
| - **JS backend**: backend が platform 関数の実体を提供する.既定ではランタイムオブジェクトを生成物に同梱する(例 `__rt["io.write_stdout"] = s => process.stdout.write(s)`).ホストが実体を注入する形にしてもよい. | ||
| - **WASM/WAMR backend**: platform 関数は WASI / host import に lower する.ユーザーには WASI を直接見せない (0016).文字列はランタイム管理の linear memory 表現で受け渡す (0007, 0015).生成モジュールが import するのは WASI の関数のみとし,未提供 capability はロード時にも解決不能となる. |
|
|
||
| ### Open Questions | ||
|
|
||
| - registry の初期セットの確定(`io` と `log` を分けるか,`io.write_stdout` を `io` と `log` のどちらの capability にするか,0017 と整合). |
|
|
||
| - `Char` は実行時にはコードポイントの整数(WebAssembly では `i32`,JavaScript では number)として表現する. | ||
| - JavaScript (Tier 2): `Char.from_code` は恒等,`String.from_char` は `String.fromCodePoint(c)`,`++` は `a + b`.全コードポイントを正しく扱う. | ||
| - WebAssembly (Tier 1): `String` は線形メモリ上の `[len: i32][utf8 bytes]`(0013/0015).`++` は `alloc(4 + len1 + len2)` + 長さ書込み + `memory.copy` ×2.`String.from_char` は **当面 ASCII(コードポイント < 128)の1バイトのみ**を符号化する(多バイト UTF-8 符号化は後続). |
| - **P2(第一引数挿入)**: 右辺が呼び出し式 `f(a1, …, an)`(n ≥ 0)のとき,`lhs |> f(a1, …, an)` は `f(lhs, a1, …, an)` と等価である (MUST).callee `f` は任意の式でよい. | ||
| - **P3(bare 右辺)**: 右辺が呼び出し式でない式 `e` のとき,`lhs |> e` は `e(lhs)` と等価である (MUST).`e` は関数値に評価されなければならない(さもなくば型エラー). | ||
| - **P4(末尾 `?`)**: 右辺末尾の error 伝播演算子 `?`(spec 0011)は,挿入の**後**に適用する.`lhs |> g?` は `(lhs |> g)?` と等価である (MUST).これにより `data |> validate? |> transform?` は `transform(validate(data)?)?` と書ける. | ||
| - **P5(評価順)**: 脱糖後の呼び出しの評価順(spec 0003)に従う.`lhs |> f(a, b)` は `lhs`,`a`,`b` の順に評価してから `f` を呼ぶ.左辺は常に最初に評価され,ちょうど一度だけ評価される. |
Comment on lines
+60
to
+64
| fn map<T, U>( | ||
| xs: Array<T>, | ||
| f: T -> U uses e | ||
| ) -> Array<U> uses e | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WASM(WASR) ターゲットにする上で再度仕様を練り直す