Skip to content

Commit 6292e84

Browse files
authored
Dump generated basilisp.core Python (#456)
Easy `make` target to dump generated Python for `basilisp.core`. Also, munge `..` macro name using a kind-of-dirty change to `basilisp.lang.util.munge`.
1 parent e596ef9 commit 6292e84

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ ENV/
6565
# Misc
6666
TODO
6767
lintout.txt
68+
lispcore.py
6869
.idea/
6970
.envrc

.prospector.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ignore-paths:
1111
- .tox
1212
- build
1313
- dist
14+
- lispcore.py
1415
- tests
1516

1617
pep8:

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ format:
2222
@pipenv run black .
2323

2424

25+
lispcore.py:
26+
@BASILISP_DO_NOT_CACHE_NAMESPACES=true \
27+
pipenv run basilisp run -c \
28+
'(with [f (python/open "lispcore.py" "w")] (.write f basilisp.core/*generated-python*))'
29+
@pipenv run black lispcore.py
30+
31+
32+
.PHONY: clean
33+
clean:
34+
@rm -rf ./lispcore.py
35+
36+
2537
.PHONY: repl
2638
repl:
2739
@BASILISP_USE_DEV_LOGGER=true pipenv run basilisp repl

src/basilisp/importer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ def _get_basilisp_bytecode(
6161
f"expected {MAGIC_NUMBER!r}"
6262
)
6363
logger.debug(message)
64-
raise ImportError(message, **exc_details) # type: ignore
64+
raise ImportError(message, **exc_details)
6565
elif len(raw_timestamp) != 4:
6666
message = f"Reached EOF while reading timestamp in {fullname}"
6767
logger.debug(message)
6868
raise EOFError(message)
6969
elif _r_long(raw_timestamp) != mtime:
7070
message = f"Non-matching timestamp ({_r_long(raw_timestamp)}) in {fullname} bytecode cache; expected {mtime}"
7171
logger.debug(message)
72-
raise ImportError(message, **exc_details) # type: ignore
72+
raise ImportError(message, **exc_details)
7373
elif len(raw_size) != 4:
7474
message = f"Reached EOF while reading size of source in {fullname}"
7575
logger.debug(message)
7676
raise EOFError(message)
7777
elif _r_long(raw_size) != source_size:
7878
message = f"Non-matching filesize ({_r_long(raw_size)}) in {fullname} bytecode cache; expected {source_size}"
7979
logger.debug(message)
80-
raise ImportError(message, **exc_details) # type: ignore
80+
raise ImportError(message, **exc_details)
8181

8282
return marshal.loads(cache_data[12:])
8383

src/basilisp/lang/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
import basilisp.lang.atom as atom
1313

14+
_DOUBLE_DOT = ".."
15+
_DOUBLE_DOT_REPLACEMENT = "__DOT_DOT__"
16+
1417
_MUNGE_REPLACEMENTS = {
1518
"+": "__PLUS__",
1619
"-": "_",
@@ -24,6 +27,7 @@
2427
"\\": "__IDIV__",
2528
"&": "__AMP__",
2629
"$": "__DOLLAR__",
30+
"%": "__PCT__",
2731
}
2832
_MUNGE_TRANSLATE_TABLE = str.maketrans(_MUNGE_REPLACEMENTS)
2933

@@ -37,6 +41,9 @@ def munge(s: str, allow_builtins: bool = False) -> str:
3741
with valid replacement strings."""
3842
new_s = s.translate(_MUNGE_TRANSLATE_TABLE)
3943

44+
if new_s == _DOUBLE_DOT:
45+
return _DOUBLE_DOT_REPLACEMENT
46+
4047
if keyword.iskeyword(new_s):
4148
return f"{new_s}_"
4249

0 commit comments

Comments
 (0)