cpyte 4.7.0__tar.gz → 4.7.2__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.2}/PKG-INFO +25 -17
  2. {cpyte-4.7.0 → cpyte-4.7.2}/readme.md +24 -16
  3. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/__init__.py +1 -1
  4. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/astparse.py +25 -9
  5. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/bytecoding.py +29 -9
  6. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/compiling.py +124 -22
  7. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/formatter.py +15 -9
  8. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/gc_runtime_addition.c +6 -6
  9. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/lsp_server.py +9 -5
  10. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/mainpie.py +50 -44
  11. cpyte-4.7.2/source/cpyte/opreof_opt.py +141 -0
  12. cpyte-4.7.2/source/cpyte/opreof_pipeline.py +429 -0
  13. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/package_manifest.py +35 -1
  14. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/runpy_runtime.c +24 -24
  15. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/semantic_analasis.py +208 -104
  16. {cpyte-4.7.0 → cpyte-4.7.2/source/cpyte.egg-info}/PKG-INFO +25 -17
  17. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte.egg-info/SOURCES.txt +3 -0
  18. {cpyte-4.7.0 → cpyte-4.7.2}/test/test_compiler_regressions.py +223 -1
  19. cpyte-4.7.2/test/test_opreof_proofs.py +274 -0
  20. {cpyte-4.7.0 → cpyte-4.7.2}/MANIFEST.in +0 -0
  21. {cpyte-4.7.0 → cpyte-4.7.2}/pyproject.toml +0 -0
  22. {cpyte-4.7.0 → cpyte-4.7.2}/setup.cfg +0 -0
  23. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/__main__.py +0 -0
  24. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/_bignum_bc.py +0 -0
  25. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/_runtime_bc.py +0 -0
  26. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/bignum.c +0 -0
  27. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/bignum_protos.h +0 -0
  28. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/clib.py +0 -0
  29. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/elf2sef.py +0 -0
  30. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/extension_hooks.py +0 -0
  31. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/floats_runtime.c +0 -0
  32. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/gc_runtime.c +0 -0
  33. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/generate_bc.py +0 -0
  34. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/lexar.py +0 -0
  35. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/linker.py +0 -0
  36. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/mksef.py +0 -0
  37. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/optimizations.py +0 -0
  38. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/runtime.c +0 -0
  39. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/runtime_scorpion.c +0 -0
  40. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/scorpion_abi.py +0 -0
  41. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/sef.py +0 -0
  42. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/ugc.h +0 -0
  43. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/ui.py +0 -0
  44. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/update_check.py +0 -0
  45. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/winjit_patch.py +0 -0
  46. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte/winjit_stubs.c +0 -0
  47. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte.egg-info/dependency_links.txt +0 -0
  48. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte.egg-info/entry_points.txt +0 -0
  49. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte.egg-info/requires.txt +0 -0
  50. {cpyte-4.7.0 → cpyte-4.7.2}/source/cpyte.egg-info/top_level.txt +0 -0
  51. {cpyte-4.7.0 → cpyte-4.7.2}/test/test_bignum_jit.py +0 -0
  52. {cpyte-4.7.0 → cpyte-4.7.2}/test/test_fuzz_del_has.py +0 -0
  53. {cpyte-4.7.0 → cpyte-4.7.2}/test/test_scorpion_abi.py +0 -0
  54. {cpyte-4.7.0 → cpyte-4.7.2}/test/test_scorpion_dl.py +0 -0
  55. {cpyte-4.7.0 → cpyte-4.7.2}/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.2
4
4
  Summary: The Cpyte programming language compiler
5
5
  Author: Hoang Duy Tung
6
6
  License: MIT
@@ -44,8 +44,16 @@ See `examples/example_package/` for a complete example package with:
44
44
 
45
45
  ### Using Extension Packages
46
46
 
47
+ **Canonical import style (preferred):**
47
48
  ```cpy
48
- import @package_name
49
+ import std.collections
50
+ import std.collections.hash_map
51
+ ```
52
+
53
+ Legacy `@...` imports (e.g. `import "@std/collections/hash_map"`) are still accepted for backward compatibility but are deprecated; `cpy format` rewrites them to the canonical dotted form.
54
+
55
+ ```cpy
56
+ import std.your_package
49
57
 
50
58
  # Use custom keywords and syntax from the package
51
59
  async def my_function() -> Promise:
@@ -108,24 +116,24 @@ measurement from any historical benchmark results and is collected on the
108
116
  dedicated benchmark runner.
109
117
 
110
118
  <!-- CPYTE_CI_BENCHMARKS_START -->
111
- Latest run: [ecd3510c0342](https://github.com/Cpyte/Cpyte/actions/runs/42362272944) · updated 2026-11-07 10:12 UTC
119
+ Latest run: [1d3eae11d67d](https://github.com/Cpyte/Cpyte/actions/runs/43207132063) · updated 2026-11-15 09:45 UTC
112
120
 
113
121
  | Benchmark | C | Cpy | Python | Cpy/C | Python/C |
114
122
  |---|---:|---:|---:|---:|---:|
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 |
123
+ | `array_sum` | 6.47ms | 6.38ms | 247.94ms | 0.99x | 38.30x |
124
+ | `bitwise_mix` | 2.58ms | 2.69ms | 698.18ms | 1.04x | 270.82x |
125
+ | `branch_mix` | 4.11ms | 4.35ms | 445.52ms | 1.06x | 108.32x |
126
+ | `call_overhead` | 2.58ms | 3.15ms | 344.81ms | 1.22x | 133.65x |
127
+ | `fib_iterative` | 16.47ms | 16.60ms | 11.184s | 1.01x | 679.05x |
128
+ | `fib_recursive` | 163.17ms | 832.00us | 7.292s | 0.01x | 44.69x |
129
+ | `float_math` | 5.76ms | 5.89ms | 256.63ms | 1.02x | 44.58x |
130
+ | `integer_mix` | 3.23ms | 3.15ms | 394.71ms | 0.98x | 122.35x |
131
+ | `loop_sum` | 685.00us | 768.00us | 2.797s | 1.12x | 4082.65x |
132
+ | `matrix_mult` | 3.81ms | 3.77ms | 1.784s | 0.99x | 468.44x |
133
+ | `mem_alloc` | 671.00us | 751.00us | 16.96ms | 1.12x | 25.27x |
134
+ | `prime_count` | 66.63ms | 77.80ms | 1.812s | 1.17x | 27.19x |
135
+ | `quicksort` | 1.86ms | 2.28ms | 29.36ms | 1.23x | 15.80x |
136
+ | `string_concat` | 741.00us | 810.00us | 25.71ms | 1.09x | 34.70x |
129
137
 
130
138
  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
139
  <!-- CPYTE_CI_BENCHMARKS_END -->
@@ -32,8 +32,16 @@ See `examples/example_package/` for a complete example package with:
32
32
 
33
33
  ### Using Extension Packages
34
34
 
35
+ **Canonical import style (preferred):**
35
36
  ```cpy
36
- import @package_name
37
+ import std.collections
38
+ import std.collections.hash_map
39
+ ```
40
+
41
+ Legacy `@...` imports (e.g. `import "@std/collections/hash_map"`) are still accepted for backward compatibility but are deprecated; `cpy format` rewrites them to the canonical dotted form.
42
+
43
+ ```cpy
44
+ import std.your_package
37
45
 
38
46
  # Use custom keywords and syntax from the package
39
47
  async def my_function() -> Promise:
@@ -96,24 +104,24 @@ measurement from any historical benchmark results and is collected on the
96
104
  dedicated benchmark runner.
97
105
 
98
106
  <!-- CPYTE_CI_BENCHMARKS_START -->
