Refactored ObjRef evaluation logic for enhanced performance and consistency across unary, binary, and field operations. Added evalValue overrides for more streamlined value resolution.
This commit is contained in:
1 parent
827df9c8cd
commit
6b957ae6a3
28 files changed
+1339
-506
No files matched your search
@@ -39,43 +39,174 @@ object FsBuiltinDocs {
|
||||
name = "Path",
|
||||
doc = "Filesystem path class. Construct with a string: `Path(\"/tmp\")`."
|
||||
) {
|
||||
// Common instance methods (subset sufficient for Quick Docs)
|
||||
method(
|
||||
name = "name",
|
||||
doc = "Base name of the path (last segment).",
|
||||
returns = type("lyng.String")
|
||||
)
|
||||
method(
|
||||
name = "parent",
|
||||
doc = "Parent directory as a Path or null if none.",
|
||||
returns = type("Path", nullable = true)
|
||||
)
|
||||
method(
|
||||
name = "segments",
|
||||
doc = "List of path segments.",
|
||||
returns = TypeGenericDoc(type("lyng.List"), listOf(type("lyng.String")))
|
||||
)
|
||||
method(
|
||||
name = "exists",
|
||||
doc = "Whether the path exists on the filesystem.",
|
||||
doc = "Check whether this path exists on the filesystem.",
|
||||
returns = type("lyng.Bool")
|
||||
)
|
||||
method(
|
||||
name = "isFile",
|
||||
doc = "Whether the path exists and is a file.",
|
||||
doc = "True if this path is a regular file (based on cached metadata).",
|
||||
returns = type("lyng.Bool")
|
||||
)
|
||||
method(
|
||||
name = "isDir",
|
||||
doc = "Whether the path exists and is a directory.",
|
||||
name = "isDirectory",
|
||||
doc = "True if this path is a directory (based on cached metadata).",
|
||||
returns = type("lyng.Bool")
|
||||
)
|
||||
method(
|
||||
name = "size",
|
||||
doc = "File size in bytes, or null when unavailable.",
|
||||
returns = type("lyng.Int", nullable = true)
|
||||
)
|
||||
method(
|
||||
name = "createdAt",
|
||||
doc = "Creation time as `Instant`, or null when unavailable.",
|
||||
returns = type("lyng.Instant", nullable = true)
|
||||
)
|
||||
method(
|
||||
name = "createdAtMillis",
|
||||
doc = "Creation time in milliseconds since epoch, or null when unavailable.",
|
||||
returns = type("lyng.Int", nullable = true)
|
||||
)
|
||||
method(
|
||||
name = "modifiedAt",
|
||||
doc = "Last modification time as `Instant`, or null when unavailable.",
|
||||
returns = type("lyng.Instant", nullable = true)
|
||||
)
|
||||
method(
|
||||
name = "modifiedAtMillis",
|
||||
doc = "Last modification time in milliseconds since epoch, or null when unavailable.",
|
||||
returns = type("lyng.Int", nullable = true)
|
||||
)
|
||||
method(
|
||||
name = "list",
|
||||
doc = "List directory entries as `Path` objects.",
|
||||
returns = TypeGenericDoc(type("lyng.List"), listOf(type("Path")))
|
||||
)
|
||||
method(
|
||||
name = "readBytes",
|
||||
doc = "Read the entire file into a binary buffer.",
|
||||
returns = type("lyng.Buffer")
|
||||
)
|
||||
method(
|
||||
name = "writeBytes",
|
||||
doc = "Write a binary buffer to the file, replacing content.",
|
||||
params = listOf(ParamDoc("bytes", type("lyng.Buffer")))
|
||||
)
|
||||
method(
|
||||
name = "appendBytes",
|
||||
doc = "Append a binary buffer to the end of the file.",
|
||||
params = listOf(ParamDoc("bytes", type("lyng.Buffer")))
|
||||
)
|
||||
method(
|
||||
name = "readUtf8",
|
||||
doc = "Read the entire file as UTF-8 string.",
|
||||
doc = "Read the entire file as a UTF-8 string.",
|
||||
returns = type("lyng.String")
|
||||
)
|
||||
method(
|
||||
name = "writeUtf8",
|
||||
doc = "Write UTF-8 string to the file (overwrite).",
|
||||
doc = "Write a UTF-8 string to the file, replacing content.",
|
||||
params = listOf(ParamDoc("text", type("lyng.String")))
|
||||
)
|
||||
method(
|
||||
name = "bytes",
|
||||
doc = "Iterate file content as `Buffer` chunks.",
|
||||
name = "appendUtf8",
|
||||
doc = "Append UTF-8 text to the end of the file.",
|
||||
params = listOf(ParamDoc("text", type("lyng.String")))
|
||||
)
|
||||
method(
|
||||
name = "metadata",
|
||||
doc = "Fetch cached metadata as a map of fields: `isFile`, `isDirectory`, `size`, `createdAtMillis`, `modifiedAtMillis`, `isSymlink`.",
|
||||
returns = TypeGenericDoc(type("lyng.Map"), listOf(type("lyng.String"), type("lyng.Any")))
|
||||
)
|
||||
method(
|
||||
name = "mkdirs",
|
||||
doc = "Create directories (like `mkdir -p`). If `mustCreate` is true and the path already exists, the call fails.",
|
||||
params = listOf(ParamDoc("mustCreate", type("lyng.Bool")))
|
||||
)
|
||||
method(
|
||||
name = "move",
|
||||
doc = "Move this path to a new location. `to` may be a `Path` or `String`.",
|
||||
params = listOf(ParamDoc("to"), ParamDoc("overwrite", type("lyng.Bool")))
|
||||
)
|
||||
method(
|
||||
name = "delete",
|
||||
doc = "Delete this path. `recursively=true` removes directories with their contents.",
|
||||
params = listOf(ParamDoc("mustExist", type("lyng.Bool")), ParamDoc("recursively", type("lyng.Bool")))
|
||||
)
|
||||
method(
|
||||
name = "copy",
|
||||
doc = "Copy this path to a new location. `to` may be a `Path` or `String`.",
|
||||
params = listOf(ParamDoc("to"), ParamDoc("overwrite", type("lyng.Bool")))
|
||||
)
|
||||
method(
|
||||
name = "glob",
|
||||
doc = "List entries matching a glob pattern (no recursion).",
|
||||
params = listOf(ParamDoc("pattern", type("lyng.String"))),
|
||||
returns = TypeGenericDoc(type("lyng.List"), listOf(type("Path")))
|
||||
)
|
||||
method(
|
||||
name = "readChunks",
|
||||
doc = "Read file in fixed-size chunks as an iterator of `Buffer`.",
|
||||
params = listOf(ParamDoc("size", type("lyng.Int"))),
|
||||
returns = TypeGenericDoc(type("lyng.Iterator"), listOf(type("lyng.Buffer")))
|
||||
)
|
||||
method(
|
||||
name = "lines",
|
||||
doc = "Iterate file as lines of text.",
|
||||
name = "readUtf8Chunks",
|
||||
doc = "Read UTF-8 text in fixed-size chunks as an iterator of `String`.",
|
||||
params = listOf(ParamDoc("size", type("lyng.Int"))),
|
||||
returns = TypeGenericDoc(type("lyng.Iterator"), listOf(type("lyng.String")))
|
||||
)
|
||||
method(
|
||||
name = "lines",
|
||||
doc = "Iterate lines of the file as `String` values.",
|
||||
returns = TypeGenericDoc(type("lyng.Iterator"), listOf(type("lyng.String")))
|
||||
)
|
||||
}
|
||||
|
||||
classDoc(
|
||||
name = "BytesIterator",
|
||||
doc = "Iterator over binary chunks."
|
||||
) {
|
||||
method("iterator", "Return this iterator instance.", returns = type("BytesIterator"))
|
||||
method("hasNext", "Whether there is another chunk available.", returns = type("lyng.Bool"))
|
||||
method("next", "Return the next chunk as a `Buffer`.", returns = type("lyng.Buffer"))
|
||||
method("cancelIteration", "Stop the iteration early.")
|
||||
}
|
||||
|
||||
classDoc(
|
||||
name = "StringChunksIterator",
|
||||
doc = "Iterator over UTF-8 text chunks."
|
||||
) {
|
||||
method("iterator", "Return this iterator instance.", returns = type("StringChunksIterator"))
|
||||
method("hasNext", "Whether there is another chunk available.", returns = type("lyng.Bool"))
|
||||
method("next", "Return the next UTF-8 chunk as a `String`.", returns = type("lyng.String"))
|
||||
method("cancelIteration", "Stop the iteration early.")
|
||||
}
|
||||
|
||||
classDoc(
|
||||
name = "LinesIterator",
|
||||
doc = "Iterator that yields lines of text."
|
||||
) {
|
||||
method("iterator", "Return this iterator instance.", returns = type("LinesIterator"))
|
||||
method("hasNext", "Whether another line is available.", returns = type("lyng.Bool"))
|
||||
method("next", "Return the next line as `String`.", returns = type("lyng.String"))
|
||||
method("cancelIteration", "Stop the iteration early.")
|
||||
}
|
||||
|
||||
// Top-level exported constants
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2026 Sergey S. Chernov real.sergeych@gmail.com
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.sergeych.lyngio.docs
|
||||
|
||||
import net.sergeych.lyng.miniast.BuiltinDocRegistry
|
||||
import net.sergeych.lyng.miniast.ParamDoc
|
||||
import net.sergeych.lyng.miniast.type
|
||||
|
||||
object ProcessBuiltinDocs {
|
||||
private var registered = false
|
||||
|
||||
fun ensure() {
|
||||
if (registered) return
|
||||
BuiltinDocRegistry.module("lyng.io.process") {
|
||||
classDoc(
|
||||
name = "Process",
|
||||
doc = "Process execution and control."
|
||||
) {
|
||||
method(
|
||||
name = "execute",
|
||||
doc = "Execute a process with arguments.",
|
||||
params = listOf(ParamDoc("executable", type("lyng.String")), ParamDoc("args", type("lyng.List"))),
|
||||
returns = type("RunningProcess"),
|
||||
isStatic = true
|
||||
)
|
||||
method(
|
||||
name = "shell",
|
||||
doc = "Execute a command via system shell.",
|
||||
params = listOf(ParamDoc("command", type("lyng.String"))),
|
||||
returns = type("RunningProcess"),
|
||||
isStatic = true
|
||||
)
|
||||
}
|
||||
|
||||
classDoc(
|
||||
name = "Platform",
|
||||
doc = "Platform information."
|
||||
) {
|
||||
method(
|
||||
name = "details",
|
||||
doc = "Get platform core details.",
|
||||
returns = type("lyng.Map"),
|
||||
isStatic = true
|
||||
)
|
||||
method(
|
||||
name = "isSupported",
|
||||
doc = "Check if processes are supported on this platform.",
|
||||
returns = type("lyng.Bool"),
|
||||
isStatic = true
|
||||
)
|
||||
}
|
||||
|
||||
classDoc(
|
||||
name = "RunningProcess",
|
||||
doc = "Handle to a running process."
|
||||
) {
|
||||
method(
|
||||
name = "stdout",
|
||||
doc = "Get standard output stream as a Flow of lines.",
|
||||
returns = type("lyng.Flow")
|
||||
)
|
||||
method(
|
||||
name = "stderr",
|
||||
doc = "Get standard error stream as a Flow of lines.",
|
||||
returns = type("lyng.Flow")
|
||||
)
|
||||
method(
|
||||
name = "signal",
|
||||
doc = "Send a signal to the process (e.g. 'SIGINT', 'SIGTERM', 'SIGKILL').",
|
||||
params = listOf(ParamDoc("signal", type("lyng.String")))
|
||||
)
|
||||
method(
|
||||
name = "waitFor",
|
||||
doc = "Wait for the process to exit and return its exit code.",
|
||||
returns = type("lyng.Int")
|
||||
)
|
||||
method(
|
||||
name = "destroy",
|
||||
doc = "Forcefully terminate the process."
|
||||
)
|
||||
}
|
||||
|
||||
// Top-level exported constants
|
||||
valDoc(
|
||||
name = "Process",
|
||||
doc = "Process execution and control.",
|
||||
type = type("Process")
|
||||
)
|
||||
valDoc(
|
||||
name = "Platform",
|
||||
doc = "Platform information.",
|
||||
type = type("Platform")
|
||||
)
|
||||
valDoc(
|
||||
name = "RunningProcess",
|
||||
doc = "Handle to a running process.",
|
||||
type = type("RunningProcess")
|
||||
)
|
||||
}
|
||||
registered = true
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user