🚀 Phase 8.2 PoC2 Achievement: 280x WASM performance boost proven\! ## New Features: - Complete benchmark framework (src/benchmarks.rs) - CLI integration: --benchmark --iterations options - 3-backend comparison: Interpreter/VM/WASM - Automated performance measurement & reporting ## Benchmark Results (100 iterations average): - WASM: 0.17ms (280x faster than Interpreter\!) - VM: 16.97ms (2.9x faster than Interpreter) - Interpreter: 48.59ms (baseline) ## Added Files: - benchmarks/bench_{light,medium,heavy}.nyash - Test cases - benchmark_summary_20250814.md - Clean results - wasm_demo/ - Browser execution environment ## Documentation Updates: - docs/execution-backends.md - Added benchmark usage - docs/CURRENT_TASK.md - Phase 8.3 Copilot coordination - CLAUDE.md - Quick benchmark access ## Copilot Integration Ready: - Phase 8.3 merge conflict avoidance strategy documented - Benchmark framework ready for Box operation performance validation - CLI integration preserved for future enhancements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
236 lines
7.7 KiB
HTML
236 lines
7.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>🎁 Nyash → WASM Test</title>
|
|
<style>
|
|
body {
|
|
font-family: 'Courier New', monospace;
|
|
background: #1e1e1e;
|
|
color: #d4d4d4;
|
|
padding: 20px;
|
|
max-width: 900px;
|
|
margin: 0 auto;
|
|
}
|
|
h1 {
|
|
color: #569cd6;
|
|
text-align: center;
|
|
}
|
|
.container {
|
|
background: #2d2d30;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
|
|
margin-bottom: 20px;
|
|
}
|
|
button {
|
|
background: #007acc;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
margin: 5px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 16px;
|
|
}
|
|
button:hover {
|
|
background: #005a9e;
|
|
}
|
|
#output {
|
|
background: #1e1e1e;
|
|
padding: 15px;
|
|
margin-top: 20px;
|
|
border-radius: 4px;
|
|
min-height: 150px;
|
|
white-space: pre-wrap;
|
|
border: 1px solid #3e3e42;
|
|
}
|
|
.nyash-title {
|
|
color: #c586c0;
|
|
font-size: 24px;
|
|
}
|
|
.success {
|
|
color: #4ec9b0;
|
|
}
|
|
.code-block {
|
|
background: #0d1117;
|
|
padding: 15px;
|
|
border-radius: 6px;
|
|
border: 1px solid #30363d;
|
|
font-family: 'Courier New', monospace;
|
|
margin: 10px 0;
|
|
color: #e6edf3;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>🎁 <span class="nyash-title">Nyash</span> → WASM Test</h1>
|
|
|
|
<div class="container">
|
|
<h2>🚀 Real Nyash WASM Execution!</h2>
|
|
<p>This page loads and executes WASM generated directly from Nyash source code!</p>
|
|
|
|
<div class="code-block">
|
|
// Original Nyash code:
|
|
static box Main {
|
|
main() {
|
|
return 42
|
|
}
|
|
}
|
|
</div>
|
|
|
|
<div>
|
|
<button onclick="loadNyashWasm()">Load Nyash WASM</button>
|
|
<button onclick="runMain()">Run main()</button>
|
|
<button onclick="testMemory()">Test Memory</button>
|
|
<button onclick="showWatSource()">Show WAT Source</button>
|
|
</div>
|
|
|
|
<div id="output">Click "Load Nyash WASM" to start...</div>
|
|
</div>
|
|
|
|
<script>
|
|
let wasmInstance = null;
|
|
let output = document.getElementById('output');
|
|
|
|
function log(message) {
|
|
output.textContent += message + '\n';
|
|
console.log(message);
|
|
}
|
|
|
|
function clearOutput() {
|
|
output.textContent = '';
|
|
}
|
|
|
|
// Load the actual WASM file generated by Nyash
|
|
async function loadNyashWasm() {
|
|
clearOutput();
|
|
try {
|
|
log('🌐 Loading Nyash-generated WASM...');
|
|
|
|
// Fetch the WAT file generated by Nyash
|
|
const response = await fetch('output.wat');
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to load output.wat: ${response.status}`);
|
|
}
|
|
|
|
const watText = await response.text();
|
|
log('📄 Nyash WAT loaded successfully!');
|
|
log('📦 Size: ' + watText.length + ' characters');
|
|
|
|
// Convert WAT to WASM binary using wabt.js
|
|
if (typeof WabtModule === 'undefined') {
|
|
throw new Error('wabt.js not loaded - using fallback mode');
|
|
}
|
|
|
|
const wabt = await WabtModule();
|
|
const module = wabt.parseWat('output.wat', watText);
|
|
const binary = module.toBinary({});
|
|
|
|
// Create import object for Nyash WASM
|
|
const importObject = {
|
|
env: {
|
|
print: (value) => {
|
|
log(`🎯 Nyash WASM output: ${value}`);
|
|
}
|
|
}
|
|
};
|
|
|
|
// Instantiate the Nyash-generated WASM module
|
|
const wasmModule = await WebAssembly.instantiate(binary.buffer, importObject);
|
|
wasmInstance = wasmModule.instance;
|
|
|
|
log('✅ Nyash WASM module loaded successfully!');
|
|
log('🎁 Everything is Box - now running in WASM!');
|
|
log('Available exports: ' + Object.keys(wasmInstance.exports).join(', '));
|
|
|
|
} catch (error) {
|
|
log('❌ Error loading Nyash WASM: ' + error.message);
|
|
log('📝 Make sure output.wat exists and wabt.js is loaded');
|
|
}
|
|
}
|
|
|
|
function runMain() {
|
|
clearOutput();
|
|
if (!wasmInstance) {
|
|
log('❌ Nyash WASM not loaded yet!');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
log('🎯 Executing Nyash main() function...');
|
|
const result = wasmInstance.exports.main();
|
|
log(`✨ Nyash main() returned: ${result}`);
|
|
log('🎉 Success! Nyash code executed in WASM browser!');
|
|
|
|
} catch (error) {
|
|
log('❌ Error running main(): ' + error.message);
|
|
}
|
|
}
|
|
|
|
function testMemory() {
|
|
clearOutput();
|
|
if (!wasmInstance) {
|
|
log('❌ Nyash WASM not loaded yet!');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
log('🧠 Testing Nyash WASM memory...');
|
|
|
|
if (wasmInstance.exports.memory) {
|
|
const memory = new Uint8Array(wasmInstance.exports.memory.buffer);
|
|
log(`✅ Memory size: ${memory.length} bytes (${memory.length/1024}KB)`);
|
|
|
|
// Write "Nyash!" to memory
|
|
const message = "Nyash WASM!";
|
|
for (let i = 0; i < message.length; i++) {
|
|
memory[i] = message.charCodeAt(i);
|
|
}
|
|
|
|
// Read it back
|
|
let readBack = '';
|
|
for (let i = 0; i < message.length; i++) {
|
|
readBack += String.fromCharCode(memory[i]);
|
|
}
|
|
|
|
log(`📝 Wrote to memory: "${message}"`);
|
|
log(`📖 Read from memory: "${readBack}"`);
|
|
log('🎁 Perfect for Nyash Box storage!');
|
|
|
|
} else {
|
|
log('❌ No memory export found');
|
|
}
|
|
|
|
} catch (error) {
|
|
log('❌ Error testing memory: ' + error.message);
|
|
}
|
|
}
|
|
|
|
function showWatSource() {
|
|
clearOutput();
|
|
log('📄 Nyash-generated WAT source:');
|
|
log('');
|
|
|
|
fetch('output.wat')
|
|
.then(response => response.text())
|
|
.then(watText => {
|
|
log(watText);
|
|
})
|
|
.catch(error => {
|
|
log('❌ Error loading WAT: ' + error.message);
|
|
});
|
|
}
|
|
|
|
// Auto-load on page start
|
|
window.onload = () => {
|
|
log('🎁 Nyash → WASM Test Ready!');
|
|
log('🚀 Generated from real Nyash compiler');
|
|
log('Click "Load Nyash WASM" to begin...');
|
|
};
|
|
</script>
|
|
|
|
<!-- Include wabt.js for WAT compilation -->
|
|
<script src="https://cdn.jsdelivr.net/npm/wabt@1.0.24/index.js"></script>
|
|
</body>
|
|
</html> |