json-model-compiler 2.0.57__tar.gz → 2.0.58__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.
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/.github/workflows/docs.yml +8 -1
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/BACKLOG.md +6 -15
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/BENCH.md +2 -2
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/HOWTO.md +2 -3
- {json_model_compiler-2.0.57/json_model_compiler.egg-info → json_model_compiler-2.0.58}/PKG-INFO +6 -6
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/README.md +5 -5
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/VERSION.md +37 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/about.sh +14 -10
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/bench.sh +5 -2
- json_model_compiler-2.0.58/json_model/data/VERSION +1 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/jmc.pod +1 -16
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/irep.py +146 -53
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/python.py +12 -3
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/Changes +8 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/lib/JSON/JsonModel.pm +3 -3
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/script.py +34 -4
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/xstatic.py +2 -1
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58/json_model_compiler.egg-info}/PKG-INFO +6 -6
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/pyproject.toml +14 -0
- json_model_compiler-2.0.57/json_model/data/VERSION +0 -1
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/.github/workflows/sanity.yml +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/.gitignore +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/.gitmodules +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/API.md +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/DESIGN.md +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/DEV.md +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/DOC.md +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/INTEGRATION.md +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/MANIFEST.in +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/Makefile +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/PUBS.md +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/SPEC.md +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/TUTO.md +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/README.md +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/__init__.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/analyze.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/clang.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/convert.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/clang_entry.c +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/clang_free.c +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/clang_init.c +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/clang_pcre2_fun.c +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/clang_re2_fun.c +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/java_free.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/java_init.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/javascript_exe.js +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/javascript_foot.js +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/javascript_free.js +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/javascript_head.js +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/javascript_init.js +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/javascript_main.js +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/perl_entry.pl +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/perl_exe.pl +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/perl_free.pl +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/perl_init.pl +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/perl_main.pl +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/perl_pkg.pl +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/plpgsql_entry.sql +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/python_entry.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/python_exe.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/python_free.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/python_init.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/data/python_main.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/export.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/java.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/javascript.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/language.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/model.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/mtypes.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/objops.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/optim.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/perl.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/plpgsql.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/predefs.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/recurse.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/regex.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/resolver.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/Makefile +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/__init__.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/c/Makefile +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/c/json-model.c +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/c/json-model.h +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/c/main.c +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/.gitignore +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/Makefile +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/README.md +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/env.sh +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/json_model/Checker.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/json_model/GSON.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/json_model/JSON.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/json_model/JSONP.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/json_model/Jackson.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/json_model/Main.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/json_model/ModelChecker.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/json_model/Path.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/json_model/Report.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/json_model/Runtime.java +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/java/pom.xml +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/js/README.md +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/js/index.js +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/js/main.js +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/js/package.json +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/.gitignore +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/LICENSE +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/MANIFEST +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/Makefile.PL +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/README +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/env.sh +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/ignore.txt +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/t/00-load.t +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/t/manifest.t +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/t/pod-coverage.t +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/t/pod.t +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/pl/xt/boilerplate.t +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/sql/META.json +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/sql/Makefile +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/sql/json_model--2.0.sql +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/sql/json_model.control +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/support.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/runtime/types.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/submodel.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/ts_export.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/url_cache.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model/utils.py +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model_compiler.egg-info/SOURCES.txt +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model_compiler.egg-info/dependency_links.txt +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model_compiler.egg-info/entry_points.txt +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model_compiler.egg-info/not-zip-safe +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model_compiler.egg-info/requires.txt +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/json_model_compiler.egg-info/top_level.txt +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/package.json +0 -0
- {json_model_compiler-2.0.57 → json_model_compiler-2.0.58}/setup.cfg +0 -0
|
@@ -14,8 +14,12 @@ jobs:
|
|
|
14
14
|
- uses: actions/checkout@v7
|
|
15
15
|
with:
|
|
16
16
|
submodules: true # for JSTS sources
|
|
17
|
+
fetch-depth: 30
|
|
18
|
+
fetch-tags: true
|
|
17
19
|
- name: Install dependencies
|
|
18
|
-
run: apt install cloc make
|
|
20
|
+
run: sudo apt install cloc make libpod-markdown-perl
|
|
21
|
+
- name: Update docsify base path for github.io
|
|
22
|
+
run: sed -i -e 's,https://json-model.org/,https://clairey-zx81.github.io/json-model/,' site/index.html
|
|
19
23
|
- name: Build site
|
|
20
24
|
run: make _site
|
|
21
25
|
- name: Upload documentation artifact
|
|
@@ -23,6 +27,9 @@ jobs:
|
|
|
23
27
|
uses: actions/upload-pages-artifact@v5
|
|
24
28
|
# with: path: _site
|
|
25
29
|
deploy:
|
|
30
|
+
permissions:
|
|
31
|
+
id-token: write
|
|
32
|
+
pages: write
|
|
26
33
|
environment:
|
|
27
34
|
name: github-pages
|
|
28
35
|
url: ${{ steps.deployment.outputs.page_url }}
|
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
# Backlog
|
|
1
|
+
# Backlog
|
|
2
2
|
|
|
3
3
|
## Current Tasks
|
|
4
4
|
|
|
5
|
-
- [ ]
|
|
6
|
-
- [ ] docker: install missing `Algorithm::LUHN` for perl JSB
|
|
5
|
+
- [ ] front: merge many internal options to trigrams
|
|
7
6
|
- [ ] bench: case failures handling needs some fixing
|
|
8
|
-
- [ ] tests: allow to skip some tests with make, depending on available runtimes
|
|
9
|
-
- [ ] tests: automate bench launch with a cron job?
|
|
10
7
|
- [ ] tests: check more bad urls (eg bad %-escape)
|
|
11
8
|
- [ ] tests: check pydantic generated classes
|
|
9
|
+
- [ ] tests: run dyn per model instead of per-dir
|
|
10
|
+
- [ ] tests: run language per model instead of per-dir
|
|
12
11
|
- [ ] static: use combined type test and value extraction when available?
|
|
13
|
-
- [ ] irep: cleanup `propesc2.c` (and others) variable res set but not used
|
|
14
12
|
- [ ] c-backend: factor out str extraction in or-list in more cases
|
|
15
13
|
- [ ] export: generate a [katydid](https://katydid.github.io/) expression, for a compatible subset
|
|
16
14
|
- [ ] static: recursive multi-discriminator hierarchisation? See UI5.
|
|
17
15
|
- [ ] static: factor out common checks on `&` with shared constraints?
|
|
16
|
+
- [ ] static: check for common object part?
|
|
18
17
|
- [ ] front: generate valid minimal, maximal and random values from a model
|
|
19
18
|
- [ ] front: generate invalid minimal values from a model
|
|
20
19
|
- [ ] optim: simplify some '!=' cases
|
|
21
20
|
- [ ] spec: allow to _remove_ definitions, eg `{ "$stuff": {"/": "$foo"}}`
|
|
22
|
-
- [ ] static: check for common object part
|
|
23
21
|
- [ ] perf: add another loop over performance collection?
|
|
24
|
-
- [ ] models: update ir model wrt recent changes
|
|
25
|
-
- [ ] tests: add test with ir model? on the fly?
|
|
26
|
-
- [ ] front: handle yaml values as well as json
|
|
27
22
|
- [ ] perf: drop and/or merge identical results when comparing
|
|
28
23
|
- [ ] backend: check `mv-34/mu` test case which may require some normalization
|
|
29
24
|
- [ ] runtime: count graphemes instead of characters? for Java, see `java.text.BreakIterator`
|
|
30
25
|
- [ ] pr: improve JSTS test results alignment between all backends (wip)
|
|
31
|
-
- [ ] front: add argument groups
|
|
32
|
-
- [ ] front: merge many internal options to trigrams
|
|
33
26
|
- [ ] perf: add stddev performance computation
|
|
34
27
|
- [ ] perf: improve resilience to bad overhead estimation
|
|
35
28
|
- [ ] perf: collect JSON parse times for comparison with validation times
|
|
@@ -55,9 +48,7 @@
|
|
|
55
48
|
- [ ] optim: remove props which match the default, in some cases?
|
|
56
49
|
- [ ] optim: regex list of words to enum?
|
|
57
50
|
- [ ] static: improve startswith pattern recognition `/^xyz.*/`
|
|
58
|
-
- [ ]
|
|
59
|
-
- [ ] test: add test categories (mark?)
|
|
60
|
-
- [ ] test: allow to skip some tests by category
|
|
51
|
+
- [ ] tests: fast mode which does not execute if source has not changed
|
|
61
52
|
- [ ] predefs: extension for _uri reference_, _iri reference_, _uri template_
|
|
62
53
|
- [ ] predefs: _url_ vs _uri_ vs _iri_
|
|
63
54
|
- [ ] predefs: improve `$URI` and `$URL`
|
|
@@ -17,8 +17,8 @@ than Blaze on average to validate JSON values in these artifacts.
|
|
|
17
17
|
|
|
18
18
|
BENCHES
|
|
19
19
|
|
|
20
|
-
Options: _content_ validate string contents (format/predef),
|
|
21
|
-
|
|
20
|
+
Options: _content_ validate string contents (format/predef), _id_ use native models when available,
|
|
21
|
+
_fix_ use improved models (eg include some bug fixes, or more precise models).
|
|
22
22
|
|
|
23
23
|
## Benchmarking Script
|
|
24
24
|
|
|
@@ -30,11 +30,10 @@ The `jmc` command can be install in a Python virtual environment from
|
|
|
30
30
|
[convenient wrapper](https://github.com/clairey-zx81/json-model/blob/main/container/jmc):
|
|
31
31
|
|
|
32
32
|
```sh
|
|
33
|
-
# podman
|
|
34
|
-
|
|
33
|
+
export POD="docker" # or "podman"
|
|
34
|
+
$POD pull docker.io/zx80/jmc
|
|
35
35
|
curl -o ./jmc https://raw.githubusercontent.com/clairey-zx81/json-model/refs/heads/main/container/jmc
|
|
36
36
|
chmod a+rx ./jmc
|
|
37
|
-
export POD="docker" # or "podman"
|
|
38
37
|
./jmc --version
|
|
39
38
|
./jmc --man
|
|
40
39
|
```
|
{json_model_compiler-2.0.57/json_model_compiler.egg-info → json_model_compiler-2.0.58}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: json_model_compiler
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.58
|
|
4
4
|
Summary: JSON Model Tools
|
|
5
5
|
Author: Fabien Coelho, Claire Yannou-Medrala
|
|
6
6
|
License-Expression: CC0-1.0
|
|
@@ -39,7 +39,7 @@ This reference implementation allows to generate code in Python, C, JavaScript,
|
|
|
39
39
|
PL/pgSQL, Perl and Java for checking a JSON value against a JSON model,
|
|
40
40
|
and to export models to JSON Schema or Pydantic.
|
|
41
41
|
|
|
42
|
-
It is dedicated to the
|
|
42
|
+
It is dedicated to the [Public Domain](https://creativecommons.org/public-domain/).
|
|
43
43
|
|
|
44
44
|
## JMC Command
|
|
45
45
|
|
|
@@ -160,16 +160,16 @@ See the [benchmark page](BENCH.md) for artifacts which compare various
|
|
|
160
160
|
[JSON Model Compiler](https://github.com/clairey-zx81/json-model) runs (C, JS, Java, Python) with
|
|
161
161
|
[Sourcemeta Blaze CLI](https://github.com/sourcemeta/jsonschema) as a baseline using test cases
|
|
162
162
|
from [JSON Schema Benchmark](https://github.com/sourcemeta-research/jsonschema-benchmark).
|
|
163
|
-
Overall, JMC-C implementation is faster than Blaze C++.
|
|
164
|
-
Moreover, JMC-
|
|
165
|
-
|
|
163
|
+
Overall, JMC-C implementation is about twice faster than Blaze C++.
|
|
164
|
+
Moreover, JMC-Java/GSON native implementations are only about 50% slower than Blaze C++,
|
|
165
|
+
and JMC-JS 200% slower, which given the intrinsic language capabilities is quite honorable.
|
|
166
166
|
|
|
167
167
|
## More Information
|
|
168
168
|
|
|
169
169
|
See the [JSON Model website](https://json-model.org),
|
|
170
170
|
which among many resources,
|
|
171
171
|
includes a [tutorial](TUTO.md) for a hands-on overview of JSON Model,
|
|
172
|
-
and links to [research papers](
|
|
172
|
+
and links to [research papers](PUBS.md) for explanations about the design.
|
|
173
173
|
|
|
174
174
|
## JSON Model Distribution
|
|
175
175
|
|
|
@@ -6,7 +6,7 @@ This reference implementation allows to generate code in Python, C, JavaScript,
|
|
|
6
6
|
PL/pgSQL, Perl and Java for checking a JSON value against a JSON model,
|
|
7
7
|
and to export models to JSON Schema or Pydantic.
|
|
8
8
|
|
|
9
|
-
It is dedicated to the
|
|
9
|
+
It is dedicated to the [Public Domain](https://creativecommons.org/public-domain/).
|
|
10
10
|
|
|
11
11
|
## JMC Command
|
|
12
12
|
|
|
@@ -127,16 +127,16 @@ See the [benchmark page](BENCH.md) for artifacts which compare various
|
|
|
127
127
|
[JSON Model Compiler](https://github.com/clairey-zx81/json-model) runs (C, JS, Java, Python) with
|
|
128
128
|
[Sourcemeta Blaze CLI](https://github.com/sourcemeta/jsonschema) as a baseline using test cases
|
|
129
129
|
from [JSON Schema Benchmark](https://github.com/sourcemeta-research/jsonschema-benchmark).
|
|
130
|
-
Overall, JMC-C implementation is faster than Blaze C++.
|
|
131
|
-
Moreover, JMC-
|
|
132
|
-
|
|
130
|
+
Overall, JMC-C implementation is about twice faster than Blaze C++.
|
|
131
|
+
Moreover, JMC-Java/GSON native implementations are only about 50% slower than Blaze C++,
|
|
132
|
+
and JMC-JS 200% slower, which given the intrinsic language capabilities is quite honorable.
|
|
133
133
|
|
|
134
134
|
## More Information
|
|
135
135
|
|
|
136
136
|
See the [JSON Model website](https://json-model.org),
|
|
137
137
|
which among many resources,
|
|
138
138
|
includes a [tutorial](TUTO.md) for a hands-on overview of JSON Model,
|
|
139
|
-
and links to [research papers](
|
|
139
|
+
and links to [research papers](PUBS.md) for explanations about the design.
|
|
140
140
|
|
|
141
141
|
## JSON Model Distribution
|
|
142
142
|
|
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# JSON Model Compiler Versions
|
|
2
2
|
|
|
3
|
+
## 2.0.58 on 2026-08-24
|
|
4
|
+
|
|
5
|
+
- pr: improve bench script
|
|
6
|
+
- pr: test push post on github.io
|
|
7
|
+
- pr: switch cristalina to post after release
|
|
8
|
+
- bench: fix report nl before per-case performance table
|
|
9
|
+
- pr: ensure accuracy of version on about page
|
|
10
|
+
- irep: cleanup bool variable set but not used
|
|
11
|
+
- irep: move mif2if earlier, rework IR optimizations
|
|
12
|
+
- ci: tweak fetch depth to help docs version computation
|
|
13
|
+
- tests: add c/clean.c targets
|
|
14
|
+
- static: and list checks should always be likely
|
|
15
|
+
- tests: add missing java and pl language tests
|
|
16
|
+
- docker: install missing `Algorithm::LUHN` for perl JSB
|
|
17
|
+
- pr: better bench and about generated pages
|
|
18
|
+
- tests: ~allow to skip some tests with make, depending on available runtimes~
|
|
19
|
+
- tests: provide convenient targets for all tasks
|
|
20
|
+
- tests: display number of assertions checked
|
|
21
|
+
- front: add argument groups
|
|
22
|
+
- front: handle yaml values as well as json
|
|
23
|
+
- tests: add test markers for C, Java, JS, TS, Python, Perl, IR, PL/pgSQL, Schemas
|
|
24
|
+
- tests: allow to skip some tests by category (`not some-mark`)
|
|
25
|
+
- front: shorten jmc pod synopsis
|
|
26
|
+
- pr: configure explicit docsify base path
|
|
27
|
+
- pr: switch to docsify@5
|
|
28
|
+
- pr: improve some pages
|
|
29
|
+
- bench: improve standard report to match available data
|
|
30
|
+
- pl-backend: send perf to stderr as others
|
|
31
|
+
- pr: add typescript prettyprint
|
|
32
|
+
- irep: do not generate empty loops
|
|
33
|
+
- python: do not generate empty loops
|
|
34
|
+
- bench: fix number of iterations for python and perl under cap
|
|
35
|
+
- bench: run and report with java GSON only
|
|
36
|
+
- bench: ~run and report with perl?~ not interesting for now (x 200.0)
|
|
37
|
+
- tests: ~split some directories?~ no, use per-model
|
|
38
|
+
- tests: run values per model instead of per-dir
|
|
39
|
+
|
|
3
40
|
## 2.0.57 on 2026-08-18
|
|
4
41
|
|
|
5
42
|
- bench: improve reporting text
|
|
@@ -5,20 +5,21 @@
|
|
|
5
5
|
|
|
6
6
|
echo "Generating ABOUT.md page…" >&2
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
git_hash=$(git show --pretty=format:"%h on %cs" --no-patch)
|
|
9
9
|
|
|
10
10
|
if type jmc > /dev/null ; then
|
|
11
11
|
version=$(jmc --version)
|
|
12
|
-
git_version=$
|
|
12
|
+
git_version=$git_hash
|
|
13
13
|
else
|
|
14
14
|
read version < json_model/data/VERSION
|
|
15
|
-
git_version="$(git rev-parse --abbrev-ref HEAD) $
|
|
15
|
+
git_version="$(git rev-parse --abbrev-ref HEAD) $git_hash"
|
|
16
16
|
fi
|
|
17
17
|
|
|
18
18
|
cat <<EOF
|
|
19
19
|
# About JSON Model
|
|
20
20
|
|
|
21
|
-
JSON Model is an on-going [research project](PUBS.md)
|
|
21
|
+
JSON Model is an on-going [research project](PUBS.md)
|
|
22
|
+
dedicated to the [Public Domain](https://creativecommons.org/public-domain/).
|
|
22
23
|
|
|
23
24
|
The following line and file counts about version **$version** (\`$git_version\`) show
|
|
24
25
|
that the compiler, code generator and runtimes are quite small, but still heavily tested
|
|
@@ -151,16 +152,19 @@ Test models cover the various features of JSON Model.
|
|
|
151
152
|
Each model is tested for each target language (Python, C, JavaScript, PL/pgSQL, Perl, Java)
|
|
152
153
|
on a set of test vectors.
|
|
153
154
|
|
|
154
|
-
-
|
|
155
|
-
-
|
|
156
|
-
-
|
|
157
|
-
-
|
|
155
|
+
- Number of test JSON models: _${n_models}_
|
|
156
|
+
- Total test JSON model locs: _${model_locs}_
|
|
157
|
+
- Number of test vector JSON values: _${n_values}_
|
|
158
|
+
- All tested JSON values (including models, generated schemas and IR, and test suite schemas): _${all_values}_
|
|
159
|
+
|
|
160
|
+
Over _150,000_ checks are performed when running non-regression tests:
|
|
161
|
+
generated files, values validated in various languages…
|
|
158
162
|
|
|
159
163
|
[Example models](https://json-model.org/MODELS) cover typical use cases and demonstrate
|
|
160
164
|
JSON Model power and ease of expression.
|
|
161
165
|
|
|
162
|
-
-
|
|
163
|
-
-
|
|
166
|
+
- Number of example models: _${n_eg_models}_
|
|
167
|
+
- Total example model locs: _${eg_models_locs}_
|
|
164
168
|
|
|
165
169
|
## Documentation
|
|
166
170
|
|
|
@@ -25,9 +25,12 @@ for artifact in $(ls site/benchmarks/*.md | sort -r) ; do
|
|
|
25
25
|
sbc=$(get_version jsonschema-cli $artifact)
|
|
26
26
|
message=""
|
|
27
27
|
[ "$(grep 'content:.*yes' $artifact)" ] && message+="content" || message+="no content"
|
|
28
|
-
[ "$(grep 'JSU_OPT.*--no-id' $artifact)" ] && message+=", no id"
|
|
28
|
+
[ "$(grep 'JSU_OPT.*--no-id' $artifact)" ] && message+=", no id" || message+=", id"
|
|
29
29
|
[ "$(grep 'fix:.*yes' $artifact)" ] && message+=", fix" || message+=", no fix"
|
|
30
|
-
echo "- Artifact [$name]($link) [JMC $jmc]($PYPI/json-model-compiler/$jmc/)
|
|
30
|
+
echo "- Artifact [$name]($link) using [JMC $jmc]($PYPI/json-model-compiler/$jmc/), "
|
|
31
|
+
echo " [JSU $jsu]($PYPI/json-schema-utils/$jsu/) and "
|
|
32
|
+
echo " [SBC $sbc](https://github.com/sourcemeta/jsonschema/releases/tag/v$sbc), "
|
|
33
|
+
echo " $message."
|
|
31
34
|
done
|
|
32
35
|
|
|
33
36
|
sed -ne '/BENCHES/,$p' < BENCH.md | grep -v '^BENCHES$'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.0.58
|
|
@@ -8,22 +8,7 @@ B<jmc> - JSON Model Compiler
|
|
|
8
8
|
|
|
9
9
|
=head1 SYNOPSIS
|
|
10
10
|
|
|
11
|
-
jmc [
|
|
12
|
-
[--maps MAPS] [--auto] [--entry ENTRY] [--regex-engine {re,re2,pcre2}] [--mark COMMENT]
|
|
13
|
-
[--allow-duplicates] [-[-no]-extend] [--loose-int] [--strict-int] [--loose-float]
|
|
14
|
-
[--strict-float] [--loose-number] [--strict-number] [--loose] [--check]
|
|
15
|
-
[-[-no]-single-line-regex] [-[-no]-optimize] [-[-no]-reporting] [-[-no]-inline]
|
|
16
|
-
[--format {json,yaml,py,c,js,plpgsql,pl,java,ts}] [-[-no]-sort] [--indent INDENT]
|
|
17
|
-
[--gen {exec,module,code,none} | --executable | --module | --code | --no-gen]
|
|
18
|
-
[--cc CC] [--cflags CFLAGS] [--cppflags CPPFLAGS] [--ldflags LDFLAGS] [-[-no]-precompiled]
|
|
19
|
-
[--include [INCLUDE ...]] [--library [LIBRARY ...]] [--define [DEFINE ...]]
|
|
20
|
-
[--javac JAVAC] [--jflags JFLAGS] [-[-no]-schema-version] [--short-version]
|
|
21
|
-
[--name NAME] [-[-no]-report] [--none] [--true] [--false] [--test-vector]
|
|
22
|
-
[--map-threshold THRESHOLD] [--map-share] [-[-no]-strcmp-optimize] [--byte-order (le|be)]
|
|
23
|
-
[--max-strcmp-cset SIZE] [-[-no]-unique-optimize] [-[-no]-regex-optimize]
|
|
24
|
-
[--may-must-open-threshold THRESHOLD] [--must-only-threshold THRESHOLD] [-[-no]-call-shortcut]
|
|
25
|
-
[--partition-threshold THRESHOLD] [--or-must-prop THRESHOLD] [--array-unrolling-size=SIZE]
|
|
26
|
-
[-[-no]-sort-must] [-[-no]-sort-may] [-[-no]-predef] [--no-opt OPTIM] [-[-no]-regex-pattern]
|
|
11
|
+
jmc [--help] [--version] [--man] [--debug] [--verbose] [--quiet] [plenty other options]
|
|
27
12
|
[--op {P,U,J,N,E,C} | --preproc | --dump | --jdump | --nope | --export | --compile]
|
|
28
13
|
[--output OUTPUT] (--model MODEL | MODEL) [VALUES ...]
|
|
29
14
|
|
|
@@ -12,42 +12,15 @@ from .language import JsonExpr, BoolExpr, IntExpr, StrExpr, PathExpr, NumExpr, E
|
|
|
12
12
|
from .mtypes import Jsonable, JsonScalar, Number, TestHint, Conditionals
|
|
13
13
|
from .runtime import Path, Report
|
|
14
14
|
|
|
15
|
-
def _j(o: str, **params) -> str:
|
|
16
|
-
"""Generate a JSON operation."""
|
|
17
|
-
return json.dumps({"o": o, **params})
|
|
18
|
-
|
|
19
|
-
def _l(s: str) -> Jsonable:
|
|
20
|
-
"""Parse a JSON operation or something else."""
|
|
21
|
-
# FIXME true/false/null handling is adhoc and can be wrong
|
|
22
|
-
try:
|
|
23
|
-
if (isinstance(s, str) and s and
|
|
24
|
-
(s[0] in '{["0123456789-' or s in ("null", "true", "false"))):
|
|
25
|
-
return json.loads(s)
|
|
26
|
-
else:
|
|
27
|
-
return s
|
|
28
|
-
except Exception:
|
|
29
|
-
# FIXME triggered on strange property names, eg "[a-z]"
|
|
30
|
-
log.warning(f"shamefully ignoring json oops on {s}")
|
|
31
|
-
return s
|
|
32
|
-
|
|
33
|
-
def _u(block: Block) -> list[Jsonable]:
|
|
34
|
-
"""Parse a JSON code block."""
|
|
35
|
-
return [ _l(i) for i in filter(lambda s: s is not None and s != "", block) ]
|
|
36
|
-
|
|
37
|
-
# constant map to json and reverse
|
|
38
|
-
def _cmap2json(mapping: dict[JsonScalar, str]) -> list[tuple[JsonScalar, str]]:
|
|
39
|
-
return [ ( c, s ) for c, s in mapping.items() ]
|
|
40
|
-
|
|
41
|
-
def _json2cmap(mapping: list[tuple[JsonScalar, str]]) -> dict[JsonScalar, str]:
|
|
42
|
-
return { c: s for c, s in mapping }
|
|
43
|
-
|
|
44
|
-
|
|
45
15
|
# compute RW effects on boolean variables
|
|
46
16
|
type Sequence = list[Jsonable]
|
|
47
17
|
# read, write, true, false
|
|
48
18
|
type Effect = tuple[set[str], set[str], dict[str, bool]]
|
|
49
19
|
type Effects = list[Effect]
|
|
50
20
|
|
|
21
|
+
#
|
|
22
|
+
# IR analysis and optimizations
|
|
23
|
+
#
|
|
51
24
|
|
|
52
25
|
# NOTE there are quite a few implicit assumptions:
|
|
53
26
|
# - variables names are used once, without aliases or shadowing
|
|
@@ -271,7 +244,7 @@ def _simpleBoolAssign(op: Jsonable, reporting: bool = True) -> bool:
|
|
|
271
244
|
op["val"] = cond
|
|
272
245
|
elif vt is False and vf is True:
|
|
273
246
|
# C ? F : T -> !C
|
|
274
|
-
op["val"] =
|
|
247
|
+
op["val"] = negate(cond)
|
|
275
248
|
elif vf is False:
|
|
276
249
|
# C ? E : F -> C && E
|
|
277
250
|
op["val"] = {"o": "&", "exprs": [ cond, tbv["val"] ]}
|
|
@@ -280,11 +253,11 @@ def _simpleBoolAssign(op: Jsonable, reporting: bool = True) -> bool:
|
|
|
280
253
|
op["val"] = {"o": "|", "exprs": [ cond, fbv["val"] ]}
|
|
281
254
|
elif vf is True:
|
|
282
255
|
# C ? E : T -> !C || E
|
|
283
|
-
op["val"] = {"o": "|", "exprs": [
|
|
256
|
+
op["val"] = {"o": "|", "exprs": [ negate(cond), tbv["val"] ]}
|
|
284
257
|
else:
|
|
285
258
|
assert vt is False
|
|
286
259
|
# C ? F : E -> !C && E
|
|
287
|
-
op["val"] = {"o": "&", "exprs": [
|
|
260
|
+
op["val"] = {"o": "&", "exprs": [ negate(cond), fbv["val"] ]}
|
|
288
261
|
return True
|
|
289
262
|
return False
|
|
290
263
|
|
|
@@ -299,7 +272,7 @@ CMP_INV = {
|
|
|
299
272
|
"<=": ">",
|
|
300
273
|
}
|
|
301
274
|
|
|
302
|
-
def
|
|
275
|
+
def negate(op: Jsonable) -> Jsonable:
|
|
303
276
|
"""Invert boolean expression."""
|
|
304
277
|
if isinstance(op, dict) and "o" in op:
|
|
305
278
|
if op["o"] in ("sc", "nc"):
|
|
@@ -348,7 +321,7 @@ def bvar_uses(op: Jsonable, var: str) -> int:
|
|
|
348
321
|
)) +
|
|
349
322
|
bvar_uses(op["false"], var)
|
|
350
323
|
)
|
|
351
|
-
case "aL"|"oL"|"iL":
|
|
324
|
+
case "aL"|"oL"|"iL"|"sfu":
|
|
352
325
|
return bvar_uses(op["body"], var)
|
|
353
326
|
case "seq":
|
|
354
327
|
return bvar_uses(op["seq"], var)
|
|
@@ -379,6 +352,7 @@ def bvar_subs(op: Jsonable, var: str, val: Jsonable) -> Jsonable:
|
|
|
379
352
|
|
|
380
353
|
def bvar_is_used(op: Jsonable, var: str) -> bool:
|
|
381
354
|
"""Whether boolean variable is used in boolean expression."""
|
|
355
|
+
# log.warning(f"used: var={var} op={op}")
|
|
382
356
|
return bvar_uses(op, var) != 0
|
|
383
357
|
|
|
384
358
|
# FIXME full simplification should require several passes
|
|
@@ -587,13 +561,13 @@ def _optimSeq(seq: Sequence, bool_vars: set[str], reporting: bool) -> Effect:
|
|
|
587
561
|
else:
|
|
588
562
|
if _isOp(op["res"], "cst"):
|
|
589
563
|
if op["res"]["c"]:
|
|
590
|
-
newop = {"o": "ret", "res":
|
|
564
|
+
newop = {"o": "ret", "res": negate(ifop["cond"])}
|
|
591
565
|
else:
|
|
592
566
|
newop = {"o": "ret", "res": {"o": "cst", "c": False}}
|
|
593
567
|
else:
|
|
594
568
|
newop = {
|
|
595
569
|
"o": "ret",
|
|
596
|
-
"res": {"o": "&", "exprs": [
|
|
570
|
+
"res": {"o": "&", "exprs": [negate(ifop["cond"]), op["res"]]}
|
|
597
571
|
}
|
|
598
572
|
# set return on latter instruction
|
|
599
573
|
ifop.clear()
|
|
@@ -813,6 +787,9 @@ def _goIR(code: Jsonable, path: Path) -> bool:
|
|
|
813
787
|
def _goStructIR(code: Jsonable, path: Path) -> bool:
|
|
814
788
|
return isinstance(code, (dict, list))
|
|
815
789
|
|
|
790
|
+
def _nopeIR(code: Jsonable, path: Path) -> Jsonable:
|
|
791
|
+
return code
|
|
792
|
+
|
|
816
793
|
def _recIR(code: Jsonable, path: Path,
|
|
817
794
|
flt: Callable[[Jsonable, Path], bool],
|
|
818
795
|
rwt: Callable[[Jsonable, Path], Jsonable]) -> Jsonable:
|
|
@@ -1045,6 +1022,8 @@ def elimDeadCode(code: Jsonable, reporting: bool) -> int:
|
|
|
1045
1022
|
# return comments and return
|
|
1046
1023
|
changes += 1
|
|
1047
1024
|
return list(filter(lambda o: _isOps(o, {"co", "ret", "seq"}), code))
|
|
1025
|
+
elif _isOps(code, {"oL", "aL", "iL"}) and _noOps(code["body"], reporting):
|
|
1026
|
+
return {"o": "ign", "#": "empty loop body"}
|
|
1048
1027
|
return code
|
|
1049
1028
|
|
|
1050
1029
|
recurseIR(code, _goIR, edcRwt)
|
|
@@ -1080,8 +1059,89 @@ def elimUnreachableCode(code: Jsonable) -> int:
|
|
|
1080
1059
|
recurseIR(code, _goStructIR, eucRwt)
|
|
1081
1060
|
return changes
|
|
1082
1061
|
|
|
1083
|
-
def
|
|
1084
|
-
|
|
1062
|
+
def elimUnusedBoolVars(code: Jsonable) -> int:
|
|
1063
|
+
"""Bool variables may be set but unused."""
|
|
1064
|
+
|
|
1065
|
+
# collect existing boolean variables
|
|
1066
|
+
bvars: dict[str, list[dict[str, Jsonable]]] = {}
|
|
1067
|
+
|
|
1068
|
+
def _bvarRwt(op: Jsonable, path: Path) -> Jsonable:
|
|
1069
|
+
nonlocal bvars
|
|
1070
|
+
if _isOp(op, "bv"):
|
|
1071
|
+
var = op["var"]
|
|
1072
|
+
if var not in bvars:
|
|
1073
|
+
bvars[var] = []
|
|
1074
|
+
bvars[var].append(op)
|
|
1075
|
+
return op
|
|
1076
|
+
|
|
1077
|
+
recurseIR(code, _goStructIR, _bvarRwt)
|
|
1078
|
+
|
|
1079
|
+
# cleanup unused ones
|
|
1080
|
+
changes: int = 0
|
|
1081
|
+
|
|
1082
|
+
for var, bops in bvars.items():
|
|
1083
|
+
if not bvar_is_used(code, var):
|
|
1084
|
+
for bop in bops:
|
|
1085
|
+
assert bop["o"] == "bv"
|
|
1086
|
+
changes += 1
|
|
1087
|
+
bop.clear()
|
|
1088
|
+
bop.update(o="ign")
|
|
1089
|
+
|
|
1090
|
+
return changes
|
|
1091
|
+
|
|
1092
|
+
def mifToIf(code: Jsonable) -> int:
|
|
1093
|
+
"""Turn multi-if in a simple if is possible."""
|
|
1094
|
+
|
|
1095
|
+
changes: int = 0
|
|
1096
|
+
|
|
1097
|
+
def mif2ifRwt(op: Jsonable, _: Path) -> Jsonable:
|
|
1098
|
+
nonlocal changes
|
|
1099
|
+
if _isOp(op, "ifs") and len(op["cond_true"]) == 1:
|
|
1100
|
+
cond, likely, btrue = op["cond_true"][0]
|
|
1101
|
+
del op["cond_true"]
|
|
1102
|
+
op.update(o="if", cond=cond, true=btrue, likely=likely)
|
|
1103
|
+
changes += 1
|
|
1104
|
+
return op
|
|
1105
|
+
|
|
1106
|
+
recurseIR(code, _goStructIR, mif2ifRwt)
|
|
1107
|
+
|
|
1108
|
+
return changes
|
|
1109
|
+
|
|
1110
|
+
def simplifySimpleIf(code: Jsonable, reporting: bool) -> int:
|
|
1111
|
+
"""If with non effective or empty sequences."""
|
|
1112
|
+
|
|
1113
|
+
changes: int = 0
|
|
1114
|
+
|
|
1115
|
+
def sisifRwt(op: Jsonable, _: Path) -> Jsonable:
|
|
1116
|
+
nonlocal changes
|
|
1117
|
+
if _isOp(op, "if"):
|
|
1118
|
+
empty_true = _noOps(op["true"], reporting)
|
|
1119
|
+
empty_false = _noOps(op["false"], reporting)
|
|
1120
|
+
if empty_true:
|
|
1121
|
+
changes += 1
|
|
1122
|
+
if empty_false:
|
|
1123
|
+
op.clear()
|
|
1124
|
+
op.update(o="ign")
|
|
1125
|
+
else:
|
|
1126
|
+
op["true"] = op["false"]
|
|
1127
|
+
op["false"] = []
|
|
1128
|
+
op["cond"] = negate(op["cond"])
|
|
1129
|
+
elif empty_false and len(op["false"]) != 0:
|
|
1130
|
+
op["false"] = []
|
|
1131
|
+
changes += 1
|
|
1132
|
+
return op
|
|
1133
|
+
|
|
1134
|
+
recurseIR(code, _goStructIR, sisifRwt)
|
|
1135
|
+
|
|
1136
|
+
return changes
|
|
1137
|
+
|
|
1138
|
+
def optimizeIR(
|
|
1139
|
+
code: Block, *,
|
|
1140
|
+
shortcuts: dict[str, str],
|
|
1141
|
+
partial: bool = True,
|
|
1142
|
+
if_optim: bool = True,
|
|
1143
|
+
reporting: bool = True
|
|
1144
|
+
) -> Block:
|
|
1085
1145
|
"""Optimize IR code."""
|
|
1086
1146
|
|
|
1087
1147
|
if not if_optim and not shortcuts:
|
|
@@ -1090,19 +1150,19 @@ def optimizeIR(code: list[Jsonable], *, shortcuts: dict[str, str], partial: bool
|
|
|
1090
1150
|
optimized, calls = 0, 0
|
|
1091
1151
|
|
|
1092
1152
|
for i, c in list(enumerate(code)):
|
|
1093
|
-
if c == "":
|
|
1153
|
+
if c is None or c == "":
|
|
1094
1154
|
continue
|
|
1095
|
-
changed: bool = False
|
|
1096
1155
|
ins = json.loads(c)
|
|
1097
|
-
if
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1156
|
+
if not _isOp(ins, "sfu"):
|
|
1157
|
+
continue
|
|
1158
|
+
changed: bool = False
|
|
1159
|
+
changed |= mifToIf(ins) > 0
|
|
1160
|
+
if partial:
|
|
1161
|
+
changed |= partialEval(ins, reporting) > 0
|
|
1162
|
+
# sequence optimizations
|
|
1163
|
+
if if_optim:
|
|
1164
|
+
_optimSeq(ins["body"], set(), reporting=reporting)
|
|
1165
|
+
changed = True # FIXME
|
|
1106
1166
|
if shortcuts: # call shortcuts
|
|
1107
1167
|
changes = callShortcuts(ins, shortcuts)
|
|
1108
1168
|
calls += changes
|
|
@@ -1110,13 +1170,47 @@ def optimizeIR(code: list[Jsonable], *, shortcuts: dict[str, str], partial: bool
|
|
|
1110
1170
|
changed |= elimCommonSub(ins) > 0
|
|
1111
1171
|
changed |= elimDeadCode(ins, reporting) > 0
|
|
1112
1172
|
changed |= elimUnreachableCode(ins) > 0
|
|
1173
|
+
changed |= elimUnusedBoolVars(ins) > 0
|
|
1174
|
+
changed |= simplifySimpleIf(ins, reporting) > 0
|
|
1113
1175
|
if changed:
|
|
1114
1176
|
code[i] = json.dumps(ins)
|
|
1115
1177
|
|
|
1116
|
-
log.info(f"optimize ir: {
|
|
1178
|
+
log.info(f"optimize ir: {len(code)} functions processed, {calls} call shortcuts")
|
|
1117
1179
|
|
|
1118
1180
|
return code
|
|
1119
1181
|
|
|
1182
|
+
#
|
|
1183
|
+
# build intermediate representation
|
|
1184
|
+
#
|
|
1185
|
+
|
|
1186
|
+
def _j(o: str, **params) -> str:
|
|
1187
|
+
"""Generate a JSON operation."""
|
|
1188
|
+
return json.dumps({"o": o, **params})
|
|
1189
|
+
|
|
1190
|
+
def _l(s: str) -> Jsonable:
|
|
1191
|
+
"""Parse a JSON operation or something else."""
|
|
1192
|
+
# FIXME true/false/null handling is adhoc and can be wrong
|
|
1193
|
+
try:
|
|
1194
|
+
if (isinstance(s, str) and s and
|
|
1195
|
+
(s[0] in '{["0123456789-' or s in ("null", "true", "false"))):
|
|
1196
|
+
return json.loads(s)
|
|
1197
|
+
else:
|
|
1198
|
+
return s
|
|
1199
|
+
except Exception:
|
|
1200
|
+
# FIXME triggered on strange property names, eg "[a-z]"
|
|
1201
|
+
log.warning(f"shamefully ignoring json oops on {s}")
|
|
1202
|
+
return s
|
|
1203
|
+
|
|
1204
|
+
def _u(block: Block) -> list[Jsonable]:
|
|
1205
|
+
"""Parse a JSON code block."""
|
|
1206
|
+
return [ _l(i) for i in filter(lambda s: s is not None and s != "", block) ]
|
|
1207
|
+
|
|
1208
|
+
# constant map to json and reverse
|
|
1209
|
+
def _cmap2json(mapping: dict[JsonScalar, str]) -> list[tuple[JsonScalar, str]]:
|
|
1210
|
+
return [ ( c, s ) for c, s in mapping.items() ]
|
|
1211
|
+
|
|
1212
|
+
def _json2cmap(mapping: list[tuple[JsonScalar, str]]) -> dict[JsonScalar, str]:
|
|
1213
|
+
return { c: s for c, s in mapping }
|
|
1120
1214
|
|
|
1121
1215
|
def _t2s(tvar: type|None) -> str:
|
|
1122
1216
|
"""Type to IR type name conversion."""
|
|
@@ -1143,7 +1237,6 @@ def _t2s(tvar: type|None) -> str:
|
|
|
1143
1237
|
# any?
|
|
1144
1238
|
raise Exception(f"unexpected type: {tvar}")
|
|
1145
1239
|
|
|
1146
|
-
|
|
1147
1240
|
class IRep(Language):
|
|
1148
1241
|
"""Generate JSON intermediate representation of backend code.
|
|
1149
1242
|
|
|
@@ -1489,6 +1582,7 @@ class IRep(Language):
|
|
|
1489
1582
|
#
|
|
1490
1583
|
# target language reconstruction
|
|
1491
1584
|
#
|
|
1585
|
+
|
|
1492
1586
|
def _s2t(tname: str|None) -> type:
|
|
1493
1587
|
"""String to type reconversion."""
|
|
1494
1588
|
match tname:
|
|
@@ -1676,7 +1770,6 @@ def ir_evaluate(ir: Jsonable, lang: Language) -> str:
|
|
|
1676
1770
|
"""Generate the target language source code from a full code JSON IR."""
|
|
1677
1771
|
code = _eval(ir, lang)
|
|
1678
1772
|
assert isinstance(code, list), "full code JSON IR"
|
|
1679
|
-
|
|
1680
1773
|
return lang.code_to_str(lang.filter_code(code))
|
|
1681
1774
|
|
|
1682
1775
|
def evaluate(ir: Code, lang: Language) -> Code:
|
|
@@ -173,13 +173,22 @@ class Python(Language):
|
|
|
173
173
|
if self._with_report else []
|
|
174
174
|
|
|
175
175
|
def arr_loop(self, arr: Var, idx: Var, val: Var, body: Block) -> Block:
|
|
176
|
-
|
|
176
|
+
if any(map(lambda i: i not in (None, ""), body)):
|
|
177
|
+
return [ f"for {idx}, {val} in enumerate({arr}):" ] + self.indent(body)
|
|
178
|
+
else:
|
|
179
|
+
return []
|
|
177
180
|
|
|
178
181
|
def obj_loop(self, obj: Var, key: Var, val: Var, body: Block) -> Block:
|
|
179
|
-
|
|
182
|
+
if any(map(lambda i: i not in (None, ""), body)):
|
|
183
|
+
return [ f"for {key}, {val} in {obj}.items():" ] + self.indent(body)
|
|
184
|
+
else:
|
|
185
|
+
return []
|
|
180
186
|
|
|
181
187
|
def int_loop(self, idx: Var, start: IntExpr, end: IntExpr, body: Block) -> Block:
|
|
182
|
-
|
|
188
|
+
if any(map(lambda i: i not in (None, ""), body)):
|
|
189
|
+
return [ f"for {idx} in range({start}, {end}):" ] + self.indent(body)
|
|
190
|
+
else:
|
|
191
|
+
return []
|
|
183
192
|
|
|
184
193
|
def if_stmt(
|
|
185
194
|
self, cond: BoolExpr, true: Block, false: Block = [], likely: TestHint = None
|