/
namespaces.go
132 lines (126 loc) · 5.17 KB
/
namespaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package fs_ns
import (
"github.com/inoxlang/inox/internal/core"
"github.com/inoxlang/inox/internal/core/symbolic"
fs_symbolic "github.com/inoxlang/inox/internal/globals/fs_ns/symbolic"
"github.com/inoxlang/inox/internal/help"
)
func init() {
core.RegisterDefaultPatternNamespace("fs", &core.PatternNamespace{
Patterns: map[string]core.Pattern{
"tree-data-item": core.NewInexactRecordPattern([]core.RecordPatternEntry{
{
Name: "path",
Pattern: core.PATH_PATTERN,
},
{
Name: "path_rel_to_parent",
Pattern: core.PATH_PATTERN,
},
}),
},
})
//register limits
core.RegisterLimit(FS_READ_LIMIT_NAME, core.ByteRateLimit, FS_READ_MIN_CHUNK_SIZE)
core.RegisterLimit(FS_WRITE_LIMIT_NAME, core.ByteRateLimit, FS_WRITE_MIN_CHUNK_SIZE)
core.RegisterLimit(FS_NEW_FILE_RATE_LIMIT_NAME, core.FrequencyLimit, 0)
core.RegisterLimit(FS_TOTAL_NEW_FILE_LIMIT_NAME, core.TotalLimit, 0)
//register symbolic version of go functions
core.RegisterSymbolicGoFunctions([]any{
Mkfile, func(ctx *symbolic.Context, path *symbolic.Path, args ...symbolic.Value) *symbolic.Error {
//ctx.SetSymbolicGoFunctionParameters(MKFILE_SYMB_PARAMS, MKFILE_ARG_NAMES)
return nil
},
Mkdir, func(ctx *symbolic.Context, dirpath *symbolic.Path, content *symbolic.OptionalParam[*symbolic.Dictionary]) *symbolic.Error {
ctx.SetSymbolicGoFunctionParameters(MKDIR_SYMB_PARAMS, MKDIR_ARG_NAMES)
return nil
},
ReadFile, func(ctx *symbolic.Context, fpath *core.Path) (*symbolic.ByteSlice, *symbolic.Error) {
ctx.SetSymbolicGoFunctionParameters(READFILE_SYMB_PARAMS, READFILE_ARG_NAMES)
return symbolic.ANY_BYTE_SLICE, nil
},
Read, func(ctx *symbolic.Context, pth *symbolic.Path, args ...symbolic.Value) (symbolic.Value, *symbolic.Error) {
return symbolic.ANY, nil
},
ListFiles, func(ctx *symbolic.Context, pathOrPattern *symbolic.OptionalParam[symbolic.Value]) (*symbolic.List, *symbolic.Error) {
ctx.SetSymbolicGoFunctionParameters(LISTFILES_SYMB_PARAMS, LISTFILES_ARG_NAMES)
return symbolic.NewListOf(symbolic.ANY_FILEINFO), nil
},
Remove, func(ctx *symbolic.Context, args ...symbolic.Value) *symbolic.Error {
return nil
},
Copy, func(ctx *symbolic.Context, args ...symbolic.Value) *symbolic.Error {
return nil
},
Rename, func(ctx *symbolic.Context, old, new *symbolic.Path) *symbolic.Error {
return nil
},
IsDir, func(ctx *symbolic.Context, pth *symbolic.Path) *symbolic.Bool {
return symbolic.ANY_BOOL
},
IsFile, func(ctx *symbolic.Context, pth *symbolic.Path) *symbolic.Bool {
return symbolic.ANY_BOOL
},
Exists, func(ctx *symbolic.Context, pth *symbolic.Path) *symbolic.Bool {
return symbolic.ANY_BOOL
},
Find, func(ctx *symbolic.Context, pth *symbolic.Path, filters ...symbolic.Pattern) (*symbolic.List, *symbolic.Error) {
return &symbolic.List{}, nil
},
OpenExisting, func(ctx *symbolic.Context, args ...symbolic.Value) (*fs_symbolic.File, *symbolic.Error) {
return &fs_symbolic.File{}, nil
},
Glob, func(ctx *symbolic.Context, patt ...*symbolic.PathPattern) *symbolic.List {
return symbolic.NewListOf(&symbolic.Path{})
},
GetTreeData, func(ctx *symbolic.Context, pth *symbolic.Path) *symbolic.Treedata {
return &symbolic.Treedata{}
},
NewMemFilesystemIL, func(ctx *symbolic.Context, maxTotalStorageSize *symbolic.ByteCount) *fs_symbolic.Filesystem {
return fs_symbolic.ANY_FILESYSTEM
},
NewFilesystemSnapshot, func(ctx *symbolic.Context, args *symbolic.Object) *symbolic.FilesystemSnapshotIL {
ctx.SetSymbolicGoFunctionParameters(NEW_FS_SNAPSHOT_SYMB_ARGS, NEW_FS_SNAPSHOT_SYMB_ARG_NAMES)
return symbolic.ANY_FS_SNAPSHOT_IL
},
})
help.RegisterHelpValues(map[string]any{
"fs.mkfile": Mkfile,
"fs.mkdir": Mkdir,
"fs.read": Read,
"fs.ls": ListFiles,
"fs.rename": Rename,
"fs.mv": Rename,
"fs.cp": Copy,
"fs.exists": Exists,
"fs.isdir": IsDir,
"fs.isfile": IsFile,
"fs.remove": Remove,
"fs.glob": Glob,
"fs.find": Find,
"fs.get_tree_data": GetTreeData,
})
}
func NewFsNamespace() *core.Namespace {
return core.NewNamespace("fs", map[string]core.Value{
"mkfile": core.WrapGoFunction(Mkfile),
"mkdir": core.WrapGoFunction(Mkdir),
"read_file": core.WrapGoFunction(ReadFile),
"read": core.WrapGoFunction(Read),
"ls": core.WrapGoFunction(ListFiles),
"rm": core.WrapGoFunction(Remove),
"remove": core.WrapGoFunction(Remove),
"cp": core.WrapGoFunction(Copy),
"mv": core.WrapGoFunction(Rename),
"rename": core.WrapGoFunction(Rename),
"isdir": core.WrapGoFunction(IsDir),
"isfile": core.WrapGoFunction(IsFile),
"find": core.WrapGoFunction(Find),
"exists": core.WrapGoFunction(Exists),
"open": core.WrapGoFunction(OpenExisting),
"glob": core.WrapGoFunction(Glob),
"get_tree_data": core.WrapGoFunction(GetTreeData),
"new_mem_filesystem": core.WrapGoFunction(NewMemFilesystemIL),
"new_snapshot": core.WrapGoFunction(NewFilesystemSnapshot),
})
}