cpyte 4.7.2__tar.gz → 4.7.3__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.2/source/cpyte.egg-info → cpyte-4.7.3}/PKG-INFO +1 -1
  2. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/__init__.py +1 -1
  3. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/astparse.py +3 -0
  4. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/bytecoding.py +88 -1
  5. {cpyte-4.7.2 → cpyte-4.7.3/source/cpyte.egg-info}/PKG-INFO +1 -1
  6. {cpyte-4.7.2 → cpyte-4.7.3}/test/test_compiler_regressions.py +6 -6
  7. {cpyte-4.7.2 → cpyte-4.7.3}/MANIFEST.in +0 -0
  8. {cpyte-4.7.2 → cpyte-4.7.3}/pyproject.toml +0 -0
  9. {cpyte-4.7.2 → cpyte-4.7.3}/readme.md +0 -0
  10. {cpyte-4.7.2 → cpyte-4.7.3}/setup.cfg +0 -0
  11. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/__main__.py +0 -0
  12. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/_bignum_bc.py +0 -0
  13. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/_runtime_bc.py +0 -0
  14. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/bignum.c +0 -0
  15. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/bignum_protos.h +0 -0
  16. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/clib.py +0 -0
  17. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/compiling.py +0 -0
  18. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/elf2sef.py +0 -0
  19. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/extension_hooks.py +0 -0
  20. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/floats_runtime.c +0 -0
  21. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/formatter.py +0 -0
  22. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/gc_runtime.c +0 -0
  23. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/gc_runtime_addition.c +0 -0
  24. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/generate_bc.py +0 -0
  25. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/lexar.py +0 -0
  26. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/linker.py +0 -0
  27. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/lsp_server.py +0 -0
  28. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/mainpie.py +0 -0
  29. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/mksef.py +0 -0
  30. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/opreof_opt.py +0 -0
  31. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/opreof_pipeline.py +0 -0
  32. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/optimizations.py +0 -0
  33. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/package_manifest.py +0 -0
  34. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/runpy_runtime.c +0 -0
  35. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/runtime.c +0 -0
  36. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/runtime_scorpion.c +0 -0
  37. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/scorpion_abi.py +0 -0
  38. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/sef.py +0 -0
  39. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/semantic_analasis.py +0 -0
  40. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/ugc.h +0 -0
  41. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/ui.py +0 -0
  42. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/update_check.py +0 -0
  43. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/winjit_patch.py +0 -0
  44. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte/winjit_stubs.c +0 -0
  45. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte.egg-info/SOURCES.txt +0 -0
  46. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte.egg-info/dependency_links.txt +0 -0
  47. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte.egg-info/entry_points.txt +0 -0
  48. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte.egg-info/requires.txt +0 -0
  49. {cpyte-4.7.2 → cpyte-4.7.3}/source/cpyte.egg-info/top_level.txt +0 -0
  50. {cpyte-4.7.2 → cpyte-4.7.3}/test/test_bignum_jit.py +0 -0
  51. {cpyte-4.7.2 → cpyte-4.7.3}/test/test_fuzz_del_has.py +0 -0
  52. {cpyte-4.7.2 → cpyte-4.7.3}/test/test_opreof_proofs.py +0 -0
  53. {cpyte-4.7.2 → cpyte-4.7.3}/test/test_scorpion_abi.py +0 -0
  54. {cpyte-4.7.2 → cpyte-4.7.3}/test/test_scorpion_dl.py +0 -0
  55. {cpyte-4.7.2 → cpyte-4.7.3}/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.2
3
+ Version: 4.7.3
4
4
  Summary: The Cpyte programming language compiler
5
5
  Author: Hoang Duy Tung
6
6
  License: MIT
@@ -1,4 +1,4 @@
1
- __version__ = "4.7.2"
1
+ __version__ = "4.7.3"
2
2
 
3
3
  # ---------------------------------------------------------------------------
4
4
  # Public library API.
@@ -2926,6 +2926,9 @@ def parse_suite(tokens: list[Token], pos: int):
2926
2926
 
