cpyte 4.7.2__tar.gz → 4.7.4__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.
- {cpyte-4.7.2/source/cpyte.egg-info → cpyte-4.7.4}/PKG-INFO +1 -1
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/__init__.py +1 -1
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/astparse.py +3 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/bytecoding.py +88 -1
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/semantic_analasis.py +6 -3
- {cpyte-4.7.2 → cpyte-4.7.4/source/cpyte.egg-info}/PKG-INFO +1 -1
- {cpyte-4.7.2 → cpyte-4.7.4}/test/test_compiler_regressions.py +6 -6
- {cpyte-4.7.2 → cpyte-4.7.4}/MANIFEST.in +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/pyproject.toml +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/readme.md +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/setup.cfg +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/__main__.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/_bignum_bc.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/_runtime_bc.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/bignum.c +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/bignum_protos.h +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/clib.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/compiling.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/elf2sef.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/extension_hooks.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/floats_runtime.c +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/formatter.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/gc_runtime.c +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/gc_runtime_addition.c +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/generate_bc.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/lexar.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/linker.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/lsp_server.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/mainpie.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/mksef.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/opreof_opt.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/opreof_pipeline.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/optimizations.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/package_manifest.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/runpy_runtime.c +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/runtime.c +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/runtime_scorpion.c +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/scorpion_abi.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/sef.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/ugc.h +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/ui.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/update_check.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/winjit_patch.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte/winjit_stubs.c +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte.egg-info/SOURCES.txt +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte.egg-info/dependency_links.txt +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte.egg-info/entry_points.txt +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte.egg-info/requires.txt +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/source/cpyte.egg-info/top_level.txt +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/test/test_bignum_jit.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/test/test_fuzz_del_has.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/test/test_opreof_proofs.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/test/test_scorpion_abi.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/test/test_scorpion_dl.py +0 -0
- {cpyte-4.7.2 → cpyte-4.7.4}/test/test_sef_tools.py +0 -0
|
@@ -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)
|
|
@@ -1583,7 +1583,10 @@ class SemanticAnalyzer:
|
|
|
1583
1583
|
# Bitwise operations are unsupported for signed `big` but are
|
|
1584
1584
|
# provided for unsigned `ubig` (which has no sign bit), so
|
|
1585
1585
|
# AND/OR/XOR/shift operate over the full magnitude.
|
|
1586
|
-
|
|
1586
|
+
# Narrow unsigned words (uint8/16/32) lower to i8/i16/i32
|
|
1587
|
+
# and are every bit as valid for bitwise ops as `int`;
|
|
1588
|
+
# excluding them made `uint32 a = x ^ y` a false E0001.
|
|
1589
|
+
valid_int_types = self._INT_TYPES + ("ubig",)
|
|
1587
1590
|
if left_t == "big" or right_t == "big":
|
|
1588
1591
|
self.error(
|
|
1589
1592
|
f"bitwise operator `{node.op.name}` not supported for `big` operands",
|
|
@@ -1610,7 +1613,7 @@ class SemanticAnalyzer:
|
|
|
1610
1613
|
node.inferred_type = "int"
|
|
1611
1614
|
return "int"
|
|
1612
1615
|
# PERCENT
|
|
1613
|
-
valid_int_types =
|
|
1616
|
+
valid_int_types = self._INT_TYPES + ("big", "ubig")
|
|
1614
1617
|
if (left_t is not None and left_t not in valid_int_types) or (
|
|
1615
1618
|
right_t is not None and right_t not in valid_int_types
|
|
1616
1619
|
):
|
|
@@ -1761,7 +1764,7 @@ class SemanticAnalyzer:
|
|
|
1761
1764
|
note="unary minus expects numeric type",
|
|
1762
1765
|
)
|
|
1763
1766
|
if node.op.name == "TILDE":
|
|
1764
|
-
valid_types =
|
|
1767
|
+
valid_types = self._INT_TYPES
|
|
1765
1768
|
if operand_t is not None and operand_t not in valid_types:
|
|
1766
1769
|
self.error(
|
|
1767
1770
|
f"bitwise NOT (`~`) not supported for `{operand_t}`",
|
|
@@ -191,8 +191,8 @@ def test_global_cpm_import_resolves_without_workspace():
|
|
|
191
191
|
)
|
|
192
192
|
|
|
193
193
|
source = (
|
|
194
|
-
'import
|
|
195
|
-
'import
|
|
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
|
|
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;
|
|
244
|
-
#
|
|
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
|
|
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
|
|
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
|