feat: 名前空間付き import (PR1: plain import + 修飾呼び出し)#133
Open
ryuichi1208 wants to merge 6 commits into
Open
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add Import AST node, Call.module, and Module.imports. parse_module accepts `import foo` before any def/type; parse_atom_postfix reads `mod.func(...)` into Call(module="mod"). `as`/`from` forms error for now. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
load_program parses the entry module and every transitively imported module from the entry directory. Detects missing modules, import cycles, and main defined in an imported module. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Process the whole LoadedProgram: collect signatures across all modules keyed by (module, name), enforce main only on the entry module, and resolve qualified calls (mod.func) against imported modules. Record each call's resolved target in call_resolution for irgen. Add analyze_program; analyze() now wraps a single module in a LoadedProgram. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
irgen emits every module's functions, qualifying imported symbols as
rw_user_<module>_<name> and resolving calls/spawns via call_resolution.
driver routes compile/emit-ir/emit-ast through load_program +
analyze_program. Add examples/import_basic{,_lib}.rw and e2e coverage.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4 tasks
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.
概要
rw を単一ファイルから複数ファイルへ拡張する、Python 風 import の PR1 / 全3 PR。
import fooで同一ディレクトリのfoo.rwを取り込み、foo.bar()と修飾して呼べるようにする。名前空間付き import の全インフラ(DOT トークン・ローダ・名前空間付き関数テーブル・irgen シンボル規約・循環検出)を本 PR に集約する。import math_lib→math_lib.add(2, 3)と修飾呼び出しmain定義もエラーrw_user_<module>_<name>シンボル)from x import y(PR2)とimport x as m(PR3)は後続。設計はdocs/specs/17-namespaced-imports.mdに 3 PR 分まとめてある。設計の要点
Call.module: Optional[str]=Noneを足し、修飾呼び出しだけを区別。デフォルト None なので既存のCall生成・ビルトイン分岐(callee == "print"等)は無改変。member-access ノード化は却下(数十の分岐が全壊するため)。(module, name)でキー化して統合解析。main必須チェックは entry モジュールのみ。SemaResult.call_resolution: Dict[id(Call), (module, name)]で呼び出しの実体を irgen に伝える。PR2/PR3 の別名解決もここに乗る。rwc/loader.pyに隔離(driver は配線のみ)。変更ファイル
rwc/lexer.pyDOTトークン(float と非衝突)rwc/ast_nodes.pyImport/Call.module/Module.importsrwc/parser.pyparse_import、mod.func()の修飾呼び出しrwc/loader.py(新規)rwc/sema.py(module,name)関数テーブル、analyze_program、call_resolutionrwc/irgen.pyrw_user_<module>_<name>シンボル、(module,name)ルックアップrwc/driver.pydocs/specs/17-*,docs/plans/2026-06-22-*examples/import_basic*,tests/*Test plan
uv run pytest -q)import_basic.rwを clang でビルド・実行し5\n20\nを確認rw_user_import_basic_lib_addシンボルを確認Non-Goals(spec 17 に明記)
パッケージ階層
pkg.sub/ 再エクスポート / ワイルドカード / 可視性 / 標準ライブラリ・検索パス / 型エイリアスの import / 循環 import の解決(検出のみ)。from/asは PR2/PR3。🤖 Generated with Claude Code