You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The KCL compiler has some technical implementation problems in the process of interacting with the file system.
The Parse stage has a messy process of reading entry for compilation, either from the file system or from incoming code snippets, because it does not have a vfs, causing some work that requires vfs to be written directly to the parser. The resolver also relies directly on the local file system.
Some apis that directly compile code snippets and the code snippets import each other, independent of local file system, and require a vfs to organize the associations between virtual code snippets.
The text was updated successfully, but these errors were encountered:
Pre-Compilation: Introduce the VFS (Virtual File System) to convert file paths into SourceFiles before compilation.
During-Compilation: Use pkgpath as the key for retrieving files. Each pkgpath corresponds to Vec<SourceFile>.
Path Consistency: Within the compiler, consistently use pkgpath style paths (regardless of Windows/Unix conventions). The conversion from different path styles to pkgpath is handled within the VFS.
Parts
PkgPath: the unified path style for VFS.
VFS: the virtual file system.
SourceFile: the file in VFS.
PkgPath
PkgPath is the unified path style for VFS.
structPkgPath{pkgpath:String,// the path in VFS, like "a.b.c.d"extension:Option<String>,// the file extension, default is "k"root:Option<String>,// the root path, default is "${KCL_MOD}"}
Implement the Into/From trait for PkgPath, convert PkgPath to PathBuf/Path, and adapt to the corresponding path style according to different platforms in the into() method.
VFS
VFS is the virtual file system.
pubtraitVFS{// Load the local file path from `path` into VFS.fnload(path:String) -> Self;// If the `pkgpath` is loaded into VFS.fnexists(pkgpath:PkgPath) -> bool;// If return the `SourceFile` by `PkgPath`fnget_source_files_by_pkgpath(pkgpath:PkgPath) -> Vec<SourceFile>;// Add a specified file into VFSfninsert_source_file_by_pkgpath(pkgpath:PkgPath);}
Load the local file path from path into VFS.
let vfs = VFS::load("/usr/local/main.k");
If the pkgpath is loaded into VFS.
pkgpath maybe a file or dir.
If it is a dir, a.b.c.d is ${KCL_MOD}/a/b/c/d.
If it is a file, a.b.c.d is ${KCL_MOD}/a/b/c/d.k by default. the extension can be specified by argument.
At present, the SourceFile in rustc has been used in KCL as the file abstraction. Here, the SourceFile in rustc is encapsulated twice, and new capabilities can be extended on the basis of reusing the existing SourceMap capabilities.
structSourceFile{// Still use the `SourceFile` in rustc.sf: rustc::SourceFile// `PkgPath` is used to associate `SourceFile` with `a.b.c.d` style path.
pkgPath:PkgPath}
Enhancement
The KCL compiler has some technical implementation problems in the process of interacting with the file system.
The Parse stage has a messy process of reading entry for compilation, either from the file system or from incoming code snippets, because it does not have a
vfs
, causing some work that requiresvfs
to be written directly to the parser. The resolver also relies directly on the local file system.Some apis that directly compile code snippets and the code snippets import each other, independent of local file system, and require a
vfs
to organize the associations between virtual code snippets.The text was updated successfully, but these errors were encountered: