cpyte 4.7.0__tar.gz → 4.7.1__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.
Files changed (55) hide show
  1. {cpyte-4.7.0/source/cpyte.egg-info → cpyte-4.7.1}/PKG-INFO +16 -16
  2. {cpyte-4.7.0 → cpyte-4.7.1}/readme.md +15 -15
  3. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/__init__.py +1 -1
  4. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/astparse.py +9 -2
  5. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/bytecoding.py +29 -9
  6. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/compiling.py +124 -22
  7. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/gc_runtime_addition.c +6 -6
  8. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/lsp_server.py +9 -5
  9. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/mainpie.py +50 -44
  10. cpyte-4.7.1/source/cpyte/opreof_opt.py +141 -0
  11. cpyte-4.7.1/source/cpyte/opreof_pipeline.py +429 -0
  12. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/package_manifest.py +35 -1
  13. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/runpy_runtime.c +24 -24
  14. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/semantic_analasis.py +78 -66
  15. {cpyte-4.7.0 → cpyte-4.7.1/source/cpyte.egg-info}/PKG-INFO +16 -16
  16. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte.egg-info/SOURCES.txt +3 -0
  17. {cpyte-4.7.0 → cpyte-4.7.1}/test/test_compiler_regressions.py +223 -1
  18. cpyte-4.7.1/test/test_opreof_proofs.py +274 -0
  19. {cpyte-4.7.0 → cpyte-4.7.1}/MANIFEST.in +0 -0
  20. {cpyte-4.7.0 → cpyte-4.7.1}/pyproject.toml +0 -0
  21. {cpyte-4.7.0 → cpyte-4.7.1}/setup.cfg +0 -0
  22. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/__main__.py +0 -0
  23. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/_bignum_bc.py +0 -0
  24. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/_runtime_bc.py +0 -0
  25. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/bignum.c +0 -0
  26. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/bignum_protos.h +0 -0
  27. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/clib.py +0 -0
  28. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/elf2sef.py +0 -0
  29. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/extension_hooks.py +0 -0
  30. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/floats_runtime.c +0 -0
  31. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/formatter.py +0 -0
  32. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/gc_runtime.c +0 -0
  33. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/generate_bc.py +0 -0
  34. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/lexar.py +0 -0
  35. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/linker.py +0 -0
  36. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/mksef.py +0 -0
  37. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/optimizations.py +0 -0
  38. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/runtime.c +0 -0
  39. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/runtime_scorpion.c +0 -0
  40. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/scorpion_abi.py +0 -0
  41. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/sef.py +0 -0
  42. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/ugc.h +0 -0
  43. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/ui.py +0 -0
  44. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/update_check.py +0 -0
  45. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/winjit_patch.py +0 -0
  46. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte/winjit_stubs.c +0 -0
  47. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte.egg-info/dependency_links.txt +0 -0
  48. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte.egg-info/entry_points.txt +0 -0
  49. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte.egg-info/requires.txt +0 -0
  50. {cpyte-4.7.0 → cpyte-4.7.1}/source/cpyte.egg-info/top_level.txt +0 -0
  51. {cpyte-4.7.0 → cpyte-4.7.1}/test/test_bignum_jit.py +0 -0
  52. {cpyte-4.7.0 → cpyte-4.7.1}/test/test_fuzz_del_has.py +0 -0
  53. {cpyte-4.7.0 → cpyte-4.7.1}/test/test_scorpion_abi.py +0 -0
  54. {cpyte-4.7.0 → cpyte-4.7.1}/test/test_scorpion_dl.py +0 -0
  55. {cpyte-4.7.0 → cpyte-4.7.1}/test/test_sef_tools.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cpyte
3
- Version: 4.7.0
3
+ Version: 4.7.1
4
4
  Summary: The Cpyte programming language compiler
5
5
  Author: Hoang Duy Tung
6
6
  License: MIT
@@ -108,24 +108,24 @@ measurement from any historical benchmark results and is collected on the
108
108
  dedicated benchmark runner.
109
109
 
110
110
  <!-- CPYTE_CI_BENCHMARKS_START -->
