cpyte 3.3.4__tar.gz → 3.4.0__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 (38) hide show
  1. {cpyte-3.3.4/source/cpyte.egg-info → cpyte-3.4.0}/PKG-INFO +1 -1
  2. {cpyte-3.3.4 → cpyte-3.4.0}/pyproject.toml +1 -1
  3. cpyte-3.4.0/source/cpyte/__init__.py +1 -0
  4. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/astparse.py +2 -0
  5. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/bignum.c +134 -1
  6. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/bytecoding.py +227 -49
  7. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/compiling.py +111 -11
  8. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/lexar.py +15 -0
  9. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/mainpie.py +26 -9
  10. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/semantic_analasis.py +248 -32
  11. {cpyte-3.3.4 → cpyte-3.4.0/source/cpyte.egg-info}/PKG-INFO +1 -1
  12. cpyte-3.3.4/source/cpyte/__init__.py +0 -1
  13. {cpyte-3.3.4 → cpyte-3.4.0}/MANIFEST.in +0 -0
  14. {cpyte-3.3.4 → cpyte-3.4.0}/readme.md +0 -0
  15. {cpyte-3.3.4 → cpyte-3.4.0}/setup.cfg +0 -0
  16. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/__main__.py +0 -0
  17. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/_bignum_bc.py +0 -0
  18. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/_runtime_bc.py +0 -0
  19. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/clib.py +0 -0
  20. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/extension_hooks.py +0 -0
  21. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/formatter.py +0 -0
  22. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/gc_runtime.c +0 -0
  23. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/generate_bc.py +0 -0
  24. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/linker.py +0 -0
  25. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/lsp_server.py +0 -0
  26. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/package_manifest.py +0 -0
  27. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/runtime.c +0 -0
  28. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/runtime_scorpion.c +0 -0
  29. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/sef.py +0 -0
  30. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/ugc.h +0 -0
  31. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/ui.py +0 -0
  32. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte/update_check.py +0 -0
  33. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte.egg-info/SOURCES.txt +0 -0
  34. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte.egg-info/dependency_links.txt +0 -0
  35. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte.egg-info/entry_points.txt +0 -0
  36. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte.egg-info/requires.txt +0 -0
  37. {cpyte-3.3.4 → cpyte-3.4.0}/source/cpyte.egg-info/top_level.txt +0 -0
  38. {cpyte-3.3.4 → cpyte-3.4.0}/test/test_bignum_jit.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cpyte
3
- Version: 3.3.4
3
+ Version: 3.4.0
4
4
  Summary: The Cpyte programming language compiler
5
5
  Author: Hoang Duy Tung
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cpyte"
7
- version = "3.3.4"
7
+ version = "3.4.0"
8
8
  description = "The Cpyte programming language compiler"
9
9
  readme = "readme.md"
10
10
  requires-python = ">=3.11"
@@ -0,0 +1 @@
1
+ __version__ = "3.4.0"
@@ -2241,6 +2241,8 @@ _TYPE_NAMES = {
2241
2241
  "long",
2242
2242
  "short",
2243
2243
  "signed",
2244
+ "big",
2245
+ "ubig",
2244
2246
  "size_t",
2245
2247
  "dynamic",
2246
2248
  }
