jaclang 0.0.1__tar.gz → 0.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of jaclang might be problematic. Click here for more details.
- jaclang-0.0.3/PKG-INFO +12 -0
- {jaclang-0.0.1 → jaclang-0.0.3}/README.md +2 -2
- jaclang-0.0.3/jaclang/__init__.py +4 -0
- jaclang-0.0.3/jaclang/cli/__init__.py +7 -0
- jaclang-0.0.3/jaclang/cli/cli.jac +46 -0
- jaclang-0.0.3/jaclang/cli/cmds.jac +14 -0
- jaclang-0.0.3/jaclang/cli/impl/__init__.py +1 -0
- jaclang-0.0.3/jaclang/cli/impl/cli_impl.jac +93 -0
- jaclang-0.0.3/jaclang/cli/impl/cmds_impl.jac +26 -0
- jaclang-0.0.3/jaclang/core/__init__.py +12 -0
- jaclang-0.0.3/jaclang/core/impl/__init__.py +1 -0
- jaclang-0.0.3/jaclang/core/impl/arch_impl.jac +112 -0
- jaclang-0.0.3/jaclang/core/impl/element_impl.jac +95 -0
- jaclang-0.0.3/jaclang/core/impl/exec_ctx_impl.jac +17 -0
- jaclang-0.0.3/jaclang/core/impl/memory_impl.jac +57 -0
- jaclang-0.0.3/jaclang/core/primitives.jac +104 -0
- jaclang-0.0.3/jaclang/jac/__init__.py +1 -0
- jaclang-0.0.3/jaclang/jac/absyntree.py +1787 -0
- jaclang-0.0.3/jaclang/jac/constant.py +46 -0
- jaclang-0.0.3/jaclang/jac/importer.py +130 -0
- jaclang-0.0.3/jaclang/jac/lexer.py +538 -0
- jaclang-0.0.3/jaclang/jac/parser.py +1474 -0
- jaclang-0.0.3/jaclang/jac/passes/__init__.py +5 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/__init__.py +25 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/ast_build_pass.py +3190 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/blue_pygen_pass.py +1335 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/decl_def_match_pass.py +278 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/import_pass.py +75 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/sub_node_tab_pass.py +30 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/tests/__init__.py +1 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/tests/test_ast_build_pass.py +61 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/tests/test_blue_pygen_pass.py +117 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/tests/test_decl_def_match_pass.py +43 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/tests/test_import_pass.py +18 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/tests/test_sub_node_pass.py +26 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/tests/test_type_analyze_pass.py +53 -0
- jaclang-0.0.3/jaclang/jac/passes/blue/type_analyze_pass.py +731 -0
- jaclang-0.0.3/jaclang/jac/passes/ir_pass.py +154 -0
- jaclang-0.0.3/jaclang/jac/passes/purple/__init__.py +17 -0
- jaclang-0.0.3/jaclang/jac/passes/purple/impl/__init__.py +1 -0
- jaclang-0.0.3/jaclang/jac/passes/purple/impl/purple_pygen_pass_impl.jac +289 -0
- jaclang-0.0.3/jaclang/jac/passes/purple/purple_pygen_pass.jac +35 -0
- jaclang-0.0.3/jaclang/jac/sym_table.py +127 -0
- jaclang-0.0.3/jaclang/jac/tests/__init__.py +1 -0
- jaclang-0.0.3/jaclang/jac/tests/fixtures/__init__.py +1 -0
- jaclang-0.0.3/jaclang/jac/tests/fixtures/activity.py +10 -0
- jaclang-0.0.3/jaclang/jac/tests/fixtures/fam.jac +68 -0
- jaclang-0.0.3/jaclang/jac/tests/fixtures/hello_world.jac +5 -0
- jaclang-0.0.3/jaclang/jac/tests/fixtures/lexer_fam.jac +61 -0
- jaclang-0.0.3/jaclang/jac/tests/fixtures/stuff.jac +6 -0
- jaclang-0.0.3/jaclang/jac/tests/test_importer.py +24 -0
- jaclang-0.0.3/jaclang/jac/tests/test_lexer.py +57 -0
- jaclang-0.0.3/jaclang/jac/tests/test_parser.py +50 -0
- jaclang-0.0.3/jaclang/jac/tests/test_utils.py +12 -0
- jaclang-0.0.3/jaclang/jac/transform.py +63 -0
- jaclang-0.0.3/jaclang/jac/transpiler.py +69 -0
- jaclang-0.0.3/jaclang/jac/utils.py +120 -0
- jaclang-0.0.3/jaclang/utils/__init__.py +1 -0
- jaclang-0.0.3/jaclang/utils/fstring_parser.py +73 -0
- jaclang-0.0.3/jaclang/utils/log.py +9 -0
- jaclang-0.0.3/jaclang/utils/sly/__init__.py +6 -0
- jaclang-0.0.3/jaclang/utils/sly/docparse.py +62 -0
- jaclang-0.0.3/jaclang/utils/sly/lex.py +510 -0
- jaclang-0.0.3/jaclang/utils/sly/yacc.py +2398 -0
- jaclang-0.0.3/jaclang/utils/test.py +81 -0
- jaclang-0.0.3/jaclang/utils/tests/__init__.py +1 -0
- jaclang-0.0.3/jaclang/utils/tests/test_fstring_parser.py +55 -0
- jaclang-0.0.3/jaclang.egg-info/PKG-INFO +12 -0
- jaclang-0.0.3/jaclang.egg-info/SOURCES.txt +72 -0
- jaclang-0.0.3/jaclang.egg-info/entry_points.txt +3 -0
- jaclang-0.0.3/jaclang.egg-info/top_level.txt +1 -0
- jaclang-0.0.3/setup.py +23 -0
- jaclang-0.0.1/PKG-INFO +0 -6
- jaclang-0.0.1/jaclang.egg-info/PKG-INFO +0 -6
- jaclang-0.0.1/jaclang.egg-info/SOURCES.txt +0 -6
- jaclang-0.0.1/jaclang.egg-info/top_level.txt +0 -1
- jaclang-0.0.1/setup.py +0 -19
- {jaclang-0.0.1 → jaclang-0.0.3}/jaclang.egg-info/dependency_links.txt +0 -0
- {jaclang-0.0.1 → jaclang-0.0.3}/setup.cfg +0 -0
jaclang-0.0.3/PKG-INFO
ADDED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Jaseci
|
|
1
|
+
# The Jac Programming Language and Jaseci Core
|
|
2
2
|
|
|
3
3
|
The next generation is upon us... (In ideation and specification phase)
|
|
4
4
|
|
|
5
|
-
Get to the docs, check the guidelines on how to contribute.
|
|
5
|
+
Get to the docs, check the guidelines on how to contribute.
|
|
6
6
|
|
|
7
7
|
## Getting Docs Up Locally
|
|
8
8
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This is the implementation of the command line interface tool for the
|
|
3
|
+
Jac language. It's built with the Jac language via bootstraping and
|
|
4
|
+
represents the first such complete Jac program.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import:py inspect;
|
|
8
|
+
import:py argparse;
|
|
9
|
+
import:py cmd;
|
|
10
|
+
include:jac impl.cli_impl;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
object Command {
|
|
14
|
+
has func: callable,
|
|
15
|
+
sig: inspect.Signature;
|
|
16
|
+
|
|
17
|
+
can:private init(func: callable);
|
|
18
|
+
can call(*args: list, **kwargs: dict);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
object CommandRegistry {
|
|
23
|
+
has:private registry: dict[str, Command],
|
|
24
|
+
sub_parsers: argparse._SubParsersActionp;
|
|
25
|
+
has:public parser: argparse.ArgumentParser;
|
|
26
|
+
|
|
27
|
+
can init;
|
|
28
|
+
can register(func: callable);
|
|
29
|
+
can get(name: str) -> Command;
|
|
30
|
+
can items -> dict[str, Command];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
object CommandShell:cmd.Cmd {
|
|
35
|
+
static has intro: str = "Welcome to the Jac CLI!",
|
|
36
|
+
prompt: str = "jac> ";
|
|
37
|
+
has cmd_reg: CommandRegistry;
|
|
38
|
+
|
|
39
|
+
can init (cmd_reg: CommandRegistry);
|
|
40
|
+
can do_exit(arg: list) -> bool;
|
|
41
|
+
can default(line: str);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
global cmd_registry = |> CommandRegistry;
|
|
46
|
+
can start_cli;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This is the implementation of the command line interface tool for the
|
|
3
|
+
Jac language. It's built with the Jac language via bootstraping and
|
|
4
|
+
represents the first such production Jac program.
|
|
5
|
+
"""
|
|
6
|
+
import:jac from cli, cmd_registry as cmd_reg;
|
|
7
|
+
|
|
8
|
+
include:jac impl.cmds_impl;
|
|
9
|
+
|
|
10
|
+
@cmd_reg.register
|
|
11
|
+
can load(filename: str);
|
|
12
|
+
|
|
13
|
+
@cmd_reg.register
|
|
14
|
+
can run(filename: str, entrypoint: str, args: list);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""For setuptools to find this dir."""
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Implemenation for Jac's command line interface."""
|
|
2
|
+
|
|
3
|
+
:o:Command:a:init(func: callable) {
|
|
4
|
+
<s>.func = func;
|
|
5
|
+
<s>.sig = func |> inspect.signature;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
:o:Command:a:call(*args: list, **kwargs: dict) {
|
|
9
|
+
return (*args, **kwargs) |> <s>.func;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
:o:CommandRegistry:a:init {
|
|
13
|
+
<s>.registry = {};
|
|
14
|
+
<s>.parser = (prog="CLI") |> argparse.ArgumentParser;
|
|
15
|
+
<s>.sub_parsers =
|
|
16
|
+
(title="commands", dest="command") |> <s>.parser.add_subparsers;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
:o:CommandRegistry:a:register(func: callable) {
|
|
20
|
+
name = func.__name__;
|
|
21
|
+
cmd = func |> Command;
|
|
22
|
+
<s>.registry[name] = cmd;
|
|
23
|
+
cmd_parser = name |> <s>.sub_parsers.add_parser;
|
|
24
|
+
for param_name, param in |> cmd.sig.parameters.items {
|
|
25
|
+
if param_name == "args" {
|
|
26
|
+
('args', nargs=argparse.REMAINDER)
|
|
27
|
+
|> cmd_parser.add_argument;
|
|
28
|
+
}
|
|
29
|
+
elif param.default is param.empty {
|
|
30
|
+
(f"-{param_name[:1]}", f"--{param_name}",
|
|
31
|
+
required=True, type=param.annotation|>eval)
|
|
32
|
+
|> cmd_parser.add_argument;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
(f"-{param_name[:1]}", f"--{param_name}",
|
|
36
|
+
default=param.default, type=param.annotation|>eval)
|
|
37
|
+
|> cmd_parser.add_argument;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return func;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
:o:CommandRegistry:a:get(name: str) -> Command {
|
|
44
|
+
return name |> <s>.registry.get;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
:o:CommandRegistry:a:items -> dict[str, Command] {
|
|
48
|
+
return |> <s>.registry.items;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
:o:CommandShell:a:init (cmd_reg: CommandRegistry) {
|
|
53
|
+
<s>.cmd_reg = cmd_reg;
|
|
54
|
+
<s> |> cmd.Cmd.__init__;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
:o:CommandShell:a:do_exit(arg: list) -> bool {
|
|
58
|
+
return True;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
:o:CommandShell:a:default(line: str) {
|
|
62
|
+
try {
|
|
63
|
+
args = |> line.split |> <s>.cmd_reg.parser.parse_args |> vars;
|
|
64
|
+
command = args["command"] |> <s>.cmd_reg.get;
|
|
65
|
+
if command {
|
|
66
|
+
args.pop("command");
|
|
67
|
+
ret = **args |> command.call;
|
|
68
|
+
if ret {
|
|
69
|
+
ret |> print;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
except Exception as e {
|
|
74
|
+
e |> print;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
:a:start_cli {
|
|
79
|
+
parser = cmd_registry.parser;
|
|
80
|
+
args = |> parser.parse_args;
|
|
81
|
+
command = args.command |> cmd_registry.get;
|
|
82
|
+
if command {
|
|
83
|
+
args = args |> vars;
|
|
84
|
+
"command" |> args.pop;
|
|
85
|
+
ret = **args |> command.call;
|
|
86
|
+
if ret {
|
|
87
|
+
ret |> print;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
shell = |> CommandShell(cmd_registry).cmdloop;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Implementations for the jac command line interface."""
|
|
2
|
+
import:py from os, path;
|
|
3
|
+
|
|
4
|
+
:a:load(filename: str) {
|
|
5
|
+
if filename.endswith(".jac"){
|
|
6
|
+
[base, mod] = path.split(filename);
|
|
7
|
+
base = './' if not base else base;
|
|
8
|
+
mod=mod[:-4];
|
|
9
|
+
__jac_import__(target=mod, base_path=base);
|
|
10
|
+
} else {
|
|
11
|
+
"Not a .jac file." :> print;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
:a:run(filename: str, entrypoint: str, args: list) {
|
|
17
|
+
if filename.endswith(".jac"){
|
|
18
|
+
[base, mod] = path.split(filename);
|
|
19
|
+
base = './' if not base else base;
|
|
20
|
+
mod=mod[:-4];
|
|
21
|
+
mod = __jac_import__(target=mod, base_path=base);
|
|
22
|
+
:> ((mod, entrypoint) :> getattr );
|
|
23
|
+
} else {
|
|
24
|
+
"Not a .jac file." :> print;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""For setuptools to find this dir."""
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Implementation for Jac's Element Abstractions"""
|
|
2
|
+
import:py from jaclang.jac.constant, EdgeDir;
|
|
3
|
+
|
|
4
|
+
:o:Node:a:__call__
|
|
5
|
+
(walk: Walker) {
|
|
6
|
+
if not (walk, Walker) :> isinstance {
|
|
7
|
+
raise ("Argument must be a Walker instance") :> TypeError;
|
|
8
|
+
}
|
|
9
|
+
<self> :> walk;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
:o:Node:a:_jac_connect_node_
|
|
13
|
+
(nd: Node, edg: Edge) -> Node {
|
|
14
|
+
(<self>, nd) :> edg._jac_attach_;
|
|
15
|
+
return <self>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
:o:Node:a:_jac_edges_to_nodes_
|
|
19
|
+
(dir: EdgeDir) -> list[Node] {
|
|
20
|
+
ret_nodes = [];
|
|
21
|
+
if dir in [EdgeDir.OUT, EdgeDir.ANY] {
|
|
22
|
+
for i in <self>._jac_edges_[EdgeDir.OUT] {
|
|
23
|
+
ret_nodes.append(i._jac_target_);
|
|
24
|
+
}
|
|
25
|
+
} elif dir in [EdgeDir.IN, EdgeDir.ANY] {
|
|
26
|
+
for i in <self>._jac_edges_[EdgeDir.IN] {
|
|
27
|
+
ret_nodes.append(i._jac_source_);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
return ret_nodes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
:o:Edge:a:__call__
|
|
35
|
+
(walk: Walker) {
|
|
36
|
+
if not (walk, Walker) :> isinstance {
|
|
37
|
+
raise ("Argument must be a Walker instance") :> TypeError;
|
|
38
|
+
}
|
|
39
|
+
<self>._jac_target_ :> walk;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
:o:Edge:a:_jac_apply_dir_
|
|
43
|
+
(dir: EdgeDir) -> Edge {
|
|
44
|
+
<self>._jac_dir_ = dir;
|
|
45
|
+
return <self>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
:o:Edge:a:_jac_attach_
|
|
49
|
+
(src: Node, trg: Node) -> Edge {
|
|
50
|
+
if <self>._jac_dir_ == EdgeDir.IN {
|
|
51
|
+
<self>._jac_source_ = trg;
|
|
52
|
+
<self>._jac_target_ = src;
|
|
53
|
+
<self> :> src._jac_edges_[EdgeDir.IN].append;
|
|
54
|
+
<self> :> trg._jac_edges_[EdgeDir.OUT].append;
|
|
55
|
+
} else {
|
|
56
|
+
<self>._jac_source_ = src;
|
|
57
|
+
<self>._jac_target_ = trg;
|
|
58
|
+
<self> :> src._jac_edges_[EdgeDir.OUT].append;
|
|
59
|
+
<self> :> trg._jac_edges_[EdgeDir.IN].append;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return <self>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
:o:Walker:a:__call__
|
|
66
|
+
(nd: Node) {
|
|
67
|
+
<self>._jac_path_ = [];
|
|
68
|
+
<self>._jac_next_ = [nd];
|
|
69
|
+
walker_type = <self>.__class__.__name__;
|
|
70
|
+
node_type = nd.__class__.__name__;
|
|
71
|
+
while <self>._jac_next_ :> len {
|
|
72
|
+
nd = 0 :> <self>._jac_next_.pop;
|
|
73
|
+
|
|
74
|
+
for i in nd._jac_ds_entry_funcs {
|
|
75
|
+
if i['func'].__qualname__.split(".")[0] == node_type and
|
|
76
|
+
<self>:>type in i['types'] {
|
|
77
|
+
(nd, <self>) :> i['func'];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for i in <self>._jac_ds_entry_funcs {
|
|
81
|
+
if i['func'].__qualname__.split(".")[0] == walker_type and
|
|
82
|
+
(nd:>type in i['types'] or nd in i['types']) { # if nd==root direct chec
|
|
83
|
+
(<self>, nd) :> i['func'];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for i in <self>._jac_ds_exit_funcs {
|
|
87
|
+
if i['func'].__qualname__.split(".")[0] == walker_type and
|
|
88
|
+
(nd:>type in i['types'] or nd in i['types']) {
|
|
89
|
+
(<self>, nd) :> i['func'];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for i in nd._jac_ds_exit_funcs {
|
|
93
|
+
if i['func'].__qualname__.split(".")[0] == node_type and
|
|
94
|
+
<self>:>type in i['types'] {
|
|
95
|
+
(nd, <self>) :> i['func'];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
nd :> <self>._jac_path_.append;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
:o:Walker:a:_jac_visit_
|
|
103
|
+
(nds: list[Node]|list[Edge]) {
|
|
104
|
+
for i in nds {
|
|
105
|
+
i :> <self>._jac_next_.append;
|
|
106
|
+
}
|
|
107
|
+
return nds :> len;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
:o:Walker:a:_jac_disengage_ {
|
|
111
|
+
<self>._jac_next_ = [];
|
|
112
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Implementation for Jac's Element Abstractions"""
|
|
2
|
+
|
|
3
|
+
:enum:AccessMode {
|
|
4
|
+
READ_ONLY,
|
|
5
|
+
READ_WRITE,
|
|
6
|
+
PRIVATE
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
:object:Element:ability:init
|
|
10
|
+
(_jac_exec_ctx: ExecutionContext) {
|
|
11
|
+
<self>.__jinfo = _jac_exec_ctx :> ExecutionContext;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
:object:Element:ability:_jac_make_public_ro {
|
|
15
|
+
<self>.__jinfo.access_mode = AccessMode.READ_ONLY;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
:object:Element:ability:_jac_make_public_rw {
|
|
19
|
+
<self>.__jinfo.access_mode = AccessMode.READ_WRITE;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
:object:Element:ability:_jac_make_private {
|
|
23
|
+
<self>.__jinfo.access_mode = AccessMode.PRIVATE;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
:object:Element:ability:_jac_is_public_ro -> bool {
|
|
27
|
+
return <self>.__jinfo.access_mode == AccessMode.READ_ONLY;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
:object:Element:ability:_jac_is_public_rw -> bool {
|
|
31
|
+
return <self>.__jinfo.access_mode == AccessMode.READ_WRITE;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
:object:Element:ability:_jac_is_private -> bool {
|
|
35
|
+
return <self>.__jinfo.access_mode == AccessMode.PRIVATE;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
:object:Element:ability:_jac_is_readable
|
|
39
|
+
(caller_id: UUID) -> bool {
|
|
40
|
+
return (
|
|
41
|
+
caller_id == <self>.owner_id
|
|
42
|
+
or |> <self>.is_public_read
|
|
43
|
+
or caller_id in <self>.ro_access
|
|
44
|
+
or caller_id in <self>.rw_access
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
:object:Element:ability:_jac_is_writable
|
|
49
|
+
(caller_id: UUID) -> bool {
|
|
50
|
+
return (
|
|
51
|
+
caller_id == <self>.owner_id
|
|
52
|
+
or |> <self>.is_public_write
|
|
53
|
+
or caller_id in <self>.rw_access
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
:object:Element:ability:_jac_give_access
|
|
58
|
+
(caller_id: UUID, read_write: bool = False) {
|
|
59
|
+
if read_write {
|
|
60
|
+
caller_id |> <self>.rw_access.add;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
caller_id |> add .> ro_access .> <self>;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:object:Element:ability:_jac_revoke_access
|
|
68
|
+
(caller_id: UUID) {
|
|
69
|
+
caller_id |> <self>.ro_access.discard;
|
|
70
|
+
caller_id |> <self>.rw_access.discard;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
:object:Object:ability:_jac_on_entry
|
|
74
|
+
(cls: type, triggers: list) {
|
|
75
|
+
can decorator(func: callable) -> callable {
|
|
76
|
+
cls._jac_ds_entry_funcs.append({'types': triggers, 'func': func});
|
|
77
|
+
can wrapper(*args: list, **kwargs: dict) -> callable {
|
|
78
|
+
return func(*args, **kwargs);
|
|
79
|
+
}
|
|
80
|
+
return wrapper;
|
|
81
|
+
}
|
|
82
|
+
return decorator;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
:object:Object:ability:_jac_on_exit
|
|
86
|
+
(cls: type, triggers: list) {
|
|
87
|
+
can decorator(func: callable) -> callable {
|
|
88
|
+
cls._jac_ds_exit_funcs.append({'types': triggers, 'func': func});
|
|
89
|
+
can wrapper(*args: list, **kwargs: dict) -> callable {
|
|
90
|
+
return func(*args, **kwargs);
|
|
91
|
+
}
|
|
92
|
+
return wrapper;
|
|
93
|
+
}
|
|
94
|
+
return decorator;
|
|
95
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Implementation for Jac's Element Abstractions"""
|
|
2
|
+
import:py from uuid, UUID, uuid4;
|
|
3
|
+
|
|
4
|
+
:object:ExecutionContext:a:init
|
|
5
|
+
(master: UUID, memory: Memory) {
|
|
6
|
+
<self>.master = master;
|
|
7
|
+
<self>.memory = memory;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
:object:ExecutionContext:a:get_root
|
|
11
|
+
() {
|
|
12
|
+
if <self>.master :> type == UUID {
|
|
13
|
+
<self>.master = Master();
|
|
14
|
+
}
|
|
15
|
+
return <self>.master.root_node;
|
|
16
|
+
}
|
|
17
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Implementation for Jac's Element Abstractions"""
|
|
2
|
+
import:py sys;
|
|
3
|
+
|
|
4
|
+
:object:Memory:ability:get_obj
|
|
5
|
+
(caller_id: UUID, item_id: UUID, override: bool = False) -> Element? {
|
|
6
|
+
ret = item_id |> <self>.index.get;
|
|
7
|
+
if override or (ret is not None and caller_id |> ret.__is_readable) {
|
|
8
|
+
return ret;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
:object:Memory:ability:has_obj
|
|
13
|
+
(item_id: UUID) -> bool {
|
|
14
|
+
return item_id in <self>.index;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
:object:Memory:ability:save_obj
|
|
18
|
+
(caller_id: UUID, item: Element) {
|
|
19
|
+
if caller_id |> item.is_writable {
|
|
20
|
+
<self>.index[item.id] = item;
|
|
21
|
+
if item._persist {
|
|
22
|
+
item |> <self>.save_obj_list.add;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
<self>.mem[item.id] = item;
|
|
26
|
+
if item._persist {
|
|
27
|
+
item |> <self>.save_obj_list.add;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
:object:Memory:ability:del_obj
|
|
32
|
+
(caller_id: UUID, item: Element) {
|
|
33
|
+
if caller_id |> item.is_writable {
|
|
34
|
+
<self>.index.pop(item.id);
|
|
35
|
+
if item._persist {
|
|
36
|
+
item |> <self>.save_obj_list.remove;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
:object:Memory:ability:get_object_distribution -> dict {
|
|
42
|
+
dist = {};
|
|
43
|
+
for i in |> <self>.index.keys {
|
|
44
|
+
t = <self>.index[i] |> type;
|
|
45
|
+
if t in dist {
|
|
46
|
+
dist[t] += 1;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
dist[t] = 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return dist;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
:object:Memory:ability:get_mem_size -> float {
|
|
56
|
+
return (<self>.index |> sys.getsizeof) / 1024.0;
|
|
57
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Jac's Key Elemental Abstractions"""
|
|
2
|
+
|
|
3
|
+
import:py from datetime, datetime;
|
|
4
|
+
import:py from uuid, UUID, uuid4;
|
|
5
|
+
import:py from jaclang.jac.constant, EdgeDir;
|
|
6
|
+
|
|
7
|
+
include:jac impl.memory_impl;
|
|
8
|
+
include:jac impl.exec_ctx_impl;
|
|
9
|
+
include:jac impl.element_impl;
|
|
10
|
+
include:jac impl.arch_impl;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
enum AccessMode;
|
|
14
|
+
|
|
15
|
+
object Memory {
|
|
16
|
+
has index: dict[UUID, Element], save_queue: list[Element];
|
|
17
|
+
|
|
18
|
+
#* Main Accessors *#
|
|
19
|
+
can get_obj(caller_id: UUID, item_id: UUID,
|
|
20
|
+
override: bool = False) -> Element?;
|
|
21
|
+
can has_obj(item_id: UUID) -> bool;
|
|
22
|
+
can save_obj(caller_id: UUID, item: Element);
|
|
23
|
+
can del_obj(caller_id: UUID, item: Element);
|
|
24
|
+
|
|
25
|
+
#* Utility Functions *#
|
|
26
|
+
can get_object_distribution -> dict;
|
|
27
|
+
can get_mem_size -> float;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
object ExecutionContext {
|
|
31
|
+
has master: Master,
|
|
32
|
+
memory: Memory;
|
|
33
|
+
|
|
34
|
+
can init(master: UUID, memory: Memory);
|
|
35
|
+
can get_root() -> Node;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
global exec_ctx = ExecutionContext(:>uuid4, Memory());
|
|
39
|
+
|
|
40
|
+
object ElementMetaData {
|
|
41
|
+
has jid: UUID = :>uuid4,
|
|
42
|
+
timestamp: datetime = :>datetime.now,
|
|
43
|
+
persist: bool = False,
|
|
44
|
+
access_mode: AccessMode = AccessMode.PRIVATE,
|
|
45
|
+
rw_access: set = :>set,
|
|
46
|
+
ro_access: set = :>set,
|
|
47
|
+
owner_id: UUID = exec_ctx.master,
|
|
48
|
+
mem: Memory = exec_ctx.memory;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
object Element {
|
|
52
|
+
has _jinfo: ElementMetaData = ElementMetaData();
|
|
53
|
+
|
|
54
|
+
can _jac_make_public_ro;
|
|
55
|
+
can _jac_make_public_rw;
|
|
56
|
+
can _jac_make_private;
|
|
57
|
+
can _jac_is_public_ro -> bool;
|
|
58
|
+
can _jac_is_public_rw -> bool;
|
|
59
|
+
can _jac_is_private -> bool;
|
|
60
|
+
can _jac_is_readable(caller_id: UUID) -> bool;
|
|
61
|
+
can _jac_is_writable(caller_id: UUID) -> bool;
|
|
62
|
+
can _jac_give_access(caller_id: UUID, read_write: bool = False);
|
|
63
|
+
can _jac_revoke_access(caller_id: UUID);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
object Object:Element {
|
|
67
|
+
static has _jac_ds_entry_funcs: list[dict]=[],
|
|
68
|
+
_jac_ds_exit_funcs: list[dict]=[];
|
|
69
|
+
|
|
70
|
+
static can _jac_on_entry(cls: type, triggers: list[type]);
|
|
71
|
+
static can _jac_on_exit(cls: type, triggers: list[type]);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
object Node:Object {
|
|
75
|
+
has _jac_edges_: dict[EdgeDir, list[Edge]]
|
|
76
|
+
= {EdgeDir.IN: [], EdgeDir.OUT: []};
|
|
77
|
+
|
|
78
|
+
can __call__(walk: Walker);
|
|
79
|
+
can _jac_connect_node_(nd: Node, edg: Edge) -> Node;
|
|
80
|
+
can _jac_edges_to_nodes_(dir: EdgeDir) -> list[Node];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
object Edge:Object {
|
|
84
|
+
has _jac_source_: Node?,
|
|
85
|
+
_jac_target_: Node?,
|
|
86
|
+
_jac_dir_: EdgeDir?;
|
|
87
|
+
|
|
88
|
+
can __call__(walk: Walker);
|
|
89
|
+
can _jac_apply_dir_(dir: EdgeDir) -> Edge;
|
|
90
|
+
can _jac_attach_(src: Node, trg: Node) -> Edge;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
object Walker:Object {
|
|
94
|
+
has _jac_path_: list[Node] = [],
|
|
95
|
+
_jac_next_: list[Node] = [];
|
|
96
|
+
|
|
97
|
+
can __call__(nd: Node);
|
|
98
|
+
can _jac_visit_(nds: list[Node]|list[Edge]);
|
|
99
|
+
can _jac_disengage_;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
object Master:Element {
|
|
103
|
+
has root_node: Node = Node();
|
|
104
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Jac compiler tools."""
|