pxt-core 8.2.10 → 8.2.12

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.
@@ -612,7 +612,7 @@ var ts;
612
612
  // Assumptions:
613
613
  // - registers can hold a pointer (data or code)
614
614
  // - special registers include: sp
615
- // - fixed registers are r0, r1, r2, r3, r5, r6
615
+ // - fixed registers are r0, r1, r2, r3, r5, r6
616
616
  // - r0 is the current value (from expression evaluation)
617
617
  // - registers for runtime calls (r0, r1,r2,r3)
618
618
  // - r5 is for captured locals in lambda
@@ -625,7 +625,7 @@ var ts;
625
625
  class AssemblerSnippets {
626
626
  nop() { return "TBD(nop)"; }
627
627
  reg_gets_imm(reg, imm) { return "TBD(reg_gets_imm)"; }
628
- // Registers are stored on the stack in numerical order
628
+ // Registers are stored on the stack in numerical order
629
629
  proc_setup(numlocals, main) { return "TBD(proc_setup)"; }
630
630
  push_fixed(reg) { return "TBD(push_fixed)"; }
631
631
  push_local(reg) { return "TBD(push_local)"; }
@@ -840,7 +840,7 @@ ${baseLabel}_nochk:
840
840
  }
841
841
  }
842
842
  };