@@ -466,7 +466,7 @@ void* bigint_pow(void* a, void* b) {
466
466
  cb->used = base->used;
467
467
  cb->negative = base->negative;
468
468
 
469
- BigNum exp_copy;
469
+ BigNum exp_copy = {0};
470
470
  _bn_reserve(&exp_copy, exp->used);
471
471
  memcpy(exp_copy.limbs, exp->limbs, exp->used * sizeof(uint64_t));
472
472
  exp_copy.used = exp->used;
@@ -592,3 +592,136 @@ char* bigint_to_str(void* p) {
592
592
  free(buf);
593
593
  return out;
594
594
  }
595
+
596
+ // --- Unsigned big (ubig) support ---
597
+ // ubig shares the BigNum sign-magnitude representation but is constrained to
598
+ // non-negative values. add/mul/div/mod/pow are mathematically identical to the
599
+ // signed versions for two non-negative operands, so `bigint_*` is reused for
600
+ // those. The operations below are where unsigned semantics genuinely differ:
601
+ // underflow-checked subtraction, unsigned comparison, and bitwise ops over the
602
+ // full magnitude (which `big` deliberately does not support).
603
+
604
+ void* ubigint_sub(void* a, void* b) {
605
+ if (!a) return b ? bigint_from_uint64(0) : bigint_from_uint64(0);
606
+ if (!b) return a;
607
+ void* r = bigint_sub(a, b);
608
+ BigNum* rt = (BigNum*)r;
609
+ if (rt->negative) {
610
+ bigint_free(r);
611
+ _bn_fail("ubig underflow: result of subtraction is negative");
612
+ }
613
+ return r;
614
+ }
615
+
616
+ int ubigint_cmp(void* a, void* b) {
617
+ BigNum* x = (BigNum*)a;
618
+ BigNum* y = (BigNum*)b;
619
+ if (!x && !y) return 0;
620
+ if (!x) return -1;
621
+ if (!y) return 1;
622
+ return _bn_cmp_mag(x, y);
623
+ }
624
+
625
+ void* ubigint_and(void* a, void* b) {
626
+ if (!a || !b) return bigint_from_uint64(0);
627
+ BigNum* x = (BigNum*)a;
628
+ BigNum* y = (BigNum*)b;
629
+ BigNum* r = _bn_alloc();
630
+ size_t n = x->used < y->used ? x->used : y->used;
631
+ _bn_reserve(r, n);
632
+ for (size_t i = 0; i < n; i++)
633
+ r->limbs[i] = x->limbs[i] & y->limbs[i];
634
+ r->used = n;
635
+ _bn_trim(r);
636
+ return r;
637
+ }
638
+
639
+ void* ubigint_or(void* a, void* b) {
640
+ if (!a && !b) return bigint_from_uint64(0);
641
+ if (!a) return b;
642
+ if (!b) return a;
643
+ BigNum* x = (BigNum*)a;
644
+ BigNum* y = (BigNum*)b;
645
+ BigNum* r = _bn_alloc();
646
+ size_t n = x->used > y->used ? x->used : y->used;
647
+ _bn_reserve(r, n);
648
+ for (size_t i = 0; i < n; i++)
649
+ r->limbs[i] = (i < x->used ? x->limbs[i] : 0) | (i < y->used ? y->limbs[i] : 0);
650
+ r->used = n;
651
+ _bn_trim(r);
652
+ return r;
653
+ }
654
+
655
+ void* ubigint_xor(void* a, void* b) {
656
+ if (!a && !b) return bigint_from_uint64(0);
657
+ if (!a) return b;
658
+ if (!b) return a;
659
+ BigNum* x = (BigNum*)a;
660
+ BigNum* y = (BigNum*)b;
661
+ BigNum* r = _bn_alloc();
662
+ size_t n = x->used > y->used ? x->used : y->used;
663
+ _bn_reserve(r, n);
664
+ for (size_t i = 0; i < n; i++)
665
+ r->limbs[i] = (i < x->used ? x->limbs[i] : 0) ^ (i < y->used ? y->limbs[i] : 0);
666
+ r->used = n;
667
+ _bn_trim(r);
668
+ return r;
669
+ }
670
+
671
+ // Left shift. `count` is a non-negative ubig; shifting left never underflows.
672
+ void* ubigint_shl(void* a, void* count) {
673
+ if (!a) return bigint_from_uint64(0);
674
+ BigNum* x = (BigNum*)a;
675
+ BigNum* c = (BigNum*)count;
676
+ uint64_t s = (c && c->used) ? c->limbs[0] : 0;
677
+ size_t limb_shift = (size_t)(s / 64);
678
+ unsigned bit_shift = (unsigned)(s % 64);
679
+ BigNum* r = _bn_alloc();
680
+ size_t n = x->used + limb_shift + (bit_shift ? 1 : 0);
681
+ _bn_reserve(r, n);
682
+ memset(r->limbs, 0, n * sizeof(uint64_t));
683
+ if (bit_shift == 0) {
684
+ for (size_t i = x->used; i > 0; i--)
685
+ r->limbs[i - 1 + limb_shift] = x->limbs[i - 1];
686
+ } else {
687
+ uint64_t carry = 0;
688
+ for (size_t i = 0; i < x->used; i++) {
689
+ uint64_t v = (x->limbs[i] << bit_shift) | carry;
690
+ carry = x->limbs[i] >> (64 - bit_shift);
691
+ r->limbs[i + limb_shift] = v;
692
+ }
693
+ if (carry)
694
+ r->limbs[x->used + limb_shift] = carry;
695
+ }
696
+ r->used = n;
697
+ _bn_trim(r);
698
+ r->negative = 0;
699
+ return r;
700
+ }
701
+
702
+ // Right shift. Counts >= the bit-width produce zero.
703
+ void* ubigint_shr(void* a, void* count) {
704
+ if (!a) return bigint_from_uint64(0);
705
+ BigNum* x = (BigNum*)a;
706
+ BigNum* c = (BigNum*)count;
707
+ uint64_t s = (c && c->used) ? c->limbs[0] : 0;
708
+ size_t limb_shift = (size_t)(s / 64);
709
+ unsigned bit_shift = (unsigned)(s % 64);
710
+ if (limb_shift >= x->used)
711
+ return bigint_from_uint64(0);
712
+ BigNum* r = _bn_alloc();
713
+ size_t n = x->used - limb_shift;
714
+ _bn_reserve(r, n);
715
+ for (size_t i = 0; i < n; i++) {
716
+ uint64_t hi = x->limbs[i + limb_shift];
717
+ uint64_t lo = (i + 1 + limb_shift < x->used) ? x->limbs[i + 1 + limb_shift] : 0;
718
+ if (bit_shift == 0)
719
+ r->limbs[i] = hi;
720
+ else
721
+ r->limbs[i] = (hi >> bit_shift) | (lo << (64 - bit_shift));
722
+ }
723
+ r->used = n;
724
+ _bn_trim(r);
725
+ r->negative = 0;
726
+ return r;
727
+ }