2927
2927
  _TYPE_NAMES = {
2928
2928
  "int",
2929
+ "uint8",
2930
+ "uint16",
2931
+ "uint32",
2929
2932
  "int64",
2930
2933
  "uint64",
2931
2934
  "float",
@@ -929,6 +929,13 @@ class LLVM:
929
929
  self.global_vars = {}
930
930
  # Constant Variable store here.
931
931
  self.const_vars = {}
932
+ # Top-level constants are evaluated in a private init function BEFORE
933
+ # user function bodies are emitted, so references to them inside those
934
+ # functions resolve (see `emit_program`). `_global_const_init` marks
935
+ # that pre-pass so runtime-valued constants lower to module globals
936
+ # instead of allocas local to the init function.
937
+ self._const_init_fn = None
938
+ self._global_const_init = False
932
939
  self.locals = {}
933
940
  self.local_types = {}
934
941
  self.string_id = 0
@@ -1845,6 +1852,64 @@ class LLVM:
1845
1852
  _collect_ccodes(toplevel)
1846
1853
  _collect_ccodes(funcdefs)
1847
1854
 
1855
+ # ---- Global constants must exist BEFORE function bodies ----
1856
+ # Top-level statements are normally lowered into `main` *after* every
1857
+ # function body has been emitted, so a global `int (X) = 5` used inside
1858
+ # a function used to hit `Undefined variable 'X' at codegen`. Evaluate
1859
+ # top-level constant declarations in a private initializer function
1860
+ # first; simple literal constants become compile-time `ir.Constant`
1861
+ # values (no runtime code at all), while runtime-valued constants are
1862
+ # lowered to module globals by `emit_vardecl`'s `_global_const_init`
1863
+ # branch. The init function is called at the start of `main`.
1864
+ const_decls = [
1865
+ n
1866
+ for n in toplevel
1867
+ if isinstance(n, VarDecl) and getattr(n, "is_const", False)
1868
+ ]
1869
+ if const_decls:
1870
+ # A constant initializer may call a user function; declare those
1871
+ # headers now (normally they are created with their bodies below).
1872
+ # Names already bound (runtime builtins, imported C functions) are
1873
+ # left alone so the existing collision checks still fire.
1874
+ for fn_node in funcdefs:
1875
+ fname = getattr(fn_node, "name", None)
1876
+ if (
1877
+ not fname
1878
+ or fname == "main"
1879
+ or fname in self.functions
1880
+ or getattr(fn_node, "decorators", None)
1881
+ ):
1882
+ continue
1883
+ try:
1884
+ fret = self.llvm_type(fn_node.rettype or "int")
1885
+ fparams = [self.llvm_type(t) for t in fn_node.params.values()]
1886
+ except Exception:
1887
+ continue
1888
+ self.functions[fname] = ir.Function(
1889
+ self.module, ir.FunctionType(fret, fparams), name=fname
1890
+ )
1891
+ init_fn = ir.Function(
1892
+ self.module,
1893
+ ir.FunctionType(ir.VoidType(), []),
1894
+ name="__cpyte_const_init",
1895
+ )
1896
+ init_entry = init_fn.append_basic_block("entry")
1897
+ saved_builder = self.builder
1898
+ saved_global_const_init = self._global_const_init
1899
+ self.builder = ir.IRBuilder(init_entry)
1900
+ self._global_const_init = True
1901
+ try:
1902
+ for node in const_decls:
1903
+ self.emit(node)
1904
+ finally:
1905
+ if init_entry.terminator is None:
1906
+ self.builder.ret_void()
1907
+ self._global_const_init = saved_global_const_init
1908
+ self.builder = saved_builder
1909
+ self._const_init_fn = init_fn
1910
+ const_ids = {id(n) for n in const_decls}
1911
+ toplevel = [n for n in toplevel if id(n) not in const_ids]
1912
+
1848
1913
  user_main = None
1849
1914
  for node in funcdefs:
1850
1915
  if getattr(node, "name", None) == "main":
@@ -1876,6 +1941,8 @@ class LLVM:
1876
1941
  gc_start_fn = self.functions.get("gc_start_thread")
1877
1942
  if gc_start_fn:
1878
1943
  self.builder.call(gc_start_fn, [])
1944
+ if self._const_init_fn is not None:
1945
+ self.builder.call(self._const_init_fn, [])
1879
1946
  for node in toplevel:
1880
1947
  self.emit(node)
1881
1948
  if not self.no_gc:
@@ -3446,6 +3513,12 @@ class LLVM:
3446
3513
  if gc_start_fn:
3447
3514
  self.builder.call(gc_start_fn, [])
3448
3515
 
3516
+ # Runtime-valued top-level constants live in module globals; initialize
3517
+ # them before any user statement (including original top-level code
3518
+ # prepended to main) runs.
3519
+ if node.name == "main" and self._const_init_fn is not None:
3520
+ self.builder.call(self._const_init_fn, [])
3521
+
3449
3522
  old_locals = self.locals
3450
3523
  old_local_types = self.local_types
3451
3524
  old_ssa = self.ssa_values
@@ -8262,7 +8335,21 @@ class LLVM:
8262
8335
  value = self._extend_to_i64(
8263
8336
  value, self._is_unsigned_node(node.init)
8264
8337
  )
8265
- if isinstance(value, ir.Constant):
8338
+ if self._global_const_init and not isinstance(value, ir.Constant):
8339
+ # Top-level constant with a runtime-valued initializer:
8340
+ # an alloca in the private init function would go out of
8341
+ # scope, so use a module-level global. `emit_variable`
8342
+ # loads through the registered const pointer.
8343
+ gv = ir.GlobalVariable(
8344
+ self.module,
8345
+ value.type,
8346
+ name=f"__const_{node.name}",
8347
+ )
8348
+ gv.initializer = ir.Constant(value.type, None)
8349
+ self.builder.store(value, gv)
8350
+ self.global_vars[node.name] = gv
8351
+ self._declare_const(node.name, gv)
8352
+ elif isinstance(value, ir.Constant):
8266
8353
  self._declare_const(node.name, value)
8267
8354
  else:
8268
8355
  ptr = self._alloca(ty, name=node.name)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cpyte
3
- Version: 4.7.2
3
+ Version: 4.7.3
4
4
  Summary: The Cpyte programming language compiler
5
5
  Author: Hoang Duy Tung
6
6
  License: MIT
@@ -191,8 +191,8 @@ def test_global_cpm_import_resolves_without_workspace():
191
191
  )
