firefly-compiler 0.5.10 → 0.5.11

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.
@@ -697,26 +697,10 @@ extend self: JsEmitter {
697
697
  | "ff:core/List.List_each" {arguments | [list, ELambda(_, Lambda(_, _, [
698
698
  MatchCase(_, [PVariable(_, name)], [], body)
699
699
  ]))]} =>
700
- mutable start = "0"
701
- mutable end = "for_a.length"
702
- let listCode = list.{
703
- | ECall(_, StaticCall("ff:core/List.List_dropFirst", _, _), _, _, [a1, a2], _) =>
704
- start = self.emitTerm(a2.value, async)
705
- if(!start.all {_.isAsciiDigit()}) {
706
- start = "Math.max(" + start + ", 0)"
707
- }
708
- self.emitTerm(a1.value, async)
709
- | ECall(_, StaticCall("ff:core/List.List_dropLast", _, _), _, _, [a1, a2], _) =>
710
- let count = self.emitTerm(a2.value, async)
711
- if(!count.all {_.isAsciiDigit()}) {
712
- end = end + " - Math.max(" + count + ", 0)"
713
- } else {
714
- end = end + " - " + count
715
- }
716
- self.emitTerm(a1.value, async)
717
- | _ =>
718
- self.emitTerm(list, async)
719
- }
700
+ let fusion = self.emitLightFusion(list, async)
701
+ let start = fusion.second.first
702
+ let end = fusion.second.second
703
+ let listCode = fusion.first
720
704
  Some(
721
705
  "for(let for_i = " + start + ", for_a = " + listCode + ", for_l = " + end +
722
706
  "; for_i < for_l; for_i++) {\n" +
@@ -727,26 +711,10 @@ extend self: JsEmitter {
727
711
  | "ff:core/List.List_eachWhile" {arguments | [list, ELambda(_, Lambda(_, _, [
728
712
  MatchCase(_, [PVariable(_, name)], [], ESequential(_, body, condition))
729
713
  ]))]} =>
730
- mutable start = "0"
731
- mutable end = "for_a.length"
732
- let listCode = list.{
733
- | ECall(_, StaticCall("ff:core/List.List_dropFirst", _, _), _, _, [a1, a2], _) =>
734
- start = self.emitTerm(a2.value, async)
735
- if(!start.all {_.isAsciiDigit()}) {
736
- start = "Math.max(" + start + ", 0)"
737
- }
738
- self.emitTerm(a1.value, async)
739
- | ECall(_, StaticCall("ff:core/List.List_dropLast", _, _), _, _, [a1, a2], _) =>
740
- let count = self.emitTerm(a2.value, async)
741
- if(!count.all {_.isAsciiDigit()}) {
742
- end = end + " - Math.max(" + count + ", 0)"
743
- } else {
744
- end = end + " - " + count
745
- }
746
- self.emitTerm(a1.value, async)
747
- | _ =>
748
- self.emitTerm(list, async)
749
- }
714
+ let fusion = self.emitLightFusion(list, async)
715
+ let start = fusion.second.first
716
+ let end = fusion.second.second
717
+ let listCode = fusion.first
750
718
  Some(
751
719
  "for(let for_i = " + start + ", for_a = " + listCode + ", for_l = " + end +
752
720
  "; for_i < for_l; for_i++) {\n" +
@@ -806,6 +774,45 @@ extend self: JsEmitter {
806
774
  None
807
775
  }
808
776
  }
777
+
778
+ emitLightFusion(list: Term, async: Bool): Pair[String, Pair[String, String]] {
779
+ mutable start = "0"
780
+ mutable end = "for_a.length"
781
+ let listCode = list.{
782
+ | ECall(_, StaticCall("ff:core/List.List_dropFirst", _, _), _, _, [a1, a2], _) =>
783
+ start = self.emitTerm(a2.value, async)
784
+ if(!start.all {_.isAsciiDigit()}) {
785
+ start = "Math.max(" + start + ", 0)"
786
+ }
787
+ self.emitTerm(a1.value, async)
788
+ | ECall(_, StaticCall("ff:core/List.List_dropLast", _, _), _, _, [a1, a2], _) =>
789
+ let count = self.emitTerm(a2.value, async)
790
+ if(!count.all {_.isAsciiDigit()}) {
791
+ end = end + " - Math.max(" + count + ", 0)"
792
+ } else {
793
+ end = end + " - " + count
794
+ }
795
+ self.emitTerm(a1.value, async)
796
+ | ECall(_, StaticCall("ff:core/List.List_takeFirst", _, _), _, _, [a1, a2], _) =>
797
+ end = self.emitTerm(a2.value, async)
798
+ if(!end.all {_.isAsciiDigit()}) {
799
+ end = "Math.max(" + end + ", 0)"
800
+ }
801
+ end = "Math.min(" + end + ", for_a.length)"
802
+ self.emitTerm(a1.value, async)
803
+ | ECall(_, StaticCall("ff:core/List.List_takeLast", _, _), _, _, [a1, a2], _) =>
804
+ let count = self.emitTerm(a2.value, async)
805
+ if(!count.all {_.isAsciiDigit()}) {
806
+ start = "Math.max(for_a.length - Math.max(" + count + ", 0), 0)"
807
+ } else {
808
+ start = "Math.max(for_a.length - " + count + ", 0)"
809
+ }
810
+ self.emitTerm(a1.value, async)
811
+ | _ =>
812
+ self.emitTerm(list, async)
813
+ }
814
+ Pair(listCode, Pair(start, end))
815
+ }
809
816
 
810
817
  emitTryCatchFinally(term: Term, last: Bool, async: Bool): Option[String] {
811
818
  function emitCatch(catchEffect: Type, cases: List[MatchCase]): String {
@@ -1944,37 +1944,10 @@ if(_guard1.length === 2 && _guard1[1].ELambda && _guard1[1].lambda_.cases_.lengt
1944
1944
  const list_ = _guard1[0];
1945
1945
  const name_ = _guard1[1].lambda_.cases_[0].patterns_[0].name_;
1946
1946
  const body_ = _guard1[1].lambda_.cases_[0].body_;
1947
- let start_ = "0";
1948
- let end_ = "for_a.length";
1949
- const listCode_ = (((_1) => {
1950
- if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropFirst" && _1.arguments_.length === 2) {
1951
- const a1_ = _1.arguments_[0];
1952
- const a2_ = _1.arguments_[1];
1953
- start_ = ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a2_.value_, async_);
1954
- if((!ff_core_String.String_all(start_, ((_w1) => {
1955
- return ff_core_Char.Char_isAsciiDigit(_w1)
1956
- })))) {
1957
- start_ = (("Math.max(" + start_) + ", 0)")
1958
- };
1959
- return ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a1_.value_, async_)
1960
- }
1961
- if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropLast" && _1.arguments_.length === 2) {
1962
- const a1_ = _1.arguments_[0];
1963
- const a2_ = _1.arguments_[1];
1964
- const count_ = ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a2_.value_, async_);
1965
- if((!ff_core_String.String_all(count_, ((_w1) => {
1966
- return ff_core_Char.Char_isAsciiDigit(_w1)
1967
- })))) {
1968
- end_ = (((end_ + " - Math.max(") + count_) + ", 0)")
1969
- } else {
1970
- end_ = ((end_ + " - ") + count_)
1971
- };
1972
- return ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a1_.value_, async_)
1973
- }
1974
- {
1975
- return ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, list_, async_)
1976
- }
1977
- }))(list_);
1947
+ const fusion_ = ff_compiler_JsEmitter.JsEmitter_emitLightFusion(self_, list_, async_);
1948
+ const start_ = fusion_.second_.first_;
1949
+ const end_ = fusion_.second_.second_;
1950
+ const listCode_ = fusion_.first_;
1978
1951
  return ff_core_Option.Some(((((((((("for(let for_i = " + start_) + ", for_a = ") + listCode_) + ", for_l = ") + end_) + "; for_i < for_l; for_i++) {\n") + ff_core_Option.Option_else(ff_core_Option.Option_map(name_, ((_w1) => {
1979
1952
  return (("const " + ff_compiler_JsEmitter.escapeKeyword_(_w1)) + " = for_a[for_i];\n")
1980
1953
  })), (() => {
@@ -1990,37 +1963,10 @@ const list_ = _guard1[0];
1990
1963
  const name_ = _guard1[1].lambda_.cases_[0].patterns_[0].name_;
1991
1964
  const body_ = _guard1[1].lambda_.cases_[0].body_.before_;
1992
1965
  const condition_ = _guard1[1].lambda_.cases_[0].body_.after_;
1993
- let start_ = "0";
1994
- let end_ = "for_a.length";
1995
- const listCode_ = (((_1) => {
1996
- if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropFirst" && _1.arguments_.length === 2) {
1997
- const a1_ = _1.arguments_[0];
1998
- const a2_ = _1.arguments_[1];
1999
- start_ = ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a2_.value_, async_);
2000
- if((!ff_core_String.String_all(start_, ((_w1) => {
2001
- return ff_core_Char.Char_isAsciiDigit(_w1)
2002
- })))) {
2003
- start_ = (("Math.max(" + start_) + ", 0)")
2004
- };
2005
- return ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a1_.value_, async_)
2006
- }
2007
- if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropLast" && _1.arguments_.length === 2) {
2008
- const a1_ = _1.arguments_[0];
2009
- const a2_ = _1.arguments_[1];
2010
- const count_ = ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a2_.value_, async_);
2011
- if((!ff_core_String.String_all(count_, ((_w1) => {
2012
- return ff_core_Char.Char_isAsciiDigit(_w1)
2013
- })))) {
2014
- end_ = (((end_ + " - Math.max(") + count_) + ", 0)")
2015
- } else {
2016
- end_ = ((end_ + " - ") + count_)
2017
- };
2018
- return ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a1_.value_, async_)
2019
- }
2020
- {
2021
- return ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, list_, async_)
2022
- }
2023
- }))(list_);
1966
+ const fusion_ = ff_compiler_JsEmitter.JsEmitter_emitLightFusion(self_, list_, async_);
1967
+ const start_ = fusion_.second_.first_;
1968
+ const end_ = fusion_.second_.second_;
1969
+ const listCode_ = fusion_.first_;
2024
1970
  return ff_core_Option.Some(((((((((((((("for(let for_i = " + start_) + ", for_a = ") + listCode_) + ", for_l = ") + end_) + "; for_i < for_l; for_i++) {\n") + ff_core_Option.Option_else(ff_core_Option.Option_map(name_, ((_w1) => {
2025
1971
  return (("const " + ff_compiler_JsEmitter.escapeKeyword_(_w1)) + " = for_a[for_i];\n")
2026
1972
  })), (() => {
@@ -2188,6 +2134,66 @@ return ff_core_Option.None()
2188
2134
  }
2189
2135
  }
2190
2136
 
2137
+ export function JsEmitter_emitLightFusion(self_, list_, async_) {
2138
+ let start_ = "0";
2139
+ let end_ = "for_a.length";
2140
+ const listCode_ = (((_1) => {
2141
+ if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropFirst" && _1.arguments_.length === 2) {
2142
+ const a1_ = _1.arguments_[0];
2143
+ const a2_ = _1.arguments_[1];
2144
+ start_ = ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a2_.value_, async_);
2145
+ if((!ff_core_String.String_all(start_, ((_w1) => {
2146
+ return ff_core_Char.Char_isAsciiDigit(_w1)
2147
+ })))) {
2148
+ start_ = (("Math.max(" + start_) + ", 0)")
2149
+ };
2150
+ return ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a1_.value_, async_)
2151
+ }
2152
+ if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropLast" && _1.arguments_.length === 2) {
2153
+ const a1_ = _1.arguments_[0];
2154
+ const a2_ = _1.arguments_[1];
2155
+ const count_ = ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a2_.value_, async_);
2156
+ if((!ff_core_String.String_all(count_, ((_w1) => {
2157
+ return ff_core_Char.Char_isAsciiDigit(_w1)
2158
+ })))) {
2159
+ end_ = (((end_ + " - Math.max(") + count_) + ", 0)")
2160
+ } else {
2161
+ end_ = ((end_ + " - ") + count_)
2162
+ };
2163
+ return ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a1_.value_, async_)
2164
+ }
2165
+ if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_takeFirst" && _1.arguments_.length === 2) {
2166
+ const a1_ = _1.arguments_[0];
2167
+ const a2_ = _1.arguments_[1];
2168
+ end_ = ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a2_.value_, async_);
2169
+ if((!ff_core_String.String_all(end_, ((_w1) => {
2170
+ return ff_core_Char.Char_isAsciiDigit(_w1)
2171
+ })))) {
2172
+ end_ = (("Math.max(" + end_) + ", 0)")
2173
+ };
2174
+ end_ = (("Math.min(" + end_) + ", for_a.length)");
2175
+ return ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a1_.value_, async_)
2176
+ }
2177
+ if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_takeLast" && _1.arguments_.length === 2) {
2178
+ const a1_ = _1.arguments_[0];
2179
+ const a2_ = _1.arguments_[1];
2180
+ const count_ = ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a2_.value_, async_);
2181
+ if((!ff_core_String.String_all(count_, ((_w1) => {
2182
+ return ff_core_Char.Char_isAsciiDigit(_w1)
2183
+ })))) {
2184
+ start_ = (("Math.max(for_a.length - Math.max(" + count_) + ", 0), 0)")
2185
+ } else {
2186
+ start_ = (("Math.max(for_a.length - " + count_) + ", 0)")
2187
+ };
2188
+ return ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, a1_.value_, async_)
2189
+ }
2190
+ {
2191
+ return ff_compiler_JsEmitter.JsEmitter_emitTerm(self_, list_, async_)
2192
+ }
2193
+ }))(list_);
2194
+ return ff_core_Pair.Pair(listCode_, ff_core_Pair.Pair(start_, end_))
2195
+ }
2196
+
2191
2197
  export function JsEmitter_emitTryCatchFinally(self_, term_, last_, async_) {
2192
2198
  function emitCatch_(catchEffect_, cases_) {
2193
2199
  const catchAsync_ = (self_.emittingAsync_ && ff_compiler_JsEmitter.effectTypeIsAsync_(catchEffect_));
@@ -3882,37 +3888,10 @@ if(_guard1.length === 2 && _guard1[1].ELambda && _guard1[1].lambda_.cases_.lengt
3882
3888
  const list_ = _guard1[0];
3883
3889
  const name_ = _guard1[1].lambda_.cases_[0].patterns_[0].name_;
3884
3890
  const body_ = _guard1[1].lambda_.cases_[0].body_;
3885
- let start_ = "0";
3886
- let end_ = "for_a.length";
3887
- const listCode_ = (await ((async (_1, $task) => {
3888
- if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropFirst" && _1.arguments_.length === 2) {
3889
- const a1_ = _1.arguments_[0];
3890
- const a2_ = _1.arguments_[1];
3891
- start_ = (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a2_.value_, async_, $task));
3892
- if((!ff_core_String.String_all(start_, ((_w1) => {
3893
- return ff_core_Char.Char_isAsciiDigit(_w1)
3894
- })))) {
3895
- start_ = (("Math.max(" + start_) + ", 0)")
3896
- };
3897
- return (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a1_.value_, async_, $task))
3898
- }
3899
- if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropLast" && _1.arguments_.length === 2) {
3900
- const a1_ = _1.arguments_[0];
3901
- const a2_ = _1.arguments_[1];
3902
- const count_ = (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a2_.value_, async_, $task));
3903
- if((!ff_core_String.String_all(count_, ((_w1) => {
3904
- return ff_core_Char.Char_isAsciiDigit(_w1)
3905
- })))) {
3906
- end_ = (((end_ + " - Math.max(") + count_) + ", 0)")
3907
- } else {
3908
- end_ = ((end_ + " - ") + count_)
3909
- };
3910
- return (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a1_.value_, async_, $task))
3911
- }
3912
- {
3913
- return (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, list_, async_, $task))
3914
- }
3915
- }))(list_, $task));
3891
+ const fusion_ = (await ff_compiler_JsEmitter.JsEmitter_emitLightFusion$(self_, list_, async_, $task));
3892
+ const start_ = fusion_.second_.first_;
3893
+ const end_ = fusion_.second_.second_;
3894
+ const listCode_ = fusion_.first_;
3916
3895
  return ff_core_Option.Some(((((((((("for(let for_i = " + start_) + ", for_a = ") + listCode_) + ", for_l = ") + end_) + "; for_i < for_l; for_i++) {\n") + ff_core_Option.Option_else(ff_core_Option.Option_map(name_, ((_w1) => {
3917
3896
  return (("const " + ff_compiler_JsEmitter.escapeKeyword_(_w1)) + " = for_a[for_i];\n")
3918
3897
  })), (() => {
@@ -3928,37 +3907,10 @@ const list_ = _guard1[0];
3928
3907
  const name_ = _guard1[1].lambda_.cases_[0].patterns_[0].name_;
3929
3908
  const body_ = _guard1[1].lambda_.cases_[0].body_.before_;
3930
3909
  const condition_ = _guard1[1].lambda_.cases_[0].body_.after_;
3931
- let start_ = "0";
3932
- let end_ = "for_a.length";
3933
- const listCode_ = (await ((async (_1, $task) => {
3934
- if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropFirst" && _1.arguments_.length === 2) {
3935
- const a1_ = _1.arguments_[0];
3936
- const a2_ = _1.arguments_[1];
3937
- start_ = (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a2_.value_, async_, $task));
3938
- if((!ff_core_String.String_all(start_, ((_w1) => {
3939
- return ff_core_Char.Char_isAsciiDigit(_w1)
3940
- })))) {
3941
- start_ = (("Math.max(" + start_) + ", 0)")
3942
- };
3943
- return (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a1_.value_, async_, $task))
3944
- }
3945
- if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropLast" && _1.arguments_.length === 2) {
3946
- const a1_ = _1.arguments_[0];
3947
- const a2_ = _1.arguments_[1];
3948
- const count_ = (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a2_.value_, async_, $task));
3949
- if((!ff_core_String.String_all(count_, ((_w1) => {
3950
- return ff_core_Char.Char_isAsciiDigit(_w1)
3951
- })))) {
3952
- end_ = (((end_ + " - Math.max(") + count_) + ", 0)")
3953
- } else {
3954
- end_ = ((end_ + " - ") + count_)
3955
- };
3956
- return (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a1_.value_, async_, $task))
3957
- }
3958
- {
3959
- return (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, list_, async_, $task))
3960
- }
3961
- }))(list_, $task));
3910
+ const fusion_ = (await ff_compiler_JsEmitter.JsEmitter_emitLightFusion$(self_, list_, async_, $task));
3911
+ const start_ = fusion_.second_.first_;
3912
+ const end_ = fusion_.second_.second_;
3913
+ const listCode_ = fusion_.first_;
3962
3914
  return ff_core_Option.Some(((((((((((((("for(let for_i = " + start_) + ", for_a = ") + listCode_) + ", for_l = ") + end_) + "; for_i < for_l; for_i++) {\n") + ff_core_Option.Option_else(ff_core_Option.Option_map(name_, ((_w1) => {
3963
3915
  return (("const " + ff_compiler_JsEmitter.escapeKeyword_(_w1)) + " = for_a[for_i];\n")
3964
3916
  })), (() => {
@@ -4126,6 +4078,66 @@ return ff_core_Option.None()
4126
4078
  }
4127
4079
  }
4128
4080
 
4081
+ export async function JsEmitter_emitLightFusion$(self_, list_, async_, $task) {
4082
+ let start_ = "0";
4083
+ let end_ = "for_a.length";
4084
+ const listCode_ = (await ((async (_1, $task) => {
4085
+ if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropFirst" && _1.arguments_.length === 2) {
4086
+ const a1_ = _1.arguments_[0];
4087
+ const a2_ = _1.arguments_[1];
4088
+ start_ = (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a2_.value_, async_, $task));
4089
+ if((!ff_core_String.String_all(start_, ((_w1) => {
4090
+ return ff_core_Char.Char_isAsciiDigit(_w1)
4091
+ })))) {
4092
+ start_ = (("Math.max(" + start_) + ", 0)")
4093
+ };
4094
+ return (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a1_.value_, async_, $task))
4095
+ }
4096
+ if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_dropLast" && _1.arguments_.length === 2) {
4097
+ const a1_ = _1.arguments_[0];
4098
+ const a2_ = _1.arguments_[1];
4099
+ const count_ = (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a2_.value_, async_, $task));
4100
+ if((!ff_core_String.String_all(count_, ((_w1) => {
4101
+ return ff_core_Char.Char_isAsciiDigit(_w1)
4102
+ })))) {
4103
+ end_ = (((end_ + " - Math.max(") + count_) + ", 0)")
4104
+ } else {
4105
+ end_ = ((end_ + " - ") + count_)
4106
+ };
4107
+ return (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a1_.value_, async_, $task))
4108
+ }
4109
+ if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_takeFirst" && _1.arguments_.length === 2) {
4110
+ const a1_ = _1.arguments_[0];
4111
+ const a2_ = _1.arguments_[1];
4112
+ end_ = (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a2_.value_, async_, $task));
4113
+ if((!ff_core_String.String_all(end_, ((_w1) => {
4114
+ return ff_core_Char.Char_isAsciiDigit(_w1)
4115
+ })))) {
4116
+ end_ = (("Math.max(" + end_) + ", 0)")
4117
+ };
4118
+ end_ = (("Math.min(" + end_) + ", for_a.length)");
4119
+ return (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a1_.value_, async_, $task))
4120
+ }
4121
+ if(_1.ECall && _1.target_.StaticCall && _1.target_.name_ === "ff:core/List.List_takeLast" && _1.arguments_.length === 2) {
4122
+ const a1_ = _1.arguments_[0];
4123
+ const a2_ = _1.arguments_[1];
4124
+ const count_ = (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a2_.value_, async_, $task));
4125
+ if((!ff_core_String.String_all(count_, ((_w1) => {
4126
+ return ff_core_Char.Char_isAsciiDigit(_w1)
4127
+ })))) {
4128
+ start_ = (("Math.max(for_a.length - Math.max(" + count_) + ", 0), 0)")
4129
+ } else {
4130
+ start_ = (("Math.max(for_a.length - " + count_) + ", 0)")
4131
+ };
4132
+ return (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, a1_.value_, async_, $task))
4133
+ }
4134
+ {
4135
+ return (await ff_compiler_JsEmitter.JsEmitter_emitTerm$(self_, list_, async_, $task))
4136
+ }
4137
+ }))(list_, $task));
4138
+ return ff_core_Pair.Pair(listCode_, ff_core_Pair.Pair(start_, end_))
4139
+ }
4140
+
4129
4141
  export async function JsEmitter_emitTryCatchFinally$(self_, term_, last_, async_, $task) {
4130
4142
  async function emitCatch_$(catchEffect_, cases_, $task) {
4131
4143
  const catchAsync_ = (self_.emittingAsync_ && ff_compiler_JsEmitter.effectTypeIsAsync_(catchEffect_));
@@ -233,7 +233,7 @@ return ff_core_Array.Array_drain(array_)
233
233
  }
234
234
 
235
235
  export function Random_sampleArray(self_, count_, array_, body_) {
236
- for(let for_i = 0, for_a = ff_core_List.List_takeFirst(ff_core_Random.Random_shuffleList(self_, ff_core_Array.Array_toList(array_, 0, 9007199254740991)), count_), for_l = for_a.length; for_i < for_l; for_i++) {
236
+ for(let for_i = 0, for_a = ff_core_Random.Random_shuffleList(self_, ff_core_Array.Array_toList(array_, 0, 9007199254740991)), for_l = Math.min(Math.max(count_, 0), for_a.length); for_i < for_l; for_i++) {
237
237
  const _w1 = for_a[for_i];
238
238
  body_(_w1)
239
239
  }
@@ -295,7 +295,7 @@ return ff_core_Array.Array_drain(array_)
295
295
  }
296
296
 
297
297
  export async function Random_sampleArray$(self_, count_, array_, body_, $task) {
298
- for(let for_i = 0, for_a = ff_core_List.List_takeFirst(ff_core_Random.Random_shuffleList(self_, ff_core_Array.Array_toList(array_, 0, 9007199254740991)), count_), for_l = for_a.length; for_i < for_l; for_i++) {
298
+ for(let for_i = 0, for_a = ff_core_Random.Random_shuffleList(self_, ff_core_Array.Array_toList(array_, 0, 9007199254740991)), for_l = Math.min(Math.max(count_, 0), for_a.length); for_i < for_l; for_i++) {
299
299
  const _w1 = for_a[for_i];
300
300
  (await body_(_w1, $task))
301
301
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "description": "Firefly compiler",
5
5
  "author": "Firefly team",
6
6
  "license": "MIT",
7
- "version": "0.5.10",
7
+ "version": "0.5.11",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/Ahnfelt/firefly-boot"
@@ -4,7 +4,7 @@
4
4
  "description": "Firefly language support",
5
5
  "author": "Firefly team",
6
6
  "license": "MIT",
7
- "version": "0.5.10",
7
+ "version": "0.5.11",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/Ahnfelt/firefly-boot"