pxt-core 12.2.3 → 12.2.4

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/built/pxt.js CHANGED
@@ -112229,6 +112229,7 @@ var pxt;
112229
112229
  let currentValue = null;
112230
112230
  let listStack = [];
112231
112231
  let currentIndent = 0;
112232
+ let currentCodeBlock = null;
112232
112233
  for (const line of lines) {
112233
112234
  if (!line.trim()) {
112234
112235
  if (currentValue) {
@@ -112236,6 +112237,33 @@ var pxt;
112236
112237
  }
112237
112238
  continue;
112238
112239
  }
112240
+ if (line.startsWith("```")) {
112241
+ if (currentCodeBlock) {
112242
+ if (currentSection) {
112243
+ if (!currentSection.codeBlocks) {
112244
+ currentSection.codeBlocks = [currentCodeBlock];
112245
+ }
112246
+ else {
112247
+ currentSection.codeBlocks.push(currentCodeBlock);
112248
+ }
112249
+ }
112250
+ currentCodeBlock = null;
112251
+ continue;
112252
+ }
112253
+ else {
112254
+ const match = /^```([a-zA-Z_\-]*)$/.exec(line);
112255
+ if (match) {
112256
+ currentCodeBlock = {
112257
+ content: "",
112258
+ languageCode: match[1]
112259
+ };
112260
+ continue;
112261
+ }
112262
+ }
112263
+ }
112264
+ else if (currentCodeBlock) {
112265
+ currentCodeBlock.content += line + "\n";
112266
+ }
112239
112267
  if (line.startsWith("#")) {
112240
112268
  const headerMatch = /^(#+)\s*(.+)$/.exec(line);
112241
112269
  if (headerMatch) {
@@ -132053,16 +132081,25 @@ var ts;
132053
132081
  let outlines = [];
132054
132082
  let values = {};
132055
132083
  let seq = 1;
132084
+ const isLdLit = (line) => line.type == "instruction" && line.instruction && line.instruction.name == "ldlit";
132056
132085
  for (let i = 0; i < f.lines.length; ++i) {
132057
132086
  let line = f.lines[i];
132058
132087
  outlines.push(line);
132059
- if (line.type == "instruction" && line.instruction && line.instruction.name == "ldlit") {
132088
+ if (isLdLit(line)) {
132060
132089
  if (!nextGoodSpot) {
132061
132090
  let limit = line.location + 900; // leave some space - real limit is 1020
132062
132091
  let j = i + 1;
132092
+ let numLdLits = 0;
132063
132093
  for (; j < f.lines.length; ++j) {
132064
132094
  if (f.lines[j].location > limit)
132065
132095
  break;
132096
+ if (isLdLit(f.lines[j])) {
132097
+ numLdLits++;
132098
+ // Short branches have 256 bytes range. We don't want to move code by anywhere
132099
+ // close to that. Each ldlit is 4 bytes.
132100
+ if (numLdLits >= 160 / 4)
132101
+ break;
132102
+ }
132066
132103
  let op = f.lines[j].getOp();
132067
132104
  if (op == "b" || op == "bb" || (op == "pop" && f.lines[j].words[2] == "pc"))
132068
132105
  nextGoodSpot = f.lines[j];
@@ -133775,6 +133812,14 @@ var ts;
133775
133812
  return null;
133776
133813
  }
133777
133814
  function isArrayType(t) {
133815
+ if (t.flags & ts.TypeFlags.Union && t.types) {
133816
+ for (const subtype of t.types) {
133817
+ if (!isArrayType(subtype)) {
133818
+ return false;
133819
+ }
133820
+ }
133821
+ return true;
133822
+ }
133778
133823
  if (!isObjectType(t)) {
133779
133824
  return false;
133780
133825
  }
@@ -133813,7 +133858,12 @@ var ts;
133813
133858
  }
133814
133859
  function arrayElementType(t, idx = -1) {
133815
133860
  if (isArrayType(t))
133816
- return checkType(t.typeArguments[0]);
133861
+ if (t.flags & ts.TypeFlags.Union) {
133862
+ return checkType(t.getNumberIndexType());
133863
+ }
133864
+ else {
133865
+ return checkType(t.typeArguments[0]);
133866
+ }
133817
133867
  return checker.getIndexTypeOfType(t, ts.IndexKind.Number);
133818
133868
  }
133819
133869
  function isFunctionType(t) {
@@ -134844,9 +134894,12 @@ ${lbl}: .short 0xffff
134844
134894
  let eltT = arrayElementType(typeOf(node));
134845
134895
  let coll = pxtc.ir.shared(pxtc.ir.rtcall("Array_::mk", []));
134846
134896
  for (let elt of node.elements) {
134847
- let mask = isRefCountedExpr(elt) ? 2 : 0;
134897
+ let mask = isRefCountedExpr(elt) ? (1 << 1) : 0;
134848
134898
  proc.emitExpr(pxtc.ir.rtcall("Array_::push", [coll, emitExpr(elt)], mask));
134849
134899
  }
134900
+ if (node.elements.length > 0)
134901
+ // Make sure there is at least one use of the array, so it doesn't get GC-ed away in the last push.
134902
+ proc.emitExpr(pxtc.ir.rtcall("langsupp::ignore", [coll], 1));
134850
134903
  return coll;
134851
134904
  }
134852
134905
  function emitObjectLiteral(node) {
@@ -134855,6 +134908,7 @@ ${lbl}: .short 0xffff
134855
134908
  pxtc.assert(!p.questionToken); // should be disallowed by TS grammar checker
134856
134909
  let keyName;
134857
134910
  let init;
134911
+ let mask = 0;
134858
134912
  if (p.kind == pxtc.SK.ShorthandPropertyAssignment) {
134859
134913
  const sp = p;
134860
134914
  pxtc.assert(!sp.equalsToken && !sp.objectAssignmentInitializer); // disallowed by TS grammar checker
@@ -134880,6 +134934,8 @@ ${lbl}: .short 0xffff
134880
134934
  keyName = p.name.kind == pxtc.SK.StringLiteral ?
134881
134935
  p.name.text : p.name.getText();
134882
134936
  init = emitExpr(p.initializer);
134937
+ if (isRefCountedExpr(p.initializer))
134938
+ mask |= 1 << 2;
134883
134939
  }
134884
134940
  const fieldId = pxtc.target.isNative
134885
134941
  ? pxtc.ir.numlit(getIfaceMemberId(keyName))
@@ -134889,8 +134945,11 @@ ${lbl}: .short 0xffff
134889
134945
  fieldId,
134890
134946
  init
134891
134947
  ];
134892
- proc.emitExpr(pxtc.ir.rtcall(pxtc.target.isNative ? "pxtrt::mapSet" : "pxtrt::mapSetByString", args));
134948
+ proc.emitExpr(pxtc.ir.rtcall(pxtc.target.isNative ? "pxtrt::mapSet" : "pxtrt::mapSetByString", args, mask));
134893
134949
  });
134950
+ // Make sure there is at least one use of the map, so it doesn't get GC-ed away in the last mapSet.
134951
+ if (node.properties.length > 0)
134952
+ proc.emitExpr(pxtc.ir.rtcall("langsupp::ignore", [expr], 1));
134894
134953
  return expr;
134895
134954
  }
134896
134955
  function emitPropertyAssignment(node) {
@@ -7737,16 +7737,25 @@ var ts;
7737
7737
  let outlines = [];
7738
7738
  let values = {};
7739
7739
  let seq = 1;
7740
+ const isLdLit = (line) => line.type == "instruction" && line.instruction && line.instruction.name == "ldlit";
7740
7741
  for (let i = 0; i < f.lines.length; ++i) {
7741
7742
  let line = f.lines[i];
7742
7743
  outlines.push(line);
7743
- if (line.type == "instruction" && line.instruction && line.instruction.name == "ldlit") {
7744
+ if (isLdLit(line)) {
7744
7745
  if (!nextGoodSpot) {
7745
7746
  let limit = line.location + 900; // leave some space - real limit is 1020
7746
7747
  let j = i + 1;
7748
+ let numLdLits = 0;
7747
7749
  for (; j < f.lines.length; ++j) {
7748
7750
  if (f.lines[j].location > limit)
7749
7751
  break;
7752
+ if (isLdLit(f.lines[j])) {
7753
+ numLdLits++;
7754
+ // Short branches have 256 bytes range. We don't want to move code by anywhere
7755
+ // close to that. Each ldlit is 4 bytes.
7756
+ if (numLdLits >= 160 / 4)
7757
+ break;
7758
+ }
7750
7759
  let op = f.lines[j].getOp();
7751
7760
  if (op == "b" || op == "bb" || (op == "pop" && f.lines[j].words[2] == "pc"))
7752
7761
  nextGoodSpot = f.lines[j];
@@ -9459,6 +9468,14 @@ var ts;
9459
9468
  return null;
9460
9469
  }
9461
9470
  function isArrayType(t) {
9471
+ if (t.flags & ts.TypeFlags.Union && t.types) {
9472
+ for (const subtype of t.types) {
9473
+ if (!isArrayType(subtype)) {
9474
+ return false;
9475
+ }
9476
+ }
9477
+ return true;
9478
+ }
9462
9479
  if (!isObjectType(t)) {
9463
9480
  return false;
9464
9481
  }
@@ -9497,7 +9514,12 @@ var ts;
9497
9514
  }
9498
9515
  function arrayElementType(t, idx = -1) {
9499
9516
  if (isArrayType(t))
9500
- return checkType(t.typeArguments[0]);
9517
+ if (t.flags & ts.TypeFlags.Union) {
9518
+ return checkType(t.getNumberIndexType());
9519
+ }
9520
+ else {
9521
+ return checkType(t.typeArguments[0]);
9522
+ }
9501
9523
  return checker.getIndexTypeOfType(t, ts.IndexKind.Number);
9502
9524
  }
9503
9525
  function isFunctionType(t) {
@@ -10528,9 +10550,12 @@ ${lbl}: .short 0xffff
10528
10550
  let eltT = arrayElementType(typeOf(node));
10529
10551
  let coll = pxtc.ir.shared(pxtc.ir.rtcall("Array_::mk", []));
10530
10552
  for (let elt of node.elements) {
10531
- let mask = isRefCountedExpr(elt) ? 2 : 0;
10553
+ let mask = isRefCountedExpr(elt) ? (1 << 1) : 0;
10532
10554
  proc.emitExpr(pxtc.ir.rtcall("Array_::push", [coll, emitExpr(elt)], mask));
10533
10555
  }
10556
+ if (node.elements.length > 0)
10557
+ // Make sure there is at least one use of the array, so it doesn't get GC-ed away in the last push.
10558
+ proc.emitExpr(pxtc.ir.rtcall("langsupp::ignore", [coll], 1));
10534
10559
  return coll;
10535
10560
  }
10536
10561
  function emitObjectLiteral(node) {
@@ -10539,6 +10564,7 @@ ${lbl}: .short 0xffff
10539
10564
  pxtc.assert(!p.questionToken); // should be disallowed by TS grammar checker
10540
10565
  let keyName;
10541
10566
  let init;
10567
+ let mask = 0;
10542
10568
  if (p.kind == pxtc.SK.ShorthandPropertyAssignment) {
10543
10569
  const sp = p;
10544
10570
  pxtc.assert(!sp.equalsToken && !sp.objectAssignmentInitializer); // disallowed by TS grammar checker
@@ -10564,6 +10590,8 @@ ${lbl}: .short 0xffff
10564
10590
  keyName = p.name.kind == pxtc.SK.StringLiteral ?
10565
10591
  p.name.text : p.name.getText();
10566
10592
  init = emitExpr(p.initializer);
10593
+ if (isRefCountedExpr(p.initializer))
10594
+ mask |= 1 << 2;
10567
10595
  }
10568
10596
  const fieldId = pxtc.target.isNative
10569
10597
  ? pxtc.ir.numlit(getIfaceMemberId(keyName))
@@ -10573,8 +10601,11 @@ ${lbl}: .short 0xffff
10573
10601
  fieldId,
10574
10602
  init
10575
10603
  ];
10576
- proc.emitExpr(pxtc.ir.rtcall(pxtc.target.isNative ? "pxtrt::mapSet" : "pxtrt::mapSetByString", args));
10604
+ proc.emitExpr(pxtc.ir.rtcall(pxtc.target.isNative ? "pxtrt::mapSet" : "pxtrt::mapSetByString", args, mask));
10577
10605
  });
10606
+ // Make sure there is at least one use of the map, so it doesn't get GC-ed away in the last mapSet.
10607
+ if (node.properties.length > 0)
10608
+ proc.emitExpr(pxtc.ir.rtcall("langsupp::ignore", [expr], 1));
10578
10609
  return expr;
10579
10610
  }
10580
10611
  function emitPropertyAssignment(node) {
package/built/pxtlib.d.ts CHANGED
@@ -1986,6 +1986,11 @@ declare namespace pxt {
1986
1986
  header: string;
1987
1987
  attributes: pxt.Map<string>;
1988
1988
  listAttributes?: pxt.Map<MarkdownList>;
1989
+ codeBlocks?: MarkdownCodeBlock[];
1990
+ }
1991
+ interface MarkdownCodeBlock {
1992
+ content: string;
1993
+ languageCode?: string;
1989
1994
  }
1990
1995
  interface MarkdownList {
1991
1996
  key: string;
package/built/pxtlib.js CHANGED
@@ -14508,6 +14508,7 @@ var pxt;
14508
14508
  let currentValue = null;
14509
14509
  let listStack = [];
14510
14510
  let currentIndent = 0;
14511
+ let currentCodeBlock = null;
14511
14512
  for (const line of lines) {
14512
14513
  if (!line.trim()) {
14513
14514
  if (currentValue) {
@@ -14515,6 +14516,33 @@ var pxt;
14515
14516
  }
14516
14517
  continue;
14517
14518
  }
14519
+ if (line.startsWith("```")) {
14520
+ if (currentCodeBlock) {
14521
+ if (currentSection) {
14522
+ if (!currentSection.codeBlocks) {
14523
+ currentSection.codeBlocks = [currentCodeBlock];
14524
+ }
14525
+ else {
14526
+ currentSection.codeBlocks.push(currentCodeBlock);
14527
+ }
14528
+ }
14529
+ currentCodeBlock = null;
14530
+ continue;
14531
+ }
14532
+ else {
14533
+ const match = /^```([a-zA-Z_\-]*)$/.exec(line);
14534
+ if (match) {
14535
+ currentCodeBlock = {
14536
+ content: "",
14537
+ languageCode: match[1]
14538
+ };
14539
+ continue;
14540
+ }
14541
+ }
14542
+ }
14543
+ else if (currentCodeBlock) {
14544
+ currentCodeBlock.content += line + "\n";
14545
+ }
14518
14546
  if (line.startsWith("#")) {
14519
14547
  const headerMatch = /^(#+)\s*(.+)$/.exec(line);
14520
14548
  if (headerMatch) {