192
192
 
193
193
  source = (
194
- 'import "@std/demo"\n'
195
- 'import "@std/extonly"\n'
194
+ 'import std.demo\n'
195
+ 'import std.extonly\n'
196
196
  'import "plain"\n'
197
197
  "public def main() -> int:\n"
198
198
  " return demo_value() + plain_value()\n"
@@ -225,7 +225,7 @@ def test_workspace_cpm_package_wins_over_global_and_dot_form_imports():
225
225
  )
226
226
 
227
227
  source = (
228
- 'import "@std.demo"\n'
228
+ 'import std.demo\n'
229
229
  "public def main() -> int:\n"
230
230
  " return local_demo()\n"
231
231
  )
@@ -240,10 +240,10 @@ def test_workspace_cpm_package_wins_over_global_and_dot_form_imports():
240
240
 
241
241
 
242
242
  def test_deep_std_extension_import_is_still_skipped():
243
- # `@std.<pkg>.<sub>` is resolved at runtime; it must not be reported as a
244
- # missing CPM package, unlike the two-segment `@std.<pkg>` package form.
243
+ # `std.<pkg>.<sub>` (and legacy `@std.<pkg>.<sub>`) is resolved at runtime;
244
+ # it must not be reported as a missing CPM package.
245
245
  parse_and_analyze(
246
- 'import "@std.math.foo"\npublic def main() -> int:\n return 0\n',
246
+ 'import std.math.foo\npublic def main() -> int:\n return 0\n',
247
247
  enable_extensions=False,
248
248
  )
249
249
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes