Skip to content

Commit cc4ac13

Browse files
committed
fixed critical bugs in WMS (W++ module system)
1 parent 7760a15 commit cc4ac13

26 files changed

Lines changed: 1035 additions & 366 deletions

test_rust_import.wpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Test Rust JSON import
2+
import "rust:json"
3+
4+
func main() {
5+
print("Testing JSON import...")
6+
let valid = json_validate("{\"test\":123}")
7+
print("JSON validation result:", valid)
8+
print("Test complete!")
9+
}

wpp-cli/demo/.simula

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ BEGIN SYSTEM SIMULATION;
1111
END SYSTEM;
1212

1313
BEGIN MAIN;
14-
PACKAGE demo;
15-
demo.name := "demo";
16-
demo.version := "1.0.0";
17-
demo.checksum := "sha256:2a57e90b72a017f5863626ee3ac4a9c42e3356b40512defaeb98fd59ae415a62";
14+
PACKAGE json;
15+
json.name := "json";
16+
json.version := "1.0.0";
17+
json.checksum := "sha256:02bd175f329720378ce83dd56a1b6b1f5291a60182d6c54b5e0d1e8d248a267a";
1818
END;
1919
END;

wpp-cli/demo/.wpp_packages/demo/main.wpp

Lines changed: 0 additions & 2 deletions
This file was deleted.

wpp-cli/demo/.wpp_packages/io/main.wpp

Lines changed: 0 additions & 200 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "wpp-json-ffi"
3+
version = "1.0.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
9+
[workspace]
10+
# This is a standalone library, not part of W++ workspace
11+
12+
[dependencies]
13+
serde_json = "1.0"
14+
libc = "0.2"
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// W++ JSON Library Demo
2+
// Demonstrates all JSON functionality
3+
4+
import { parse, stringify, pretty, validate, isValid, get, getString, getInt, merge } from "json"
5+
6+
func main() {
7+
print("=== W++ JSON Library Demo ===")
8+
print("")
9+
10+
// ========================================
11+
// 1. JSON Parsing and Validation
12+
// ========================================
13+
print("--- JSON Parsing & Validation ---")
14+
15+
let valid_json = "{\"name\":\"Alice\",\"age\":30,\"city\":\"NYC\"}"
16+
let invalid_json = "{name: Alice}" // Missing quotes
17+
18+
print("Valid JSON:", valid_json)
19+
print("Is valid?", isValid(valid_json))
20+
21+
print("Invalid JSON:", invalid_json)
22+
print("Is valid?", isValid(invalid_json))
23+
print("")
24+
25+
// ========================================
26+
// 2. JSON Stringify and Pretty Print
27+
// ========================================
28+
print("--- JSON Stringify & Pretty Print ---")
29+
30+
let user_json = "{\"name\":\"Bob\",\"age\":25,\"hobbies\":[\"coding\",\"gaming\"]}"
31+
32+
print("Minified:")
33+
print(stringify(user_json))
34+
print("")
35+
36+
print("Pretty (2 spaces):")
37+
print(pretty(user_json, 2))
38+
print("")
39+
40+
print("Pretty (4 spaces):")
41+
print(pretty(user_json, 4))
42+
print("")
43+
44+
// ========================================
45+
// 3. JSON Query Operations
46+
// ========================================
47+
print("--- JSON Query Operations ---")
48+
49+
let person = "{\"user\":{\"name\":\"Charlie\",\"email\":\"charlie@example.com\"},\"score\":100}"
50+
51+
print("Full JSON:", person)
52+
print("")
53+
54+
print("Get nested value (user.name):")
55+
print(get(person, "user.name"))
56+
print("")
57+
58+
print("Get string value (direct):")
59+
let simple = "{\"title\":\"Hello World\",\"count\":42}"
60+
print("Title:", getString(simple, "title"))
61+
print("Count:", getInt(simple, "count"))
62+
print("")
63+
64+
// ========================================
65+
// 4. JSON Merge
66+
// ========================================
67+
print("--- JSON Merge ---")
68+
69+
let obj1 = "{\"a\":1,\"b\":2}"
70+
let obj2 = "{\"b\":3,\"c\":4}"
71+
72+
print("Object 1:", obj1)
73+
print("Object 2:", obj2)
74+
print("Merged:", pretty(merge(obj1, obj2), 2))
75+
print("")
76+
77+
// ========================================
78+
// 5. Complex Nested JSON
79+
// ========================================
80+
print("--- Complex Nested JSON ---")
81+
82+
let complex = "{\"users\":[{\"id\":1,\"name\":\"Alice\"},{\"id\":2,\"name\":\"Bob\"}],\"metadata\":{\"version\":\"1.0\",\"count\":2}}"
83+
84+
print("Complex JSON (pretty):")
85+
print(pretty(complex, 2))
86+
print("")
87+
88+
print("Get metadata.version:")
89+
print(get(complex, "metadata.version"))
90+
print("")
91+
92+
// ========================================
93+
// 6. Error Handling
94+
// ========================================
95+
print("--- Error Handling ---")
96+
97+
let malformed = "{broken json"
98+
print("Malformed JSON:", malformed)
99+
print("Validation result:", validate(malformed))
100+
print("")
101+
102+
print("=== Demo Complete ===")
103+
}

0 commit comments

Comments
 (0)