Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
tweaks for importer behavior and bug emerged
Browse files Browse the repository at this point in the history
  • Loading branch information
marsninja committed Nov 17, 2023
1 parent 42fc96c commit 7fddcde
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jaclang/cli/cmds.jac
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import:jac from cli, cmd_registry as cmd_reg;
include:jac cmds_impl;

@cmd_reg.register
can run(filename: str);
can run(filename: str, main: bool = False);

@cmd_reg.register
can enter(filename: str, entrypoint: str, args: list);
Expand Down
8 changes: 6 additions & 2 deletions jaclang/cli/cmds_impl.jac
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import:py from jaclang.jac.constant, Constants as C;

"""Load a .jac file and return the entrypoint function."""
:c:run
(filename: str) {
(filename: str, main: bool = False) {
if filename.endswith(".jac"){
[base, mod] = os.path.split(filename);
base = './' if not base else base;
mod=mod[:-4];
__jac_import__(target=mod, base_path=base, override_name="__main__");
main = False; # TODO: This is a hack due to default bug, fix it.
__jac_import__(
target=mod, base_path=base,
override_name=None # ("__main__" if main else None)
);
} else {
"Not a .jac file." :> print;
}
Expand Down
2 changes: 1 addition & 1 deletion jaclang/jac/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def jac_import(
else:
sys.modules[module_name] = module

module.__name__ = override_name if override_name else module.__name__
exec(codeobj, module.__dict__)
# module.__name__ = override_name if override_name else module.__name__

return module
2 changes: 1 addition & 1 deletion jaclang/jac/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def make_dev() -> None:
parser = jl.Lark_StandAlone(lexer_callbacks={"COMMENT": _comment_callback}) # type: ignore
JacTransformer = jl.Transformer[jl.Tree[str], ast.AstNode]

class TreeToAST(JacTransformer): # type: ignore
class TreeToAST(JacTransformer):
"""Transform parse tree to AST."""

def __init__(self, parser: JacParser, *args: bool, **kwargs: bool) -> None:
Expand Down

0 comments on commit 7fddcde

Please sign in to comment.