@ironm00n/pyret-lang 0.0.4 → 0.0.5

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.
package/Makefile CHANGED
@@ -13,7 +13,7 @@ PHASEA = build/phaseA
13
13
  PHASEB = build/phaseB
14
14
  PHASEC = build/phaseC
15
15
  BUNDLED_DEPS = build/bundled-node-deps.js
16
- SHELL := /usr/bin/env bash
16
+ SHELL := bash
17
17
 
18
18
  # CUSTOMIZE THESE IF NECESSARY
19
19
  PARSERS := $(patsubst src/js/base/%-grammar.bnf,src/js/%-parser.js,$(wildcard src/$(JSBASE)/*-grammar.bnf))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ironm00n/pyret-lang",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "The Pyret programming language",
5
5
  "main": "build/phase0/main-wrapper.js",
6
6
  "directories": {
@@ -1,5 +1,6 @@
1
1
  import base as _
2
2
  import essentials2020 as _
3
+ import starter2024 as _
3
4
 
4
5
  import arrays as _
5
6
  import ast as _
@@ -53,3 +54,5 @@ import image-typed as _
53
54
  import color as _
54
55
  import csv as _
55
56
  import charts as _
57
+
58
+
@@ -160,31 +160,7 @@ define("pyret-base/js/js-numbers", function() {
160
160
 
161
161
  // fromFixnum: fixnum -> pyretnum
162
162
  var fromFixnum = function(x, errbacks) {
163
- if (!isFinite(x)) {
164
- return Roughnum.makeInstance(x, errbacks);
165
- }
166
- var nf = Math.floor(x);
167
- if (nf === x) {
168
- if (isOverflow(nf)) {
169
- return makeBignum(expandExponent(x+''));
170
- } else {
171
- return nf;
172
- }
173
- } else {
174
- // used to return float, now rational
175
- var stringRep = x.toString();
176
- var match = stringRep.match(/^(.*)\.(.*)$/);
177
- if (match) {
178
- var afterDecimal = parseInt(match[2]);
179
- var factorToInt = Math.pow(10, match[2].length);
180
- var extraFactor = _integerGcd(factorToInt, afterDecimal);
181
- var multFactor = factorToInt / extraFactor;
182
- return Rational.makeInstance(Math.round(x*multFactor), Math.round(factorToInt/extraFactor), errbacks);
183
- } else {
184
- return Rational.makeInstance(x, 1, errbacks);
185
- }
186
-
187
- }
163
+ return fromString(String(x), errbacks);
188
164
  };
189
165
 
190
166
  var expandExponent = function(s) {
@@ -813,6 +789,8 @@ define("pyret-base/js/js-numbers", function() {
813
789
  // NB: all of these trig-gy generic functions should now return roughnum rather than float
814
790
  // (except for an arg of 0, etc)
815
791
 
792
+ var ln10 = Math.log(10)
793
+
816
794
  // log: pyretnum -> pyretnum
817
795
  var log = function(n, errbacks) {
818
796
  if ( eqv(n, 1, errbacks) ) {
@@ -824,7 +802,40 @@ define("pyret-base/js/js-numbers", function() {
824
802
  if (typeof(n) === 'number') {
825
803
  return Roughnum.makeInstance(Math.log(n), errbacks);
826
804
  }
827
- return n.log(errbacks);
805
+ if (isRational(n) && !isInteger(n)) {
806
+ return subtract(log(numerator(n, errbacks), errbacks),
807
+ log(denominator(n, errbacks), errbacks),
808
+ errbacks);
809
+ }
810
+ var nFix = n.toFixnum();
811
+ if (typeof(nFix) === 'number' && nFix !== Infinity) {
812
+ return Roughnum.makeInstance(Math.log(nFix), errbacks);
813
+ }
814
+ // at this point, n must be a very large positive number;
815
+ // n > 1e308, i.e, has at least 308 digits;
816
+ // we can safely ignore its fractional part;
817
+ var nStr = n.round(errbacks).toString();
818
+ var nLen = nStr.length;
819
+ // we furthermore need only the integer part's first few digits
820
+ // although we must remember the number of digits ignored;
821
+ var firstFewLen = 308; // has to be <= 308
822
+ // say integer N = yyy...yyyxxx...xxx
823
+ // where the number of x's is nx;
824
+ // So N ~= yyy...yyy * 10^nx
825
+ // We'll first find the common (base 10) log of N
826
+ // log10(N) ~= log10(yyy...yyy * 10^nx)
827
+ // = log10(yyy...yyy) + nx
828
+ // Now to convert this to the natural log
829
+ // ln(N) = log10(N) / log10(e)
830
+ // = log10(N) * ln(10)
831
+ // ~= [log10(yyy...yyy) + nx] * ln(10)
832
+ // = log10(yyy...yyy) * ln(10) + nx * ln(10)
833
+ // = ln(yyy...yyy) + nx * ln(10)
834
+ // JS gives us ln(yyy...yyy) and ln(10) so we have a good
835
+ // approximation for ln(N)
836
+ var nFirstFew = parseInt(nStr.substring(0, firstFewLen));
837
+ var nLog = Math.log(nFirstFew) + (nLen - firstFewLen) * ln10;
838
+ return Roughnum.makeInstance(nLog, errbacks);
828
839
  };
829
840
 
830
841
  // tan: pyretnum -> pyretnum
@@ -2033,7 +2044,6 @@ define("pyret-base/js/js-numbers", function() {
2033
2044
 
2034
2045
  var roughnumRatRegexp = new RegExp("^~([+-]?\\d+)/(\\d+)$");
2035
2046
 
2036
-
2037
2047
  var scientificPattern = new RegExp("^([+-]?\\d*\\.?\\d*)[Ee]([+]?\\d+)$");
2038
2048
 
2039
2049
  // fromString: string -> (pyretnum | false)
@@ -2889,8 +2899,13 @@ define("pyret-base/js/js-numbers", function() {
2889
2899
  function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
2890
2900
 
2891
2901
  // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
2892
- function bnpExp(e,z) {
2893
- if(e > 0xffffffff || e < 1) return BigInteger.ONE;
2902
+ function bnpExp(e, z, errbacks) {
2903
+ if (greaterThan(e, 0xffffffff, errbacks)) {
2904
+ errbacks.throwDomainError('expt: exponent ' + e + ' too large');
2905
+ }
2906
+ if (lessThan(e, 1, errbacks)) {
2907
+ return BigInteger.ONE;
2908
+ }
2894
2909
  var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
2895
2910
  g.copyTo(r);
2896
2911
  while(--i >= 0) {
@@ -2902,10 +2917,10 @@ define("pyret-base/js/js-numbers", function() {
2902
2917
  }
2903
2918
 
2904
2919
  // (public) this^e % m, 0 <= e < 2^32
2905
- function bnModPowInt(e,m) {
2920
+ function bnModPowInt(e, m, errbacks) {
2906
2921
  var z;
2907
2922
  if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
2908
- return this.bnpExp(e,z);
2923
+ return this.bnpExp(e, z, errbacks);
2909
2924
  }
2910
2925
 
2911
2926
  // protected
@@ -3274,7 +3289,9 @@ define("pyret-base/js/js-numbers", function() {
3274
3289
  NullExp.prototype.sqrTo = nSqrTo;
3275
3290
 
3276
3291
  // (public) this^e
3277
- function bnPow(e) { return this.bnpExp(e,new NullExp()); }
3292
+ function bnPow(e, errbacks) {
3293
+ return this.bnpExp(e,new NullExp(), errbacks);
3294
+ }
3278
3295
 
3279
3296
  // (protected) r = lower n words of "this * a", a.t <= n
3280
3297
  // "this" should be the larger one if appropriate.
@@ -3774,48 +3791,48 @@ define("pyret-base/js/js-numbers", function() {
3774
3791
 
3775
3792
  // round: -> pyretnum
3776
3793
  // Round to the nearest integer.
3777
- BigInteger.prototype.round = function(n, errbacks) {
3794
+ BigInteger.prototype.round = function(errbacks) {
3778
3795
  return this;
3779
3796
  };
3780
3797
 
3781
- BigInteger.prototype.roundEven = function(n, errbacks) {
3798
+ BigInteger.prototype.roundEven = function(errbacks) {
3782
3799
  return this;
3783
3800
  };
3784
3801
 
3785
3802
  // log: -> pyretnum
3786
3803
  // Produce the log.
3787
- BigInteger.prototype.log = function(n, errbacks) {
3804
+ BigInteger.prototype.log = function(errbacks) {
3788
3805
  return log(this.toFixnum(), errbacks);
3789
3806
  };
3790
3807
 
3791
3808
  // tan: -> pyretnum
3792
3809
  // Produce the tan.
3793
- BigInteger.prototype.tan = function(n, errbacks) {
3810
+ BigInteger.prototype.tan = function(errbacks) {
3794
3811
  return tan(this.toFixnum(), errbacks);
3795
3812
  };
3796
3813
 
3797
3814
  // atan: -> pyretnum
3798
3815
  // Produce the arc tangent.
3799
- BigInteger.prototype.atan = function(n, errbacks) {
3816
+ BigInteger.prototype.atan = function(errbacks) {
3800
3817
  return atan(this.toFixnum(), errbacks);
3801
3818
  };
3802
3819
 
3803
3820
  // cos: -> pyretnum
3804
3821
  // Produce the cosine.
3805
- BigInteger.prototype.cos = function(n, errbacks) {
3822
+ BigInteger.prototype.cos = function(errbacks) {
3806
3823
  return cos(this.toFixnum(), errbacks);
3807
3824
  };
3808
3825
 
3809
3826
  // sin: -> pyretnum
3810
3827
  // Produce the sine.
3811
- BigInteger.prototype.sin = function(n, errbacks) {
3828
+ BigInteger.prototype.sin = function(errbacks) {
3812
3829
  return sin(this.toFixnum(), errbacks);
3813
3830
  };
3814
3831
 
3815
3832
  // expt: pyretnum -> pyretnum
3816
3833
  // Produce the power to the input.
3817
3834
  BigInteger.prototype.expt = function(n, errbacks) {
3818
- return bnPow.call(this, n);
3835
+ return bnPow.call(this, n, errbacks);
3819
3836
  };
3820
3837
 
3821
3838
  // exp: -> pyretnum
@@ -3829,13 +3846,13 @@ define("pyret-base/js/js-numbers", function() {
3829
3846
 
3830
3847
  // acos: -> pyretnum
3831
3848
  // Produce the arc cosine.
3832
- BigInteger.prototype.acos = function(n, errbacks) {
3849
+ BigInteger.prototype.acos = function(errbacks) {
3833
3850
  return acos(this.toFixnum(), errbacks);
3834
3851
  };
3835
3852
 
3836
3853
  // asin: -> pyretnum
3837
3854
  // Produce the arc sine.
3838
- BigInteger.prototype.asin = function(n, errbacks) {
3855
+ BigInteger.prototype.asin = function(errbacks) {
3839
3856
  return asin(this.toFixnum(), errbacks);
3840
3857
  };
3841
3858