843
- if (this.bin.options.breakpoints) {
843
+ if (this.bin.breakpoints) {
844
844
  this.write(this.t.debugger_proc(bkptLabel));
845
845
  }
846
846
  this.baseStackSize = 1; // push {lr}
@@ -883,7 +883,7 @@ ${baseLabel}_nochk:
883
883
  this.write(`; ${s.expr.data}`);
884
884
  break;
885
885
  case pxtc.ir.SK.Breakpoint:
886
- if (this.bin.options.breakpoints) {
886
+ if (this.bin.breakpoints) {
887
887
  let lbl = `__brkp_${s.breakpointInfo.id}`;
888
888
  if (s.breakpointInfo.isDebuggerStmt) {
889
889
  this.write(this.t.debugger_stmt(lbl));
@@ -2282,7 +2282,7 @@ var ts;
2282
2282
  "bind",
2283
2283
  "leaveAccessor"
2284
2284
  ];
2285
- function jsEmit(bin) {
2285
+ function jsEmit(bin, cres) {
2286
2286
  let jssource = "(function (ectx) {\n'use strict';\n";
2287
2287
  for (let n of evalIfaceFields) {
2288
2288
  jssource += `const ${n} = ectx.${n};\n`;
@@ -2294,7 +2294,7 @@ var ts;
2294
2294
  jssource += "pxsim.setTitle(" + JSON.stringify(bin.getTitle()) + ");\n";
2295
2295
  let cfg = {};
2296
2296
  let cfgKey = {};
2297
- for (let ce of bin.res.configData || []) {
2297
+ for (let ce of cres.configData || []) {
2298
2298
  cfg[ce.key + ""] = ce.value;
2299
2299
  cfgKey[ce.name] = ce.key;
2300
2300
  }
@@ -2324,8 +2324,8 @@ var ts;
2324
2324
  bin.usedClassInfos.forEach(info => {
2325
2325
  jssource += vtableToJs(info);
2326
2326
  });
2327
- if (bin.res.breakpoints)
2328
- jssource += `\nconst breakpoints = setupDebugger(${bin.res.breakpoints.length}, [${bin.globals.filter(c => c.isUserVariable).map(c => `"${c.uniqueName()}"`).join(",")}])\n`;
2327
+ if (cres.breakpoints)
2328
+ jssource += `\nconst breakpoints = setupDebugger(${cres.breakpoints.length}, [${bin.globals.filter(c => c.isUserVariable).map(c => `"${c.uniqueName()}"`).join(",")}])\n`;
2329
2329
  jssource += `\nreturn ${bin.procs[0] ? bin.procs[0].label() : "null"}\n})\n`;
2330
2330
  const total = jssource.length;
2331
2331
  const perc = (n) => ((100 * n) / total).toFixed(2) + "%";
@@ -2459,7 +2459,7 @@ function ${id}(s) {
2459
2459
  let id = s.breakpointInfo.id;
2460
2460
  let lbl;
2461
2461
  write(`s.lastBrkId = ${id};`);
2462
- if (bin.options.breakpoints) {
2462
+ if (bin.breakpoints) {
2463
2463
  lbl = ++lblIdx;
2464
2464
  let brkCall = `return breakpoint(s, ${lbl}, ${id}, r0);`;
2465
2465
  if (s.breakpointInfo.isDebuggerStmt) {
@@ -2467,12 +2467,12 @@ function ${id}(s) {
2467
2467
  }
2468
2468
  else {
2469
2469
  write(`if ((breakpoints[0] && isBreakFrame(s)) || breakpoints[${id}]) ${brkCall}`);
2470
- if (bin.options.trace) {
2470
+ if (bin.trace) {
2471
2471
  write(`else return trace(${id}, s, ${lbl}, ${proc.label()}.info);`);
2472
2472
  }
2473
2473
  }
2474
2474
  }
2475
- else if (bin.options.trace) {
2475
+ else if (bin.trace) {
2476
2476
  lbl = ++lblIdx;
2477
2477
  write(`return trace(${id}, s, ${lbl}, ${proc.label()}.info);`);
2478
2478
  }
@@ -3414,7 +3414,7 @@ ${info.id}_IfaceVT:
3414
3414
  }
3415
3415
  }
3416
3416
  /* eslint-disable no-trailing-spaces */
3417
- function vmEmit(bin, opts) {
3417
+ function vmEmit(bin, opts, cres) {
3418
3418
  let vmsource = `; VM start
3419
3419
  _img_start:
3420
3420
  ${pxtc.hexfile.hexPrelude()}
@@ -3518,7 +3518,7 @@ _start_${name}:
3518
3518
  + "\n.word 0, 0, 0 ; dummy entry to make sure not empty");
3519
3519
  section("numberLiterals", SectionType.NumberLiterals, () => ctx.dblText.join("\n")
3520
3520
  + "\n.word 0, 0 ; dummy entry to make sure not empty");
3521
- const cfg = bin.res.configData || [];
3521
+ const cfg = cres.configData || [];
3522
3522
  section("configData", SectionType.ConfigData, () => cfg.map(d => ` .word ${d.key}, ${d.value} ; ${d.name}=${d.value}`).join("\n")
3523
3523
  + "\n .word 0, 0");
3524
3524
  let s = ctx.opcodes.map(s => s == null ? "" : s).join("\x00") + "\x00";
@@ -9702,8 +9702,9 @@ var ts;
9702
9702
  }
9703
9703
  let bin = new Binary();
9704
9704
  let proc;
9705
- bin.res = res;
9706
- bin.options = opts;
9705
+ bin.trace = opts.trace;
9706
+ bin.breakpoints = opts.breakpoints;
9707
+ bin.name = opts.name;
9707
9708
  bin.target = opts.target;
9708
9709
  function reset() {
9709
9710
  bin.reset();
@@ -9929,29 +9930,8 @@ var ts;
9929
9930
  info.captured = true;
9930
9931
  }
9931
9932
  }
9932
- function recordAction(f) {
9933
- const r = f(bin);
9934
- if (needsUsingInfo)
9935
- bin.recordAction(currUsingContext, f);
9936
- return r;
9937
- }
9938
9933
  function getIfaceMemberId(name, markUsed = false) {
9939
- return recordAction(bin => {
9940
- if (markUsed) {
9941
- if (!pxtc.U.lookup(bin.explicitlyUsedIfaceMembers, name)) {
9942
- pxtc.U.assert(!bin.finalPass);
9943
- bin.explicitlyUsedIfaceMembers[name] = true;
9944
- }
9945
- }
9946
- let v = pxtc.U.lookup(bin.ifaceMemberMap, name);
9947
- if (v != null)
9948
- return v;
9949
- pxtc.U.assert(!bin.finalPass);
9950
- // this gets renumbered before the final pass
9951
- v = bin.ifaceMemberMap[name] = -1;
9952
- bin.emitString(name);
9953
- return v;
9954
- });
9934
+ return recordGetInterfaceId(bin, name, markUsed, needsUsingInfo, currUsingContext);
9955
9935
  }
9956
9936
  function finalEmit() {
9957
9937
  if (opts.noEmit)
@@ -9975,13 +9955,16 @@ var ts;
9975
9955
  bin.writeFile("platformio.json", JSON.stringify(extinfo.platformio, null, 2));
9976
9956
  });
9977
9957
  if (opts.target.nativeType == pxtc.NATIVE_TYPE_VM)
9978
- pxtc.vmEmit(bin, opts);
9958
+ pxtc.vmEmit(bin, opts, res);
9979
9959
  else
9980
9960
  pxtc.processorEmit(bin, opts, res);
9981
9961
  }
9982
9962
  else {
9983
- pxtc.jsEmit(bin);
9963
+ pxtc.jsEmit(bin, res);
9984
9964
  }
9965
+ // Clear writeFile so that we don't leak the reference to res, which
9966
+ // includes the entire source of the program
9967
+ bin.writeFile = undefined;
9985
9968
  }
9986
9969
  function typeCheckVar(tp) {
9987
9970
  if (tp.flags & ts.TypeFlags.Void) {
@@ -10698,9 +10681,7 @@ ${lbl}: .short 0xffff
10698
10681
  markUsed(decl);
10699
10682
  }
10700
10683
  function emitAndMarkString(str) {
10701
- return recordAction(bin => {
10702
- return bin.emitString(str);
10703
- });
10684
+ return recordEmitAndMarkString(bin, str, needsUsingInfo, currUsingContext);
10704
10685
  }
10705
10686
  function recordUsage(decl) {
10706
10687
  if (!needsUsingInfo)
@@ -11547,7 +11528,7 @@ ${lbl}: .short 0xffff
11547
11528
  pinfo.proc = myProc;
11548
11529
  myProc.usingCtx = currUsingContext;
11549
11530
  proc = myProc;
11550
- recordAction(bin => bin.addProc(myProc));
11531
+ recordAddProc(bin, myProc, needsUsingInfo, currUsingContext);
11551
11532
  }
11552
11533
  proc.captured = locals;
11553
11534
  const initalizedFields = [];
@@ -13464,7 +13445,7 @@ ${lbl}: .short 0xffff
13464
13445
  this.numStmts = 0;
13465
13446
  }
13466
13447
  getTitle() {
13467
- const title = this.options.name || pxtc.U.lf("Untitled");
13448
+ const title = this.name || pxtc.U.lf("Untitled");
13468
13449
  if (title.length >= 90)
13469
13450
  return title.slice(0, 87) + "...";
13470
13451
  else
@@ -13552,6 +13533,36 @@ ${lbl}: .short 0xffff
13552
13533
  return !!(type.flags & (ts.TypeFlags.NumberLike | ts.TypeFlags.EnumLike | ts.TypeFlags.BooleanLike));
13553
13534
  }
13554
13535
  }
13536
+ function recordAction(bin, needsUsingInfo, currUsingContext, f) {
13537
+ const r = f(bin);
13538
+ if (needsUsingInfo)
13539
+ bin.recordAction(currUsingContext, f);
13540
+ return r;
13541
+ }
13542
+ function recordAddProc(bin, proc, needsUsingInfo, currUsingContext) {
13543
+ recordAction(bin, needsUsingInfo, currUsingContext, b => b.addProc(proc));
13544
+ }
13545
+ function recordGetInterfaceId(bin, name, markUsed, needsUsingInfo, currUsingContext) {
13546
+ return recordAction(bin, needsUsingInfo, currUsingContext, bin => {
13547
+ if (markUsed) {
13548
+ if (!pxtc.U.lookup(bin.explicitlyUsedIfaceMembers, name)) {
13549
+ pxtc.U.assert(!bin.finalPass);
13550
+ bin.explicitlyUsedIfaceMembers[name] = true;
13551
+ }
13552
+ }
13553
+ let v = pxtc.U.lookup(bin.ifaceMemberMap, name);
13554
+ if (v != null)
13555
+ return v;
13556
+ pxtc.U.assert(!bin.finalPass);
13557
+ // this gets renumbered before the final pass
13558
+ v = bin.ifaceMemberMap[name] = -1;
13559
+ bin.emitString(name);
13560
+ return v;
13561
+ });
13562
+ }
13563
+ function recordEmitAndMarkString(bin, str, needsUsingInfo, currUsingContext) {
13564
+ return recordAction(bin, needsUsingInfo, currUsingContext, b => b.emitString(str));
13565
+ }
13555
13566
  })(pxtc = ts.pxtc || (ts.pxtc = {}));
13556
13567
  })(ts || (ts = {}));
13557
13568
  /// <reference path="../../localtypings/pxtarget.d.ts"/>
@@ -15575,7 +15586,7 @@ var ts;
15575
15586
  for (let i = 0; i < hd.length; ++i)
15576
15587
  pxt.HF2.write16(resbuf, i * 2 + ctx.jmpStartAddr, hd[i]);
15577
15588
  if (uf2 && !bin.target.switches.rawELF) {
15578
- let bn = bin.options.name || "pxt";
15589
+ let bn = bin.name || "pxt";
15579
15590
  bn = bn.replace(/[^a-zA-Z0-9\-\.]+/g, "_");
15580
15591
  uf2.filename = "Projects/" + bn + ".elf";
15581
15592
  pxtc.UF2.writeBytes(uf2, 0, resbuf);
@@ -15822,7 +15833,7 @@ ${lbl}: ${snippets.obj_header("pxt::number_vt")}
15822
15833
  }
15823
15834
  }
15824
15835
  pxtc.computeHashMultiplier = computeHashMultiplier;
15825
- function vtableToAsm(info, opts, bin) {
15836
+ function vtableToAsm(info, opts, bin, res) {
15826
15837
  /*
15827
15838
  uint16_t numbytes;
15828
15839
  ValType objectType;
@@ -15910,7 +15921,7 @@ ${hexfile.hexPrelude()}
15910
15921
  .hex 873266330af9dbdb ; replaced in binary by program hash
15911
15922
  `;
15912
15923
  }
15913
- function serialize(bin, opts) {
15924
+ function serialize(bin, opts, res) {
15914
15925
  let asmsource = `
15915
15926
  .short ${bin.globalsWords} ; num. globals
15916
15927
  .short 0 ; patched with number of 64 bit words resulting from assembly
@@ -15945,7 +15956,7 @@ ${hexfile.hexPrelude()}
15945
15956
  asmsource += snippets.arithmetic();
15946
15957
  asmsource += "_helpers_end:\n\n";
15947
15958
  bin.usedClassInfos.forEach(info => {
15948
- asmsource += vtableToAsm(info, opts, bin);
15959
+ asmsource += vtableToAsm(info, opts, bin, res);
15949
15960
  });
15950
15961
  asmsource += `\n.balign 4\n.object _pxt_iface_member_names\n_pxt_iface_member_names:\n`;
15951
15962
  asmsource += ` .word ${bin.ifaceMembers.length}\n`;
@@ -15957,7 +15968,7 @@ ${hexfile.hexPrelude()}
15957
15968
  asmsource += ` .word 0\n`;
15958
15969
  asmsource += "_vtables_end:\n\n";
15959
15970
  asmsource += `\n.balign 4\n.object _pxt_config_data\n_pxt_config_data:\n`;
15960
- const cfg = bin.res.configData || [];
15971
+ const cfg = res.configData || [];
15961
15972
  // asmsource += ` .word ${cfg.length}, 0 ; num. entries`
15962
15973
  for (let d of cfg) {
15963
15974
  asmsource += ` .word ${d.key}, ${d.value} ; ${d.name}=${d.value}\n`;
@@ -16226,7 +16237,7 @@ __flash_checksums:
16226
16237
  return elts.map(s => `"${s}"`).join(",");
16227
16238
  }
16228
16239
  function processorEmit(bin, opts, cres) {
16229
- const src = serialize(bin, opts);
16240
+ const src = serialize(bin, opts, cres);
16230
16241
  const opts0 = pxtc.U.flatClone(opts);
16231
16242
  // normally, this would already have been done, but if the main variant
16232
16243
  // is disabled, another variant may be set up
package/built/pxtsim.d.ts CHANGED
@@ -465,6 +465,10 @@ declare namespace pxsim {
465
465
  delay?: number;
466
466
  modalContext?: string;
467
467
  }
468
+ interface SimulatorAutomaticThumbnailMessage extends SimulatorMessage {
469
+ type: "thumbnail";
470
+ frames: ImageData[];
471
+ }
468
472
  interface SimulatorAddExtensionsMessage extends SimulatorMessage {
469
473
  type: "addextensions";
470
474
  /**
@@ -1147,6 +1151,10 @@ declare namespace pxsim {
1147
1151
  perfOffset: number;
1148
1152
  perfElapsed: number;
1149
1153
  perfStack: number;
1154
+ lastInteractionTime: number;
1155
+ lastThumbnailTime: number;
1156
+ thumbnailRecordingIntervalRef: number;
1157
+ thumbnailFrames: ImageData[];
1150
1158
  refCountingDebug: boolean;
1151
1159
  private refObjId;
1152
1160
  overwriteResume: (retPC: number) => void;
@@ -1191,6 +1199,7 @@ declare namespace pxsim {
1191
1199
  pauseScheduled(): void;
1192
1200
  resumeAllPausedScheduled(): void;
1193
1201
  cleanScheduledExpired(): void;
1202
+ registerUserInteraction(): void;
1194
1203
  }
1195
1204
  class PerfCounter {
1196
1205
  name: string;
package/built/pxtsim.js CHANGED
@@ -5758,17 +5758,8 @@ var pxsim;
5758
5758
  this.board.screenshotAsync(this.recordingWidth)
5759
5759
  .then(imageData => {
5760
5760
  // check for duplicate images
5761
- if (this.recordingLastImageData && imageData
5762
- && this.recordingLastImageData.data.byteLength == imageData.data.byteLength) {
5763
- const d0 = this.recordingLastImageData.data;
5764
- const d1 = imageData.data;
5765
- const n = d0.byteLength;
5766
- let i = 0;
5767
- for (i = 0; i < n; ++i)
5768
- if (d0[i] != d1[i])
5769
- break;
5770
- if (i == n) // same, don't send update
5771
- return;
5761
+ if (this.recordingLastImageData && isImageDataEqual(this.recordingLastImageData, imageData)) {
5762
+ return;
5772
5763
  }
5773
5764
  this.recordingLastImageData = imageData;
5774
5765
  Runtime.postMessage({
@@ -5948,6 +5939,28 @@ var pxsim;
5948
5939
  return ts.totalRuntime > elapsed;
5949
5940
  });
5950
5941
  }
5942
+ registerUserInteraction() {
5943
+ this.lastInteractionTime = Date.now();
5944
+ if (this.thumbnailRecordingIntervalRef || this.lastThumbnailTime && this.lastInteractionTime - this.lastThumbnailTime < 1000)
5945
+ return;
5946
+ this.thumbnailFrames = [];
5947
+ this.thumbnailRecordingIntervalRef = setInterval(async () => {
5948
+ const imageData = await this.board.screenshotAsync();
5949
+ if (this.thumbnailFrames.length && isImageDataEqual(imageData, this.thumbnailFrames[this.thumbnailFrames.length - 1])) {
5950
+ return;
5951
+ }
5952
+ this.thumbnailFrames.push(imageData);
5953
+ if (Date.now() - this.lastInteractionTime > 10000 || this.thumbnailFrames.length > 30) {
5954
+ clearInterval(this.thumbnailRecordingIntervalRef);
5955
+ this.thumbnailRecordingIntervalRef = undefined;
5956
+ this.lastThumbnailTime = Date.now();
5957
+ Runtime.postMessage({
5958
+ type: "thumbnail",
5959
+ frames: this.thumbnailFrames
5960
+ });
5961
+ }
5962
+ }, 66);
5963
+ }
5951
5964
  }
5952
5965
  pxsim.Runtime = Runtime;
5953
5966
  class PerfCounter {
@@ -5961,6 +5974,16 @@ var pxsim;
5961
5974
  }
5962
5975
  }
5963
5976
  pxsim.PerfCounter = PerfCounter;
5977
+ function isImageDataEqual(d0, d1) {
5978
+ if (d0.data.byteLength !== d1.data.byteLength)
5979
+ return false;
5980
+ const n = d0.data.byteLength;
5981
+ let i = 0;
5982
+ for (i = 0; i < n; ++i)
5983
+ if (d0.data[i] != d1.data[i])
5984
+ break;
5985
+ return i === n;
5986
+ }
5964
5987
  })(pxsim || (pxsim = {}));
5965
5988
  var pxsim;
5966
5989
  (function (pxsim) {