Phase 10.7/10.5c: include cycle detection (VM/Interpreter), minimal pyc IR→Nyash, String unification bridge (VM partial), add core plugins: RegexBox/EncodingBox/TOMLBox/PathBox + examples; wire nyash.toml; begin String interop for internal vs plugin boxes; update CURRENT_TASK.md
This commit is contained in:
9
examples/cycle_a.nyash
Normal file
9
examples/cycle_a.nyash
Normal file
@ -0,0 +1,9 @@
|
||||
// Cycle test A -> B -> A
|
||||
include "examples/cycle_b.nyash"
|
||||
|
||||
static box A {
|
||||
main() {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
9
examples/cycle_b.nyash
Normal file
9
examples/cycle_b.nyash
Normal file
@ -0,0 +1,9 @@
|
||||
// Cycle test B -> A
|
||||
include "examples/cycle_a.nyash"
|
||||
|
||||
static box B {
|
||||
main() {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
8
examples/encoding_min.nyash
Normal file
8
examples/encoding_min.nyash
Normal file
@ -0,0 +1,8 @@
|
||||
static box Main {
|
||||
main() {
|
||||
local e = new EncodingBox()
|
||||
local b64 = e.base64Encode("hello")
|
||||
// quick check: "hello" -> aGVsbG8=
|
||||
return b64.length() == 8
|
||||
}
|
||||
}
|
||||
8
examples/path_min.nyash
Normal file
8
examples/path_min.nyash
Normal file
@ -0,0 +1,8 @@
|
||||
static box Main {
|
||||
main() {
|
||||
local p = new PathBox()
|
||||
local j = p.join("/usr", "bin")
|
||||
local b = p.basename(j)
|
||||
return b
|
||||
}
|
||||
}
|
||||
35
examples/plugin_box_as_arg_demo.nyash
Normal file
35
examples/plugin_box_as_arg_demo.nyash
Normal file
@ -0,0 +1,35 @@
|
||||
// プラグインBoxが箱を引数に取る例のデモ
|
||||
|
||||
// HttpServer/Request/Responseの例
|
||||
local server = new HttpServerBox()
|
||||
server.start(8080)
|
||||
|
||||
// acceptはHttpRequestBoxを返す
|
||||
local request = server.accept() // returns box
|
||||
|
||||
// HttpResponseBoxを作成
|
||||
local response = new HttpResponseBox()
|
||||
response.setStatus(200)
|
||||
response.setHeader("Content-Type", "text/plain")
|
||||
response.write("Hello from Nyash!")
|
||||
|
||||
// ★ HttpRequestBox.respond()はHttpResponseBox(別の箱)を引数に取る!
|
||||
request.respond(response) // Box引数の実例!
|
||||
|
||||
// 他の例:ArrayBoxにプラグインBoxを格納
|
||||
local array = new ArrayBox()
|
||||
local file1 = new FileBox()
|
||||
local file2 = new FileBox()
|
||||
|
||||
// ArrayBoxは任意のBoxを引数に取れる
|
||||
array.push(file1) // FileBox(プラグインBox)を引数に
|
||||
array.push(file2) // 別のFileBoxインスタンスも
|
||||
|
||||
// MapBoxでも同様
|
||||
local map = new MapBox()
|
||||
local net = new HttpClientBox()
|
||||
|
||||
// MapBoxも任意のBoxを値として設定できる
|
||||
map.set("client", net) // HttpClientBox(プラグインBox)を引数に
|
||||
|
||||
print("Plugin boxes can take other boxes as arguments!")
|
||||
8
examples/regex_min.nyash
Normal file
8
examples/regex_min.nyash
Normal file
@ -0,0 +1,8 @@
|
||||
static box Main {
|
||||
main() {
|
||||
local r = new RegexBox()
|
||||
r.compile("a+")
|
||||
return r.isMatch("caaab")
|
||||
}
|
||||
}
|
||||
|
||||
8
examples/toml_min.nyash
Normal file
8
examples/toml_min.nyash
Normal file
@ -0,0 +1,8 @@
|
||||
static box Main {
|
||||
main() {
|
||||
local t = new TOMLBox()
|
||||
t.parse("[a]\nvalue=42\n")
|
||||
local j = t.toJson()
|
||||
return j
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user