Implement RitzMain() convention and Main.wasm standard

**Convention: RitzMain() entry point**
Every Ritz file now requires a `@component def RitzMain()` as the entry point.
This provides a consistent, predictable entry point for all applications.

**Universal Main.wasm output**
Build system now always outputs Main.wasm instead of ComponentName.wasm.
This means every example uses the exact same HTML boilerplate!

**Changes:**

**Codegen (llvm_codegen_signals.py):**
- Check for RitzMain component at generation time
- Error if RitzMain not found: "No RitzMain component found!"
- Always call `render_RitzMain()` from main() entry point
- Fix: Scope reactive text nodes to components (`@reactive_text_ComponentName_N_node`)
  - Prevents global name collisions when multiple components have reactive text

**Build (build.py):**
- Output Main.wasm in same directory as source file
- Output Main.ll (LLVM IR) for inspection
- Convention over configuration!

**Loader (ritz-runtime.js):**
- Auto-detect component name from WASM filename
- `new RitzLoader().load('Main.wasm')` - no second parameter needed!
- Component name used only for status messages

**Template (examples/template.html):**
- Minimal boilerplate - literally 25 lines
- Just copy and change nothing!
- Loads Main.wasm - works for every example

**Styles (examples/runtime/styles.css):**
- Shared styles for all examples
- Clean, modern defaults
- App container, buttons, inputs, typography

**Example (HighFive):**
```python
@component
def HighFive():
    # ... component logic

@component
def RitzMain():
    """Entry point - required!"""
    yield HighFive()
```

**Result:**
✅ Every example: copy template.html, change nothing
✅ Every example: builds to Main.wasm
✅ Consistent entry point: RitzMain()
✅ No more component name boilerplate

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Aaron SinclairandClaude committed 2025-11-15 15:46:36 -08:00
1 parent 999327172e
commit ddd2c03a9d
9 files changed
+261 -52

No files matched your search

+11 -33
View File
@@ -3,45 +3,23 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{TITLE}} - Ritz Framework</title>
<link rel="stylesheet" href="../runtime/ritz-debug.css">
<link rel="stylesheet" href="{{COMPONENT}}.css">
<title>Ritz Example</title>
<link rel="stylesheet" href="../runtime/styles.css">
</head>
<body>
<div id="app"></div>
<div id="ritz-debug" class="ritz-debug hidden">
<div class="debug-header">
<h3>🎭 Ritz Debug</h3>
<button onclick="ritzDebug.toggle()">×</button>
</div>
<div id="status" class="status">Loading...</div>
<div class="debug-content">
<div class="debug-section">
<h4>Pipeline</h4>
<pre>{{COMPONENT}}.py → AST → IR → LLVM → WASM</pre>
</div>
<div class="debug-section">
<h4>Commands</h4>
<pre>ritzRuntime.getLog()
ritzInstance.exports</pre>
</div>
</div>
</div>
<div id="status"></div>
<script src="../runtime/ritz-runtime.js"></script>
<script src="../runtime/ritz-debug.js"></script>
<script>
// Load component
const loader = new RitzLoader({
rootElement: document.getElementById('app'),
statusElement: document.getElementById('status'),
onLoad: (runtime, instance) => {
console.log('✅ Component loaded');
console.log('Debug: ritzRuntime, ritzInstance');
}
});
loader.load('{{COMPONENT}}.wasm', '{{COMPONENT}}');
// Load Main.wasm - automatically calls RitzMain() component
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
new RitzLoader().load('Main.wasm');
});
} else {
new RitzLoader().load('Main.wasm');
}
</script>
</body>
</html>