feat: add await syntax for direct async function calls and new generator/phonebook apps

Add compiler support for calling async functions directly with `await fn(args)` syntax, automatically translating to `await fn.call(args)`. Introduce `create_merge` Makefile target for merging Wren source files. Include new `apps/generator.wren` source code generator using OpenRouter API, `apps/phonebook.wren` CLI phonebook with SQLite backend, and `apps/minitut.md` Wren tutorial reference. Update `example/await_demo.wren` with parameterized async functions, nested awaits, and expression usage. Fix JSON parsing in `example/openrouter_demo.wren` to strip markdown code fences. Document new await syntax in `manual/api/scheduler.html`.
This commit is contained in:
2026-01-25 09:50:20 +00:00
parent e0cc7791e3
commit eadfc8e9cb
48 changed files with 1543 additions and 86 deletions
+97
View File
@@ -0,0 +1,97 @@
// wren source code generator v1.0
// Generation time: 0.101419
import "io" for File, Directory, Stdin, Stdout
import "sqlite" for Database
class Phonebook {
construct new() {
_db = Database.memory()
init_()
}
init_() {
_db.execute("CREATE TABLE IF NOT EXISTS contacts (id INTEGER PRIMARY KEY, name TEXT, phone TEXT)", [])
}
add(name, phone) {
_db.execute("INSERT INTO contacts (name, phone) VALUES (?, ?)", [name, phone])
System.print("Contact added: %(name)")
}
list() {
var rows = _db.query("SELECT * FROM contacts", [])
if (rows.isEmpty) {
System.print("No contacts found.")
return
}
System.print("\n--- Phonebook ---")
for (row in rows) {
System.print("%(row["name"]) : %(row["phone"])")
}
System.print("")
}
search(name) {
var rows = _db.query("SELECT * FROM contacts WHERE name LIKE ?", ["\%" + name + "\%"])
if (rows.isEmpty) {
System.print("No contacts found for '%(name)'.")
return
}
System.print("\n--- Search Results ---")
for (row in rows) {
System.print("%(row[1]) : %(row[2])")
}
System.print("")
}
delete(name) {
_db.execute("DELETE FROM contacts WHERE name = ?", [name])
System.print("Contact deleted: %(name)")
}
run() {
System.print("\n=== CLI Phonebook ===")
var running = true
while (running) {
System.print("\n1. Add contact")
System.print("2. List contacts")
System.print("3. Search contact")
System.print("4. Delete contact")
System.print("5. Exit")
System.write("Choose option: ")
Stdout.flush()
var choice = Stdin.readLine().trim()
if (choice == "1") {
System.write("Name: ")
Stdout.flush()
var name = Stdin.readLine().trim()
System.write("Phone: ")
Stdout.flush()
var phone = Stdin.readLine().trim()
add(name, phone)
} else if (choice == "2") {
list()
} else if (choice == "3") {
System.write("Search name: ")
Stdout.flush()
var name = Stdin.readLine().trim()
search(name)
} else if (choice == "4") {
System.write("Contact name to delete: ")
Stdout.flush()
var name = Stdin.readLine().trim()
delete(name)
} else if (choice == "5") {
System.print("Goodbye!")
running = false
} else {
System.print("Invalid option.")
}
}
}
}
var pb = Phonebook.new()
pb.run()