111
- Latest run: [ecd3510c0342](https://github.com/Cpyte/Cpyte/actions/runs/42362272944) · updated 2026-11-07 10:12 UTC
111
+ Latest run: [1d3eae11d67d](https://github.com/Cpyte/Cpyte/actions/runs/43207132063) · updated 2026-11-15 09:45 UTC
112
112
 
113
113
  | Benchmark | C | Cpy | Python | Cpy/C | Python/C |
114
114
  |---|---:|---:|---:|---:|---:|
115
- | `array_sum` | 8.58ms | 8.78ms | 268.58ms | 1.02x | 31.31x |
116
- | `bitwise_mix` | 3.06ms | 3.14ms | 835.76ms | 1.03x | 272.68x |
117
- | `branch_mix` | 4.66ms | 6.09ms | 474.55ms | 1.31x | 101.92x |
118
- | `call_overhead` | 3.14ms | 3.69ms | 372.64ms | 1.17x | 118.52x |
119
- | `fib_iterative` | 17.12ms | 17.31ms | 11.994s | 1.01x | 700.56x |
120
- | `fib_recursive` | 167.15ms | 1.18ms | 7.787s | 0.01x | 46.59x |
121
- | `float_math` | 6.33ms | 6.54ms | 272.00ms | 1.03x | 42.98x |
122
- | `integer_mix` | 3.65ms | 3.74ms | 404.68ms | 1.03x | 110.93x |
123
- | `loop_sum` | 1.11ms | 1.13ms | 2.978s | 1.01x | 2673.66x |
124
- | `matrix_mult` | 4.59ms | 4.58ms | 1.912s | 1.00x | 416.55x |
125
- | `mem_alloc` | 1.01ms | 1.21ms | 23.54ms | 1.19x | 23.30x |
126
- | `prime_count` | 68.04ms | 79.02ms | 1.927s | 1.16x | 28.33x |
127
- | `quicksort` | 2.48ms | 3.00ms | 39.87ms | 1.21x | 16.09x |
128
- | `string_concat` | 1.13ms | 1.25ms | 32.65ms | 1.11x | 28.94x |
115
+ | `array_sum` | 6.47ms | 6.38ms | 247.94ms | 0.99x | 38.30x |
116
+ | `bitwise_mix` | 2.58ms | 2.69ms | 698.18ms | 1.04x | 270.82x |
117
+ | `branch_mix` | 4.11ms | 4.35ms | 445.52ms | 1.06x | 108.32x |
118
+ | `call_overhead` | 2.58ms | 3.15ms | 344.81ms | 1.22x | 133.65x |
119
+ | `fib_iterative` | 16.47ms | 16.60ms | 11.184s | 1.01x | 679.05x |
120
+ | `fib_recursive` | 163.17ms | 832.00us | 7.292s | 0.01x | 44.69x |
121
+ | `float_math` | 5.76ms | 5.89ms | 256.63ms | 1.02x | 44.58x |
122
+ | `integer_mix` | 3.23ms | 3.15ms | 394.71ms | 0.98x | 122.35x |
123
+ | `loop_sum` | 685.00us | 768.00us | 2.797s | 1.12x | 4082.65x |
124
+ | `matrix_mult` | 3.81ms | 3.77ms | 1.784s | 0.99x | 468.44x |
125
+ | `mem_alloc` | 671.00us | 751.00us | 16.96ms | 1.12x | 25.27x |
126
+ | `prime_count` | 66.63ms | 77.80ms | 1.812s | 1.17x | 27.19x |
127
+ | `quicksort` | 1.86ms | 2.28ms | 29.36ms | 1.23x | 15.80x |
128
+ | `string_concat` | 741.00us | 810.00us | 25.71ms | 1.09x | 34.70x |
129
129
 
130
130
  Process wall time includes startup. These are measurements from the dedicated `cpyte-official-runner-1`, not the historical benchmark figures elsewhere in this README; results can vary with host load and software versions.
131
131
  <!-- CPYTE_CI_BENCHMARKS_END -->
@@ -96,24 +96,24 @@ measurement from any historical benchmark results and is collected on the
96
96
  dedicated benchmark runner.
97
97
 
98
98
  <!-- CPYTE_CI_BENCHMARKS_START -->
99
- Latest run: [ecd3510c0342](https://github.com/Cpyte/Cpyte/actions/runs/42362272944) · updated 2026-11-07 10:12 UTC
99
+ Latest run: [1d3eae11d67d](https://github.com/Cpyte/Cpyte/actions/runs/43207132063) · updated 2026-11-15 09:45 UTC
100
100
 
101
101
  | Benchmark | C | Cpy | Python | Cpy/C | Python/C |
102
102
  |---|---:|---:|---:|---:|---:|
103
- | `array_sum` | 8.58ms | 8.78ms | 268.58ms | 1.02x | 31.31x |
104
- | `bitwise_mix` | 3.06ms | 3.14ms | 835.76ms | 1.03x | 272.68x |
105
- | `branch_mix` | 4.66ms | 6.09ms | 474.55ms | 1.31x | 101.92x |
106
- | `call_overhead` | 3.14ms | 3.69ms | 372.64ms | 1.17x | 118.52x |
107
- | `fib_iterative` | 17.12ms | 17.31ms | 11.994s | 1.01x | 700.56x |
108
- | `fib_recursive` | 167.15ms | 1.18ms | 7.787s | 0.01x | 46.59x |
109
- | `float_math` | 6.33ms | 6.54ms | 272.00ms | 1.03x | 42.98x |
110
- | `integer_mix` | 3.65ms | 3.74ms | 404.68ms | 1.03x | 110.93x |
111
- | `loop_sum` | 1.11ms | 1.13ms | 2.978s | 1.01x | 2673.66x |
112
- | `matrix_mult` | 4.59ms | 4.58ms | 1.912s | 1.00x | 416.55x |
113
- | `mem_alloc` | 1.01ms | 1.21ms | 23.54ms | 1.19x | 23.30x |
114
- | `prime_count` | 68.04ms | 79.02ms | 1.927s | 1.16x | 28.33x |
115
- | `quicksort` | 2.48ms | 3.00ms | 39.87ms | 1.21x | 16.09x |
116
- | `string_concat` | 1.13ms | 1.25ms | 32.65ms | 1.11x | 28.94x |
103
+ | `array_sum` | 6.47ms | 6.38ms | 247.94ms | 0.99x | 38.30x |
104
+ | `bitwise_mix` | 2.58ms | 2.69ms | 698.18ms | 1.04x | 270.82x |
105
+ | `branch_mix` | 4.11ms | 4.35ms | 445.52ms | 1.06x | 108.32x |
106
+ | `call_overhead` | 2.58ms | 3.15ms | 344.81ms | 1.22x | 133.65x |
107
+ | `fib_iterative` | 16.47ms | 16.60ms | 11.184s | 1.01x | 679.05x |
108
+ | `fib_recursive` | 163.17ms | 832.00us | 7.292s | 0.01x | 44.69x |
109
+ | `float_math` | 5.76ms | 5.89ms | 256.63ms | 1.02x | 44.58x |
110
+ | `integer_mix` | 3.23ms | 3.15ms | 394.71ms | 0.98x | 122.35x |
111
+ | `loop_sum` | 685.00us | 768.00us | 2.797s | 1.12x | 4082.65x |
112
+ | `matrix_mult` | 3.81ms | 3.77ms | 1.784s | 0.99x | 468.44x |
113
+ | `mem_alloc` | 671.00us | 751.00us | 16.96ms | 1.12x | 25.27x |
114
+ | `prime_count` | 66.63ms | 77.80ms | 1.812s | 1.17x | 27.19x |
115
+ | `quicksort` | 1.86ms | 2.28ms | 29.36ms | 1.23x | 15.80x |
116
+ | `string_concat` | 741.00us | 810.00us | 25.71ms | 1.09x | 34.70x |
117
117
 
118
118
  Process wall time includes startup. These are measurements from the dedicated `cpyte-official-runner-1`, not the historical benchmark figures elsewhere in this README; results can vary with host load and software versions.
119
119
  <!-- CPYTE_CI_BENCHMARKS_END -->
@@ -1,4 +1,4 @@
1
- __version__ = "4.7.0"
1
+ __version__ = "4.7.1"
2
2
 
3
3
  # ---------------------------------------------------------------------------
4
4
  # Public library API.
@@ -529,9 +529,16 @@ def _parse_binary(tokens: list[Token], pos: int, min_prec: int):
529
529
  TokenType.DEDENT,
530
530
  ):
531
531
  pos += 1
532
- next_prec = _prec(op) if op.type != TokenType.KEYWORD else IN_PREC + 1
533
- if op.type == TokenType.POW:
532
+ # `**` is the one right-associative operator (2 ** 3 ** 2 is
533
+ # 2 ** (3 ** 2)); everything else binds left, which means parsing
534
+ # the right-hand side one level tighter so `a - b + c` folds to
535
+ # `(a - b) + c` rather than `a - (b + c)`.
536
+ if op.type == TokenType.KEYWORD:
537
+ next_prec = IN_PREC + 1
538
+ elif op.type == TokenType.POW:
534
539
  next_prec = _prec(op)
540
+ else:
541
+ next_prec = _prec(op) + 1
535
542
  right, pos = _parse_binary(tokens, pos, next_prec)
536
543
  left = BinOp(left, op.type, right, token=op)
537
544
 
@@ -1126,15 +1126,17 @@ class LLVM:
1126
1126
  class_ptr = _i8ptr
1127
1127
  func_ptr = _i8ptr
1128
1128
  runpy_fns = [
1129
- ("create_table", table_ptr, [_i64]),
1130
- ("hashmap_put", table_ptr, [table_ptr, void_ptr, void_ptr]),
1131
- ("hashmap_get", void_ptr, [table_ptr, void_ptr]),
1132
- ("hashmap_contains", _i32, [table_ptr, void_ptr]),
1133
- ("hashmap_erase", table_ptr, [table_ptr, void_ptr]),
1134
- ("hashmap_destroy", _void, [table_ptr]),
1135
- ("hashmap_is_valid", _i32, [table_ptr]),
1136
- ("hashmap_size", _i64, [table_ptr]),
1137
- ("hashmap_is_empty", _i32, [table_ptr]),
1129
+ # Prefixed names only: unprefixed create_table/hashmap_* squatted
1130
+ # on generic identifiers user code (e.g. stdlib collections) needs.
1131
+ ("runpy_create_table", table_ptr, [_i64]),
1132
+ ("runpy_hashmap_put", table_ptr, [table_ptr, void_ptr, void_ptr]),
1133
+ ("runpy_hashmap_get", void_ptr, [table_ptr, void_ptr]),
1134
+ ("runpy_hashmap_contains", _i32, [table_ptr, void_ptr]),
1135
+ ("runpy_hashmap_erase", table_ptr, [table_ptr, void_ptr]),
1136
+ ("runpy_hashmap_destroy", _void, [table_ptr]),
1137
+ ("runpy_hashmap_is_valid", _i32, [table_ptr]),
1138
+ ("runpy_hashmap_size", _i64, [table_ptr]),
1139
+ ("runpy_hashmap_is_empty", _i32, [table_ptr]),
1138
1140
  ("runpy_create_function", func_ptr, [_i32, void_ptr, void_ptr]),
1139
1141
  ("runpy_create_tables", table_ptr, []),
1140
1142
  ("runpy_create_class", class_ptr, [_i64]),
@@ -3415,6 +3417,16 @@ class LLVM:
3415
3417
 
3416
3418
  if node.name in self.functions:
3417
3419
  func = self.functions[node.name]
3420
+ # Reusing a pre-declared runtime function with a different
3421
+ # signature would attach this body to the runtime's parameter
3422
+ # types (the source of opaque-struct GEP IndexErrors); reject
3423
+ # the name clash with a clear error instead.
3424
+ if str(func.function_type) != str(ir.FunctionType(ret_ty, param_tys)):
3425
+ self._codegen_error(
3426
+ f"function `{node.name}` collides with a runtime builtin "
3427
+ f"of the same name; rename it",
3428
+ node,
3429
+ )
3418
3430
  else:
3419
3431
  func = ir.Function(
3420
3432
  self.module, ir.FunctionType(ret_ty, param_tys), name=node.name
@@ -4826,6 +4838,14 @@ class LLVM:
4826
4838
  or rf is not None
4827
4839
  )
4828
4840
 
4841
+ # OProof integration note: an experimental prover-backed rewrite used
4842
+ # to live here behind CPYTE_OPROOF/OPROOF_OPT. It was removed because
4843
+ # it changed generated code incorrectly: cpyte's floor `//` was mapped
4844
+ # to OProof's truncating `divs` (`7 // -2` became `-3`), and an OProof
4845
+ # builtin rewrite folded `x % 1` to `x`. OProof is now a *test-only*
4846
+ # equivalence oracle (test/test_opreof_proofs.py); no prover output may
4847
+ # change emitted IR. The env vars no longer affect codegen.
4848
+
4829
4849
  # ---- Constant folding: both operands are integral literals ----
4830
4850
  lv = _const_int_value(left_node)
4831
4851
  rv = _const_int_value(right_node)
@@ -1124,6 +1124,89 @@ def _mpfr_include_dir() -> str | None:
1124
1124
  return None
1125
1125
 
1126
1126
 
1127
+ def _find_openssl_paths():
1128
+ """Find OpenSSL include and lib dirs (for linking crypto into ccode/JIT/AOT)."""
1129
+ # Try hook-provided paths first (from loaded build hooks, e.g. cryptography)
1130
+ try:
1131
+ from .extension_hooks import get_global_hook_dispatcher, CompilerContext
1132
+ disp = get_global_hook_dispatcher()
1133
+ ctx = CompilerContext()
1134
+ try:
1135
+ disp.collect_build_configuration(ctx)
1136
+ except Exception:
1137
+ pass
1138
+ inc = None
1139
+ libdir = None
1140
+ for pth in (ctx.include_paths or []):
1141
+ if pth and os.path.isdir(pth):
1142
+ if os.path.isfile(os.path.join(pth, 'openssl', 'evp.h')):
1143
+ inc = pth
1144
+ break
1145
+ for pth in (ctx.library_paths or []):
1146
+ if pth and os.path.isdir(pth):
1147
+ libdir = pth
1148
+ break
1149
+ if inc and libdir:
1150
+ return inc, libdir
1151
+ if inc:
1152
+ cand = os.path.join(os.path.dirname(inc), 'lib')
1153
+ if os.path.isdir(cand):
1154
+ return inc, cand
1155
+ except Exception:
1156
+ pass
1157
+ inc = os.environ.get("CPYTE_OPENSSL_INCLUDE")
1158
+ libdir = os.environ.get("CPYTE_OPENSSL_LIBDIR") or os.environ.get("CPYTE_OPENSSL_LIB")
1159
+ if inc and libdir:
1160
+ return inc, libdir
1161
+ if inc:
1162
+ cand = os.path.join(os.path.dirname(inc), "lib")
1163
+ return inc, cand if os.path.isdir(cand) else None
1164
+ try:
1165
+ r = subprocess.run(["pkg-config", "--cflags", "openssl"], capture_output=True, text=True, timeout=5)
1166
+ if r.returncode == 0:
1167
+ for f in (r.stdout or "").strip().split():
1168
+ if f.startswith("-I"):
1169
+ inc = f[2:]
1170
+ break
1171
+ r2 = subprocess.run(["pkg-config", "--libs-only-L", "openssl"], capture_output=True, text=True, timeout=5)
1172
+ if r2.returncode == 0:
1173
+ for f in (r2.stdout or "").strip().split():
1174
+ if f.startswith("-L"):
1175
+ libdir = f[2:]
1176
+ break
1177
+ if inc:
1178
+ return inc, libdir
1179
+ except Exception:
1180
+ pass
1181
+ if shutil.which("brew"):
1182
+ try:
1183
+ for name in ("openssl@3", "openssl"):
1184
+ r = subprocess.run(["brew", "--prefix", name], capture_output=True, text=True, timeout=5)
1185
+ if r.returncode == 0:
1186
+ prefix = r.stdout.strip()
1187
+ inc = os.path.join(prefix, "include")
1188
+ lib = os.path.join(prefix, "lib")
1189
+ if os.path.isdir(inc) and os.path.isfile(os.path.join(inc, "openssl", "evp.h")):
1190
+ return inc, lib
1191
+ except Exception:
1192
+ pass
1193
+ for prefix in ["/opt/homebrew/opt/openssl@3", "/usr/local/opt/openssl@3", "/opt/homebrew/opt/openssl", "/usr/local/opt/openssl"]:
1194
+ inc = os.path.join(prefix, "include")
1195
+ lib = os.path.join(prefix, "lib")
1196
+ if os.path.isdir(inc) and os.path.isfile(os.path.join(inc, "openssl", "evp.h")):
1197
+ return inc, lib
1198
+ if os.path.isfile(os.path.join("/usr/include", "openssl", "evp.h")):
1199
+ libdir = "/usr/lib" if os.path.isdir("/usr/lib") else "/usr/lib/x86_64-linux-gnu"
1200
+ if os.path.isdir(libdir):
1201
+ return "/usr/include", libdir
1202
+ for inc in ["/usr/include", "/usr/local/include"]:
1203
+ if os.path.isfile(os.path.join(inc, "openssl", "evp.h")):
1204
+ libdir = "/usr/lib" if os.path.isdir("/usr/lib") else "/usr/local/lib"
1205
+ if os.path.isdir(libdir):
1206
+ return inc, libdir
1207
+ return None, None
1208
+
1209
+
1127
1210
  def _runtime_extra_flags(src_path: str) -> tuple:
1128
1211
  """Extra clang flags needed to compile a runtime C source.
1129
1212
 
@@ -1183,6 +1266,14 @@ def aot_link_libraries() -> list:
1183
1266
  libs = ["m", "gmp"]
1184
1267
  if _mpfr_include_dir() is not None:
1185
1268
  libs.append("mpfr")
1269
+ # OpenSSL for cryptography ccode (EVP/HMAC). Try to detect.
1270
+ try:
1271
+ inc, libdir = _find_openssl_paths()
1272
+ if inc:
1273
+ libs.append("ssl")
1274
+ libs.append("crypto")
1275
+ except Exception:
1276
+ pass
1186
1277
  return libs
1187
1278
 
1188
1279
 
@@ -1190,32 +1281,27 @@ _GMP_LINK_NEEDLE = re.compile(r"(?:gmp[a-z]*_|mpfr_|libgmp|libmpfr|-lgmp|-lmpfr)
1190
1281
 
1191
1282
 
1192
1283
  def aot_link_executable(linker, objects, output, **kwargs):
1193
- """Link an AOT executable, pulling in GMP/MPFR only when it is needed.
1194
-
1195
- The bignum runtime's kept helpers (``_BIGNUM_KEEP``) always reference
1196
- ``mpz_*``, but ``-dead_strip``/``--gc-sections`` drop them when the program
1197
- never touches ``big``/``ubig``. Linking libgmp + libmpfr unconditionally
1198
- still records them in the executable's load commands, so every launch pays
1199
- the dynamic loader for two extra shared libraries -- a fixed cost that is
1200
- large relative to short benchmarks. So try the link with libc/libm only and
1201
- retry with the full runtime library set only when the linker reports an
1202
- unresolved GMP/MPFR symbol.
1203
-
1204
- A static scan of the object cannot decide this: every program object
1205
- declares the kept bignum helpers (and they reference ``mpz_*``), so the
1206
- symbol table looks identical whether or not the program uses ``big``.
1207
- """
1284
+ """Link an AOT executable, pulling in GMP/MPFR/OpenSSL only when needed."""
1208
1285
  libs = ["m"]
1209
1286
  ok, stderr = linker.link(objects, output, libraries=libs, check=False, **kwargs)
1210
1287
  if ok:
1211
1288
  return output
1212
- if not _GMP_LINK_NEEDLE.search(stderr or ""):
1213
- print_err(f"link error: {format_cc_diag(stderr)}")
1214
- raise SystemExit(1)
1215
- libs = aot_link_libraries()
1216
- kwargs["library_paths"] = _gmp_library_paths()
1217
- linker.link(objects, output, libraries=libs, **kwargs)
1218
- return output
1289
+ # If missing GMP/MPFR or OpenSSL symbols, add libraries
1290
+ if _GMP_LINK_NEEDLE.search(stderr or "") or "EVP_" in (stderr or "") or "HMAC" in (stderr or "") or "openssl" in (stderr or "").lower():
1291
+ libs = aot_link_libraries()
1292
+ lp = list(kwargs.get("library_paths") or [])
1293
+ lp.extend(_gmp_library_paths())
1294
+ try:
1295
+ _o_inc, _o_lib = _find_openssl_paths()
1296
+ if _o_lib and _o_lib not in lp:
1297
+ lp.append(_o_lib)
1298
+ except Exception:
1299
+ pass
1300
+ kwargs["library_paths"] = lp
1301
+ linker.link(objects, output, libraries=libs, **kwargs)
1302
+ return output
1303
+ print_err(f"link error: {format_cc_diag(stderr)}")
1304
+ raise SystemExit(1)
1219
1305
 
1220
1306
 
1221
1307
  def _cached_c_ir(
@@ -1351,6 +1437,13 @@ def run_jit(
1351
1437
  if src.endswith(".ll"):
1352
1438
  with open(src) as f:
1353
1439
  return src, f.read(), None
1440
+ extra = []
1441
+ try:
1442
+ openssl_inc, _ = _find_openssl_paths()
1443
+ if openssl_inc:
1444
+ extra.append(f"-I{openssl_inc}")
1445
+ except Exception:
1446
+ pass
1354
1447
  r = subprocess.run(
1355
1448
  [
1356
1449
  llvm_cc,
@@ -1360,6 +1453,7 @@ def run_jit(
1360
1453
  "-target",
1361
1454
  target.triple,
1362
1455
  "-fno-stack-protector",
1456
+ *extra,
1363
1457
  "-o",
1364
1458
  "-",
1365
1459
  src,
@@ -2008,12 +2102,20 @@ def run_aot(
2008
2102
  compile_jobs.append((_RUNPY_RUNTIME_C, output + ".runpy.o"))
2009
2103
 
2010
2104
  def _linker_compile(src, out):
2105
+ extra = []
2106
+ try:
2107
+ openssl_inc, _ = _find_openssl_paths()
2108
+ if openssl_inc:
2109
+ extra.append(f"-I{openssl_inc}")
2110
+ except Exception:
2111
+ pass
2011
2112
  linker.compile_c(
2012
2113
  src,
2013
2114
  output=out,
2014
2115
  opt_level=3,
2015
2116
  pic=pic,
2016
2117
  eh=(not no_userspace and src == _RUNTIME_C),
2118
+ extra_flags=tuple(extra),
2017
2119
  )
2018
2120
  return out
2019
2121
 
@@ -16,7 +16,7 @@ typedef struct {
16
16
  size_t allocation_offset;
17
17
  } StackHeader;
18
18
 
19
- bool stack_init(StackAllocator *a, size_t capacity) {
19
+ bool cpyte_stack_init(StackAllocator *a, size_t capacity) {
20
20
  a->memory = malloc(capacity);
21
21
  if (!a->memory) return false;
22
22
 
@@ -25,7 +25,7 @@ bool stack_init(StackAllocator *a, size_t capacity) {
25
25
  return true;
26
26
  }
27
27
 
28
- void *stack_alloc(StackAllocator *a, size_t size) {
28
+ void *cpyte_stack_alloc(StackAllocator *a, size_t size) {
29
29
  const size_t alignment = _Alignof(max_align_t);
30
30
 
31
31
  size_t header_pos = a->offset;
@@ -51,7 +51,7 @@ void *stack_alloc(StackAllocator *a, size_t size) {
51
51
  return a->memory + data_pos;
52
52
  }
53
53
 
54
- bool stack_free(StackAllocator *a, void *ptr) {
54
+ bool cpyte_stack_free(StackAllocator *a, void *ptr) {
55
55
  if (!ptr || !a->memory) return false;
56
56
 
57
57
  uintptr_t base = (uintptr_t)a->memory;
@@ -71,11 +71,11 @@ bool stack_free(StackAllocator *a, void *ptr) {
71
71
  return true;
72
72
  }
73
73
 
74
- void stack_reset(StackAllocator *a) {
74
+ void cpyte_stack_reset(StackAllocator *a) {
75
75
  a->offset = 0;
76
76
  }
77
77
 
78
- void stack_destroy(StackAllocator *a) {
78
+ void cpyte_stack_destroy(StackAllocator *a) {
79
79
  free(a->memory);
80
80
  a->memory = NULL;
81
81
  a->capacity = 0;
@@ -90,6 +90,6 @@ typedef struct ArenaPage {
90
90
  unsigned char data[];
91
91
  } ArenaPage;
92
92
 
93
- void* arena_alloc(size_t size) {
93
+ void* cpyte_arena_alloc(size_t size) {
94
94
  size_t needp = size / PAGE_SIZE + (size % PAGE_SIZE != 0);
95
95
  }
@@ -30,6 +30,7 @@ from .astparse import (
30
30
  from .clib import _BUILTIN_LIB_HEADERS
31
31
  from .formatter import format_source
32
32
  from .lexar import Lexer, LexerError, TokenType
33
+ from .package_manifest import cpm_module_roots
33
34
  from .semantic_analasis import SemanticAnalyzer
34
35
 
35
36
  logging.basicConfig(level=logging.INFO, format="%(message)s")
@@ -287,9 +288,11 @@ _SNIPPETS = {
287
288
  def _load_manifest_keywords(workspace_root):
288
289
  """Register package manifest keywords so the lexer recognises extension
289
290
  keywords/operators before lexing — mirrors the compiler CLI path in
290
- mainpie. Safe to call repeatedly (global registry de-dupes by package)."""
291
- if not workspace_root:
292
- return
291
+ mainpie. Safe to call repeatedly (global registry de-dupes by package).
292
+
293
+ Global ``~/.cpm`` packages must be loaded even when the editor has no
294
+ workspace folder open, so there is no workspace guard here.
295
+ """
293
296
  try:
294
297
  from .mainpie import _load_package_manifests_from_source
295
298
 
@@ -972,8 +975,9 @@ def _import_dir_completions(partial, file_dir, workspace_root):
972
975
  bases.append(file_dir)
973
976
  if workspace_root:
974
977
  bases.append(workspace_root)
975
- if workspace_root:
976
- bases.append(os.path.join(workspace_root, ".cpm", "modules"))
978
+ # CPM direct installs are global (~/.cpm/modules); manifest-driven ones
979
+ # stay under the workspace. Offer completions from both.
980
+ bases.extend(cpm_module_roots(workspace_root, file_dir))
977
981
 
978
982
  for base in bases:
979
983
  if not base:
@@ -40,6 +40,7 @@ if __package__:
40
40
  from .linker import Linker, format_cc_diag
41
41
  from .package_manifest import (
42
42
  ManifestParser,
43
+ cpm_module_roots,
43
44
  get_global_registry,
44
45
  iter_cpm_version_dirs,
45
46
  )
@@ -85,6 +86,7 @@ else:
85
86
  from cpyte.linker import Linker, format_cc_diag
86
87
  from cpyte.package_manifest import (
87
88
  ManifestParser,
89
+ cpm_module_roots,
88
90
  get_global_registry,
89
91
  iter_cpm_version_dirs,
90
92
  )
@@ -337,58 +339,62 @@ def _sync_lexer_hooks() -> None:
337
339
  register_operators(operators)
338
340
 
339
341
 
340
- def _load_package_manifests_from_source(workspace_root: str) -> None:
341
- """
342
- Load all package manifests from CPM packages in the workspace.
342
+ def _load_package_manifests_from_source(workspace_root: str | None) -> None:
343
+ """Load manifests from all installed CPM packages.
343
344
 
344
- This ensures that package extensions (keywords, operators, etc.) are
345
- available during lexing and parsing.
345
+ Direct ``cpm install <pkg>`` packages live in ``~/.cpm/modules`` while
346
+ manifest-driven installs stay in ``<workspace>/.cpm/modules``. Both are
347
+ searched, and global packages work even without a workspace. This makes
348
+ package-provided keywords/operators available before lexing/parsing.
346
349
  """
347
- cpm_root = os.path.join(workspace_root, ".cpm", "modules")
348
- if not os.path.isdir(cpm_root):
349
- return
350
-
351
350
  manifest_registry = get_global_registry()
352
351
 
353
- # Load all available packages in the workspace
354
- for package_name, version_dir in iter_cpm_version_dirs(cpm_root):
355
- # Check if already loaded
356
- if manifest_registry.is_loaded(package_name):
352
+ for cpm_root in cpm_module_roots(workspace_root):
353
+ if not os.path.isdir(cpm_root):
357
354
  continue
358
355
 
359
- manifest_path = os.path.join(version_dir, "package.json")
360
- if not os.path.exists(manifest_path):
361
- continue
356
+ for dir_package, version_dir in iter_cpm_version_dirs(cpm_root):
357
+ # iter_cpm_version_dirs yields scoped dirs as "@scope/name";
358
+ # manifest.name (from package.json) is usually just "name".
359
+ base_name = dir_package.rsplit("/", 1)[-1]
360
+ if manifest_registry.is_loaded(base_name):
361
+ continue
362
362
 
363
- try:
364
- manifest = ManifestParser.validate_and_parse(manifest_path)
365
-
366
- # Register declared keywords/operators with the lexer.
367
- if manifest.capabilities.keywords:
368
- register_keywords(manifest.capabilities.keywords)
369
- if manifest.capabilities.operators:
370
- register_operators(manifest.capabilities.operators)
371
-
372
- # Register manifest
373
- manifest_registry.register(manifest)
374
-
375
- # Lexer + parser hooks must be available before lexing/parsing the
376
- # source file. Remaining stages load lazily when the package is
377
- # actually imported (see semantic analysis).
378
- parser_phase = manifest.extensions.parser_phase_hooks()
379
- if parser_phase:
380
- HookLoader.load_hooks_from_package(
381
- package_name,
382
- version_dir,
383
- parser_phase,
384
- get_global_hook_registry(),
385
- CompilerContext(data={"package_dir": version_dir}),
386
- )
363
+ manifest_path = os.path.join(version_dir, "package.json")
364
+ if not os.path.exists(manifest_path):
365
+ continue
387
366
 
388
- except Exception as e:
389
- if get_global_hook_registry().strict:
390
- raise
391
- ui.print_warn(f"Failed to load package manifest for '{package_name}': {e}")
367
+ try:
368
+ manifest = ManifestParser.validate_and_parse(manifest_path)
369
+ if manifest_registry.is_loaded(manifest.name):
370
+ continue
371
+
372
+ # Register declared keywords/operators with the lexer.
373
+ if manifest.capabilities.keywords:
374
+ register_keywords(manifest.capabilities.keywords)
375
+ if manifest.capabilities.operators:
376
+ register_operators(manifest.capabilities.operators)
377
+
378
+ manifest_registry.register(manifest)
379
+
380
+ # Lexer + parser hooks must be available before lexing/parsing
381
+ # the source. Remaining stages load lazily at import time.
382
+ parser_phase = manifest.extensions.parser_phase_hooks()
383
+ if parser_phase:
384
+ HookLoader.load_hooks_from_package(
385
+ manifest.name,
386
+ version_dir,
387
+ parser_phase,
388
+ get_global_hook_registry(),
389
+ CompilerContext(data={"package_dir": version_dir}),
390
+ )
391
+
392
+ except Exception as e:
393
+ if get_global_hook_registry().strict:
394
+ raise
395
+ ui.print_warn(
396
+ f"Failed to load package manifest for '{base_name}': {e}"
397
+ )
392
398
 
393
399
  # Feed hook-declared keywords/operators to the lexer.
394
400
  _sync_lexer_hooks()