feat: Prepare for code modularization and cleanup
- Archive old documentation and test files to `docs/archive/` and `local_tests/`. - Remove various temporary and old files from the project root. - Add `nekocode-rust` analysis tool and its output files (`nekocode/`, `.nekocode_sessions/`, `analysis.json`). - Minor updates to `apps/chip8_nyash/chip8_emulator.nyash` and `local_tests` files. This commit cleans up the repository and sets the stage for further code modularization efforts, particularly in the `src/interpreter` and `src/parser` modules, based on recent analysis.
This commit is contained in:
29
local_tests/debug_socket.nyash
Normal file
29
local_tests/debug_socket.nyash
Normal file
@ -0,0 +1,29 @@
|
||||
// Debug the listen issue
|
||||
static box Main {
|
||||
main() {
|
||||
print("🔍 Debugging socket listen issue...")
|
||||
|
||||
local socket
|
||||
socket = new SocketBox()
|
||||
|
||||
local bindOk
|
||||
bindOk = socket.bind("127.0.0.1", 8080)
|
||||
print("Bind result: " + bindOk.toString())
|
||||
|
||||
// Test server state after bind
|
||||
local isServerResult
|
||||
isServerResult = socket.isServer()
|
||||
print("Is server after bind: " + isServerResult.toString())
|
||||
|
||||
local listenOk
|
||||
listenOk = socket.listen(10)
|
||||
print("Listen result: " + listenOk.toString())
|
||||
|
||||
// Close
|
||||
local closeOk
|
||||
closeOk = socket.close()
|
||||
print("Close result: " + closeOk.toString())
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
30
local_tests/demo_phase9_51_fixes.nyash
Normal file
30
local_tests/demo_phase9_51_fixes.nyash
Normal file
@ -0,0 +1,30 @@
|
||||
// Demo: Phase 9.51 WASM + HTTPServer fixes working
|
||||
static box Main {
|
||||
init { counter, result, server }
|
||||
|
||||
main() {
|
||||
// WASM-compatible loop (Jump/Branch instructions now supported)
|
||||
me.counter = 0
|
||||
me.result = 0
|
||||
|
||||
loop(me.counter < 5) {
|
||||
me.result = me.result + me.counter
|
||||
me.counter = me.counter + 1
|
||||
}
|
||||
|
||||
print("Loop result (WASM-compatible):")
|
||||
print(me.result)
|
||||
|
||||
// HTTPServer bind + listen now works
|
||||
me.server = new HTTPServerBox()
|
||||
local bindOk = me.server.bind("127.0.0.1", 8080)
|
||||
local listenOk = me.server.listen(10)
|
||||
|
||||
print("HTTPServer bind:")
|
||||
print(bindOk)
|
||||
print("HTTPServer listen:")
|
||||
print(listenOk)
|
||||
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
110
local_tests/http_server_demo.nyash
Normal file
110
local_tests/http_server_demo.nyash
Normal file
@ -0,0 +1,110 @@
|
||||
// 🌐 HTTP Server Infrastructure Demonstration
|
||||
// Phase 9.5: Showcases complete HTTP server box implementation
|
||||
// Ready for AOT compilation once Phase 9 is complete
|
||||
|
||||
static box Main {
|
||||
init { server, request, response, result }
|
||||
|
||||
main() {
|
||||
print("🌐 === Nyash HTTP Server Infrastructure Demo ===")
|
||||
print("🎯 Phase 9.5: HTTP Server validation for AOT compilation")
|
||||
print("")
|
||||
|
||||
// Demonstrate HTTPServerBox creation
|
||||
print("📦 1. Creating HTTPServerBox...")
|
||||
me.server = new HTTPServerBox()
|
||||
print("✅ HTTPServerBox: " + me.server.toString())
|
||||
print("")
|
||||
|
||||
// Demonstrate HTTPRequestBox creation and parsing
|
||||
print("📬 2. Creating HTTPRequestBox...")
|
||||
me.request = new HTTPRequestBox()
|
||||
print("✅ HTTPRequestBox: " + me.request.toString())
|
||||
print("")
|
||||
|
||||
// Demonstrate HTTPResponseBox creation
|
||||
print("📤 3. Creating HTTPResponseBox...")
|
||||
me.response = new HTTPResponseBox()
|
||||
print("✅ HTTPResponseBox: " + me.response.toString())
|
||||
print("")
|
||||
|
||||
// Demonstrate SocketBox (TCP layer)
|
||||
print("🔌 4. Creating SocketBox...")
|
||||
local socket
|
||||
socket = new SocketBox()
|
||||
print("✅ SocketBox: " + socket.toString())
|
||||
print("")
|
||||
|
||||
// Show API capabilities
|
||||
print("🛠️ 5. Available HTTP Server APIs:")
|
||||
print(" HTTPServerBox:")
|
||||
print(" • bind(address, port) - Bind to network address")
|
||||
print(" • listen(backlog) - Start listening for connections")
|
||||
print(" • start() - Begin HTTP server main loop")
|
||||
print(" • get(path, handler) - Register GET route")
|
||||
print(" • post(path, handler) - Register POST route")
|
||||
print(" • stop() - Stop the server")
|
||||
print("")
|
||||
print(" HTTPRequestBox:")
|
||||
print(" • getMethod() - HTTP method (GET, POST, etc.)")
|
||||
print(" • getPath() - URL path")
|
||||
print(" • getHeader(name) - Get specific header")
|
||||
print(" • getBody() - Request body content")
|
||||
print("")
|
||||
print(" HTTPResponseBox:")
|
||||
print(" • setStatus(code, message) - Set HTTP status")
|
||||
print(" • setHeader(name, value) - Set response header")
|
||||
print(" • setBody(content) - Set response body")
|
||||
print(" • toHttpString() - Generate HTTP response")
|
||||
print("")
|
||||
print(" SocketBox:")
|
||||
print(" • bind(address, port) - TCP socket bind")
|
||||
print(" • listen(backlog) - TCP listen")
|
||||
print(" • accept() - Accept client connections")
|
||||
print(" • read() / write(data) - Socket I/O")
|
||||
print(" • close() - Close socket")
|
||||
print("")
|
||||
|
||||
// Demonstrate the future server usage pattern
|
||||
print("🚀 6. Future Usage Pattern (Post-AOT):")
|
||||
print(" nyash --compile-native http_server.nyash -o server.exe")
|
||||
print(" ./server.exe --port 8080")
|
||||
print(" curl http://localhost:8080/api/status")
|
||||
print("")
|
||||
|
||||
// Show memory management features
|
||||
print("🧠 7. Memory Management Features:")
|
||||
print(" • Everything is Box architecture")
|
||||
print(" • fini() system for resource cleanup")
|
||||
print(" • weak reference support")
|
||||
print(" • Arc<Mutex<...>> for thread safety")
|
||||
print(" • Drop trait for automatic cleanup")
|
||||
print("")
|
||||
|
||||
// Performance characteristics
|
||||
print("⚡ 8. Performance Characteristics:")
|
||||
print(" • Multi-threaded request handling")
|
||||
print(" • Connection pooling and management")
|
||||
print(" • Async/await with nowait support")
|
||||
print(" • Ready for 100+ concurrent connections")
|
||||
print("")
|
||||
|
||||
// Phase 9.5 readiness
|
||||
print("🎯 9. Phase 9.5 Readiness Status:")
|
||||
print(" ✅ TCP socket infrastructure complete")
|
||||
print(" ✅ HTTP protocol handling implemented")
|
||||
print(" ✅ Request/Response parsing ready")
|
||||
print(" ✅ Route handling system available")
|
||||
print(" ✅ Memory management architecture")
|
||||
print(" ✅ AOT compilation ready")
|
||||
print(" ⏳ Load testing pending (requires socket debug)")
|
||||
print(" ⏳ Concurrent validation pending")
|
||||
print("")
|
||||
|
||||
me.result = "HTTP Server Infrastructure Demo Complete"
|
||||
print("🏁 " + me.result)
|
||||
print("🎉 Ready for Phase 9 AOT implementation!")
|
||||
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
117
local_tests/http_server_simple.nyash
Normal file
117
local_tests/http_server_simple.nyash
Normal file
@ -0,0 +1,117 @@
|
||||
// 🌐 HTTP Server Example - Phase 9.5 Validation
|
||||
// Demonstrates Nyash HTTP server with concurrent request handling
|
||||
|
||||
// Simple API Handler Box
|
||||
box APIHandler {
|
||||
init { }
|
||||
|
||||
pack() {
|
||||
// Empty initialization for static-like usage
|
||||
}
|
||||
|
||||
// Home page handler
|
||||
home(request) {
|
||||
local html
|
||||
html = "<html><body>"
|
||||
html = html + "<h1>🐱 Nyash HTTP Server</h1>"
|
||||
html = html + "<p>Everything is Box! Server running successfully.</p>"
|
||||
html = html + "<ul>"
|
||||
html = html + "<li><a href='/api/status'>Server Status</a></li>"
|
||||
html = html + "<li><a href='/api/info'>Server Info</a></li>"
|
||||
html = html + "<li><a href='/nonexistent'>404 Test</a></li>"
|
||||
html = html + "</ul>"
|
||||
html = html + "</body></html>"
|
||||
|
||||
return html
|
||||
}
|
||||
|
||||
// Status API handler
|
||||
status(request) {
|
||||
local json
|
||||
json = "{"
|
||||
json = json + "\"status\": \"running\","
|
||||
json = json + "\"server\": \"Nyash HTTP Server\","
|
||||
json = json + "\"version\": \"1.0.0\","
|
||||
json = json + "\"timestamp\": \"" + Time.now() + "\","
|
||||
json = json + "\"everything_is\": \"Box\""
|
||||
json = json + "}"
|
||||
|
||||
return json
|
||||
}
|
||||
|
||||
// Info API handler
|
||||
info(request) {
|
||||
local json
|
||||
json = "{"
|
||||
json = json + "\"message\": \"Nyash Programming Language\","
|
||||
json = json + "\"philosophy\": \"Everything is Box\","
|
||||
json = json + "\"features\": ["
|
||||
json = json + "\"Async/Await\","
|
||||
json = json + "\"HTTP Server\","
|
||||
json = json + "\"Memory Management\","
|
||||
json = json + "\"AOT Compilation\""
|
||||
json = json + "]"
|
||||
json = json + "}"
|
||||
|
||||
return json
|
||||
}
|
||||
}
|
||||
|
||||
// Main HTTP Server Box
|
||||
static box Main {
|
||||
init { server, handler, running }
|
||||
|
||||
main() {
|
||||
print("🌐 Starting Nyash HTTP Server...")
|
||||
|
||||
// Initialize components
|
||||
me.server = new HTTPServerBox()
|
||||
me.handler = new APIHandler()
|
||||
me.running = true
|
||||
|
||||
// Configure server
|
||||
local bindResult
|
||||
bindResult = me.server.bind("127.0.0.1", 8080)
|
||||
|
||||
if (bindResult.toString() != "true") {
|
||||
print("❌ Failed to bind to port 8080")
|
||||
return false
|
||||
}
|
||||
|
||||
local listenResult
|
||||
listenResult = me.server.listen(128)
|
||||
|
||||
if (listenResult.toString() != "true") {
|
||||
print("❌ Failed to listen on port 8080")
|
||||
return false
|
||||
}
|
||||
|
||||
// Register routes
|
||||
print("📋 Registering routes...")
|
||||
me.server.get("/", me.handler.home)
|
||||
me.server.get("/api/status", me.handler.status)
|
||||
me.server.get("/api/info", me.handler.info)
|
||||
|
||||
print("✅ Server configuration complete")
|
||||
print("🚀 Server starting on http://127.0.0.1:8080")
|
||||
print("📡 Test URLs:")
|
||||
print(" http://127.0.0.1:8080/ - Home page")
|
||||
print(" http://127.0.0.1:8080/api/status - Status API")
|
||||
print(" http://127.0.0.1:8080/api/info - Info API")
|
||||
print("")
|
||||
print("Press Ctrl+C to stop the server")
|
||||
print("=" * 50)
|
||||
|
||||
// Start server (blocking)
|
||||
local result
|
||||
result = me.server.start()
|
||||
|
||||
if (result.toString() == "true") {
|
||||
print("✅ Server started successfully")
|
||||
return true
|
||||
} else {
|
||||
print("❌ Server failed to start")
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
237
local_tests/kilo_editor.nyash
Normal file
237
local_tests/kilo_editor.nyash
Normal file
@ -0,0 +1,237 @@
|
||||
// Kilo Text Editor - Memory Management Stress Test
|
||||
// This tests Box method calls and memory management extensively
|
||||
|
||||
// KiloEditor Box - stores editor state
|
||||
box KiloEditor {
|
||||
init { lines, cursor_row, cursor_col, filename, dirty }
|
||||
|
||||
// Initialize empty editor
|
||||
init_empty() {
|
||||
me.lines = new ArrayBox()
|
||||
me.cursor_row = 0
|
||||
me.cursor_col = 0
|
||||
me.filename = ""
|
||||
me.dirty = false
|
||||
|
||||
// Start with one empty line
|
||||
local empty_line
|
||||
empty_line = new StringBox()
|
||||
me.lines.push(empty_line)
|
||||
}
|
||||
|
||||
// Get current line as StringBox
|
||||
get_current_line() {
|
||||
return me.lines.get(me.cursor_row)
|
||||
}
|
||||
|
||||
// Insert character at cursor position
|
||||
insert_char(ch) {
|
||||
local current_line
|
||||
local left_part
|
||||
local right_part
|
||||
local new_line
|
||||
|
||||
current_line = me.get_current_line()
|
||||
|
||||
// Split line at cursor position
|
||||
left_part = current_line.substring(0, me.cursor_col)
|
||||
right_part = current_line.substring(me.cursor_col, current_line.length())
|
||||
|
||||
// Create new line with inserted character
|
||||
new_line = left_part.concat(ch).concat(right_part)
|
||||
|
||||
// Replace line in array
|
||||
me.lines.set(me.cursor_row, new_line)
|
||||
|
||||
// Move cursor
|
||||
me.cursor_col = me.cursor_col + 1
|
||||
me.dirty = true
|
||||
}
|
||||
|
||||
// Delete character before cursor
|
||||
delete_char() {
|
||||
local current_line
|
||||
local left_part
|
||||
local right_part
|
||||
local new_line
|
||||
|
||||
if me.cursor_col > 0 {
|
||||
current_line = me.get_current_line()
|
||||
|
||||
// Split line at cursor position
|
||||
left_part = current_line.substring(0, me.cursor_col - 1)
|
||||
right_part = current_line.substring(me.cursor_col, current_line.length())
|
||||
|
||||
// Create new line without deleted character
|
||||
new_line = left_part.concat(right_part)
|
||||
|
||||
// Replace line in array
|
||||
me.lines.set(me.cursor_row, new_line)
|
||||
|
||||
// Move cursor back
|
||||
me.cursor_col = me.cursor_col - 1
|
||||
me.dirty = true
|
||||
}
|
||||
}
|
||||
|
||||
// Insert new line at cursor
|
||||
insert_newline() {
|
||||
local current_line
|
||||
local left_part
|
||||
local right_part
|
||||
|
||||
current_line = me.get_current_line()
|
||||
|
||||
// Split current line
|
||||
left_part = current_line.substring(0, me.cursor_col)
|
||||
right_part = current_line.substring(me.cursor_col, current_line.length())
|
||||
|
||||
// Update current line with left part
|
||||
me.lines.set(me.cursor_row, left_part)
|
||||
|
||||
// Insert new line with right part
|
||||
me.lines.insert(me.cursor_row + 1, right_part)
|
||||
|
||||
// Move cursor to start of new line
|
||||
me.cursor_row = me.cursor_row + 1
|
||||
me.cursor_col = 0
|
||||
me.dirty = true
|
||||
}
|
||||
|
||||
// Get editor stats for memory testing
|
||||
get_stats() {
|
||||
local stats
|
||||
local total_chars
|
||||
local line_count
|
||||
local i
|
||||
local current_line
|
||||
|
||||
stats = new StringBox()
|
||||
line_count = me.lines.length()
|
||||
total_chars = 0
|
||||
|
||||
// Count total characters across all lines
|
||||
i = 0
|
||||
loop(i < line_count) {
|
||||
current_line = me.lines.get(i)
|
||||
total_chars = total_chars + current_line.length()
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
stats = stats.concat("Lines: ").concat(line_count.toString())
|
||||
stats = stats.concat(" | Chars: ").concat(total_chars.toString())
|
||||
stats = stats.concat(" | Cursor: ").concat(me.cursor_row.toString())
|
||||
stats = stats.concat(",").concat(me.cursor_col.toString())
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
// Render editor content (simplified)
|
||||
render() {
|
||||
local line_count
|
||||
local i
|
||||
local current_line
|
||||
local line_display
|
||||
|
||||
print("=== Kilo Editor ===")
|
||||
|
||||
line_count = me.lines.length()
|
||||
i = 0
|
||||
|
||||
loop(i < line_count) {
|
||||
current_line = me.lines.get(i)
|
||||
|
||||
// Create line display with line number
|
||||
line_display = (i + 1).toString().concat(": ").concat(current_line.toString())
|
||||
|
||||
// Mark current line with cursor
|
||||
if i == me.cursor_row {
|
||||
line_display = line_display.concat(" <-- cursor at col ").concat(me.cursor_col.toString())
|
||||
}
|
||||
|
||||
print(line_display)
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
print("---")
|
||||
print(me.get_stats())
|
||||
print("===================")
|
||||
}
|
||||
}
|
||||
|
||||
// Test the kilo editor with intensive Box operations
|
||||
local editor
|
||||
local test_char
|
||||
local i
|
||||
|
||||
print("Starting Kilo Editor Memory Test...")
|
||||
|
||||
// Create editor
|
||||
editor = new KiloEditor()
|
||||
editor.init_empty()
|
||||
|
||||
print("Initial state:")
|
||||
editor.render()
|
||||
|
||||
// Test 1: Insert multiple characters (stress StringBox creation)
|
||||
print("Test 1: Inserting 'Hello World'...")
|
||||
editor.insert_char("H")
|
||||
editor.insert_char("e")
|
||||
editor.insert_char("l")
|
||||
editor.insert_char("l")
|
||||
editor.insert_char("o")
|
||||
editor.insert_char(" ")
|
||||
editor.insert_char("W")
|
||||
editor.insert_char("o")
|
||||
editor.insert_char("r")
|
||||
editor.insert_char("l")
|
||||
editor.insert_char("d")
|
||||
|
||||
editor.render()
|
||||
|
||||
// Test 2: Insert new lines (stress ArrayBox operations)
|
||||
print("Test 2: Adding new lines...")
|
||||
editor.insert_newline()
|
||||
editor.insert_char("L")
|
||||
editor.insert_char("i")
|
||||
editor.insert_char("n")
|
||||
editor.insert_char("e")
|
||||
editor.insert_char(" ")
|
||||
editor.insert_char("2")
|
||||
|
||||
editor.insert_newline()
|
||||
editor.insert_char("L")
|
||||
editor.insert_char("i")
|
||||
editor.insert_char("n")
|
||||
editor.insert_char("e")
|
||||
editor.insert_char(" ")
|
||||
editor.insert_char("3")
|
||||
|
||||
editor.render()
|
||||
|
||||
// Test 3: Delete operations (memory cleanup test)
|
||||
print("Test 3: Testing deletions...")
|
||||
editor.delete_char()
|
||||
editor.delete_char()
|
||||
editor.delete_char()
|
||||
|
||||
editor.render()
|
||||
|
||||
// Test 4: Intensive operations for memory stress
|
||||
print("Test 4: Memory stress test - 50 operations...")
|
||||
i = 0
|
||||
loop(i < 10) {
|
||||
editor.insert_char("X")
|
||||
editor.delete_char()
|
||||
editor.insert_char("Y")
|
||||
editor.delete_char()
|
||||
editor.insert_char("Z")
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
editor.render()
|
||||
|
||||
print("Kilo Editor Memory Test Complete!")
|
||||
local final_stats
|
||||
final_stats = editor.get_stats()
|
||||
print(final_stats)
|
||||
79
local_tests/kilo_simple_test.nyash
Normal file
79
local_tests/kilo_simple_test.nyash
Normal file
@ -0,0 +1,79 @@
|
||||
// Simple Kilo Editor Test - Step by step validation
|
||||
// Test basic Box operations before full editor
|
||||
|
||||
local s1
|
||||
local s2
|
||||
local s3
|
||||
local result
|
||||
|
||||
print("=== StringBox Methods Test ===")
|
||||
|
||||
// Test basic StringBox operations
|
||||
s1 = "" // Create empty string instead of new StringBox()
|
||||
print("Created empty StringBox")
|
||||
|
||||
s2 = "Hello"
|
||||
print("String length test:")
|
||||
result = s2.length()
|
||||
print(result)
|
||||
|
||||
print("String substring test:")
|
||||
result = s2.substring(1, 4)
|
||||
print(result)
|
||||
|
||||
print("String concat test:")
|
||||
s3 = " World"
|
||||
result = s2.concat(s3)
|
||||
print(result)
|
||||
|
||||
print("=== ArrayBox Methods Test ===")
|
||||
|
||||
local arr
|
||||
local item
|
||||
local len
|
||||
|
||||
arr = new ArrayBox()
|
||||
print("Created empty ArrayBox")
|
||||
|
||||
len = arr.length()
|
||||
print("Array length:")
|
||||
print(len)
|
||||
|
||||
print("=== Basic Editor Component Test ===")
|
||||
|
||||
// Test a simple editor component without full complexity
|
||||
box SimpleEditor {
|
||||
init { text, cursor }
|
||||
|
||||
init_empty() {
|
||||
me.text = ""
|
||||
me.cursor = 0
|
||||
}
|
||||
|
||||
append_char(ch) {
|
||||
me.text = me.text.concat(ch)
|
||||
me.cursor = me.cursor + 1
|
||||
}
|
||||
|
||||
get_text() {
|
||||
return me.text
|
||||
}
|
||||
|
||||
get_cursor() {
|
||||
return me.cursor
|
||||
}
|
||||
}
|
||||
|
||||
local editor
|
||||
editor = new SimpleEditor()
|
||||
editor.init_empty()
|
||||
|
||||
print("Testing simple editor:")
|
||||
editor.append_char("H")
|
||||
editor.append_char("i")
|
||||
|
||||
print("Editor text:")
|
||||
print(editor.get_text())
|
||||
|
||||
print("Editor cursor:")
|
||||
print(editor.get_cursor())
|
||||
96
local_tests/memory_demo.nyash
Normal file
96
local_tests/memory_demo.nyash
Normal file
@ -0,0 +1,96 @@
|
||||
// Focused Memory Management Demo - Phase 8.7 Success
|
||||
// Demonstrates VM BoxCall fixing enables real-world applications
|
||||
|
||||
print("=== Phase 8.7 Memory Management Demo ===")
|
||||
|
||||
// Test 1: Text Processing Memory Pattern (like kilo editor)
|
||||
print("Text Processing Pattern:")
|
||||
|
||||
local text
|
||||
local word
|
||||
local result
|
||||
local i
|
||||
|
||||
text = "Hello_World_Test"
|
||||
result = ""
|
||||
|
||||
// Simulate text editing operations (create/modify strings)
|
||||
i = 0
|
||||
loop(i < 5) {
|
||||
word = text.substring(i * 2, i * 2 + 4)
|
||||
result = result.concat(word).concat("|")
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
print("Text processing result:")
|
||||
print(result)
|
||||
print("Result length:")
|
||||
print(result.length())
|
||||
|
||||
// Test 2: Data Structure Memory Pattern
|
||||
print("Data Structure Pattern:")
|
||||
|
||||
local arr1
|
||||
local arr2
|
||||
local arr_total
|
||||
|
||||
// Create multiple collections (memory allocation)
|
||||
arr1 = new ArrayBox()
|
||||
arr2 = new ArrayBox()
|
||||
|
||||
// Verify array operations work
|
||||
arr_total = arr1.length() + arr2.length()
|
||||
print("Array total length:")
|
||||
print(arr_total)
|
||||
|
||||
// Test 3: Computational Memory Pattern
|
||||
print("Computational Pattern:")
|
||||
|
||||
local base
|
||||
local computed
|
||||
local final_result
|
||||
|
||||
base = "Value"
|
||||
computed = ""
|
||||
|
||||
// Computational loop with memory allocation
|
||||
i = 0
|
||||
loop(i < 8) {
|
||||
computed = base.concat("_").concat(i.toString())
|
||||
final_result = computed.concat("_processed")
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
print("Final computed result:")
|
||||
print(final_result)
|
||||
print("Final length:")
|
||||
print(final_result.length())
|
||||
|
||||
// Test 4: Memory Cleanup Validation
|
||||
print("Memory Cleanup Validation:")
|
||||
|
||||
local temp
|
||||
local cleanup_count
|
||||
|
||||
cleanup_count = 0
|
||||
|
||||
// Create temporary objects that should be cleaned up
|
||||
i = 0
|
||||
loop(i < 10) {
|
||||
temp = "Temp".concat(i.toString()).concat("_data")
|
||||
cleanup_count = cleanup_count + temp.length()
|
||||
// temp goes out of scope each iteration - tests cleanup
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
print("Cleanup validation count:")
|
||||
print(cleanup_count)
|
||||
|
||||
print("=== Demo Results ===")
|
||||
print("✅ StringBox methods: substring, concat, length, toString")
|
||||
print("✅ ArrayBox methods: creation, length access")
|
||||
print("✅ IntegerBox methods: toString, arithmetic")
|
||||
print("✅ Memory patterns: allocation, modification, cleanup")
|
||||
print("✅ VM BoxCall: proper method dispatch and return values")
|
||||
print("=== Phase 8.7 SUCCESS ===")
|
||||
print("Real-world memory management validated!")
|
||||
182
local_tests/memory_stress_test.nyash
Normal file
182
local_tests/memory_stress_test.nyash
Normal file
@ -0,0 +1,182 @@
|
||||
// Comprehensive Memory Stress Test - Built-in Box Operations
|
||||
// Phase 8.7: Real-world Memory Management Testing
|
||||
// Tests intensive Box method calls and memory allocation patterns
|
||||
|
||||
print("=== Phase 8.7 Memory Stress Test ===")
|
||||
print("Testing intensive Box operations for memory management")
|
||||
|
||||
// Test 1: Intensive String Operations (Creating many StringBox objects)
|
||||
print("Test 1: String Memory Stress")
|
||||
|
||||
local str_base
|
||||
local result
|
||||
local i
|
||||
local temp_str
|
||||
|
||||
str_base = "Base"
|
||||
result = ""
|
||||
|
||||
// Create 20 iterations of string concatenation (40 string objects)
|
||||
i = 0
|
||||
loop(i < 20) {
|
||||
temp_str = str_base.concat("_").concat(i.toString())
|
||||
result = result.concat(temp_str).concat(",")
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
print("String concatenation result length:")
|
||||
print(result.length())
|
||||
|
||||
// Test 2: Substring Memory Stress (Creating substring objects)
|
||||
print("Test 2: Substring Memory Stress")
|
||||
|
||||
local long_string
|
||||
local substr_count
|
||||
local substr_result
|
||||
|
||||
long_string = "This_is_a_very_long_string_for_testing_memory_allocation_patterns"
|
||||
substr_count = 0
|
||||
substr_result = ""
|
||||
|
||||
// Extract 15 substrings (15 more string objects)
|
||||
i = 0
|
||||
loop(i < 15) {
|
||||
temp_str = long_string.substring(i, i + 5)
|
||||
substr_result = substr_result.concat(temp_str).concat("|")
|
||||
substr_count = substr_count + 1
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
print("Substring operations completed:")
|
||||
print(substr_count)
|
||||
print("Substring result length:")
|
||||
print(substr_result.length())
|
||||
|
||||
// Test 3: ArrayBox Memory Stress (Creating arrays and accessing elements)
|
||||
print("Test 3: ArrayBox Memory Stress")
|
||||
|
||||
local arr1
|
||||
local arr2
|
||||
local arr3
|
||||
local arr_len
|
||||
local element
|
||||
|
||||
// Create multiple ArrayBox objects
|
||||
arr1 = new ArrayBox()
|
||||
arr2 = new ArrayBox()
|
||||
arr3 = new ArrayBox()
|
||||
|
||||
print("Created 3 ArrayBox objects")
|
||||
|
||||
// Test array length operations (multiple method calls)
|
||||
arr_len = arr1.length()
|
||||
print("Array 1 length:")
|
||||
print(arr_len)
|
||||
|
||||
arr_len = arr2.length()
|
||||
print("Array 2 length:")
|
||||
print(arr_len)
|
||||
|
||||
arr_len = arr3.length()
|
||||
print("Array 3 length:")
|
||||
print(arr_len)
|
||||
|
||||
// Test 4: Mixed Operations Memory Stress
|
||||
print("Test 4: Mixed Operations Memory Stress")
|
||||
|
||||
local operation_count
|
||||
local mixed_result
|
||||
local number_str
|
||||
local bool_str
|
||||
|
||||
operation_count = 0
|
||||
mixed_result = "Start"
|
||||
|
||||
// Perform 25 mixed operations (creating many temporary objects)
|
||||
i = 0
|
||||
loop(i < 25) {
|
||||
// String operations
|
||||
temp_str = "Item".concat(i.toString())
|
||||
mixed_result = mixed_result.concat("_").concat(temp_str)
|
||||
|
||||
// Integer operations
|
||||
number_str = (i * 2).toString()
|
||||
mixed_result = mixed_result.concat("(").concat(number_str).concat(")")
|
||||
|
||||
// Boolean operations
|
||||
bool_str = (i > 10).toString()
|
||||
mixed_result = mixed_result.concat("[").concat(bool_str).concat("]")
|
||||
|
||||
operation_count = operation_count + 1
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
print("Mixed operations completed:")
|
||||
print(operation_count)
|
||||
print("Mixed result length:")
|
||||
print(mixed_result.length())
|
||||
|
||||
// Test 5: Rapid Object Creation/Disposal Pattern
|
||||
print("Test 5: Rapid Object Creation Pattern")
|
||||
|
||||
local rapid_count
|
||||
local rapid_result_len
|
||||
|
||||
rapid_count = 0
|
||||
|
||||
// Create and immediately use objects (tests garbage collection)
|
||||
i = 0
|
||||
loop(i < 30) {
|
||||
// Each iteration creates multiple temporary objects
|
||||
temp_str = "Rapid".concat(i.toString()).concat("_Test")
|
||||
result = temp_str.substring(0, 10).concat("_End")
|
||||
rapid_result_len = result.length()
|
||||
rapid_count = rapid_count + 1
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
print("Rapid object creation cycles:")
|
||||
print(rapid_count)
|
||||
print("Final rapid result length:")
|
||||
print(rapid_result_len)
|
||||
|
||||
// Test 6: Nested Method Call Stress
|
||||
print("Test 6: Nested Method Call Stress")
|
||||
|
||||
local nested_count
|
||||
local nested_result
|
||||
|
||||
nested_count = 0
|
||||
|
||||
// Perform nested method calls (stress the call stack)
|
||||
i = 0
|
||||
loop(i < 15) {
|
||||
// Multiple levels of method chaining
|
||||
nested_result = "Start".concat("_").concat(i.toString()).concat("_Mid").concat("_").concat((i * 3).toString()).concat("_End")
|
||||
temp_str = nested_result.substring(2, nested_result.length() - 2)
|
||||
result = temp_str.concat("_Final").concat(i.toString())
|
||||
nested_count = nested_count + 1
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
print("Nested method call cycles:")
|
||||
print(nested_count)
|
||||
print("Final nested result length:")
|
||||
print(result.length())
|
||||
|
||||
// Memory Test Summary
|
||||
print("=== Memory Test Summary ===")
|
||||
print("String operations: Extensive concatenation and substring")
|
||||
print("Array operations: Multiple ArrayBox creation and access")
|
||||
print("Mixed operations: Combined string/integer/boolean processing")
|
||||
print("Rapid creation: High-frequency object allocation patterns")
|
||||
print("Nested calls: Deep method call chains")
|
||||
print("=== Test Complete ===")
|
||||
|
||||
// Calculate total operations estimate
|
||||
local total_ops
|
||||
total_ops = 20 + 15 + 3 + 25 + 30 + 15 // Sum of all loop iterations
|
||||
print("Estimated total Box operations:")
|
||||
print(total_ops)
|
||||
print("Each operation created multiple temporary objects")
|
||||
print("Memory management system successfully handled complex patterns!")
|
||||
37
local_tests/phase6_demo.nyash
Normal file
37
local_tests/phase6_demo.nyash
Normal file
@ -0,0 +1,37 @@
|
||||
// Phase 6 Box Reference Operations - Demonstration
|
||||
|
||||
// This demonstrates the new MIR/VM infrastructure for Box operations
|
||||
// while the interpreter works on simpler expressions, the MIR/VM
|
||||
// foundation is now in place for more complex Box field operations.
|
||||
|
||||
local message
|
||||
message = "Phase 6 Box Reference Operations Implemented!"
|
||||
print(message)
|
||||
|
||||
local status
|
||||
status = "✅ RefNew/RefGet/RefSet instructions added"
|
||||
print(status)
|
||||
|
||||
local weak_support
|
||||
weak_support = "✅ WeakNew/WeakLoad instructions added"
|
||||
print(weak_support)
|
||||
|
||||
local barriers
|
||||
barriers = "✅ BarrierRead/BarrierWrite instructions added"
|
||||
print(barriers)
|
||||
|
||||
local vm_status
|
||||
vm_status = "✅ VM execution support implemented"
|
||||
print(vm_status)
|
||||
|
||||
local effect_status
|
||||
effect_status = "✅ Effect tracking system enhanced"
|
||||
print(effect_status)
|
||||
|
||||
local test_status
|
||||
test_status = "✅ All unit tests passing"
|
||||
print(test_status)
|
||||
|
||||
local ready
|
||||
ready = "🚀 Ready for higher-level Box field operations!"
|
||||
print(ready)
|
||||
43
local_tests/simple_demo.nyash
Normal file
43
local_tests/simple_demo.nyash
Normal file
@ -0,0 +1,43 @@
|
||||
// Simple Final Demo - Phase 8.7 BoxCall Success
|
||||
// Clean demonstration of VM BoxCall functionality
|
||||
|
||||
print("=== Phase 8.7 VM BoxCall Demo ===")
|
||||
|
||||
// Test StringBox methods
|
||||
local text
|
||||
local result
|
||||
text = "Hello_World"
|
||||
result = text.substring(0, 5)
|
||||
print("Substring result:")
|
||||
print(result)
|
||||
|
||||
result = text.concat("_Success")
|
||||
print("Concat result:")
|
||||
print(result)
|
||||
|
||||
print("Length:")
|
||||
print(result.length())
|
||||
|
||||
// Test ArrayBox methods
|
||||
local arr
|
||||
arr = new ArrayBox()
|
||||
print("Array length:")
|
||||
print(arr.length())
|
||||
|
||||
// Test Integer methods
|
||||
local num
|
||||
num = 42
|
||||
result = num.toString()
|
||||
print("Number to string:")
|
||||
print(result)
|
||||
|
||||
// Test Boolean methods
|
||||
local flag
|
||||
flag = true
|
||||
result = flag.toString()
|
||||
print("Boolean to string:")
|
||||
print(result)
|
||||
|
||||
print("=== Success! ===")
|
||||
print("VM BoxCall methods working perfectly!")
|
||||
print("Ready for real-world applications!")
|
||||
4
local_tests/simple_mir_test.nyash
Normal file
4
local_tests/simple_mir_test.nyash
Normal file
@ -0,0 +1,4 @@
|
||||
// Very simple field access test
|
||||
local str
|
||||
str = "Hello World"
|
||||
print(str)
|
||||
@ -1 +1 @@
|
||||
print("Simple test")
|
||||
static box Main { main() { return 42 } }
|
||||
|
||||
7
local_tests/test_aot.nyash
Normal file
7
local_tests/test_aot.nyash
Normal file
@ -0,0 +1,7 @@
|
||||
// Simple arithmetic test for all backends
|
||||
local a, b, c, d, result
|
||||
a = 10
|
||||
b = 20
|
||||
c = 30
|
||||
d = 40
|
||||
result = a + b + c + d
|
||||
17
local_tests/test_arc_fix.nyash
Normal file
17
local_tests/test_arc_fix.nyash
Normal file
@ -0,0 +1,17 @@
|
||||
static box Main {
|
||||
init { server }
|
||||
|
||||
main() {
|
||||
me.server = new SocketBox()
|
||||
|
||||
print("=== Before bind ===")
|
||||
print("isServer: " + me.server.isServer())
|
||||
|
||||
me.server.bind("127.0.0.1", 8080)
|
||||
|
||||
print("=== After bind ===")
|
||||
print("isServer: " + me.server.isServer()) // This should be true if fix works!
|
||||
|
||||
return me.server.isServer()
|
||||
}
|
||||
}
|
||||
62
local_tests/test_arc_mutex_bug.nyash
Normal file
62
local_tests/test_arc_mutex_bug.nyash
Normal file
@ -0,0 +1,62 @@
|
||||
// 🔥 Arc<Mutex>状態共有破壊バグの最小再現テスト
|
||||
|
||||
static box Main {
|
||||
init { console, server, result }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
|
||||
// 🎯 テスト1: SocketBox作成・bind・状態確認
|
||||
me.console.log("=== Arc<Mutex>状態共有破壊バグ再現テスト ===")
|
||||
|
||||
// Step 1: SocketBox作成
|
||||
me.server = new SocketBox()
|
||||
me.console.log("1. SocketBox作成完了")
|
||||
|
||||
// Step 2: bind実行(is_server = trueに設定されるはず)
|
||||
local bind_result
|
||||
bind_result = me.server.bind("127.0.0.1", 18080)
|
||||
me.console.log("2. bind完了, 結果: " + bind_result.toString())
|
||||
|
||||
// Step 3: 状態確認(ここでclone()が発生する可能性)
|
||||
local is_server_check1
|
||||
is_server_check1 = me.server.isServer()
|
||||
me.console.log("3. isServer()チェック1: " + is_server_check1.toString())
|
||||
|
||||
// Step 4: 変数再代入(clone()確実に発生)
|
||||
local server_copy
|
||||
server_copy = me.server
|
||||
me.console.log("4. サーバー変数コピー完了")
|
||||
|
||||
// Step 5: コピー後の状態確認
|
||||
local is_server_check2
|
||||
is_server_check2 = server_copy.isServer()
|
||||
me.console.log("5. コピー後isServer()チェック2: " + is_server_check2.toString())
|
||||
|
||||
// Step 6: 元の変数での状態確認
|
||||
local is_server_check3
|
||||
is_server_check3 = me.server.isServer()
|
||||
me.console.log("6. 元変数isServer()チェック3: " + is_server_check3.toString())
|
||||
|
||||
// 🔍 期待結果 vs 実際結果
|
||||
me.console.log("")
|
||||
me.console.log("=== 結果分析 ===")
|
||||
me.console.log("期待結果: 全てtrueであるべき(Arc共有なら)")
|
||||
me.console.log("実際結果:")
|
||||
me.console.log(" bind後: " + is_server_check1.toString())
|
||||
me.console.log(" copy後: " + is_server_check2.toString())
|
||||
me.console.log(" 元変数: " + is_server_check3.toString())
|
||||
|
||||
if is_server_check1.toString() == "true" and is_server_check2.toString() == "false" {
|
||||
me.console.log("")
|
||||
me.console.log("🔥 BUG CONFIRMED: clone()でArc共有が破壊されています!")
|
||||
me.result = "bug_confirmed"
|
||||
} else {
|
||||
me.console.log("")
|
||||
me.console.log("✅ 予想外: 問題が修正されている可能性")
|
||||
me.result = "unexpected_fix"
|
||||
}
|
||||
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
24
local_tests/test_arc_sharing.nyash
Normal file
24
local_tests/test_arc_sharing.nyash
Normal file
@ -0,0 +1,24 @@
|
||||
// Test Arc sharing issue
|
||||
static box Main {
|
||||
main() {
|
||||
print("🔬 Testing Arc sharing...")
|
||||
|
||||
local socket1
|
||||
socket1 = new SocketBox()
|
||||
|
||||
local socket2
|
||||
socket2 = socket1 // This should clone
|
||||
|
||||
print("Before bind - socket1.isServer(): " + socket1.isServer().toString())
|
||||
print("Before bind - socket2.isServer(): " + socket2.isServer().toString())
|
||||
|
||||
socket1.bind("127.0.0.1", 8080)
|
||||
|
||||
print("After bind - socket1.isServer(): " + socket1.isServer().toString())
|
||||
print("After bind - socket2.isServer(): " + socket2.isServer().toString())
|
||||
|
||||
socket1.close()
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
7
local_tests/test_arithmetic.nyash
Normal file
7
local_tests/test_arithmetic.nyash
Normal file
@ -0,0 +1,7 @@
|
||||
// 算術演算テスト
|
||||
print(2 + 3)
|
||||
print(10 - 4)
|
||||
print(5 * 3)
|
||||
print(15 / 3)
|
||||
print("Hello" + "World")
|
||||
print("Test" * 3)
|
||||
31
local_tests/test_array_debug.nyash
Normal file
31
local_tests/test_array_debug.nyash
Normal file
@ -0,0 +1,31 @@
|
||||
// ArrayBox動作確認テスト
|
||||
static box ArrayTest {
|
||||
init { arr, random }
|
||||
|
||||
main() {
|
||||
me.random = new RandomBox()
|
||||
me.arr = new ArrayBox()
|
||||
|
||||
print("=== ArrayBox動作テスト ===")
|
||||
|
||||
// 初期状態確認
|
||||
print("初期長さ: " + me.arr.length().toString())
|
||||
|
||||
// 要素追加
|
||||
me.arr.push("要素1")
|
||||
print("push後の長さ: " + me.arr.length().toString())
|
||||
|
||||
me.arr.push("要素2")
|
||||
print("2回目push後の長さ: " + me.arr.length().toString())
|
||||
|
||||
// 乱数テスト
|
||||
local randomNum
|
||||
randomNum = me.random.next()
|
||||
print("乱数生成: " + randomNum.toString())
|
||||
|
||||
// ArrayBox内容確認
|
||||
print("配列内容: " + me.arr.toString())
|
||||
|
||||
return "テスト完了"
|
||||
}
|
||||
}
|
||||
43
local_tests/test_array_length_fix.nyash
Normal file
43
local_tests/test_array_length_fix.nyash
Normal file
@ -0,0 +1,43 @@
|
||||
// Test for ArrayBox.length() functionality
|
||||
static box ArrayLengthTest {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🧪 Testing ArrayBox.length() functionality")
|
||||
|
||||
// Test 1: Empty array
|
||||
local empty_array = new ArrayBox()
|
||||
local empty_length = empty_array.length()
|
||||
me.console.log("Empty array length: " + empty_length) // Expected: 0
|
||||
|
||||
// Test 2: Array with elements
|
||||
local test_array = new ArrayBox()
|
||||
test_array.push("first")
|
||||
test_array.push("second")
|
||||
test_array.push("third")
|
||||
|
||||
local length_after_push = test_array.length()
|
||||
me.console.log("Array length after 3 pushes: " + length_after_push) // Expected: 3
|
||||
|
||||
// Test 3: Array after pop
|
||||
local popped = test_array.pop()
|
||||
me.console.log("Popped element: " + popped)
|
||||
|
||||
local length_after_pop = test_array.length()
|
||||
me.console.log("Array length after pop: " + length_after_pop) // Expected: 2
|
||||
|
||||
// Test 4: Verify elements are still accessible
|
||||
local first_element = test_array.get(0)
|
||||
local second_element = test_array.get(1)
|
||||
me.console.log("Element at index 0: " + first_element)
|
||||
me.console.log("Element at index 1: " + second_element)
|
||||
|
||||
// Test 5: Edge case - accessing beyond length
|
||||
local beyond_length = test_array.get(5)
|
||||
me.console.log("Element beyond length: " + beyond_length) // Expected: null
|
||||
|
||||
me.console.log("✅ ArrayBox.length() tests completed")
|
||||
return "ArrayBox functionality verified"
|
||||
}
|
||||
}
|
||||
11
local_tests/test_array_state_issue.nyash
Normal file
11
local_tests/test_array_state_issue.nyash
Normal file
@ -0,0 +1,11 @@
|
||||
// 🚨 ArrayBox状態保持問題のテスト
|
||||
static box Main {
|
||||
init { result }
|
||||
main() {
|
||||
local arr
|
||||
arr = new ArrayBox()
|
||||
arr.push("hello") // 状態変更
|
||||
me.result = arr.length() // 期待値: 1, 実際: 0?
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
12
local_tests/test_async_simple.nyash
Normal file
12
local_tests/test_async_simple.nyash
Normal file
@ -0,0 +1,12 @@
|
||||
// Simple async test with proper variable declarations
|
||||
static box Main {
|
||||
init { result }
|
||||
|
||||
main() {
|
||||
local f1
|
||||
nowait f1 = 42
|
||||
me.result = await f1
|
||||
print(me.result)
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
20
local_tests/test_basic_sharing.nyash
Normal file
20
local_tests/test_basic_sharing.nyash
Normal file
@ -0,0 +1,20 @@
|
||||
// Test basic field access sharing
|
||||
static box Main {
|
||||
init { mybox }
|
||||
|
||||
main() {
|
||||
me.mybox = new IntegerBox(100)
|
||||
|
||||
print("=== Test 1: Basic field access ===")
|
||||
local temp1
|
||||
temp1 = me.mybox
|
||||
print("temp1 ID: " + temp1.toString())
|
||||
|
||||
local temp2
|
||||
temp2 = me.mybox
|
||||
print("temp2 ID: " + temp2.toString())
|
||||
|
||||
// The IDs should be the same if sharing works
|
||||
return temp1
|
||||
}
|
||||
}
|
||||
7
local_tests/test_basic_wasm.nyash
Normal file
7
local_tests/test_basic_wasm.nyash
Normal file
@ -0,0 +1,7 @@
|
||||
static box Main {
|
||||
main() {
|
||||
print("WASM Box Operations Test")
|
||||
print(42 + 8)
|
||||
return 50
|
||||
}
|
||||
}
|
||||
27
local_tests/test_birth_simple.nyash
Normal file
27
local_tests/test_birth_simple.nyash
Normal file
@ -0,0 +1,27 @@
|
||||
# 🌟 birth() テスト - 生命をBoxに与える!
|
||||
|
||||
box Life {
|
||||
init { name, energy }
|
||||
|
||||
birth(lifeName) { # 生命を誕生させる
|
||||
me.name = lifeName
|
||||
me.energy = 100
|
||||
print("🌟 " + lifeName + " が誕生しました!")
|
||||
}
|
||||
|
||||
introduce() {
|
||||
print("私の名前は " + me.name + " です。エネルギーは " + me.energy + " です。")
|
||||
return me.name
|
||||
}
|
||||
}
|
||||
|
||||
print("=== birth() 構文テスト開始 ===")
|
||||
|
||||
# birth()コンストラクタでLife作成
|
||||
local alice = new Life("Alice")
|
||||
alice.introduce()
|
||||
|
||||
local bob = new Life("Bob")
|
||||
bob.introduce()
|
||||
|
||||
print("=== birth() テスト完了 ===")
|
||||
@ -1,35 +1,14 @@
|
||||
// 🧪 新Box作成テスト - メソッド呼び出しなし
|
||||
box SimpleBox {
|
||||
init { value }
|
||||
|
||||
pack(v) {
|
||||
me.value = v
|
||||
}
|
||||
}
|
||||
|
||||
print("=== New Box Creation Test ===")
|
||||
|
||||
// 📊 BufferBox Test
|
||||
print("🔹 Creating BufferBox...")
|
||||
local buffer
|
||||
buffer = new BufferBox()
|
||||
print("✅ BufferBox created successfully!")
|
||||
|
||||
// 🔍 RegexBox Test
|
||||
print("🔹 Creating RegexBox...")
|
||||
local regex
|
||||
regex = new RegexBox("[0-9]+")
|
||||
print("✅ RegexBox created successfully!")
|
||||
|
||||
// 📋 JSONBox Test
|
||||
print("🔹 Creating JSONBox...")
|
||||
local json
|
||||
json = new JSONBox("{\"name\": \"test\"}")
|
||||
print("✅ JSONBox created successfully!")
|
||||
|
||||
// 🌊 StreamBox Test
|
||||
print("🔹 Creating StreamBox...")
|
||||
local stream
|
||||
stream = new StreamBox()
|
||||
print("✅ StreamBox created successfully!")
|
||||
|
||||
// 🌐 HTTPClientBox Test
|
||||
print("🔹 Creating HTTPClientBox...")
|
||||
local http
|
||||
http = new HTTPClientBox()
|
||||
print("✅ HTTPClientBox created successfully!")
|
||||
|
||||
print("\n🎉 All Arc<Mutex> Boxes created successfully!")
|
||||
static box Main {
|
||||
main() {
|
||||
local obj = new SimpleBox(100)
|
||||
return 200
|
||||
}
|
||||
}
|
||||
21
local_tests/test_box_id_sharing.nyash
Normal file
21
local_tests/test_box_id_sharing.nyash
Normal file
@ -0,0 +1,21 @@
|
||||
// Test for Arc sharing - checking if same Box ID is returned
|
||||
static box Main {
|
||||
init { server }
|
||||
|
||||
main() {
|
||||
me.server = new SocketBox()
|
||||
|
||||
print("=== First access ===")
|
||||
local temp1
|
||||
temp1 = me.server
|
||||
print("Box ID: " + temp1.toString())
|
||||
|
||||
print("=== Second access ===")
|
||||
local temp2
|
||||
temp2 = me.server
|
||||
print("Box ID: " + temp2.toString())
|
||||
|
||||
// If Arc sharing works, both should have same ID
|
||||
return temp1
|
||||
}
|
||||
}
|
||||
32
local_tests/test_boxcall_fix.nyash
Normal file
32
local_tests/test_boxcall_fix.nyash
Normal file
@ -0,0 +1,32 @@
|
||||
// Test script to validate BoxCall fix
|
||||
// This should work with both interpreter and VM backends
|
||||
|
||||
// Test StringBox method calls
|
||||
local s
|
||||
local len_result
|
||||
local str_result
|
||||
s = "Hello World"
|
||||
len_result = s.length()
|
||||
str_result = s.toString()
|
||||
|
||||
print(len_result)
|
||||
print(str_result)
|
||||
|
||||
// Test IntegerBox method calls
|
||||
local num
|
||||
local num_str
|
||||
local abs_num
|
||||
num = 42
|
||||
num_str = num.toString()
|
||||
abs_num = num.abs()
|
||||
|
||||
print(num_str)
|
||||
print(abs_num)
|
||||
|
||||
// Test BoolBox method calls
|
||||
local flag
|
||||
local bool_str
|
||||
flag = true
|
||||
bool_str = flag.toString()
|
||||
|
||||
print(bool_str)
|
||||
15
local_tests/test_buffer_simple.nyash
Normal file
15
local_tests/test_buffer_simple.nyash
Normal file
@ -0,0 +1,15 @@
|
||||
// シンプルなBufferBoxテスト
|
||||
static box Main {
|
||||
main() {
|
||||
print("BufferBox基本テスト開始")
|
||||
|
||||
local buffer = new BufferBox()
|
||||
print("BufferBox作成完了")
|
||||
|
||||
// 基本メソッドテスト
|
||||
local len = buffer.length()
|
||||
print("length: " + len)
|
||||
|
||||
return "complete"
|
||||
}
|
||||
}
|
||||
37
local_tests/test_c_app_port_validation.nyash
Normal file
37
local_tests/test_c_app_port_validation.nyash
Normal file
@ -0,0 +1,37 @@
|
||||
// Final validation test for C app port fixes
|
||||
static box CAppPortFixValidation {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🎉 Final Validation Test - C App Port Fixes")
|
||||
|
||||
// Test the core fixes that enable the C apps to work
|
||||
me.console.log("1. ✅ ModuloBox E0046 error fixed - % operator now works")
|
||||
me.console.log("2. ✅ Static box instantiation pattern corrected")
|
||||
me.console.log("3. ✅ NULL literal support added to tokenizer/parser/AST")
|
||||
me.console.log("4. ✅ ArrayBox.length() usage patterns fixed")
|
||||
|
||||
// Verify critical functionality
|
||||
local modulo_result = 4096 % 4096
|
||||
me.console.log("Chip-8 modulo test: 4096 % 4096 = " + modulo_result)
|
||||
|
||||
local test_array = new ArrayBox()
|
||||
test_array.push("test")
|
||||
local length_result = test_array.length()
|
||||
me.console.log("Array length test: " + length_result.toString())
|
||||
|
||||
local null_test = null
|
||||
if null_test == null {
|
||||
me.console.log("Null literal test: ✅ PASSED")
|
||||
}
|
||||
|
||||
me.console.log("🚀 All C applications should now:")
|
||||
me.console.log(" - Tinyproxy: Parse and run without static box errors")
|
||||
me.console.log(" - Chip-8: Use % operator for bit manipulation")
|
||||
me.console.log(" - Kilo: Handle ArrayBox.length() correctly")
|
||||
|
||||
me.console.log("✅ All critical fixes validated!")
|
||||
return "C app port fixes complete"
|
||||
}
|
||||
}
|
||||
175
local_tests/test_chip8_fini_simple.nyash
Normal file
175
local_tests/test_chip8_fini_simple.nyash
Normal file
@ -0,0 +1,175 @@
|
||||
// 🧪 Chip-8 fini Propagation Simple Test - Phase 10 Feature Verification
|
||||
|
||||
// Simple CPU component for fini testing
|
||||
box SimpleCPU {
|
||||
init { memory_ref, graphics_ref, sound_ref }
|
||||
|
||||
SimpleCPU() {
|
||||
me.memory_ref = null
|
||||
me.graphics_ref = null
|
||||
me.sound_ref = null
|
||||
print("🔧 SimpleCPU created")
|
||||
}
|
||||
|
||||
// ⭐ Phase 10: fini propagation test
|
||||
fini() {
|
||||
print("🔄 CPU cleanup triggered - fini propagation starting")
|
||||
|
||||
// Clean up dependent components in order
|
||||
if (me.memory_ref != null) {
|
||||
me.memory_ref.cleanup()
|
||||
print("📦 Memory cleanup completed")
|
||||
}
|
||||
|
||||
if (me.graphics_ref != null) {
|
||||
me.graphics_ref.cleanup()
|
||||
print("🖼️ Graphics cleanup completed")
|
||||
}
|
||||
|
||||
if (me.sound_ref != null) {
|
||||
me.sound_ref.cleanup()
|
||||
print("🔊 Sound cleanup completed")
|
||||
}
|
||||
|
||||
print("✅ CPU fini propagation complete")
|
||||
}
|
||||
|
||||
link_components(memory, graphics, sound) {
|
||||
me.memory_ref = memory
|
||||
me.graphics_ref = graphics
|
||||
me.sound_ref = sound
|
||||
print("🔗 Components linked to CPU")
|
||||
}
|
||||
}
|
||||
|
||||
// Simple Memory component
|
||||
box SimpleMemory {
|
||||
init { data, alive }
|
||||
|
||||
SimpleMemory() {
|
||||
me.data = new ArrayBox()
|
||||
me.alive = true
|
||||
me.data.push("memory_data_1")
|
||||
me.data.push("memory_data_2")
|
||||
print("💾 SimpleMemory created with 2 data items")
|
||||
}
|
||||
|
||||
read_data() {
|
||||
if (me.alive) {
|
||||
return me.data.get(0)
|
||||
} else {
|
||||
print("⚠️ Memory component destroyed - access blocked")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
print("🧹 Memory cleanup: clearing data")
|
||||
me.data.clear()
|
||||
me.alive = false
|
||||
}
|
||||
}
|
||||
|
||||
// Simple Graphics component
|
||||
box SimpleGraphics {
|
||||
init { pixels, alive }
|
||||
|
||||
SimpleGraphics() {
|
||||
me.pixels = new ArrayBox()
|
||||
me.alive = true
|
||||
me.pixels.push(0)
|
||||
me.pixels.push(1)
|
||||
me.pixels.push(0)
|
||||
print("🖼️ SimpleGraphics created with 3 pixels")
|
||||
}
|
||||
|
||||
draw() {
|
||||
if (me.alive) {
|
||||
print("🎨 Drawing graphics...")
|
||||
return true
|
||||
} else {
|
||||
print("⚠️ Graphics component destroyed - draw blocked")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
print("🧹 Graphics cleanup: clearing display")
|
||||
me.pixels.clear()
|
||||
me.alive = false
|
||||
}
|
||||
}
|
||||
|
||||
// Simple Sound component
|
||||
box SimpleSound {
|
||||
init { volume, alive }
|
||||
|
||||
SimpleSound() {
|
||||
me.volume = 50
|
||||
me.alive = true
|
||||
print("🔊 SimpleSound created with volume " + me.volume)
|
||||
}
|
||||
|
||||
play() {
|
||||
if (me.alive) {
|
||||
print("🔔 Playing sound at volume " + me.volume)
|
||||
return true
|
||||
} else {
|
||||
print("⚠️ Sound component destroyed - playback blocked")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
print("🧹 Sound cleanup: stopping audio")
|
||||
me.volume = 0
|
||||
me.alive = false
|
||||
}
|
||||
}
|
||||
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🧪 Phase 10: Chip-8 fini Propagation Test")
|
||||
|
||||
// Create CPU and components
|
||||
local cpu = new SimpleCPU()
|
||||
local memory = new SimpleMemory()
|
||||
local graphics = new SimpleGraphics()
|
||||
local sound = new SimpleSound()
|
||||
|
||||
// Link components for fini propagation
|
||||
cpu.link_components(memory, graphics, sound)
|
||||
|
||||
// Test normal operation
|
||||
me.console.log("=== Normal Operation Test ===")
|
||||
local mem_data = memory.read_data()
|
||||
me.console.log("Memory data: " + mem_data)
|
||||
|
||||
local gfx_result = graphics.draw()
|
||||
me.console.log("Graphics draw result: " + gfx_result)
|
||||
|
||||
local sound_result = sound.play()
|
||||
me.console.log("Sound play result: " + sound_result)
|
||||
|
||||
// Test fini propagation
|
||||
me.console.log("=== fini Propagation Test ===")
|
||||
cpu.fini()
|
||||
|
||||
// Test operation after fini
|
||||
me.console.log("=== Post-fini Operation Test ===")
|
||||
local mem_data2 = memory.read_data()
|
||||
me.console.log("Memory data after fini: " + mem_data2)
|
||||
|
||||
local gfx_result2 = graphics.draw()
|
||||
me.console.log("Graphics draw after fini: " + gfx_result2)
|
||||
|
||||
local sound_result2 = sound.play()
|
||||
me.console.log("Sound play after fini: " + sound_result2)
|
||||
|
||||
me.console.log("🎉 Phase 10 fini propagation test complete!")
|
||||
return "fini propagation test finished"
|
||||
}
|
||||
}
|
||||
33
local_tests/test_complete_socketbox_fix.nyash
Normal file
33
local_tests/test_complete_socketbox_fix.nyash
Normal file
@ -0,0 +1,33 @@
|
||||
// Complete test for the SocketBox state preservation fix
|
||||
static box Main {
|
||||
init { server }
|
||||
|
||||
main() {
|
||||
print("=== SocketBox State Preservation Test ===")
|
||||
|
||||
// 1. Create new SocketBox
|
||||
me.server = new SocketBox()
|
||||
|
||||
print("=== Before bind ===")
|
||||
print("isServer: " + me.server.isServer())
|
||||
|
||||
// 2. Call bind() which should set is_server=true
|
||||
me.server.bind("127.0.0.1", 8080)
|
||||
|
||||
print("=== After bind ===")
|
||||
print("isServer: " + me.server.isServer())
|
||||
|
||||
// 3. Test multiple accesses
|
||||
print("=== Multiple access test ===")
|
||||
local temp1
|
||||
temp1 = me.server
|
||||
print("temp1.isServer(): " + temp1.isServer())
|
||||
|
||||
local temp2
|
||||
temp2 = me.server
|
||||
print("temp2.isServer(): " + temp2.isServer())
|
||||
|
||||
// If the fix works, all should return true
|
||||
return me.server.isServer()
|
||||
}
|
||||
}
|
||||
126
local_tests/test_comprehensive_fixes.nyash
Normal file
126
local_tests/test_comprehensive_fixes.nyash
Normal file
@ -0,0 +1,126 @@
|
||||
// Comprehensive test for all C app port fixes
|
||||
static box ComprehensiveFixTest {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🧪 Comprehensive C Application Port Fix Test")
|
||||
|
||||
// Test 1: ModuloBox % operator
|
||||
me.test_modulo_operator()
|
||||
|
||||
// Test 2: ArrayBox.length() functionality
|
||||
me.test_array_length()
|
||||
|
||||
// Test 3: Static box patterns
|
||||
me.test_static_box_usage()
|
||||
|
||||
// Test 4: Null literal support
|
||||
me.test_null_literals()
|
||||
|
||||
me.console.log("🎉 All fix tests completed successfully!")
|
||||
return "All C app port fixes verified"
|
||||
}
|
||||
|
||||
test_modulo_operator() {
|
||||
me.console.log("📐 Testing % operator (ModuloBox fix)...")
|
||||
|
||||
// Chip-8 style operations
|
||||
local opcode_test = 4096 % 4096
|
||||
if opcode_test == 0 {
|
||||
me.console.log("✅ Chip-8 4096 % 4096 = 0")
|
||||
} else {
|
||||
me.console.log("❌ Chip-8 modulo failed: " + opcode_test)
|
||||
}
|
||||
|
||||
local reg_test = 256 % 16
|
||||
if reg_test == 0 {
|
||||
me.console.log("✅ Register extraction 256 % 16 = 0")
|
||||
} else {
|
||||
me.console.log("❌ Register modulo failed: " + reg_test)
|
||||
}
|
||||
|
||||
local basic_test = 17 % 5
|
||||
if basic_test == 2 {
|
||||
me.console.log("✅ Basic modulo 17 % 5 = 2")
|
||||
} else {
|
||||
me.console.log("❌ Basic modulo failed: " + basic_test)
|
||||
}
|
||||
}
|
||||
|
||||
test_array_length() {
|
||||
me.console.log("📊 Testing ArrayBox.length() functionality...")
|
||||
|
||||
local test_array = new ArrayBox()
|
||||
local initial_length = test_array.length()
|
||||
|
||||
// Verify initial length is 0
|
||||
if initial_length.toString() == "0" {
|
||||
me.console.log("✅ Empty array length = 0")
|
||||
} else {
|
||||
me.console.log("❌ Empty array length failed: " + initial_length)
|
||||
}
|
||||
|
||||
// Add elements and test
|
||||
test_array.push("line1")
|
||||
test_array.push("line2")
|
||||
test_array.push("line3")
|
||||
|
||||
local populated_length = test_array.length()
|
||||
if populated_length.toString() == "3" {
|
||||
me.console.log("✅ Array with 3 elements length = 3")
|
||||
} else {
|
||||
me.console.log("❌ Populated array length failed: " + populated_length)
|
||||
}
|
||||
|
||||
// Test pop and length consistency
|
||||
local popped = test_array.pop()
|
||||
local after_pop_length = test_array.length()
|
||||
if after_pop_length.toString() == "2" {
|
||||
me.console.log("✅ Array after pop length = 2")
|
||||
} else {
|
||||
me.console.log("❌ Array after pop length failed: " + after_pop_length)
|
||||
}
|
||||
}
|
||||
|
||||
test_static_box_usage() {
|
||||
me.console.log("🏗️ Testing static box usage patterns...")
|
||||
|
||||
// Test that we can call static methods correctly
|
||||
local result = ComprehensiveFixTest.static_test_method()
|
||||
if result == "static success" {
|
||||
me.console.log("✅ Static method call works")
|
||||
} else {
|
||||
me.console.log("❌ Static method call failed: " + result)
|
||||
}
|
||||
|
||||
// Test static field access
|
||||
me.console.log("✅ Static field access through 'me' works")
|
||||
}
|
||||
|
||||
test_null_literals() {
|
||||
me.console.log("🔧 Testing null literal support...")
|
||||
|
||||
// Test null assignment
|
||||
local null_var = null
|
||||
if null_var == null {
|
||||
me.console.log("✅ Null assignment and comparison works")
|
||||
} else {
|
||||
me.console.log("❌ Null assignment failed")
|
||||
}
|
||||
|
||||
// Test null vs non-null
|
||||
local non_null_var = "not null"
|
||||
if non_null_var != null {
|
||||
me.console.log("✅ Non-null comparison works")
|
||||
} else {
|
||||
me.console.log("❌ Non-null comparison failed")
|
||||
}
|
||||
|
||||
me.console.log("✅ Null literal support verified")
|
||||
}
|
||||
|
||||
static_test_method() {
|
||||
return "static success"
|
||||
}
|
||||
}
|
||||
34
local_tests/test_debug_clone_state.nyash
Normal file
34
local_tests/test_debug_clone_state.nyash
Normal file
@ -0,0 +1,34 @@
|
||||
# Diagnostic test to understand clone state sharing
|
||||
static box Main {
|
||||
init { console, socket1, socket2 }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🔬 Clone State Diagnostic Test")
|
||||
|
||||
# Create original SocketBox
|
||||
me.socket1 = new SocketBox()
|
||||
|
||||
# Set state via bind
|
||||
local bindResult = me.socket1.bind("127.0.0.1", 19001)
|
||||
me.console.log("✅ bind() result: " + bindResult.toString())
|
||||
|
||||
# Check state immediately
|
||||
local isServer1 = me.socket1.isServer()
|
||||
me.console.log("🔍 socket1.isServer() after bind: " + isServer1.toString())
|
||||
|
||||
# Now check toString to see the socket ID
|
||||
local socketStr1 = me.socket1.toString()
|
||||
me.console.log("🆔 socket1 ID after bind: " + socketStr1)
|
||||
|
||||
# Check state again to see if we get the same socket ID
|
||||
local isServer2 = me.socket1.isServer()
|
||||
me.console.log("🔍 socket1.isServer() second call: " + isServer2.toString())
|
||||
|
||||
# Check toString again
|
||||
local socketStr2 = me.socket1.toString()
|
||||
me.console.log("🆔 socket1 ID second call: " + socketStr2)
|
||||
|
||||
return "DIAGNOSTIC_COMPLETE"
|
||||
}
|
||||
}
|
||||
63
local_tests/test_debug_socket_trace.nyash
Normal file
63
local_tests/test_debug_socket_trace.nyash
Normal file
@ -0,0 +1,63 @@
|
||||
# 🔥 SocketBox完全デバッグトレース
|
||||
# ファイルログ出力 + パーサーレベル追跡
|
||||
|
||||
static box Main {
|
||||
init { console, server, result, debug_id }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.debug_id = "TRACE_MAIN"
|
||||
me.console.log("🔥 SocketBox完全デバッグトレース開始")
|
||||
me.console.log("Debug ID: " + me.debug_id)
|
||||
|
||||
# Step 1: SocketBox作成
|
||||
me.console.log("=== Step 1: SocketBox作成 ===")
|
||||
me.server = new SocketBox()
|
||||
me.console.log("✅ SocketBox作成完了")
|
||||
me.console.log("作成されたSocketBox: " + me.server.toString())
|
||||
|
||||
# Step 2: 初期状態確認
|
||||
me.console.log("=== Step 2: 初期状態確認 ===")
|
||||
local initialState = me.server.isServer()
|
||||
me.console.log("初期isServer状態: " + initialState.toString())
|
||||
|
||||
# Step 3: bind実行 (詳細ログ出力)
|
||||
me.console.log("=== Step 3: bind実行 ===")
|
||||
me.console.log("bind呼び出し前のSocketBox: " + me.server.toString())
|
||||
|
||||
local bindResult = me.server.bind("127.0.0.1", 18080)
|
||||
me.console.log("bind戻り値: " + bindResult.toString())
|
||||
|
||||
# Step 4: bind後状態確認
|
||||
me.console.log("=== Step 4: bind後状態確認 ===")
|
||||
me.console.log("bind実行後のSocketBox: " + me.server.toString())
|
||||
|
||||
local postBindState = me.server.isServer()
|
||||
me.console.log("bind後isServer状態: " + postBindState.toString())
|
||||
|
||||
# Step 5: 再確認テスト
|
||||
me.console.log("=== Step 5: 再確認テスト ===")
|
||||
local recheck1 = me.server.isServer()
|
||||
local recheck2 = me.server.isServer()
|
||||
me.console.log("再確認1: " + recheck1.toString())
|
||||
me.console.log("再確認2: " + recheck2.toString())
|
||||
|
||||
# Step 6: 結果判定
|
||||
me.console.log("=== Step 6: 結果判定 ===")
|
||||
if postBindState.equals(true) {
|
||||
me.result = "🎉 SUCCESS: 状態保持正常"
|
||||
me.console.log(me.result)
|
||||
} else {
|
||||
me.result = "❌ FAILED: 状態保持失敗"
|
||||
me.console.log(me.result)
|
||||
me.console.log("bind結果: " + bindResult.toString())
|
||||
me.console.log("期待値: true, 実際値: " + postBindState.toString())
|
||||
}
|
||||
|
||||
# クリーンアップ
|
||||
me.server.close()
|
||||
me.console.log("🧹 クリーンアップ完了")
|
||||
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
32
local_tests/test_delegation_basic.nyash
Normal file
32
local_tests/test_delegation_basic.nyash
Normal file
@ -0,0 +1,32 @@
|
||||
box Parent {
|
||||
init { name }
|
||||
|
||||
pack(n) {
|
||||
me.name = n
|
||||
}
|
||||
|
||||
greet() {
|
||||
return "Hello " + me.name
|
||||
}
|
||||
}
|
||||
|
||||
box Child from Parent {
|
||||
init { age }
|
||||
|
||||
pack(n, a) {
|
||||
from Parent.pack(n)
|
||||
me.age = a
|
||||
}
|
||||
|
||||
override greet() {
|
||||
local base = from Parent.greet()
|
||||
return base + " (age " + me.age + ")"
|
||||
}
|
||||
}
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local c = new Child("Alice", 25)
|
||||
return c.greet()
|
||||
}
|
||||
}
|
||||
44
local_tests/test_detailed_debug.nyash
Normal file
44
local_tests/test_detailed_debug.nyash
Normal file
@ -0,0 +1,44 @@
|
||||
// 🔍 詳細デバッグテスト - Box IDとArcポインタ追跡
|
||||
|
||||
static box Main {
|
||||
init { console, server }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
|
||||
me.console.log("=== 詳細デバッグ: Box ID & Arc ポインタ追跡 ===")
|
||||
|
||||
// Step 1: SocketBox作成直後
|
||||
me.server = new SocketBox()
|
||||
me.console.log("1. SocketBox作成直後:")
|
||||
me.console.log(" Box toString: " + me.server.toString())
|
||||
me.console.log(" isServer: " + me.server.isServer().toString())
|
||||
|
||||
// Step 2: bind実行
|
||||
me.console.log("")
|
||||
me.console.log("2. bind実行...")
|
||||
local bind_result
|
||||
bind_result = me.server.bind("127.0.0.1", 18080)
|
||||
me.console.log(" bind結果: " + bind_result.toString())
|
||||
|
||||
// Step 3: bind直後の状態
|
||||
me.console.log("")
|
||||
me.console.log("3. bind直後:")
|
||||
me.console.log(" Box toString: " + me.server.toString())
|
||||
me.console.log(" isServer: " + me.server.isServer().toString())
|
||||
|
||||
// Step 4: 明示的な変数代入なし - 直接アクセス
|
||||
me.console.log("")
|
||||
me.console.log("4. 直接アクセス:")
|
||||
me.console.log(" me.server.isServer(): " + me.server.isServer().toString())
|
||||
|
||||
// Step 5: 複数回連続アクセス
|
||||
me.console.log("")
|
||||
me.console.log("5. 複数回アクセス:")
|
||||
me.console.log(" 1回目: " + me.server.isServer().toString())
|
||||
me.console.log(" 2回目: " + me.server.isServer().toString())
|
||||
me.console.log(" 3回目: " + me.server.isServer().toString())
|
||||
|
||||
return "debug_completed"
|
||||
}
|
||||
}
|
||||
26
local_tests/test_direct_clone.nyash
Normal file
26
local_tests/test_direct_clone.nyash
Normal file
@ -0,0 +1,26 @@
|
||||
# Isolate the Arc sharing issue
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🔬 Direct Clone Test")
|
||||
|
||||
# Create socket and bind
|
||||
local socket1 = new SocketBox()
|
||||
local bindResult = socket1.bind("127.0.0.1", 19777)
|
||||
me.console.log("✅ Bind result: " + bindResult.toString())
|
||||
|
||||
# Clone the socket manually
|
||||
local socket2 = socket1
|
||||
|
||||
# Check if clone has the same state
|
||||
local isServer1 = socket1.isServer()
|
||||
local isServer2 = socket2.isServer()
|
||||
|
||||
me.console.log("🔍 socket1.isServer(): " + isServer1.toString())
|
||||
me.console.log("🔍 socket2.isServer(): " + isServer2.toString())
|
||||
|
||||
return "DIRECT_CLONE_TEST"
|
||||
}
|
||||
}
|
||||
12
local_tests/test_direct_extern.nyash
Normal file
12
local_tests/test_direct_extern.nyash
Normal file
@ -0,0 +1,12 @@
|
||||
# Test direct external calls pattern
|
||||
static box Main {
|
||||
init { result }
|
||||
|
||||
main() {
|
||||
# Direct external call (this should trigger ExternCall)
|
||||
console.log("Direct console call test")
|
||||
|
||||
me.result = "Direct call demo completed"
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
17
local_tests/test_extern_call_demo.nyash
Normal file
17
local_tests/test_extern_call_demo.nyash
Normal file
@ -0,0 +1,17 @@
|
||||
# Phase 9.7 ExternCall Demo - Modified for explicit console creation
|
||||
# Test console.log and canvas operations
|
||||
|
||||
static box Main {
|
||||
init { result, console }
|
||||
|
||||
main() {
|
||||
# Create console instance for testing
|
||||
me.console = new ConsoleBox()
|
||||
|
||||
# Test console.log external call
|
||||
me.console.log("Hello from Nyash via ExternCall!")
|
||||
|
||||
me.result = "ExternCall demo completed"
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
23
local_tests/test_field_access.nyash
Normal file
23
local_tests/test_field_access.nyash
Normal file
@ -0,0 +1,23 @@
|
||||
// Test for Phase 6 Box reference operations
|
||||
// Simple field access test
|
||||
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("Testing Phase 6 Box reference operations")
|
||||
|
||||
// Create a simple object
|
||||
local obj
|
||||
obj = new StringBox("Hello")
|
||||
|
||||
// Test field access
|
||||
local result
|
||||
result = obj.length
|
||||
|
||||
print("Field access result: " + result)
|
||||
|
||||
return "Phase 6 test completed"
|
||||
}
|
||||
}
|
||||
29
local_tests/test_field_arc_sharing.nyash
Normal file
29
local_tests/test_field_arc_sharing.nyash
Normal file
@ -0,0 +1,29 @@
|
||||
# Test Arc sharing for field access
|
||||
static box Main {
|
||||
init { console, server }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🔬 Field Access Arc Sharing Test")
|
||||
|
||||
# Store socket in field
|
||||
me.server = new SocketBox()
|
||||
me.console.log("✅ Created me.server")
|
||||
|
||||
# Test 1: Multiple field accesses
|
||||
local str1 = me.server.toString()
|
||||
me.console.log("📊 First field access: " + str1)
|
||||
|
||||
local str2 = me.server.toString()
|
||||
me.console.log("📊 Second field access: " + str2)
|
||||
|
||||
# Test 2: State change via field access
|
||||
local bindResult = me.server.bind("127.0.0.1", 19888)
|
||||
me.console.log("✅ Bind via field access: " + bindResult.toString())
|
||||
|
||||
local isServer = me.server.isServer()
|
||||
me.console.log("🔍 isServer via field access: " + isServer.toString())
|
||||
|
||||
return "FIELD_ACCESS_ARC_TEST"
|
||||
}
|
||||
}
|
||||
16
local_tests/test_field_mir.nyash
Normal file
16
local_tests/test_field_mir.nyash
Normal file
@ -0,0 +1,16 @@
|
||||
// Test field access MIR generation
|
||||
static box TestBox {
|
||||
init { name, value }
|
||||
}
|
||||
|
||||
static box Main {
|
||||
init { test_obj }
|
||||
|
||||
main() {
|
||||
me.test_obj = new TestBox()
|
||||
local result
|
||||
result = me.test_obj.name
|
||||
print(result)
|
||||
return "Done"
|
||||
}
|
||||
}
|
||||
19
local_tests/test_field_operations.nyash
Normal file
19
local_tests/test_field_operations.nyash
Normal file
@ -0,0 +1,19 @@
|
||||
box Counter {
|
||||
init { count }
|
||||
|
||||
pack() {
|
||||
me.count = 0
|
||||
}
|
||||
|
||||
increment() {
|
||||
me.count = me.count + 1
|
||||
return me.count
|
||||
}
|
||||
}
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local c = new Counter()
|
||||
return c.increment()
|
||||
}
|
||||
}
|
||||
51
local_tests/test_final_validation.nyash
Normal file
51
local_tests/test_final_validation.nyash
Normal file
@ -0,0 +1,51 @@
|
||||
// Final validation test for the SocketBox state preservation fix
|
||||
// This test replicates the exact scenario described in issue #74
|
||||
|
||||
static box Main {
|
||||
init { server }
|
||||
|
||||
main() {
|
||||
print("=== Issue #74 Validation Test ===")
|
||||
print("Testing SocketBox state preservation across field accesses")
|
||||
print("")
|
||||
|
||||
// Create SocketBox and store in field
|
||||
me.server = new SocketBox()
|
||||
|
||||
print("Step 1: Initial state")
|
||||
print("me.server.isServer(): " + me.server.isServer()) // Should be false
|
||||
print("")
|
||||
|
||||
print("Step 2: Calling bind() to set server state")
|
||||
me.server.bind("127.0.0.1", 8080) // This should set is_server=true
|
||||
print("bind() completed")
|
||||
print("")
|
||||
|
||||
print("Step 3: Checking state after bind()")
|
||||
print("me.server.isServer(): " + me.server.isServer()) // Should be true if fix works!
|
||||
print("")
|
||||
|
||||
// Additional tests: multiple accesses should all return same state
|
||||
print("Step 4: Multiple field access test")
|
||||
local server1
|
||||
server1 = me.server
|
||||
print("server1.isServer(): " + server1.isServer()) // Should be true
|
||||
|
||||
local server2
|
||||
server2 = me.server
|
||||
print("server2.isServer(): " + server2.isServer()) // Should be true
|
||||
|
||||
print("")
|
||||
print("=== Test Summary ===")
|
||||
if (me.server.isServer()) {
|
||||
print("✅ SUCCESS: SocketBox state preserved across field accesses!")
|
||||
print(" The 'Everything is Box' design now correctly shares state")
|
||||
print(" for stateful boxes like SocketBox, P2PBox, etc.")
|
||||
} else {
|
||||
print("❌ FAILURE: SocketBox state was not preserved")
|
||||
print(" The fix did not work as expected")
|
||||
}
|
||||
|
||||
return me.server.isServer()
|
||||
}
|
||||
}
|
||||
42
local_tests/test_http_server_basic.nyash
Normal file
42
local_tests/test_http_server_basic.nyash
Normal file
@ -0,0 +1,42 @@
|
||||
// 🌐 Simple HTTP Server Box Test
|
||||
// Tests HTTPServerBox creation and basic operations
|
||||
|
||||
static box Main {
|
||||
init { server, result }
|
||||
|
||||
main() {
|
||||
print("🌐 Testing HTTPServerBox functionality...")
|
||||
|
||||
// Create HTTPServerBox
|
||||
me.server = new HTTPServerBox()
|
||||
print("✅ HTTPServerBox created: " + me.server.toString())
|
||||
|
||||
// Test binding
|
||||
print("🔌 Testing bind operation...")
|
||||
local bindResult
|
||||
bindResult = me.server.bind("127.0.0.1", 8080)
|
||||
print("📡 Bind result: " + bindResult.toString())
|
||||
|
||||
if (bindResult.toString() == "true") {
|
||||
print("✅ Successfully bound to port 8080")
|
||||
|
||||
// Test listen
|
||||
print("👂 Testing listen operation...")
|
||||
local listenResult
|
||||
listenResult = me.server.listen(10)
|
||||
print("📡 Listen result: " + listenResult.toString())
|
||||
|
||||
if (listenResult.toString() == "true") {
|
||||
print("✅ HTTPServerBox ready!")
|
||||
me.result = "HTTPServerBox test successful"
|
||||
} else {
|
||||
me.result = "HTTPServerBox listen failed"
|
||||
}
|
||||
} else {
|
||||
me.result = "HTTPServerBox bind failed"
|
||||
}
|
||||
|
||||
print("🏁 Test completed: " + me.result)
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
21
local_tests/test_http_server_real.nyash
Normal file
21
local_tests/test_http_server_real.nyash
Normal file
@ -0,0 +1,21 @@
|
||||
// Test HTTPServer listen functionality
|
||||
static box Main {
|
||||
init { server, console }
|
||||
|
||||
main() {
|
||||
me.server = new HTTPServerBox()
|
||||
me.console = new ConsoleBox()
|
||||
|
||||
// Test bind and listen operations
|
||||
local bindResult = me.server.bind("127.0.0.1", 8080)
|
||||
me.console.log("Bind result:")
|
||||
print(bindResult)
|
||||
|
||||
local listenResult = me.server.listen(10)
|
||||
me.console.log("Listen result:")
|
||||
print(listenResult)
|
||||
|
||||
// Should return true if listen actually works
|
||||
return listenResult
|
||||
}
|
||||
}
|
||||
48
local_tests/test_kilo_memory_simple.nyash
Normal file
48
local_tests/test_kilo_memory_simple.nyash
Normal file
@ -0,0 +1,48 @@
|
||||
// 🧪 Kilo Memory Efficiency Simple Test - Phase 10 Feature Verification
|
||||
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🧪 Phase 10 Kilo Memory Test")
|
||||
|
||||
// Simple text buffer simulation
|
||||
local buffer = new ArrayBox()
|
||||
me.console.log("📊 Created empty buffer")
|
||||
|
||||
// Test 1: Add some text
|
||||
buffer.push("Hello World")
|
||||
buffer.push("Second Line")
|
||||
me.console.log("✅ Added 2 lines: " + buffer.length() + " total")
|
||||
|
||||
// Test 2: Memory monitoring simulation
|
||||
local line_count = buffer.length()
|
||||
local estimated_memory = line_count * 20 // Simple estimation
|
||||
me.console.log("📈 Estimated memory: " + estimated_memory + " bytes")
|
||||
|
||||
// Test 3: "Accidental full copy" simulation
|
||||
local old_memory = estimated_memory
|
||||
buffer.push("This is a much longer line that might cause memory issues if copied inefficiently")
|
||||
|
||||
local new_line_count = buffer.length()
|
||||
local new_memory = new_line_count * 20
|
||||
local memory_growth = new_memory - old_memory
|
||||
|
||||
me.console.log("📊 Memory growth: " + old_memory + " -> " + new_memory + " (+"+memory_growth+")")
|
||||
|
||||
if (memory_growth > 100) {
|
||||
me.console.log("⚠️ Large memory growth detected! Possible inefficient copy")
|
||||
} else {
|
||||
me.console.log("✅ Memory growth within normal range")
|
||||
}
|
||||
|
||||
// Test 4: Operation counting
|
||||
local operation_count = 3 // We did 3 push operations
|
||||
local memory_per_op = new_memory / operation_count
|
||||
me.console.log("📈 Average memory per operation: " + memory_per_op + " bytes")
|
||||
|
||||
me.console.log("🎉 Phase 10 Kilo memory efficiency test complete!")
|
||||
return "Kilo memory test finished"
|
||||
}
|
||||
}
|
||||
7
local_tests/test_local_vars.nyash
Normal file
7
local_tests/test_local_vars.nyash
Normal file
@ -0,0 +1,7 @@
|
||||
static box Main {
|
||||
main() {
|
||||
local x = 10
|
||||
local y = 20
|
||||
return x + y
|
||||
}
|
||||
}
|
||||
19
local_tests/test_me_field_fix.nyash
Normal file
19
local_tests/test_me_field_fix.nyash
Normal file
@ -0,0 +1,19 @@
|
||||
static box Main {
|
||||
init { server }
|
||||
|
||||
main() {
|
||||
me.server = new SocketBox()
|
||||
me.server.bind("127.0.0.1", 8080)
|
||||
|
||||
local result = me.server.isServer()
|
||||
print("isServer result: " + result)
|
||||
|
||||
if (result) {
|
||||
print("✅ me フィールドが正しく更新されています!")
|
||||
} else {
|
||||
print("❌ me フィールドが更新されていません")
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
19
local_tests/test_minimal_no_methods.nyash
Normal file
19
local_tests/test_minimal_no_methods.nyash
Normal file
@ -0,0 +1,19 @@
|
||||
# 🔍 SocketBox最小テスト - メソッド呼び出しなし
|
||||
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("SocketBox最小テスト開始")
|
||||
|
||||
# SocketBox作成のみ
|
||||
local socket = new SocketBox()
|
||||
me.console.log("SocketBox作成完了")
|
||||
|
||||
# メソッド呼び出し一切なし
|
||||
me.console.log("テスト完了")
|
||||
|
||||
return "SUCCESS_MINIMAL"
|
||||
}
|
||||
}
|
||||
31
local_tests/test_minimal_socket.nyash
Normal file
31
local_tests/test_minimal_socket.nyash
Normal file
@ -0,0 +1,31 @@
|
||||
# 🔥 最小限SocketBoxテスト - bind()のみ
|
||||
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("最小限SocketBoxテスト開始")
|
||||
|
||||
# SocketBox作成
|
||||
local socket = new SocketBox()
|
||||
me.console.log("SocketBox作成完了")
|
||||
|
||||
# bind前状態
|
||||
local beforeBind = socket.isServer()
|
||||
me.console.log("Before: " + beforeBind.toString())
|
||||
|
||||
# bind実行
|
||||
local bindResult = socket.bind("127.0.0.1", 19999)
|
||||
me.console.log("Bind: " + bindResult.toString())
|
||||
|
||||
# bind後状態
|
||||
local afterBind = socket.isServer()
|
||||
me.console.log("After: " + afterBind.toString())
|
||||
|
||||
# クリーンアップ
|
||||
socket.close()
|
||||
|
||||
return "DONE"
|
||||
}
|
||||
}
|
||||
10
local_tests/test_mir_nowait.nyash
Normal file
10
local_tests/test_mir_nowait.nyash
Normal file
@ -0,0 +1,10 @@
|
||||
// Async operations MIR test
|
||||
static box Main {
|
||||
main() {
|
||||
nowait f1 = 42
|
||||
local result
|
||||
result = await f1
|
||||
print(result)
|
||||
return result
|
||||
}
|
||||
}
|
||||
14
local_tests/test_mir_object.nyash
Normal file
14
local_tests/test_mir_object.nyash
Normal file
@ -0,0 +1,14 @@
|
||||
// Object operations MIR test
|
||||
box DataBox {
|
||||
init { value }
|
||||
}
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local obj
|
||||
obj = new DataBox()
|
||||
obj.value = 1
|
||||
print(obj.value)
|
||||
return obj.value
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,9 @@
|
||||
/*!
|
||||
* Simple test for basic MIR functionality
|
||||
*/
|
||||
|
||||
// A simple Nyash program for testing MIR compilation
|
||||
print(42 + 10)
|
||||
// Simple MIR test
|
||||
static box Main {
|
||||
main() {
|
||||
local result
|
||||
result = 42 + 8
|
||||
print(result)
|
||||
return result
|
||||
}
|
||||
}
|
||||
31
local_tests/test_modulo_operator_fix.nyash
Normal file
31
local_tests/test_modulo_operator_fix.nyash
Normal file
@ -0,0 +1,31 @@
|
||||
// Test % operator functionality after ModuloBox fix
|
||||
static box ModuloTest {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🧪 Testing % operator after ModuloBox fix")
|
||||
|
||||
// Test 1: Basic modulo operation
|
||||
local result1 = 10 % 3
|
||||
me.console.log("10 % 3 = " + result1) // Expected: 1
|
||||
|
||||
// Test 2: Chip-8 style operations
|
||||
local result2 = 4096 % 4096
|
||||
me.console.log("4096 % 4096 = " + result2) // Expected: 0
|
||||
|
||||
local result3 = 256 % 16
|
||||
me.console.log("256 % 16 = " + result3) // Expected: 0
|
||||
|
||||
// Test 3: Common modulo patterns
|
||||
local result4 = 17 % 5
|
||||
me.console.log("17 % 5 = " + result4) // Expected: 2
|
||||
|
||||
// Test 4: Zero check (should not crash)
|
||||
local result5 = 42 % 1
|
||||
me.console.log("42 % 1 = " + result5) // Expected: 0
|
||||
|
||||
me.console.log("✅ Modulo operator tests completed")
|
||||
return "ModuloBox fix verified"
|
||||
}
|
||||
}
|
||||
25
local_tests/test_modulo_simple.nyash
Normal file
25
local_tests/test_modulo_simple.nyash
Normal file
@ -0,0 +1,25 @@
|
||||
// 🧪 % Modulo Operator Test - Simple functionality verification
|
||||
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🧪 Testing % Modulo Operator")
|
||||
|
||||
// Test 1: Basic modulo operation
|
||||
local result1 = 10 % 3
|
||||
me.console.log("10 % 3 = " + result1)
|
||||
|
||||
// Test 2: Chip-8 style bit masking
|
||||
local result2 = 4096 % 4096
|
||||
me.console.log("4096 % 4096 = " + result2)
|
||||
|
||||
// Test 3: Another typical case
|
||||
local result3 = 256 % 16
|
||||
me.console.log("256 % 16 = " + result3)
|
||||
|
||||
me.console.log("✅ % Modulo operator test complete!")
|
||||
return "Modulo test finished"
|
||||
}
|
||||
}
|
||||
40
local_tests/test_multiple_stateful_boxes.nyash
Normal file
40
local_tests/test_multiple_stateful_boxes.nyash
Normal file
@ -0,0 +1,40 @@
|
||||
// Comprehensive test for multiple stateful boxes
|
||||
static box Main {
|
||||
init { socket, debug_tracker }
|
||||
|
||||
main() {
|
||||
print("=== Comprehensive Stateful Box Test ===")
|
||||
|
||||
// Test 1: SocketBox (the main issue)
|
||||
print("=== Test 1: SocketBox ===")
|
||||
me.socket = new SocketBox()
|
||||
print("Before bind - isServer: " + me.socket.isServer())
|
||||
me.socket.bind("127.0.0.1", 8080)
|
||||
print("After bind - isServer: " + me.socket.isServer())
|
||||
|
||||
// Test multiple field accesses
|
||||
local socket1
|
||||
socket1 = me.socket
|
||||
local socket2
|
||||
socket2 = me.socket
|
||||
print("socket1.isServer(): " + socket1.isServer())
|
||||
print("socket2.isServer(): " + socket2.isServer())
|
||||
|
||||
// Test 2: DebugBox (should already work)
|
||||
print("=== Test 2: DebugBox ===")
|
||||
me.debug_tracker = new DebugBox()
|
||||
me.debug_tracker.enableTracking()
|
||||
print("Tracking enabled: " + me.debug_tracker.isTrackingEnabled())
|
||||
|
||||
// Test multiple accesses
|
||||
local debug1
|
||||
debug1 = me.debug_tracker
|
||||
local debug2
|
||||
debug2 = me.debug_tracker
|
||||
print("debug1.isTrackingEnabled(): " + debug1.isTrackingEnabled())
|
||||
print("debug2.isTrackingEnabled(): " + debug2.isTrackingEnabled())
|
||||
|
||||
print("=== All tests completed ===")
|
||||
return me.socket.isServer()
|
||||
}
|
||||
}
|
||||
30
local_tests/test_no_isserver.nyash
Normal file
30
local_tests/test_no_isserver.nyash
Normal file
@ -0,0 +1,30 @@
|
||||
# 🔍 isServer()を使わないテスト - 問題箇所特定
|
||||
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("isServer()なしテスト開始")
|
||||
|
||||
# SocketBox作成
|
||||
local socket = new SocketBox()
|
||||
me.console.log("SocketBox作成完了")
|
||||
|
||||
# toString()テスト(isServer()を内部で呼んでいるかも)
|
||||
me.console.log("toString()テスト開始")
|
||||
local socketStr = socket.toString()
|
||||
me.console.log("SocketBox: " + socketStr)
|
||||
|
||||
# bind実行(isServer()を呼ばずに)
|
||||
me.console.log("bind実行開始")
|
||||
local bindResult = socket.bind("127.0.0.1", 19999)
|
||||
me.console.log("Bind結果: " + bindResult.toString())
|
||||
|
||||
# クリーンアップ
|
||||
socket.close()
|
||||
me.console.log("テスト完了")
|
||||
|
||||
return "SUCCESS_NO_ISSERVER"
|
||||
}
|
||||
}
|
||||
10
local_tests/test_normal_field.nyash
Normal file
10
local_tests/test_normal_field.nyash
Normal file
@ -0,0 +1,10 @@
|
||||
static box Main {
|
||||
init { obj }
|
||||
|
||||
main() {
|
||||
me.obj = new StringBox("test")
|
||||
local result = me.obj.length()
|
||||
print(result)
|
||||
return result
|
||||
}
|
||||
}
|
||||
36
local_tests/test_null_literal_support.nyash
Normal file
36
local_tests/test_null_literal_support.nyash
Normal file
@ -0,0 +1,36 @@
|
||||
// Test null literal support
|
||||
static box NullLiteralTest {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🧪 Testing null literal support")
|
||||
|
||||
// Test 1: Basic null assignment
|
||||
local null_value = null
|
||||
me.console.log("Null value: " + null_value)
|
||||
|
||||
// Test 2: Null comparison
|
||||
if null_value == null {
|
||||
me.console.log("✅ Null comparison works")
|
||||
} else {
|
||||
me.console.log("❌ Null comparison failed")
|
||||
}
|
||||
|
||||
// Test 3: Null vs non-null
|
||||
local non_null = "not null"
|
||||
if non_null != null {
|
||||
me.console.log("✅ Non-null comparison works")
|
||||
} else {
|
||||
me.console.log("❌ Non-null comparison failed")
|
||||
}
|
||||
|
||||
// Test 4: Null in conditions
|
||||
if null_value == null {
|
||||
me.console.log("✅ Null condition evaluation works")
|
||||
}
|
||||
|
||||
me.console.log("✅ Null literal tests completed")
|
||||
return "Null literal support verified"
|
||||
}
|
||||
}
|
||||
5
local_tests/test_numeric_wasm.nyash
Normal file
5
local_tests/test_numeric_wasm.nyash
Normal file
@ -0,0 +1,5 @@
|
||||
static box Main {
|
||||
main() {
|
||||
return 42 + 8
|
||||
}
|
||||
}
|
||||
26
local_tests/test_nyashstd.nyash
Normal file
26
local_tests/test_nyashstd.nyash
Normal file
@ -0,0 +1,26 @@
|
||||
// Nyash標準ライブラリテスト
|
||||
// Phase 0: using nyashstd 基本機能
|
||||
|
||||
using nyashstd
|
||||
|
||||
local result
|
||||
result = string.create("Hello World")
|
||||
print(result)
|
||||
|
||||
local upper_result
|
||||
upper_result = string.upper(result)
|
||||
print(upper_result)
|
||||
|
||||
local number
|
||||
number = integer.create(42)
|
||||
print(number)
|
||||
|
||||
local flag
|
||||
flag = bool.create(true)
|
||||
print(flag)
|
||||
|
||||
local arr
|
||||
arr = array.create()
|
||||
print(arr)
|
||||
|
||||
console.log("✅ using nyashstd test completed!")
|
||||
34
local_tests/test_nyashstd_extension.nyash
Normal file
34
local_tests/test_nyashstd_extension.nyash
Normal file
@ -0,0 +1,34 @@
|
||||
// nyashstd拡張テスト - 基本型作成関数
|
||||
|
||||
using nyashstd
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
print("🌟 nyashstd拡張テスト開始")
|
||||
|
||||
// 既存のstring.upper()テスト
|
||||
local text = string.upper("hello")
|
||||
print("string.upper(): " + text)
|
||||
|
||||
// 新機能: string.create()テスト
|
||||
local created_string = string.create("created text")
|
||||
print("string.create(): " + created_string)
|
||||
|
||||
// 新機能: integer.create()テスト
|
||||
local num = integer.create(42)
|
||||
print("integer.create(): " + num)
|
||||
|
||||
// 新機能: bool.create()テスト
|
||||
local flag = bool.create(true)
|
||||
print("bool.create(): " + flag)
|
||||
|
||||
// 新機能: array.create()テスト
|
||||
local arr = array.create()
|
||||
print("array.create(): " + arr)
|
||||
|
||||
// 新機能: console.log()テスト
|
||||
console.log("Hello from console.log()!")
|
||||
|
||||
print("✅ nyashstd拡張テスト完了")
|
||||
}
|
||||
}
|
||||
63
local_tests/test_other_box_comparison.nyash
Normal file
63
local_tests/test_other_box_comparison.nyash
Normal file
@ -0,0 +1,63 @@
|
||||
# 🔍 他のBox動作確認 - SocketBoxとの比較分析
|
||||
# 正常に動作するBoxの状態保持を検証
|
||||
|
||||
static box Main {
|
||||
init { console, result }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🔍 他のBox動作確認テスト開始")
|
||||
|
||||
# ===== MapBox状態テスト =====
|
||||
me.console.log("=== MapBox状態テスト ===")
|
||||
local testMap = new MapBox()
|
||||
me.console.log("MapBox作成: " + testMap.toString())
|
||||
|
||||
testMap.set("key1", "value1")
|
||||
local getValue = testMap.get("key1")
|
||||
me.console.log("MapBox set/get: " + getValue.toString())
|
||||
|
||||
# ===== ArrayBox状態テスト =====
|
||||
me.console.log("=== ArrayBox状態テスト ===")
|
||||
local testArray = new ArrayBox()
|
||||
me.console.log("ArrayBox作成: " + testArray.toString())
|
||||
|
||||
testArray.push("item1")
|
||||
local arraySize = testArray.size()
|
||||
me.console.log("ArrayBox push/size: " + arraySize.toString())
|
||||
|
||||
# ===== MathBox状態テスト =====
|
||||
me.console.log("=== MathBox状態テスト ===")
|
||||
local testMath = new MathBox()
|
||||
me.console.log("MathBox作成: " + testMath.toString())
|
||||
|
||||
local mathResult = testMath.add(5, 3)
|
||||
me.console.log("MathBox add: " + mathResult.toString())
|
||||
|
||||
# ===== SocketBox状態テスト(問題箇所) =====
|
||||
me.console.log("=== SocketBox状態テスト(問題箇所) ===")
|
||||
local testSocket = new SocketBox()
|
||||
me.console.log("SocketBox作成: " + testSocket.toString())
|
||||
|
||||
local beforeBind = testSocket.isServer()
|
||||
me.console.log("Before bind: isServer = " + beforeBind.toString())
|
||||
|
||||
local bindResult = testSocket.bind("127.0.0.1", 18080)
|
||||
me.console.log("Bind result = " + bindResult.toString())
|
||||
|
||||
local afterBind = testSocket.isServer()
|
||||
me.console.log("After bind: isServer = " + afterBind.toString())
|
||||
|
||||
testSocket.close()
|
||||
|
||||
# ===== 結果判定 =====
|
||||
if afterBind.equals(true) {
|
||||
me.result = "SocketBox正常動作"
|
||||
} else {
|
||||
me.result = "SocketBox状態保持失敗 - 他のBoxは正常"
|
||||
}
|
||||
|
||||
me.console.log("🎯 テスト結果: " + me.result)
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
1
local_tests/test_other_boxes_quick.nyash
Normal file
1
local_tests/test_other_boxes_quick.nyash
Normal file
@ -0,0 +1 @@
|
||||
static box Main { init { console } main() { me.console = new ConsoleBox() local str = new StringBox("test") me.console.log("StringBox: " + str.toString()) local num = new IntegerBox(42) me.console.log("IntegerBox: " + num.toString()) return "OTHER_BOXES_OK" } }
|
||||
47
local_tests/test_other_boxes_working.nyash
Normal file
47
local_tests/test_other_boxes_working.nyash
Normal file
@ -0,0 +1,47 @@
|
||||
# test_other_boxes_working.nyash
|
||||
# ✅ 他のBox型正常動作確認(SocketBoxとの対比)
|
||||
|
||||
static box Main {
|
||||
init { console, results }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("✅ 他のBox正常動作確認テスト開始")
|
||||
me.results = new ArrayBox()
|
||||
|
||||
# Test 1: ArrayBox正常動作確認
|
||||
me.console.log("Test 1: ArrayBox...")
|
||||
local array = new ArrayBox()
|
||||
array.push("test_item")
|
||||
local arraySize = array.size()
|
||||
me.console.log("✅ ArrayBox正常: size=" + arraySize.toString())
|
||||
me.results.push("ArrayBox:OK")
|
||||
|
||||
# Test 2: MapBox正常動作確認
|
||||
me.console.log("Test 2: MapBox...")
|
||||
local map = new MapBox()
|
||||
map.set("test_key", "test_value")
|
||||
local mapValue = map.get("test_key")
|
||||
me.console.log("✅ MapBox正常: value=" + mapValue.toString())
|
||||
me.results.push("MapBox:OK")
|
||||
|
||||
# Test 3: IntegerBox正常動作確認
|
||||
me.console.log("Test 3: IntegerBox...")
|
||||
local num = new IntegerBox(42)
|
||||
local numStr = num.toString()
|
||||
me.console.log("✅ IntegerBox正常: " + numStr)
|
||||
me.results.push("IntegerBox:OK")
|
||||
|
||||
# Test 4: StringBox正常動作確認
|
||||
me.console.log("Test 4: StringBox...")
|
||||
local str = new StringBox("Hello")
|
||||
local strLen = str.length()
|
||||
me.console.log("✅ StringBox正常: length=" + strLen.toString())
|
||||
me.results.push("StringBox:OK")
|
||||
|
||||
local totalResults = me.results.size()
|
||||
me.console.log("🎉 他のBox全て正常動作: " + totalResults.toString() + "件成功")
|
||||
|
||||
return "OTHER_BOXES_ALL_OK"
|
||||
}
|
||||
}
|
||||
57
local_tests/test_pack_transparency.nyash
Normal file
57
local_tests/test_pack_transparency.nyash
Normal file
@ -0,0 +1,57 @@
|
||||
# 🔥 Phase 8.8: pack透明化システム テスト
|
||||
# ユーザーは`pack`を一切意識せず、`from BuiltinBox()`で自動動作
|
||||
|
||||
print("=== pack透明化システム テスト開始 ===")
|
||||
|
||||
# テストA: ユーザー定義Box基本動作 (birth優先)
|
||||
box Life {
|
||||
init { name, energy }
|
||||
|
||||
birth(lifeName) {
|
||||
me.name = lifeName
|
||||
me.energy = 100
|
||||
}
|
||||
|
||||
introduce() {
|
||||
return "私の名前は " + me.name + " です。"
|
||||
}
|
||||
}
|
||||
|
||||
local alice = new Life("Alice")
|
||||
print("A. " + alice.introduce())
|
||||
|
||||
# テストB: ビルトインBox継承(明示的pack使用)
|
||||
box EnhancedString from StringBox {
|
||||
init { prefix }
|
||||
|
||||
pack(content) {
|
||||
from StringBox.pack(content) # 明示的pack
|
||||
me.prefix = ">>> "
|
||||
}
|
||||
|
||||
override toString() {
|
||||
return me.prefix + from StringBox.toString()
|
||||
}
|
||||
}
|
||||
|
||||
local enhanced = new EnhancedString("Hello")
|
||||
print("B. " + enhanced.toString())
|
||||
|
||||
# テストC: 透明化システム動作 - 最重要テスト
|
||||
box SimpleString from StringBox {
|
||||
init { prefix }
|
||||
|
||||
birth(content, prefixStr) {
|
||||
from StringBox(content) # ← 透明化!内部的にpack呼び出し
|
||||
me.prefix = prefixStr
|
||||
}
|
||||
|
||||
override toString() {
|
||||
return me.prefix + from StringBox.toString()
|
||||
}
|
||||
}
|
||||
|
||||
local simple = new SimpleString("World", "<<< ")
|
||||
print("C. " + simple.toString())
|
||||
|
||||
print("=== pack透明化システム テスト完了 ===")
|
||||
40
local_tests/test_pack_transparency_basic.nyash
Normal file
40
local_tests/test_pack_transparency_basic.nyash
Normal file
@ -0,0 +1,40 @@
|
||||
# 🔥 Phase 8.8: pack透明化システム 基本テスト
|
||||
# ユーザーは`pack`を一切意識せず、`from BuiltinBox()`で自動動作
|
||||
|
||||
print("=== pack透明化システム基本テスト開始 ===")
|
||||
|
||||
# テストA: ユーザー定義Box基本動作 (birth優先)
|
||||
box Life {
|
||||
init { name, energy }
|
||||
|
||||
birth(lifeName) {
|
||||
me.name = lifeName
|
||||
me.energy = 100
|
||||
}
|
||||
|
||||
introduce() {
|
||||
return "私の名前は " + me.name + " です。"
|
||||
}
|
||||
}
|
||||
|
||||
local alice = new Life("Alice")
|
||||
print("A. " + alice.introduce())
|
||||
|
||||
# テストB: 透明化システム動作 - 最重要テスト
|
||||
box SimpleString from StringBox {
|
||||
init { prefix }
|
||||
|
||||
birth(content, prefixStr) {
|
||||
from StringBox(content) # ← 透明化!内部的にpack呼び出し
|
||||
me.prefix = prefixStr
|
||||
}
|
||||
|
||||
getMessage() {
|
||||
return me.prefix + "test message"
|
||||
}
|
||||
}
|
||||
|
||||
local simple = new SimpleString("World", "<<< ")
|
||||
print("B. " + simple.getMessage())
|
||||
|
||||
print("=== pack透明化システム基本テスト完了 ===")
|
||||
63
local_tests/test_pack_transparency_comprehensive.nyash
Normal file
63
local_tests/test_pack_transparency_comprehensive.nyash
Normal file
@ -0,0 +1,63 @@
|
||||
# 🔥 Phase 8.8: pack透明化システム 包括テスト
|
||||
# 全ビルトインBox継承パターンと mixed inheritance のテスト
|
||||
|
||||
print("=== pack透明化システム包括テスト開始 ===")
|
||||
|
||||
# テスト1: IntegerBox 透明化
|
||||
box SmartInteger from IntegerBox {
|
||||
init { isPositive }
|
||||
|
||||
birth(value) {
|
||||
from IntegerBox(value) # 透明化システム
|
||||
me.isPositive = value > 0
|
||||
}
|
||||
|
||||
getInfo() {
|
||||
if me.isPositive {
|
||||
return "正数です"
|
||||
} else {
|
||||
return "負数または0です"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local num1 = new SmartInteger(42)
|
||||
print("1. " + num1.getInfo())
|
||||
|
||||
local num2 = new SmartInteger(-5)
|
||||
print("2. " + num2.getInfo())
|
||||
|
||||
# テスト2: 混在テスト - ビルトイン継承 + ユーザー定義
|
||||
box AdvancedCalc from MathBox {
|
||||
init { history }
|
||||
|
||||
birth() {
|
||||
from MathBox() # 透明化システム
|
||||
me.history = new ArrayBox()
|
||||
}
|
||||
|
||||
addToHistory(operation) {
|
||||
me.history.push(operation)
|
||||
return "履歴に追加: " + operation
|
||||
}
|
||||
}
|
||||
|
||||
box SimpleCalculator {
|
||||
init { result }
|
||||
|
||||
birth() {
|
||||
me.result = 0
|
||||
}
|
||||
|
||||
getResult() {
|
||||
return "結果: " + me.result
|
||||
}
|
||||
}
|
||||
|
||||
local calc1 = new AdvancedCalc() # ビルトイン継承
|
||||
local calc2 = new SimpleCalculator() # ユーザー定義
|
||||
|
||||
print("3. " + calc1.addToHistory("2+2=4"))
|
||||
print("4. " + calc2.getResult())
|
||||
|
||||
print("=== pack透明化システム包括テスト完了 ===")
|
||||
20
local_tests/test_pack_transparency_errors.nyash
Normal file
20
local_tests/test_pack_transparency_errors.nyash
Normal file
@ -0,0 +1,20 @@
|
||||
# 🔥 Phase 8.8: pack透明化システム エラーケーステスト
|
||||
# 適切なエラーメッセージとpackの隠蔽確認
|
||||
|
||||
print("=== pack透明化システム エラーケーステスト開始 ===")
|
||||
|
||||
# テスト1: 引数不一致エラー
|
||||
box BadStringBox from StringBox {
|
||||
init { prefix }
|
||||
|
||||
birth(content, extra) {
|
||||
# StringBoxは1引数だが2つ渡すとエラー
|
||||
from StringBox(content, extra)
|
||||
me.prefix = "test"
|
||||
}
|
||||
}
|
||||
|
||||
print("エラーテスト1: 引数不一致")
|
||||
local bad = new BadStringBox("hello", "extra")
|
||||
|
||||
print("=== pack透明化システム エラーケーステスト完了 ===")
|
||||
61
local_tests/test_pack_transparency_final.nyash
Normal file
61
local_tests/test_pack_transparency_final.nyash
Normal file
@ -0,0 +1,61 @@
|
||||
# 🔥 Phase 8.8: pack透明化システム 最終統合テスト
|
||||
# 全機能の協調動作確認
|
||||
|
||||
print("=== pack透明化システム最終統合テスト開始 ===")
|
||||
|
||||
# 1. 従来のbirth機能(ユーザー定義Box)
|
||||
box Animal {
|
||||
init { name, species }
|
||||
|
||||
birth(animalName, animalSpecies) {
|
||||
me.name = animalName
|
||||
me.species = animalSpecies
|
||||
}
|
||||
|
||||
introduce() {
|
||||
return me.name + " は " + me.species + " です"
|
||||
}
|
||||
}
|
||||
|
||||
# 2. pack透明化(ビルトインBox継承)
|
||||
box SmartString from StringBox {
|
||||
init { metadata }
|
||||
|
||||
birth(content, meta) {
|
||||
from StringBox(content) # 透明化
|
||||
me.metadata = meta
|
||||
}
|
||||
|
||||
getInfo() {
|
||||
return "内容の情報: " + me.metadata
|
||||
}
|
||||
}
|
||||
|
||||
# 3. 複数のビルトインBox透明化
|
||||
box Calculator from MathBox {
|
||||
init { precision }
|
||||
|
||||
birth(precisionLevel) {
|
||||
from MathBox.birth() # Explicit syntax after Phase 8.9
|
||||
me.precision = precisionLevel
|
||||
}
|
||||
|
||||
getPrecision() {
|
||||
return "精度: " + me.precision
|
||||
}
|
||||
}
|
||||
|
||||
# テスト実行
|
||||
print("1. ユーザー定義Box:")
|
||||
local cat = new Animal("ミケ", "猫")
|
||||
print(cat.introduce())
|
||||
|
||||
print("2. StringBox透明化:")
|
||||
local smartStr = new SmartString("Hello World", "UTF-8")
|
||||
print(smartStr.getInfo())
|
||||
|
||||
print("3. MathBox透明化:")
|
||||
local calc = new Calculator("高精度")
|
||||
print(calc.getPrecision())
|
||||
|
||||
print("=== 全テスト成功!pack透明化システム完了 ===")テム完了 ===")
|
||||
82
local_tests/test_phase975b_boxes.nyash
Normal file
82
local_tests/test_phase975b_boxes.nyash
Normal file
@ -0,0 +1,82 @@
|
||||
// Phase 9.75-B修正テスト - RwLock変換後の各Box動作確認
|
||||
// ArrayBox、MapBox、BufferBox、StreamBox、DebugBoxテスト
|
||||
|
||||
static box Main {
|
||||
init { console, result }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🧪 Phase 9.75-B Box型テスト開始")
|
||||
|
||||
// ArrayBox RwLock変換テスト
|
||||
me.console.log("\n📦 ArrayBox RwLock テスト")
|
||||
local array
|
||||
array = new ArrayBox()
|
||||
array.push("test1")
|
||||
array.push("test2")
|
||||
local arrayLen
|
||||
arrayLen = array.length()
|
||||
me.console.log("ArrayBox length: " + arrayLen.toString())
|
||||
|
||||
local firstItem
|
||||
firstItem = array.get(0)
|
||||
me.console.log("ArrayBox first item: " + firstItem.toString())
|
||||
|
||||
// MapBox RwLock変換テスト
|
||||
me.console.log("\n🗺️ MapBox RwLock テスト")
|
||||
local map
|
||||
map = new MapBox()
|
||||
map.set("key1", "value1")
|
||||
map.set("key2", "value2")
|
||||
|
||||
local value1
|
||||
value1 = map.get("key1")
|
||||
me.console.log("MapBox get key1: " + value1.toString())
|
||||
|
||||
local mapSize
|
||||
mapSize = map.size()
|
||||
me.console.log("MapBox size: " + mapSize.toString())
|
||||
|
||||
// BufferBox RwLock変換テスト
|
||||
me.console.log("\n📄 BufferBox RwLock テスト")
|
||||
local buffer
|
||||
buffer = new BufferBox()
|
||||
buffer.write("Hello")
|
||||
buffer.write(" ")
|
||||
buffer.write("World")
|
||||
|
||||
local bufferContent
|
||||
bufferContent = buffer.toString()
|
||||
me.console.log("BufferBox content: " + bufferContent)
|
||||
|
||||
local bufferSize
|
||||
bufferSize = buffer.size()
|
||||
me.console.log("BufferBox size: " + bufferSize.toString())
|
||||
|
||||
// StreamBox RwLock変換テスト
|
||||
me.console.log("\n🌊 StreamBox RwLock テスト")
|
||||
local stream
|
||||
stream = new StreamBox()
|
||||
stream.write("Stream data")
|
||||
|
||||
local streamContent
|
||||
streamContent = stream.read()
|
||||
me.console.log("StreamBox read: " + streamContent.toString())
|
||||
|
||||
// DebugBox RwLock変換テスト
|
||||
me.console.log("\n🐛 DebugBox RwLock テスト")
|
||||
local debug
|
||||
debug = new DebugBox()
|
||||
debug.startTracking()
|
||||
debug.trackBox(array, "test array")
|
||||
|
||||
local memoryReport
|
||||
memoryReport = debug.memoryReport()
|
||||
me.console.log("DebugBox tracking: " + memoryReport.toString())
|
||||
|
||||
me.console.log("\n✅ Phase 9.75-B すべてのBox型テスト完了")
|
||||
me.result = "SUCCESS: RwLock変換後のBox型動作正常"
|
||||
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
36
local_tests/test_phase_8_9_error_cases.nyash
Normal file
36
local_tests/test_phase_8_9_error_cases.nyash
Normal file
@ -0,0 +1,36 @@
|
||||
# Phase 8.9: Error case tests
|
||||
# These should all produce compile errors after transparency system removal
|
||||
|
||||
print("=== Error Test Cases (should all fail after Phase 8.9) ===")
|
||||
|
||||
# Error Case 1: Simple transparency syntax
|
||||
box BadString from StringBox {
|
||||
init { prefix }
|
||||
|
||||
birth(content) {
|
||||
from StringBox(content) # ❌ Should error
|
||||
me.prefix = "bad"
|
||||
}
|
||||
}
|
||||
|
||||
# Error Case 2: Multiple argument transparency
|
||||
box BadInteger from IntegerBox {
|
||||
init { multiplier }
|
||||
|
||||
birth(value) {
|
||||
from IntegerBox(value) # ❌ Should error
|
||||
me.multiplier = 2
|
||||
}
|
||||
}
|
||||
|
||||
# Error Case 3: Zero argument transparency
|
||||
box BadMath from MathBox {
|
||||
init { precision }
|
||||
|
||||
birth() {
|
||||
from MathBox() # ❌ Should error
|
||||
me.precision = "high"
|
||||
}
|
||||
}
|
||||
|
||||
print("=== If you see this message, transparency system was NOT properly removed! ===")
|
||||
59
local_tests/test_phase_8_9_explicit_birth.nyash
Normal file
59
local_tests/test_phase_8_9_explicit_birth.nyash
Normal file
@ -0,0 +1,59 @@
|
||||
# Phase 8.9: Test explicit birth() syntax
|
||||
# This file tests that explicit birth() calls work correctly
|
||||
|
||||
print("=== Testing explicit birth() syntax ===")
|
||||
|
||||
# Test 1: Basic explicit birth() call
|
||||
box SimpleBox {
|
||||
init { content }
|
||||
|
||||
birth(data) {
|
||||
me.content = data
|
||||
print("SimpleBox birth: " + data)
|
||||
}
|
||||
|
||||
getContent() {
|
||||
return me.content
|
||||
}
|
||||
}
|
||||
|
||||
local simple = new SimpleBox("test_data")
|
||||
print("Content: " + simple.getContent())
|
||||
|
||||
# Test 2: Explicit birth() with inheritance
|
||||
box EnhancedString from StringBox {
|
||||
init { prefix }
|
||||
|
||||
birth(content, prefixStr) {
|
||||
from StringBox.birth(content) # ✅ Explicit syntax
|
||||
me.prefix = prefixStr
|
||||
print("EnhancedString birth: " + prefixStr + " -> " + content)
|
||||
}
|
||||
|
||||
override toString() {
|
||||
return me.prefix + ": " + from StringBox.toString()
|
||||
}
|
||||
}
|
||||
|
||||
local enhanced = new EnhancedString("Hello World", "MESSAGE")
|
||||
print("Enhanced string: " + enhanced.toString())
|
||||
|
||||
# Test 3: Multiple inheritance levels
|
||||
box SuperEnhancedString from EnhancedString {
|
||||
init { suffix }
|
||||
|
||||
birth(content, prefixStr, suffixStr) {
|
||||
from EnhancedString.birth(content, prefixStr) # ✅ Explicit parent birth
|
||||
me.suffix = suffixStr
|
||||
print("SuperEnhancedString birth: " + suffixStr)
|
||||
}
|
||||
|
||||
override toString() {
|
||||
return from EnhancedString.toString() + " [" + me.suffix + "]"
|
||||
}
|
||||
}
|
||||
|
||||
local superEnh = new SuperEnhancedString("Amazing", "SUPER", "END")
|
||||
print("Super enhanced: " + superEnh.toString())
|
||||
|
||||
print("=== All explicit birth() tests passed ===")
|
||||
84
local_tests/test_phase_8_9_transparency_removal.nyash
Normal file
84
local_tests/test_phase_8_9_transparency_removal.nyash
Normal file
@ -0,0 +1,84 @@
|
||||
# Phase 8.9: birth() Unified System Test
|
||||
# Test 1: Transparency system must produce compile errors
|
||||
# Test 2: Explicit birth() syntax must work correctly
|
||||
# Test 3: Weak reference nullification after fini()
|
||||
|
||||
print("=== Phase 8.9: Testing transparency removal and explicit birth() syntax ===")
|
||||
|
||||
# Test 1: This should produce a compile error after changes
|
||||
# from StringBox(content) # ❌ Should error after transparency removal
|
||||
|
||||
# Test 2: Explicit birth() syntax - should work correctly
|
||||
box EnhancedString from StringBox {
|
||||
init { prefix }
|
||||
|
||||
birth(content, prefixStr) {
|
||||
from StringBox.birth(content) # ✅ Explicit syntax - must work
|
||||
me.prefix = prefixStr
|
||||
}
|
||||
|
||||
override toString() {
|
||||
return me.prefix + ": " + from StringBox.toString()
|
||||
}
|
||||
}
|
||||
|
||||
print("Test 2: Explicit birth() syntax")
|
||||
local enhanced = new EnhancedString("Hello World", "Enhanced")
|
||||
print(enhanced.toString())
|
||||
|
||||
# Test 3: Weak reference nullification after fini
|
||||
box CPU {
|
||||
init { name, memory }
|
||||
|
||||
birth(cpuName) {
|
||||
me.name = cpuName
|
||||
print("CPU " + me.name + " initialized")
|
||||
}
|
||||
|
||||
fini() {
|
||||
print("CPU " + me.name + " finalizing...")
|
||||
if (me.memory != null) {
|
||||
me.memory.cleanup()
|
||||
}
|
||||
print("CPU " + me.name + " finalized")
|
||||
}
|
||||
}
|
||||
|
||||
box Memory {
|
||||
init { data, weak cpu_ref }
|
||||
|
||||
birth(cpu) {
|
||||
me.data = "memory_data"
|
||||
me.cpu_ref = cpu # This becomes a weak reference
|
||||
print("Memory initialized with weak CPU reference")
|
||||
}
|
||||
|
||||
checkCPU() {
|
||||
if (me.cpu_ref != null) {
|
||||
return "CPU is alive: " + me.cpu_ref.name
|
||||
} else {
|
||||
return "CPU reference is null"
|
||||
}
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
print("Memory cleanup called")
|
||||
me.data = "cleaned"
|
||||
}
|
||||
}
|
||||
|
||||
print("Test 3: Weak reference nullification after fini")
|
||||
local cpu = new CPU("TestCPU")
|
||||
local memory = new Memory(cpu)
|
||||
cpu.memory = memory
|
||||
|
||||
# Before fini
|
||||
print("Before CPU fini: " + memory.checkCPU())
|
||||
|
||||
# After fini - weak reference should be nullified
|
||||
cpu.fini()
|
||||
cpu = null
|
||||
|
||||
print("After CPU fini: " + memory.checkCPU())
|
||||
|
||||
print("=== Phase 8.9 tests completed ===")
|
||||
24
local_tests/test_phase_b_validation.nyash
Normal file
24
local_tests/test_phase_b_validation.nyash
Normal file
@ -0,0 +1,24 @@
|
||||
// 🚨 ArrayBox状態保持テスト - コアとなる問題を検証
|
||||
static box Main {
|
||||
init { result1, result2, result3 }
|
||||
main() {
|
||||
// テスト1: 基本的な状態保持
|
||||
local arr1
|
||||
arr1 = new ArrayBox()
|
||||
arr1.push("hello")
|
||||
me.result1 = arr1.length() // 期待値: 1
|
||||
|
||||
// テスト2: 複数操作の状態保持
|
||||
local arr2
|
||||
arr2 = new ArrayBox()
|
||||
arr2.push("first")
|
||||
arr2.push("second")
|
||||
me.result2 = arr2.length() // 期待値: 2
|
||||
|
||||
// テスト3: 変数再利用での状態保持
|
||||
arr1.push("world")
|
||||
me.result3 = arr1.length() // 期待値: 2
|
||||
|
||||
return me.result1
|
||||
}
|
||||
}
|
||||
9
local_tests/test_simple.nyash
Normal file
9
local_tests/test_simple.nyash
Normal file
@ -0,0 +1,9 @@
|
||||
# Simple test without external calls
|
||||
static box Main {
|
||||
init { result }
|
||||
|
||||
main() {
|
||||
me.result = "Simple test"
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
24
local_tests/test_simple_arc_fix.nyash
Normal file
24
local_tests/test_simple_arc_fix.nyash
Normal file
@ -0,0 +1,24 @@
|
||||
// Simple test case to verify Arc sharing fix
|
||||
static box Main {
|
||||
init { counter }
|
||||
|
||||
main() {
|
||||
me.counter = new IntegerBox(42)
|
||||
|
||||
print("=== Initial value ===")
|
||||
print("counter: " + me.counter.to_string())
|
||||
|
||||
// Test if getting the same field returns the same object
|
||||
local temp1
|
||||
temp1 = me.counter
|
||||
|
||||
local temp2
|
||||
temp2 = me.counter
|
||||
|
||||
print("=== Testing shared reference ===")
|
||||
print("temp1: " + temp1.to_string())
|
||||
print("temp2: " + temp2.to_string())
|
||||
|
||||
return me.counter
|
||||
}
|
||||
}
|
||||
27
local_tests/test_simple_array.nyash
Normal file
27
local_tests/test_simple_array.nyash
Normal file
@ -0,0 +1,27 @@
|
||||
// ArrayBox length問題の緊急調査
|
||||
static box ArrayDebugTest {
|
||||
init { arr }
|
||||
|
||||
main() {
|
||||
print("=== ArrayBox緊急デバッグ ===")
|
||||
|
||||
// ArrayBox作成
|
||||
me.arr = new ArrayBox()
|
||||
print("作成直後のlength: " + me.arr.length().toString())
|
||||
|
||||
// 要素追加
|
||||
me.arr.push("test1")
|
||||
print("push後のlength: " + me.arr.length().toString())
|
||||
|
||||
me.arr.push("test2")
|
||||
print("2個目push後のlength: " + me.arr.length().toString())
|
||||
|
||||
// 直接的なテスト
|
||||
local newArr
|
||||
newArr = new ArrayBox()
|
||||
newArr.push("direct")
|
||||
print("新しい配列のlength: " + newArr.length().toString())
|
||||
|
||||
return "debug完了"
|
||||
}
|
||||
}
|
||||
10
local_tests/test_simple_array2.nyash
Normal file
10
local_tests/test_simple_array2.nyash
Normal file
@ -0,0 +1,10 @@
|
||||
// 更にシンプルなArrayBoxテスト
|
||||
local arr
|
||||
arr = new ArrayBox()
|
||||
print("初期length: " + arr.length().toString())
|
||||
|
||||
arr.push("item1")
|
||||
print("push後length: " + arr.length().toString())
|
||||
|
||||
arr.push("item2")
|
||||
print("2つ目push後length: " + arr.length().toString())
|
||||
14
local_tests/test_simple_field.nyash
Normal file
14
local_tests/test_simple_field.nyash
Normal file
@ -0,0 +1,14 @@
|
||||
// Simpler test for field access MIR
|
||||
static box Main {
|
||||
init { obj }
|
||||
|
||||
main() {
|
||||
me.obj = "test"
|
||||
local field_value
|
||||
|
||||
// This should trigger field access parsing
|
||||
field_value = me.obj
|
||||
print(field_value)
|
||||
return "Done"
|
||||
}
|
||||
}
|
||||
18
local_tests/test_simple_loop.nyash
Normal file
18
local_tests/test_simple_loop.nyash
Normal file
@ -0,0 +1,18 @@
|
||||
// Test simple loop for WASM compilation
|
||||
static box Main {
|
||||
init { counter, result }
|
||||
|
||||
main() {
|
||||
me.counter = 0
|
||||
me.result = 0
|
||||
|
||||
// Simple loop that should generate Jump/Branch instructions
|
||||
loop(me.counter < 5) {
|
||||
me.result = me.result + me.counter
|
||||
me.counter = me.counter + 1
|
||||
}
|
||||
|
||||
print(me.result)
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
6
local_tests/test_simple_wasm_aot.nyash
Normal file
6
local_tests/test_simple_wasm_aot.nyash
Normal file
@ -0,0 +1,6 @@
|
||||
# 🎯 Simple WASM vs AOT WASM 比較テスト
|
||||
local x
|
||||
x = 42
|
||||
local y
|
||||
y = x + 58
|
||||
return y
|
||||
79
local_tests/test_simple_weak_ref.nyash
Normal file
79
local_tests/test_simple_weak_ref.nyash
Normal file
@ -0,0 +1,79 @@
|
||||
// Simple weak reference test for Phase 10.2
|
||||
|
||||
// Test CPU with fini
|
||||
box TestCPU {
|
||||
init { memory, name }
|
||||
|
||||
TestCPU() {
|
||||
me.name = "TestCPU"
|
||||
print("CPU initialized: " + me.name)
|
||||
}
|
||||
|
||||
fini() {
|
||||
print("CPU fini called - cleaning up memory")
|
||||
if (me.memory != null) {
|
||||
me.memory.cleanup()
|
||||
}
|
||||
print("CPU fini complete")
|
||||
}
|
||||
}
|
||||
|
||||
// Test Memory with weak reference
|
||||
box TestMemory {
|
||||
init { data, weak cpu_ref }
|
||||
|
||||
TestMemory(cpu_instance) {
|
||||
me.data = new ArrayBox()
|
||||
me.data.push("test_data")
|
||||
me.cpu_ref = cpu_instance // This will be automatically downgraded to weak
|
||||
print("Memory initialized with weak CPU reference")
|
||||
}
|
||||
|
||||
read_data() {
|
||||
if (me.cpu_ref != null) {
|
||||
print("CPU is alive - returning data")
|
||||
return me.data.get(0)
|
||||
} else {
|
||||
print("CPU is destroyed - access blocked")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
print("Memory cleanup called")
|
||||
me.data.clear()
|
||||
}
|
||||
}
|
||||
|
||||
// Main test
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🧪 Testing weak references and fini propagation")
|
||||
|
||||
// Create CPU and Memory
|
||||
local cpu = new TestCPU()
|
||||
|
||||
local memory = new TestMemory(cpu)
|
||||
|
||||
// Link memory to CPU for fini propagation
|
||||
cpu.memory = memory
|
||||
|
||||
// Test 1: Normal operation
|
||||
me.console.log("Test 1: Normal operation")
|
||||
local result1 = memory.read_data()
|
||||
me.console.log("Read result: " + result1)
|
||||
|
||||
// Test 2: After CPU destruction
|
||||
me.console.log("Test 2: Destroying CPU...")
|
||||
cpu.fini()
|
||||
cpu = null
|
||||
|
||||
local result2 = memory.read_data()
|
||||
me.console.log("Read after CPU destruction: " + result2)
|
||||
|
||||
return "Test complete"
|
||||
}
|
||||
}
|
||||
34
local_tests/test_socket_bind_only.nyash
Normal file
34
local_tests/test_socket_bind_only.nyash
Normal file
@ -0,0 +1,34 @@
|
||||
# 🔥 SocketBox bind()のみテスト - toString()なし
|
||||
|
||||
static box Main {
|
||||
init { console, result }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("SocketBox bind()テスト開始")
|
||||
|
||||
# SocketBox作成
|
||||
local socket = new SocketBox()
|
||||
me.console.log("SocketBox作成完了")
|
||||
|
||||
# bind実行(toString()やisServer()を避ける)
|
||||
me.console.log("bind実行開始...")
|
||||
local bindResult = socket.bind("127.0.0.1", 19999)
|
||||
me.console.log("bind実行完了")
|
||||
|
||||
# bindResultの状態だけ確認
|
||||
if bindResult.equals(true) {
|
||||
me.result = "BIND_SUCCESS"
|
||||
me.console.log("bind成功!")
|
||||
} else {
|
||||
me.result = "BIND_FAILED"
|
||||
me.console.log("bind失敗!")
|
||||
}
|
||||
|
||||
# クリーンアップ
|
||||
socket.close()
|
||||
me.console.log("テスト完了")
|
||||
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
21
local_tests/test_socket_deadlock_minimal.nyash
Normal file
21
local_tests/test_socket_deadlock_minimal.nyash
Normal file
@ -0,0 +1,21 @@
|
||||
# test_socket_deadlock_minimal.nyash
|
||||
# 🚨 Issue #76: SocketBoxデッドロック最小再現ケース
|
||||
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🔥 SocketBoxデッドロック最小テスト開始")
|
||||
|
||||
local socket = new SocketBox()
|
||||
me.console.log("✅ SocketBox作成成功")
|
||||
|
||||
# ここで無限ブロック予想
|
||||
me.console.log("bind()実行開始...")
|
||||
local result = socket.bind("127.0.0.1", 19999)
|
||||
me.console.log("❌ この行は出力されない(デッドロック)")
|
||||
|
||||
return "SHOULD_NOT_REACH"
|
||||
}
|
||||
}
|
||||
42
local_tests/test_socket_methods_comprehensive.nyash
Normal file
42
local_tests/test_socket_methods_comprehensive.nyash
Normal file
@ -0,0 +1,42 @@
|
||||
# test_socket_methods_comprehensive.nyash
|
||||
# 🚨 Issue #76: SocketBox全メソッドデッドロック確認
|
||||
|
||||
static box Main {
|
||||
init { console, results }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🔥 SocketBox全メソッドテスト開始")
|
||||
me.results = new ArrayBox()
|
||||
|
||||
local socket = new SocketBox()
|
||||
me.console.log("✅ SocketBox作成完了")
|
||||
|
||||
# Test 1: toString() メソッド
|
||||
me.console.log("Test 1: toString()実行...")
|
||||
local socketStr = socket.toString() # デッドロック予想
|
||||
me.console.log("❌ toString()完了: " + socketStr)
|
||||
me.results.push("toString:OK")
|
||||
|
||||
# Test 2: isServer() メソッド
|
||||
me.console.log("Test 2: isServer()実行...")
|
||||
local isServer = socket.isServer() # デッドロック予想
|
||||
me.console.log("❌ isServer()完了: " + isServer.toString())
|
||||
me.results.push("isServer:OK")
|
||||
|
||||
# Test 3: bind() メソッド
|
||||
me.console.log("Test 3: bind()実行...")
|
||||
local bindResult = socket.bind("127.0.0.1", 19999) # デッドロック予想
|
||||
me.console.log("❌ bind()完了: " + bindResult.toString())
|
||||
me.results.push("bind:OK")
|
||||
|
||||
# Test 4: close() メソッド
|
||||
me.console.log("Test 4: close()実行...")
|
||||
local closeResult = socket.close() # デッドロック予想
|
||||
me.console.log("❌ close()完了: " + closeResult.toString())
|
||||
me.results.push("close:OK")
|
||||
|
||||
me.console.log("🎉 全テスト完了: " + me.results.size().toString() + "件成功")
|
||||
return "ALL_METHODS_OK"
|
||||
}
|
||||
}
|
||||
23
local_tests/test_socket_simple.nyash
Normal file
23
local_tests/test_socket_simple.nyash
Normal file
@ -0,0 +1,23 @@
|
||||
// Simple test for SocketBox state sharing
|
||||
static box Main {
|
||||
main() {
|
||||
print("🧪 Testing SocketBox state sharing...")
|
||||
|
||||
local socket
|
||||
socket = new SocketBox()
|
||||
|
||||
print("Initial isServer: " + socket.isServer().toString())
|
||||
|
||||
local bindOk
|
||||
bindOk = socket.bind("127.0.0.1", 8080)
|
||||
print("Bind result: " + bindOk.toString())
|
||||
|
||||
print("After bind isServer: " + socket.isServer().toString())
|
||||
|
||||
local closeOk
|
||||
closeOk = socket.close()
|
||||
print("Close result: " + closeOk.toString())
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
42
local_tests/test_socket_state_preservation.nyash
Normal file
42
local_tests/test_socket_state_preservation.nyash
Normal file
@ -0,0 +1,42 @@
|
||||
# PR #75 SocketBox状態保持テスト
|
||||
# Arc<dyn NyashBox>修正効果の検証
|
||||
|
||||
static box Main {
|
||||
init { console, server, result }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🔥 SocketBox状態保持テスト開始")
|
||||
|
||||
# SocketBox作成
|
||||
me.server = new SocketBox()
|
||||
me.console.log("✅ SocketBox作成完了")
|
||||
|
||||
# bind前のisServer確認
|
||||
local isServerBefore = me.server.isServer()
|
||||
me.console.log("Before bind: isServer = " + isServerBefore.toString())
|
||||
|
||||
# bind実行(状態設定)
|
||||
local bindResult = me.server.bind("127.0.0.1", 18080)
|
||||
me.console.log("Bind result = " + bindResult.toString())
|
||||
|
||||
# bind後のisServer確認(🎯 重要:これがtrueになるべき)
|
||||
local isServerAfter = me.server.isServer()
|
||||
me.console.log("After bind: isServer = " + isServerAfter.toString())
|
||||
|
||||
# テスト結果判定
|
||||
if isServerAfter.equals(true) {
|
||||
me.console.log("🎉 SUCCESS: SocketBox状態保持修正完了!")
|
||||
me.result = "PASS: State preservation works"
|
||||
} else {
|
||||
me.console.log("❌ FAILED: SocketBox状態が失われている")
|
||||
me.result = "FAIL: State preservation broken"
|
||||
}
|
||||
|
||||
# クリーンアップ
|
||||
me.server.close()
|
||||
me.console.log("🧹 SocketBox closed")
|
||||
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
59
local_tests/test_socketbox_comprehensive.nyash
Normal file
59
local_tests/test_socketbox_comprehensive.nyash
Normal file
@ -0,0 +1,59 @@
|
||||
# test_socketbox_comprehensive.nyash
|
||||
# 🎯 Comprehensive test to verify SocketBox deadlock fix and functionality
|
||||
|
||||
static box Main {
|
||||
init { console, results }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🎯 SocketBox Comprehensive Functionality Test")
|
||||
me.results = new StringBox("Test Results: ")
|
||||
|
||||
# Test 1: Basic creation and method calls
|
||||
me.console.log("Test 1: Basic SocketBox operations...")
|
||||
local socket = new SocketBox()
|
||||
local initial_str = socket.toString()
|
||||
local initial_server = socket.isServer()
|
||||
|
||||
me.results = new StringBox(me.results.toString() + "create:OK ")
|
||||
me.console.log("✅ Creation and basic methods: " + initial_server.toString())
|
||||
|
||||
# Test 2: Bind operation and state change
|
||||
me.console.log("Test 2: Bind operation...")
|
||||
local bind_result = socket.bind("127.0.0.1", 17777)
|
||||
local after_bind_server = socket.isServer()
|
||||
|
||||
me.results = new StringBox(me.results.toString() + "bind:OK ")
|
||||
me.console.log("✅ Bind result: " + bind_result.toString())
|
||||
|
||||
# Test 3: Multiple method calls on same socket
|
||||
me.console.log("Test 3: Multiple operations...")
|
||||
local str1 = socket.toString()
|
||||
local str2 = socket.toString()
|
||||
local server1 = socket.isServer()
|
||||
local server2 = socket.isServer()
|
||||
|
||||
me.results = new StringBox(me.results.toString() + "multiple:OK ")
|
||||
me.console.log("✅ Multiple calls completed")
|
||||
|
||||
# Test 4: Close operation
|
||||
me.console.log("Test 4: Close operation...")
|
||||
local close_result = socket.close()
|
||||
local after_close_str = socket.toString()
|
||||
|
||||
me.results = new StringBox(me.results.toString() + "close:OK ")
|
||||
me.console.log("✅ Close result: " + close_result.toString())
|
||||
|
||||
# Test 5: Create new socket after close
|
||||
me.console.log("Test 5: New socket creation...")
|
||||
local socket2 = new SocketBox()
|
||||
local new_str = socket2.toString()
|
||||
local new_server = socket2.isServer()
|
||||
|
||||
me.results = new StringBox(me.results.toString() + "new:OK ")
|
||||
me.console.log("✅ New socket created successfully")
|
||||
|
||||
me.console.log("🎉 All tests passed! " + me.results.toString())
|
||||
return "COMPREHENSIVE_SUCCESS"
|
||||
}
|
||||
}
|
||||
38
local_tests/test_socketbox_fix_validation.nyash
Normal file
38
local_tests/test_socketbox_fix_validation.nyash
Normal file
@ -0,0 +1,38 @@
|
||||
# test_socketbox_fix_validation.nyash
|
||||
# ✅ Validation test for SocketBox deadlock fix
|
||||
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🎯 SocketBox Deadlock Fix Validation")
|
||||
|
||||
local socket = new SocketBox()
|
||||
me.console.log("✅ SocketBox created successfully")
|
||||
|
||||
# Test 1: Basic method calls that were deadlocking
|
||||
me.console.log("Test 1: toString() method...")
|
||||
local str = socket.toString()
|
||||
me.console.log("✅ toString() success: " + str)
|
||||
|
||||
me.console.log("Test 2: isServer() before bind...")
|
||||
local isServerBefore = socket.isServer()
|
||||
me.console.log("✅ isServer() before: " + isServerBefore.toString())
|
||||
|
||||
me.console.log("Test 3: bind() method...")
|
||||
local bindResult = socket.bind("127.0.0.1", 18888)
|
||||
me.console.log("✅ bind() success: " + bindResult.toString())
|
||||
|
||||
me.console.log("Test 4: isServer() after bind...")
|
||||
local isServerAfter = socket.isServer()
|
||||
me.console.log("✅ isServer() after: " + isServerAfter.toString())
|
||||
|
||||
me.console.log("Test 5: close() method...")
|
||||
local closeResult = socket.close()
|
||||
me.console.log("✅ close() success: " + closeResult.toString())
|
||||
|
||||
me.console.log("🎉 All SocketBox methods working without deadlock!")
|
||||
return "SOCKETBOX_FIX_VALIDATED"
|
||||
}
|
||||
}
|
||||
61
local_tests/test_socketbox_state_fix.nyash
Normal file
61
local_tests/test_socketbox_state_fix.nyash
Normal file
@ -0,0 +1,61 @@
|
||||
// SocketBox状態保持問題テスト - Phase 9.75-B修正検証
|
||||
// PR #89修正後のSocketBox状態永続化テスト
|
||||
|
||||
static box Main {
|
||||
init { console, result }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🔧 SocketBox状態保持テスト開始")
|
||||
|
||||
// SocketBox作成
|
||||
local server
|
||||
server = new SocketBox()
|
||||
me.console.log("✅ SocketBox作成完了")
|
||||
|
||||
// bind操作 - 状態設定
|
||||
local bindResult
|
||||
bindResult = server.bind("127.0.0.1", "8080")
|
||||
me.console.log("🔥 bind結果: " + bindResult.toString())
|
||||
|
||||
// 重要テスト:isServer()状態確認
|
||||
local isServerBefore
|
||||
isServerBefore = server.isServer()
|
||||
me.console.log("🔥 bind後のisServer(): " + isServerBefore.toString())
|
||||
|
||||
// toString()テスト
|
||||
local socketString
|
||||
socketString = server.toString()
|
||||
me.console.log("🔥 server.toString(): " + socketString)
|
||||
|
||||
// 再度isServer()確認 - 状態永続性テスト
|
||||
local isServerAfter
|
||||
isServerAfter = server.isServer()
|
||||
me.console.log("🔥 2回目のisServer(): " + isServerAfter.toString())
|
||||
|
||||
// listen()テスト
|
||||
local listenResult
|
||||
listenResult = server.listen("10")
|
||||
me.console.log("🔥 listen結果: " + listenResult.toString())
|
||||
|
||||
// 最終状態確認
|
||||
local finalState
|
||||
finalState = server.isServer()
|
||||
me.console.log("🔥 最終isServer(): " + finalState.toString())
|
||||
|
||||
// 期待結果確認
|
||||
if finalState.toString() == "true" {
|
||||
me.console.log("🎉 SocketBox状態保持問題修正確認!")
|
||||
me.result = "SUCCESS: SocketBox状態が正常に保持されています"
|
||||
} else {
|
||||
me.console.log("❌ SocketBox状態保持問題が残存")
|
||||
me.result = "FAILED: SocketBox状態が失われています"
|
||||
}
|
||||
|
||||
// クリーンアップ
|
||||
server.close()
|
||||
me.console.log("✅ テスト完了")
|
||||
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
31
local_tests/test_state_sharing_validation.nyash
Normal file
31
local_tests/test_state_sharing_validation.nyash
Normal file
@ -0,0 +1,31 @@
|
||||
// 🎯 Phase B-C 验证测试 - 确认状态共享修复是否有效
|
||||
static box Main {
|
||||
init { array_test, map_test, buffer_test, socket_test }
|
||||
main() {
|
||||
// ArrayBox测试
|
||||
local arr
|
||||
arr = new ArrayBox()
|
||||
arr.push("hello")
|
||||
me.array_test = arr.length() // 期待: 1
|
||||
|
||||
// MapBox测试
|
||||
local map
|
||||
map = new MapBox()
|
||||
map.set("key1", "value1")
|
||||
me.map_test = map.size() // 期待: 1
|
||||
|
||||
// BufferBox测试
|
||||
local buf
|
||||
buf = new BufferBox()
|
||||
buf.write([72, 101, 108, 108, 111]) // "Hello"
|
||||
me.buffer_test = buf.length() // 期待: 5
|
||||
|
||||
// SocketBox测试
|
||||
local sock
|
||||
sock = new SocketBox()
|
||||
sock.bind("127.0.0.1", 8080)
|
||||
me.socket_test = 1 // 暂时设为1,表示创建成功
|
||||
|
||||
return me.array_test
|
||||
}
|
||||
}
|
||||
71
local_tests/test_static_box_patterns.nyash
Normal file
71
local_tests/test_static_box_patterns.nyash
Normal file
@ -0,0 +1,71 @@
|
||||
// Test for proper static box usage patterns
|
||||
static box StaticBoxTest {
|
||||
init { console, test_result }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🧪 Testing proper static box patterns")
|
||||
|
||||
// ✅ Correct: Call static method directly
|
||||
local result = StaticBoxTest.test_static_method()
|
||||
me.console.log("Static method result: " + result)
|
||||
|
||||
// ✅ Correct: Access static box fields through me
|
||||
me.test_result = "Static box initialization successful"
|
||||
me.console.log("Static field access: " + me.test_result)
|
||||
|
||||
me.console.log("✅ Static box pattern tests completed")
|
||||
return "Static box usage verified"
|
||||
}
|
||||
|
||||
test_static_method() {
|
||||
return "Static method executed successfully"
|
||||
}
|
||||
}
|
||||
|
||||
// Test proxy server pattern (simplified)
|
||||
static box SimpleProxyTest {
|
||||
init { console, port, running }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🌐 Testing simplified proxy server pattern")
|
||||
|
||||
// ✅ Correct: Initialize static box fields
|
||||
me.port = 8080
|
||||
me.running = true
|
||||
|
||||
me.console.log("Proxy configured on port: " + me.port)
|
||||
me.console.log("Proxy running status: " + me.running)
|
||||
|
||||
// ✅ Correct: Call other static methods
|
||||
local startup_result = SimpleProxyTest.simulate_startup()
|
||||
me.console.log("Startup result: " + startup_result)
|
||||
|
||||
return "Proxy simulation complete"
|
||||
}
|
||||
|
||||
simulate_startup() {
|
||||
return "Proxy server simulation started successfully"
|
||||
}
|
||||
}
|
||||
|
||||
// Entry point
|
||||
static box Main {
|
||||
init { console }
|
||||
|
||||
main() {
|
||||
me.console = new ConsoleBox()
|
||||
me.console.log("🚀 Testing Static Box Patterns")
|
||||
|
||||
// Test both static box patterns
|
||||
local test1_result = StaticBoxTest.main()
|
||||
me.console.log("Test 1: " + test1_result)
|
||||
|
||||
local test2_result = SimpleProxyTest.main()
|
||||
me.console.log("Test 2: " + test2_result)
|
||||
|
||||
me.console.log("✅ All static box pattern tests passed")
|
||||
return "Static box tests complete"
|
||||
}
|
||||
}
|
||||
5
local_tests/test_static_main_compatibility.nyash
Normal file
5
local_tests/test_static_main_compatibility.nyash
Normal file
@ -0,0 +1,5 @@
|
||||
static box Main {
|
||||
main() {
|
||||
return 42
|
||||
}
|
||||
}
|
||||
51
local_tests/test_tcp_server.nyash
Normal file
51
local_tests/test_tcp_server.nyash
Normal file
@ -0,0 +1,51 @@
|
||||
// 🌐 Simple HTTP Server Test - Basic TCP functionality
|
||||
// Tests TCP socket operations before full HTTP implementation
|
||||
|
||||
static box Main {
|
||||
init { server, result }
|
||||
|
||||
main() {
|
||||
print("🚀 Testing TCP Socket Server functionality...")
|
||||
|
||||
// Create and test SocketBox
|
||||
me.server = new SocketBox()
|
||||
print("✅ SocketBox created: " + me.server.toString())
|
||||
|
||||
// Test binding to local address
|
||||
print("🔌 Testing bind operation...")
|
||||
local bindResult
|
||||
bindResult = me.server.bind("127.0.0.1", 8080)
|
||||
print("📡 Bind result: " + bindResult.toString())
|
||||
|
||||
if (bindResult.toString() == "true") {
|
||||
print("✅ Successfully bound to port 8080")
|
||||
|
||||
// Test listen operation
|
||||
print("👂 Testing listen operation...")
|
||||
local listenResult
|
||||
listenResult = me.server.listen(10)
|
||||
print("📡 Listen result: " + listenResult.toString())
|
||||
|
||||
if (listenResult.toString() == "true") {
|
||||
print("✅ Successfully listening on port 8080")
|
||||
print("🎯 Server is ready to accept connections!")
|
||||
print("📝 Note: This is a basic test - no actual connections accepted")
|
||||
|
||||
// Close the server
|
||||
print("🛑 Closing server...")
|
||||
local closeResult
|
||||
closeResult = me.server.close()
|
||||
print("📡 Close result: " + closeResult.toString())
|
||||
|
||||
me.result = "TCP Server test completed successfully"
|
||||
} else {
|
||||
me.result = "Failed to listen on port 8080"
|
||||
}
|
||||
} else {
|
||||
me.result = "Failed to bind to port 8080"
|
||||
}
|
||||
|
||||
print("🏁 Test completed: " + me.result)
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
14
local_tests/test_user_defined_box.nyash
Normal file
14
local_tests/test_user_defined_box.nyash
Normal file
@ -0,0 +1,14 @@
|
||||
box DataBox {
|
||||
init { value }
|
||||
|
||||
pack(v) {
|
||||
me.value = v
|
||||
}
|
||||
}
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local obj = new DataBox(42)
|
||||
return obj.value
|
||||
}
|
||||
}
|
||||
19
local_tests/test_wasm_box_integration.nyash
Normal file
19
local_tests/test_wasm_box_integration.nyash
Normal file
@ -0,0 +1,19 @@
|
||||
box SimpleData {
|
||||
init { x, y }
|
||||
|
||||
pack(a, b) {
|
||||
me.x = a
|
||||
me.y = b
|
||||
}
|
||||
|
||||
sum() {
|
||||
return me.x + me.y
|
||||
}
|
||||
}
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local data = new SimpleData(10, 20)
|
||||
return data.sum()
|
||||
}
|
||||
}
|
||||
7
local_tests/test_wasm_box_ops.nyash
Normal file
7
local_tests/test_wasm_box_ops.nyash
Normal file
@ -0,0 +1,7 @@
|
||||
static box Main {
|
||||
main() {
|
||||
local obj = new DataBox(42)
|
||||
print(obj.value)
|
||||
return obj.value
|
||||
}
|
||||
}
|
||||
9
local_tests/test_wasm_simple.nyash
Normal file
9
local_tests/test_wasm_simple.nyash
Normal file
@ -0,0 +1,9 @@
|
||||
# Simple WASM ExternCall test - for manual MIR injection
|
||||
static box Main {
|
||||
init { result }
|
||||
|
||||
main() {
|
||||
me.result = "WASM test ready"
|
||||
return me.result
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user