99
- Latest run: [ecd3510c0342](https://github.com/Cpyte/Cpyte/actions/runs/42362272944) · updated 2026-11-07 10:12 UTC
107
+ Latest run: [1d3eae11d67d](https://github.com/Cpyte/Cpyte/actions/runs/43207132063) · updated 2026-11-15 09:45 UTC
100
108
 
101
109
  | Benchmark | C | Cpy | Python | Cpy/C | Python/C |
102
110
  |---|---:|---:|---:|---:|---:|
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 |
111
+ | `array_sum` | 6.47ms | 6.38ms | 247.94ms | 0.99x | 38.30x |
112
+ | `bitwise_mix` | 2.58ms | 2.69ms | 698.18ms | 1.04x | 270.82x |
113
+ | `branch_mix` | 4.11ms | 4.35ms | 445.52ms | 1.06x | 108.32x |
114
+ | `call_overhead` | 2.58ms | 3.15ms | 344.81ms | 1.22x | 133.65x |
115
+ | `fib_iterative` | 16.47ms | 16.60ms | 11.184s | 1.01x | 679.05x |
116
+ | `fib_recursive` | 163.17ms | 832.00us | 7.292s | 0.01x | 44.69x |
117
+ | `float_math` | 5.76ms | 5.89ms | 256.63ms | 1.02x | 44.58x |
118
+ | `integer_mix` | 3.23ms | 3.15ms | 394.71ms | 0.98x | 122.35x |
119
+ | `loop_sum` | 685.00us | 768.00us | 2.797s | 1.12x | 4082.65x |
120
+ | `matrix_mult` | 3.81ms | 3.77ms | 1.784s | 0.99x | 468.44x |
121
+ | `mem_alloc` | 671.00us | 751.00us | 16.96ms | 1.12x | 25.27x |
122
+ | `prime_count` | 66.63ms | 77.80ms | 1.812s | 1.17x | 27.19x |
123
+ | `quicksort` | 1.86ms | 2.28ms | 29.36ms | 1.23x | 15.80x |
124
+ | `string_concat` | 741.00us | 810.00us | 25.71ms | 1.09x | 34.70x |
117
125
 
118
126
  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
127
  <!-- CPYTE_CI_BENCHMARKS_END -->
@@ -1,4 +1,4 @@
1
- __version__ = "4.7.0"
1
+ __version__ = "4.7.2"
2
2
 
3
3
  # ---------------------------------------------------------------------------
4
4
  # Public library API.
@@ -478,9 +478,7 @@ def _parse_ternary(tokens: list[Token], pos: int):
478
478
  then, pos = _parse_ternary(tokens, pos)
479
479
  pos = _skip_expr_newlines(tokens, pos)
480
480
  if pos >= len(tokens) or tokens[pos].type != TokenType.COLON:
481
- raise TernaryParseError(
482
- 'Expected ":" in conditional expression', tok
483
- )
481
+ raise TernaryParseError('Expected ":" in conditional expression', tok)
484
482
  pos += 1
485
483
  pos = _skip_expr_newlines(tokens, pos)
486
484
  orelse, pos = _parse_ternary(tokens, pos)
@@ -529,9 +527,16 @@ def _parse_binary(tokens: list[Token], pos: int, min_prec: int):
529
527
  TokenType.DEDENT,
530
528
  ):
531
529
  pos += 1
532
- next_prec = _prec(op) if op.type != TokenType.KEYWORD else IN_PREC + 1
533
- if op.type == TokenType.POW:
530
+ # `**` is the one right-associative operator (2 ** 3 ** 2 is
531
+ # 2 ** (3 ** 2)); everything else binds left, which means parsing
532
+ # the right-hand side one level tighter so `a - b + c` folds to
533
+ # `(a - b) + c` rather than `a - (b + c)`.
534
+ if op.type == TokenType.KEYWORD:
535
+ next_prec = IN_PREC + 1
536
+ elif op.type == TokenType.POW:
534
537
  next_prec = _prec(op)
538
+ else:
539
+ next_prec = _prec(op) + 1
535
540
  right, pos = _parse_binary(tokens, pos, next_prec)
536
541
  left = BinOp(left, op.type, right, token=op)
537
542
 
@@ -1307,8 +1312,6 @@ def parse_file(tokens: list[Token], pos: int = 0, enable_extensions: bool = True
1307
1312
  if pos >= len(tokens) or tokens[pos].type in (TokenType.EOF, TokenType.DEDENT):
1308
1313
  break
1309
1314
 
1310
- tok = tokens[pos]
1311
-
1312
1315
  all_hooks = _get_all_parser_hooks(enable_extensions)
1313
1316
  if all_hooks:
1314
1317
  ctx = _make_parser_ctx(tokens, pos)
@@ -2029,8 +2032,22 @@ def parse_import(tokens: list[Token], pos: int):
2029
2032
  return node, pos
2030
2033
  elif t.type == TokenType.IDENTIFIER:
2031
2034
  assert t.value is not None
2032
- module = t.value
2035
+ first = t.value
2033
2036
  pos += 1
2037
+ parts = [first]
2038
+ # Allow dotted form: group.pkg.sub or pkg.sub or std.collections.hash_map
2039
+ while pos < len(tokens) and tokens[pos].type == TokenType.DOT:
2040
+ # look ahead: dot followed by identifier
2041
+ if pos + 1 >= len(tokens) or tokens[pos + 1].type != TokenType.IDENTIFIER:
2042
+ break
2043
+ pos += 1 # consume dot
2044
+ part = tokens[pos].value
2045
+ assert part is not None
2046
+ parts.append(part)
2047
+ pos += 1
2048
+ # Also allow slash form in the same token stream? probably not common now
2049
+ module = ".".join(parts)
2050
+ node = Import(module, token=tok)
2034
2051
  else:
2035
2052
  raise ParseError("Expected module name or quoted header path", t)
2036
2053
 
@@ -3411,7 +3428,6 @@ def parse_switch(tokens: list[Token], pos: int):
3411
3428
  TokenType.EOF,
3412
3429
  ):
3413
3430
  if tokens[pos].type == TokenType.KEYWORD and tokens[pos].value == "case":
3414
- tok2 = tokens[pos]
3415
3431
  pos += 1
3416
3432
  case_val, pos = parse_expression(tokens, pos)
3417
3433
  if pos >= len(tokens) or tokens[pos].type != TokenType.COLON:
@@ -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
 
@@ -1,3 +1,4 @@
1
+ import re as _re
1
2
  from dataclasses import dataclass, field
2
3
 
3
4
  from . import astparse
@@ -80,6 +81,8 @@ def _escape_string(value: str) -> str:
80
81
  return '"' + "".join(_STRING_ESCAPES.get(ch, ch) for ch in value) + '"'
81
82
 
82
83
 
84
+ _IDENT_RE = _re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
85
+
83
86
  def _char_text(code: int) -> str:
84
87
  ch = chr(code & 0xFF)
85
88
  return "'" + _STRING_ESCAPES.get(ch, ch) + "'"
@@ -395,11 +398,19 @@ class _Formatter:
395
398
  def _emit_import(self, node, level: int):
396
399
  module = node.module
397
400
  if module.startswith("@"):
398
- text = f"import @{module[1:].replace('/', '.')}"
399
- elif _IDENT_RE.match(module):
400
- text = f"import {module}"
401
+ # canonical: strip '@' and turn '/' into '.'
402
+ canon = module[1:].replace("/", ".")
403
+ text = f"import {canon}"
401
404
  else:
402
- text = f"import {_escape_string(module)}"
405
+ # already in dotted or other form
406
+ if _IDENT_RE.match(module):
407
+ text = f"import {module}"
408
+ else:
409
+ # could be "a.b.c"
410
+ if all(_IDENT_RE.match(p) for p in module.split(".") if p):
411
+ text = f"import {module}"
412
+ else:
413
+ text = f"import {_escape_string(module)}"
403
414
  if getattr(node, "sdk_path", None):
404
415
  text += f" sdk({_escape_string(node.sdk_path)})"
405
416
  self._emit_simple(node, text, level)
@@ -564,11 +575,6 @@ class _Formatter:
564
575
  self._emit_simple(node, text + ")", level)
565
576
 
566
577
 
567
- import re as _re
568
-
569
- _IDENT_RE = _re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
570
-
571
-
572
578
  def _need_parens(child, parent_op, is_right: bool) -> bool:
573
579
  if not isinstance(child, astparse.BinOp):
574
580
  return False
@@ -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: