cpyte 4.6.3__tar.gz → 4.6.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.
Files changed (51) hide show
  1. {cpyte-4.6.3/source/cpyte.egg-info → cpyte-4.6.4}/PKG-INFO +1 -1
  2. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/__init__.py +1 -1
  3. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/bytecoding.py +20 -2
  4. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/gc_runtime.c +35 -4
  5. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/lsp_server.py +78 -20
  6. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/semantic_analasis.py +18 -5
  7. {cpyte-4.6.3 → cpyte-4.6.4/source/cpyte.egg-info}/PKG-INFO +1 -1
  8. {cpyte-4.6.3 → cpyte-4.6.4}/MANIFEST.in +0 -0
  9. {cpyte-4.6.3 → cpyte-4.6.4}/pyproject.toml +0 -0
  10. {cpyte-4.6.3 → cpyte-4.6.4}/readme.md +0 -0
  11. {cpyte-4.6.3 → cpyte-4.6.4}/setup.cfg +0 -0
  12. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/__main__.py +0 -0
  13. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/_bignum_bc.py +0 -0
  14. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/_runtime_bc.py +0 -0
  15. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/astparse.py +0 -0
  16. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/bignum.c +0 -0
  17. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/bignum_protos.h +0 -0
  18. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/clib.py +0 -0
  19. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/compiling.py +0 -0
  20. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/elf2sef.py +0 -0
  21. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/extension_hooks.py +0 -0
  22. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/floats_runtime.c +0 -0
  23. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/formatter.py +0 -0
  24. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/generate_bc.py +0 -0
  25. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/lexar.py +0 -0
  26. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/linker.py +0 -0
  27. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/mainpie.py +0 -0
  28. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/mksef.py +0 -0
  29. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/optimizations.py +0 -0
  30. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/package_manifest.py +0 -0
  31. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/runpy_runtime.c +0 -0
  32. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/runtime.c +0 -0
  33. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/runtime_scorpion.c +0 -0
  34. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/scorpion_abi.py +0 -0
  35. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/sef.py +0 -0
  36. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/ugc.h +0 -0
  37. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/ui.py +0 -0
  38. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/update_check.py +0 -0
  39. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/winjit_patch.py +0 -0
  40. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte/winjit_stubs.c +0 -0
  41. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte.egg-info/SOURCES.txt +0 -0
  42. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte.egg-info/dependency_links.txt +0 -0
  43. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte.egg-info/entry_points.txt +0 -0
  44. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte.egg-info/requires.txt +0 -0
  45. {cpyte-4.6.3 → cpyte-4.6.4}/source/cpyte.egg-info/top_level.txt +0 -0
  46. {cpyte-4.6.3 → cpyte-4.6.4}/test/test_bignum_jit.py +0 -0
  47. {cpyte-4.6.3 → cpyte-4.6.4}/test/test_compiler_regressions.py +0 -0
  48. {cpyte-4.6.3 → cpyte-4.6.4}/test/test_fuzz_del_has.py +0 -0
  49. {cpyte-4.6.3 → cpyte-4.6.4}/test/test_scorpion_abi.py +0 -0
  50. {cpyte-4.6.3 → cpyte-4.6.4}/test/test_scorpion_dl.py +0 -0
  51. {cpyte-4.6.3 → cpyte-4.6.4}/test/test_sef_tools.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cpyte
3
- Version: 4.6.3
3
+ Version: 4.6.4
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.6.3"
1
+ __version__ = "4.6.4"
2
2
 
3
3
  # ---------------------------------------------------------------------------
4
4
  # Public library API.
@@ -825,6 +825,7 @@ class LLVM:
825
825
  self._malloc_fn = None
826
826
  self._free_fn = None
827
827
  self._gc_alloc_fn = None
828
+ self._gc_uninit_alloc_fn = None
828
829
  self._gc_write_barrier_fn = None
829
830
  self._sizeof_cache = {}
830
831
  self._llvm_type_cache = {} # (module tag, type name) -> ir.Type
@@ -1824,13 +1825,17 @@ class LLVM:
1824
1825
  def _concat_strings(self, left, right):
1825
1826
  """Concatenate two heap strings (i8*), returning a new heap string."""
1826
1827
  strlen_fn = self._get_strlen_fn()
1827
- malloc_fn = self._get_malloc_fn()
1828
+ alloc_fn = (
1829
+ self._get_malloc_fn()
1830
+ if self.no_gc
1831
+ else self._get_gc_uninit_alloc_fn()
1832
+ )
1828
1833
  memcpy_fn = self._get_memcpy_fn()
1829
1834
  left_len = self.builder.call(strlen_fn, [left])
1830
1835
  right_len = self.builder.call(strlen_fn, [right])
1831
1836
  total_len = self.builder.add(left_len, right_len)
1832
1837
  plus_one = self.builder.add(total_len, ir.Constant(total_len.type, 1))
1833
- new_str = self.builder.call(malloc_fn, [self.builder.zext(plus_one, _i64)])
1838
+ new_str = self.builder.call(alloc_fn, [self.builder.zext(plus_one, _i64)])
1834
1839
  self.builder.call(memcpy_fn, [new_str, left, left_len])
1835
1840
  dest_plus = self.builder.gep(new_str, [left_len], inbounds=True)
1836
1841
  self.builder.call(memcpy_fn, [dest_plus, right, right_len])
@@ -2684,6 +2689,19 @@ class LLVM:
2684
2689
  self._gc_alloc_fn = fn
2685
2690
  return fn
2686
2691
 
2692
+ def _get_gc_uninit_alloc_fn(self):
2693
+ fn = self._gc_uninit_alloc_fn
2694
+ if fn is not None:
2695
+ return fn
2696
+ for f in self.module.functions:
2697
+ if f.name == "gc_malloc_uninit":
2698
+ self._gc_uninit_alloc_fn = f
2699
+ return f
2700
+ fnty = ir.FunctionType(_i8ptr, [_i64])
2701
+ fn = ir.Function(self.module, fnty, "gc_malloc_uninit")
2702
+ self._gc_uninit_alloc_fn = fn
2703
+ return fn
2704
+
2687
2705
  def _get_write_barrier_fn(self):
2688
2706
  # Get the gc_write_barrier function for pointer stores between heap objects
2689
2707
  fn = self._gc_write_barrier_fn
@@ -106,6 +106,7 @@ void gc_trace(const char* what, size_t v) {
106
106
 
107
107
  #define TLAB_SIZE (64 * 1024) /* 64 KB per TLAB */
108
108
  #define TLAB_MAX_ALLOC (2 * 1024) /* Max size for TLAB fast path */
109
+ #define TLAB_STRING_SIZE (256 * 1024)
109
110
 
110
111
  typedef struct {
111
112
  char *start; /* Start of current TLAB */
@@ -143,13 +144,17 @@ static tlab_t* tlab_get(void) {
143
144
  # define TLAB_GET() tlab_get()
144
145
  #endif
145
146
 
146
- static void* tlab_alloc(size_t size) {
147
+ static void* tlab_alloc(size_t size, size_t min_block_size) {
148
+ if (size > SIZE_MAX - (sizeof(void*) - 1)) {
149
+ return NULL;
150
+ }
147
151
  /* Round up to pointer alignment */
148
152
  size = (size + sizeof(void*) - 1) & ~(sizeof(void*) - 1);
149
153
 
150
- if (TLAB_GET()->start == NULL || TLAB_GET()->current + size > TLAB_GET()->end) {
154
+ if (TLAB_GET()->start == NULL ||
155
+ (size_t)(TLAB_GET()->end - TLAB_GET()->current) < size) {
151
156
  /* TLAB exhausted or not initialized: allocate new block from global heap */
152
- size_t block_size = (size > TLAB_SIZE) ? size : TLAB_SIZE;
157
+ size_t block_size = (size > min_block_size) ? size : min_block_size;
153
158
 
154
159
  gc_lock_init();
155
160
  CPY_MUTEX_LOCK(&gc_lock_);
@@ -396,7 +401,7 @@ void gc_init(void) {
396
401
  void* gc_malloc(size_t size) {
397
402
  /* Try TLAB first for small allocations (fast path, lock-free) */
398
403
  if (size <= TLAB_MAX_ALLOC) {
399
- void *ptr = tlab_alloc(size);
404
+ void *ptr = tlab_alloc(size, TLAB_SIZE);
400
405
  if (ptr != NULL) {
401
406
  gc_alloc_bytes += size;
402
407
  if (gc_threshold != 0 && gc_alloc_bytes >= gc_threshold) {
@@ -442,6 +447,32 @@ void* gc_malloc(size_t size) {
442
447
  return TO_USER(obj);
443
448
  }
444
449
 
450
+ /*
451
+ * Allocate a buffer whose caller initializes every byte. String concatenation
452
+ * uses this path so larger results can share a thread-local arena instead of
453
+ * requiring a tracked GC object and global-lock acquisition per result.
454
+ */
455
+ void* gc_malloc_uninit(size_t size) {
456
+ if (size == 0) {
457
+ size = 1;
458
+ }
459
+
460
+ if (size <= TLAB_STRING_SIZE) {
461
+ size_t block_size = size <= TLAB_MAX_ALLOC
462
+ ? TLAB_SIZE
463
+ : TLAB_STRING_SIZE;
464
+ void* ptr = tlab_alloc(size, block_size);
465
+ if (ptr != NULL) {
466
+ gc_alloc_bytes += size;
467
+ if (gc_threshold != 0 && gc_alloc_bytes >= gc_threshold) {
468
+ gc_collect();
469
+ }
470
+ return ptr;
471
+ }
472
+ }
473
+ return gc_malloc(size);
474
+ }
475
+
445
476
  /* Write barrier: call on every pointer store between heap objects.
446
477
  * parent_ptr and child_ptr are the user-visible payload pointers. */
447
478
  void gc_write_barrier(void* parent_ptr, void* child_ptr) {
@@ -2442,7 +2442,9 @@ if __name__ == "__main__":
2442
2442
 
2443
2443
  @server.feature(lsp.TEXT_DOCUMENT_PREPARE_CALL_HIERARCHY)
2444
2444
  @server.thread()
2445
- def prepare_call_hierarchy(ls: CpyLanguageServer, params: lsp.CallHierarchyPrepareParams):
2445
+ def prepare_call_hierarchy(
2446
+ ls: CpyLanguageServer, params: lsp.CallHierarchyPrepareParams
2447
+ ):
2446
2448
  try:
2447
2449
  uri = params.text_document.uri
2448
2450
  line = params.position.line
@@ -2456,8 +2458,13 @@ def prepare_call_hierarchy(ls: CpyLanguageServer, params: lsp.CallHierarchyPrepa
2456
2458
  if isinstance(node, FuncDef) and node.name == word:
2457
2459
  tok_node = getattr(node, "_token", None) or tok
2458
2460
  rng = lsp.Range(
2459
- start=lsp.Position(line=tok_node.line - 1, character=tok_node.column - 1),
2460
- end=lsp.Position(line=tok_node.line - 1, character=tok_node.column - 1 + len(tok_node.value or "")),
2461
+ start=lsp.Position(
2462
+ line=tok_node.line - 1, character=tok_node.column - 1
2463
+ ),
2464
+ end=lsp.Position(
2465
+ line=tok_node.line - 1,
2466
+ character=tok_node.column - 1 + len(tok_node.value or ""),
2467
+ ),
2461
2468
  )
2462
2469
  return [
2463
2470
  lsp.CallHierarchyItem(
@@ -2485,16 +2492,33 @@ def incoming_calls(ls: CpyLanguageServer, params: lsp.CallHierarchyIncomingCalls
2485
2492
  for node in parsed:
2486
2493
  if isinstance(node, FuncDef):
2487
2494
  for call in _iter_calls_in_stmt(node):
2488
- if isinstance(call.callee, Variable) and call.callee.name == func_name:
2495
+ if (
2496
+ isinstance(call.callee, Variable)
2497
+ and call.callee.name == func_name
2498
+ ):
2489
2499
  tok = getattr(call.callee, "_token", None)
2490
2500
  if tok:
2491
2501
  rng = lsp.Range(
2492
- start=lsp.Position(line=tok.line - 1, character=tok.column - 1),
2493
- end=lsp.Position(line=tok.line - 1, character=tok.column - 1 + len(tok.value or "")),
2502
+ start=lsp.Position(
2503
+ line=tok.line - 1, character=tok.column - 1
2504
+ ),
2505
+ end=lsp.Position(
2506
+ line=tok.line - 1,
2507
+ character=tok.column - 1 + len(tok.value or ""),
2508
+ ),
2494
2509
  )
2495
2510
  ntrng = lsp.Range(
2496
- start=lsp.Position(line=(getattr(node, "_token") or tok).line - 1, character=(getattr(node, "_token") or tok).column - 1),
2497
- end=lsp.Position(line=(getattr(node, "_token") or tok).line - 1, character=(getattr(node, "_token") or tok).column - 1 + len(node.name)),
2511
+ start=lsp.Position(
2512
+ line=(getattr(node, "_token") or tok).line - 1,
2513
+ character=(getattr(node, "_token") or tok).column
2514
+ - 1,
2515
+ ),
2516
+ end=lsp.Position(
2517
+ line=(getattr(node, "_token") or tok).line - 1,
2518
+ character=(getattr(node, "_token") or tok).column
2519
+ - 1
2520
+ + len(node.name),
2521
+ ),
2498
2522
  )
2499
2523
  results.append(
2500
2524
  lsp.CallHierarchyIncomingCall(
@@ -2529,8 +2553,13 @@ def outgoing_calls(ls: CpyLanguageServer, params: lsp.CallHierarchyOutgoingCalls
2529
2553
  tok = getattr(call.callee, "_token", None)
2530
2554
  if tok:
2531
2555
  rng = lsp.Range(
2532
- start=lsp.Position(line=tok.line - 1, character=tok.column - 1),
2533
- end=lsp.Position(line=tok.line - 1, character=tok.column - 1 + len(tok.value or "")),
2556
+ start=lsp.Position(
2557
+ line=tok.line - 1, character=tok.column - 1
2558
+ ),
2559
+ end=lsp.Position(
2560
+ line=tok.line - 1,
2561
+ character=tok.column - 1 + len(tok.value or ""),
2562
+ ),
2534
2563
  )
2535
2564
  results.append(
2536
2565
  lsp.CallHierarchyOutgoingCall(
@@ -2552,7 +2581,9 @@ def outgoing_calls(ls: CpyLanguageServer, params: lsp.CallHierarchyOutgoingCalls
2552
2581
 
2553
2582
  @server.feature(lsp.TEXT_DOCUMENT_PREPARE_TYPE_HIERARCHY)
2554
2583
  @server.thread()
2555
- def prepare_type_hierarchy(ls: CpyLanguageServer, params: lsp.TypeHierarchyPrepareParams):
2584
+ def prepare_type_hierarchy(
2585
+ ls: CpyLanguageServer, params: lsp.TypeHierarchyPrepareParams
2586
+ ):
2556
2587
  try:
2557
2588
  uri = params.text_document.uri
2558
2589
  line = params.position.line
@@ -2566,8 +2597,13 @@ def prepare_type_hierarchy(ls: CpyLanguageServer, params: lsp.TypeHierarchyPrepa
2566
2597
  if isinstance(node, ClassDef) and node.name == word:
2567
2598
  tok_node = getattr(node, "_token", None) or tok
2568
2599
  rng = lsp.Range(
2569
- start=lsp.Position(line=tok_node.line - 1, character=tok_node.column - 1),
2570
- end=lsp.Position(line=tok_node.line - 1, character=tok_node.column - 1 + len(tok_node.value or "")),
2600
+ start=lsp.Position(
2601
+ line=tok_node.line - 1, character=tok_node.column - 1
2602
+ ),
2603
+ end=lsp.Position(
2604
+ line=tok_node.line - 1,
2605
+ character=tok_node.column - 1 + len(tok_node.value or ""),
2606
+ ),
2571
2607
  )
2572
2608
  return [
2573
2609
  lsp.TypeHierarchyItem(
@@ -2593,15 +2629,24 @@ def supertypes(ls: CpyLanguageServer, params: lsp.TypeHierarchySupertypesParams)
2593
2629
  _, tokens, parsed, analyzer, _, _ = _get_bundle(ls, uri)
2594
2630
  results = []
2595
2631
  for node in parsed:
2596
- if isinstance(node, ClassDef) and node.name == class_name and getattr(node, "base", None):
2632
+ if (
2633
+ isinstance(node, ClassDef)
2634
+ and node.name == class_name
2635
+ and getattr(node, "base", None)
2636
+ ):
2597
2637
  base_name = node.base
2598
2638
  for bnode in parsed:
2599
2639
  if isinstance(bnode, ClassDef) and bnode.name == base_name:
2600
2640
  btok = getattr(bnode, "_token", None)
2601
2641
  if btok:
2602
2642
  rng = lsp.Range(
2603
- start=lsp.Position(line=btok.line - 1, character=btok.column - 1),
2604
- end=lsp.Position(line=btok.line - 1, character=btok.column - 1 + len(btok.value or "")),
2643
+ start=lsp.Position(
2644
+ line=btok.line - 1, character=btok.column - 1
2645
+ ),
2646
+ end=lsp.Position(
2647
+ line=btok.line - 1,
2648
+ character=btok.column - 1 + len(btok.value or ""),
2649
+ ),
2605
2650
  )
2606
2651
  results.append(
2607
2652
  lsp.TypeHierarchyItem(
@@ -2631,8 +2676,13 @@ def subtypes(ls: CpyLanguageServer, params: lsp.TypeHierarchySubtypesParams):
2631
2676
  tok_node = getattr(node, "_token", None)
2632
2677
  if tok_node:
2633
2678
  rng = lsp.Range(
2634
- start=lsp.Position(line=tok_node.line - 1, character=tok_node.column - 1),
2635
- end=lsp.Position(line=tok_node.line - 1, character=tok_node.column - 1 + len(tok_node.value or "")),
2679
+ start=lsp.Position(
2680
+ line=tok_node.line - 1, character=tok_node.column - 1
2681
+ ),
2682
+ end=lsp.Position(
2683
+ line=tok_node.line - 1,
2684
+ character=tok_node.column - 1 + len(tok_node.value or ""),
2685
+ ),
2636
2686
  )
2637
2687
  results.append(
2638
2688
  lsp.TypeHierarchyItem(
@@ -2682,8 +2732,16 @@ def workspace_symbol(ls: CpyLanguageServer, params: lsp.WorkspaceSymbolParams):
2682
2732
  location=lsp.Location(
2683
2733
  uri=uri,
2684
2734
  range=lsp.Range(
2685
- start=lsp.Position(line=tok.line - 1, character=tok.column - 1),
2686
- end=lsp.Position(line=tok.line - 1, character=tok.column - 1 + len(tok.value or "")),
2735
+ start=lsp.Position(
2736
+ line=tok.line - 1,
2737
+ character=tok.column - 1,
2738
+ ),
2739
+ end=lsp.Position(
2740
+ line=tok.line - 1,
2741
+ character=tok.column
2742
+ - 1
2743
+ + len(tok.value or ""),
2744
+ ),
2687
2745
  ),
2688
2746
  ),
2689
2747
  )
@@ -532,12 +532,25 @@ def _coerce_assign_ok(src_t, dst_t):
532
532
  if src_t == "str" and (dst_t.endswith("*") or dst_t == "char"):
533
533
  return True
534
534
  # big/ubig compatibility
535
- if (src_t, dst_t) in (("big", "int"), ("big", "int64"), ("big", "uint64"),
536
- ("int", "big"), ("int64", "big"), ("uint64", "big"),
537
- ("ubig", "big"), ("big", "ubig")):
535
+ if (src_t, dst_t) in (
536
+ ("big", "int"),
537
+ ("big", "int64"),
538
+ ("big", "uint64"),
539
+ ("int", "big"),
540
+ ("int64", "big"),
541
+ ("uint64", "big"),
542
+ ("ubig", "big"),
543
+ ("big", "ubig"),
544
+ ):
538
545
  return True
539
- if (src_t, dst_t) in (("ubig", "int"), ("ubig", "int64"), ("ubig", "uint64"),
540
- ("int", "ubig"), ("int64", "ubig"), ("uint64", "ubig")):
546
+ if (src_t, dst_t) in (
547
+ ("ubig", "int"),
548
+ ("ubig", "int64"),
549
+ ("ubig", "uint64"),
550
+ ("int", "ubig"),
551
+ ("int64", "ubig"),
552
+ ("uint64", "ubig"),
553
+ ):
541
554
  return True
542
555
  return (src_t, dst_t) in (
543
556
  ("int", "int64"),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cpyte
3
- Version: 4.6.3
3
+ Version: 4.6.4
4
4
  Summary: The Cpyte programming language compiler
5
5
  Author: Hoang Duy Tung
6
6
  License: MIT
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