pxt-core 8.2.11 → 8.2.13

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/cli.js CHANGED
@@ -3891,11 +3891,6 @@ async function testSnippetsAsync(snippets, re, pyStrictSyntaxCheck) {
3891
3891
  }
3892
3892
  return;
3893
3893
  }
3894
- if (++codeSnippetCount % 40 == 0) {
3895
- // clean up cache every once in a while to speed up / clear up mem
3896
- // TODO probably this should be handled in the service host as it does become a perf concern
3897
- cleanService();
3898
- }
3899
3894
  const isPy = snippet.ext === "py";
3900
3895
  const inFiles = Object.assign({ [pxt.MAIN_TS]: isPy ? "" : snippet.code, [pxt.MAIN_PY]: isPy ? snippet.code : "", [pxt.MAIN_BLOCKS]: "" }, (snippet.extraFiles || {}));
3901
3896
  const { pkg, opts } = await getCompileResources(inFiles, snippet.packages);
package/built/pxt.js CHANGED
@@ -121892,7 +121892,7 @@ var ts;
121892
121892
  // Assumptions:
121893
121893
  // - registers can hold a pointer (data or code)
121894
121894
  // - special registers include: sp
121895
- // - fixed registers are r0, r1, r2, r3, r5, r6
121895
+ // - fixed registers are r0, r1, r2, r3, r5, r6
121896
121896
  // - r0 is the current value (from expression evaluation)
121897
121897
  // - registers for runtime calls (r0, r1,r2,r3)
121898
121898
  // - r5 is for captured locals in lambda
@@ -121905,7 +121905,7 @@ var ts;
121905
121905
  class AssemblerSnippets {
121906
121906
  nop() { return "TBD(nop)"; }
121907
121907
  reg_gets_imm(reg, imm) { return "TBD(reg_gets_imm)"; }
121908
- // Registers are stored on the stack in numerical order
121908
+ // Registers are stored on the stack in numerical order
121909
121909
  proc_setup(numlocals, main) { return "TBD(proc_setup)"; }
121910
121910
  push_fixed(reg) { return "TBD(push_fixed)"; }
121911
121911
  push_local(reg) { return "TBD(push_local)"; }
@@ -122120,7 +122120,7 @@ ${baseLabel}_nochk:
122120
122120
  }
122121
122121
  }
122122
122122
  };
122123
- if (this.bin.options.breakpoints) {
122123
+ if (this.bin.breakpoints) {
122124
122124
  this.write(this.t.debugger_proc(bkptLabel));
122125
122125
  }
122126
122126
  this.baseStackSize = 1; // push {lr}
@@ -122163,7 +122163,7 @@ ${baseLabel}_nochk:
122163
122163
  this.write(`; ${s.expr.data}`);
122164
122164
  break;
122165
122165
  case pxtc.ir.SK.Breakpoint:
122166
- if (this.bin.options.breakpoints) {
122166
+ if (this.bin.breakpoints) {
122167
122167
  let lbl = `__brkp_${s.breakpointInfo.id}`;
122168
122168
  if (s.breakpointInfo.isDebuggerStmt) {
122169
122169
  this.write(this.t.debugger_stmt(lbl));
@@ -123562,7 +123562,7 @@ var ts;
123562
123562
  "bind",
123563
123563
  "leaveAccessor"
123564
123564
  ];
123565
- function jsEmit(bin) {
123565
+ function jsEmit(bin, cres) {
123566
123566
  let jssource = "(function (ectx) {\n'use strict';\n";
123567
123567
  for (let n of evalIfaceFields) {
123568
123568
  jssource += `const ${n} = ectx.${n};\n`;
@@ -123574,7 +123574,7 @@ var ts;
123574
123574
  jssource += "pxsim.setTitle(" + JSON.stringify(bin.getTitle()) + ");\n";
123575
123575
  let cfg = {};
123576
123576
  let cfgKey = {};
123577
- for (let ce of bin.res.configData || []) {
123577
+ for (let ce of cres.configData || []) {
123578
123578
  cfg[ce.key + ""] = ce.value;
123579
123579
  cfgKey[ce.name] = ce.key;
123580
123580
  }
@@ -123604,8 +123604,8 @@ var ts;
123604
123604
  bin.usedClassInfos.forEach(info => {
123605
123605
  jssource += vtableToJs(info);
123606
123606
  });
123607
- if (bin.res.breakpoints)
123608
- jssource += `\nconst breakpoints = setupDebugger(${bin.res.breakpoints.length}, [${bin.globals.filter(c => c.isUserVariable).map(c => `"${c.uniqueName()}"`).join(",")}])\n`;
123607
+ if (cres.breakpoints)
123608
+ jssource += `\nconst breakpoints = setupDebugger(${cres.breakpoints.length}, [${bin.globals.filter(c => c.isUserVariable).map(c => `"${c.uniqueName()}"`).join(",")}])\n`;
123609
123609
  jssource += `\nreturn ${bin.procs[0] ? bin.procs[0].label() : "null"}\n})\n`;
123610
123610
  const total = jssource.length;
123611
123611
  const perc = (n) => ((100 * n) / total).toFixed(2) + "%";
@@ -123739,7 +123739,7 @@ function ${id}(s) {
123739
123739
  let id = s.breakpointInfo.id;
123740
123740
  let lbl;
123741
123741
  write(`s.lastBrkId = ${id};`);
123742
- if (bin.options.breakpoints) {
123742
+ if (bin.breakpoints) {
123743
123743
  lbl = ++lblIdx;
123744
123744
  let brkCall = `return breakpoint(s, ${lbl}, ${id}, r0);`;
123745
123745
  if (s.breakpointInfo.isDebuggerStmt) {
@@ -123747,12 +123747,12 @@ function ${id}(s) {
123747
123747
  }
123748
123748
  else {
123749
123749
  write(`if ((breakpoints[0] && isBreakFrame(s)) || breakpoints[${id}]) ${brkCall}`);
123750
- if (bin.options.trace) {
123750
+ if (bin.trace) {
123751
123751
  write(`else return trace(${id}, s, ${lbl}, ${proc.label()}.info);`);
123752
123752
  }
123753
123753
  }
123754
123754
  }
123755
- else if (bin.options.trace) {
123755
+ else if (bin.trace) {
123756
123756
  lbl = ++lblIdx;
123757
123757
  write(`return trace(${id}, s, ${lbl}, ${proc.label()}.info);`);
123758
123758
  }
@@ -124694,7 +124694,7 @@ ${info.id}_IfaceVT:
124694
124694
  }
124695
124695
  }
124696
124696
  /* eslint-disable no-trailing-spaces */
124697
- function vmEmit(bin, opts) {
124697
+ function vmEmit(bin, opts, cres) {
124698
124698
  let vmsource = `; VM start
124699
124699
  _img_start:
124700
124700
  ${pxtc.hexfile.hexPrelude()}
@@ -124798,7 +124798,7 @@ _start_${name}:
124798
124798
  + "\n.word 0, 0, 0 ; dummy entry to make sure not empty");
124799
124799
  section("numberLiterals", SectionType.NumberLiterals, () => ctx.dblText.join("\n")
124800
124800
  + "\n.word 0, 0 ; dummy entry to make sure not empty");
124801
- const cfg = bin.res.configData || [];
124801
+ const cfg = cres.configData || [];
124802
124802
  section("configData", SectionType.ConfigData, () => cfg.map(d => ` .word ${d.key}, ${d.value} ; ${d.name}=${d.value}`).join("\n")
124803
124803
  + "\n .word 0, 0");
124804
124804
  let s = ctx.opcodes.map(s => s == null ? "" : s).join("\x00") + "\x00";
@@ -130982,8 +130982,9 @@ var ts;
130982
130982
  }
130983
130983
  let bin = new Binary();
130984
130984
  let proc;
130985
- bin.res = res;
130986
- bin.options = opts;
130985
+ bin.trace = opts.trace;
130986
+ bin.breakpoints = opts.breakpoints;
130987
+ bin.name = opts.name;
130987
130988
  bin.target = opts.target;
130988
130989
  function reset() {
130989
130990
  bin.reset();
@@ -131209,29 +131210,8 @@ var ts;
131209
131210
  info.captured = true;
131210
131211
  }
131211
131212
  }
131212
- function recordAction(f) {
131213
- const r = f(bin);
131214
- if (needsUsingInfo)
131215
- bin.recordAction(currUsingContext, f);
131216
- return r;
131217
- }
131218
131213
  function getIfaceMemberId(name, markUsed = false) {
131219
- return recordAction(bin => {
131220
- if (markUsed) {
131221
- if (!pxtc.U.lookup(bin.explicitlyUsedIfaceMembers, name)) {
131222
- pxtc.U.assert(!bin.finalPass);
131223
- bin.explicitlyUsedIfaceMembers[name] = true;
131224
- }
131225
- }
131226
- let v = pxtc.U.lookup(bin.ifaceMemberMap, name);
131227
- if (v != null)
131228
- return v;
131229
- pxtc.U.assert(!bin.finalPass);
131230
- // this gets renumbered before the final pass
131231
- v = bin.ifaceMemberMap[name] = -1;
131232
- bin.emitString(name);
131233
- return v;
131234
- });
131214
+ return recordGetInterfaceId(bin, name, markUsed, needsUsingInfo, currUsingContext);
131235
131215
  }
131236
131216
  function finalEmit() {
131237
131217
  if (opts.noEmit)
@@ -131255,13 +131235,16 @@ var ts;
131255
131235
  bin.writeFile("platformio.json", JSON.stringify(extinfo.platformio, null, 2));
131256
131236
  });
131257
131237
  if (opts.target.nativeType == pxtc.NATIVE_TYPE_VM)
131258
- pxtc.vmEmit(bin, opts);
131238
+ pxtc.vmEmit(bin, opts, res);
131259
131239
  else
131260
131240
  pxtc.processorEmit(bin, opts, res);
131261
131241
  }
131262
131242
  else {
131263
- pxtc.jsEmit(bin);
131243
+ pxtc.jsEmit(bin, res);
131264
131244
  }
131245
+ // Clear writeFile so that we don't leak the reference to res, which
131246
+ // includes the entire source of the program
131247
+ bin.writeFile = undefined;
131265
131248
  }
131266
131249
  function typeCheckVar(tp) {
131267
131250
  if (tp.flags & ts.TypeFlags.Void) {
@@ -131978,9 +131961,7 @@ ${lbl}: .short 0xffff
131978
131961
  markUsed(decl);
131979
131962
  }
131980
131963
  function emitAndMarkString(str) {
131981
- return recordAction(bin => {
131982
- return bin.emitString(str);
131983
- });
131964
+ return recordEmitAndMarkString(bin, str, needsUsingInfo, currUsingContext);
131984
131965
  }
131985
131966
  function recordUsage(decl) {
131986
131967
  if (!needsUsingInfo)
@@ -132827,7 +132808,7 @@ ${lbl}: .short 0xffff
132827
132808
  pinfo.proc = myProc;
132828
132809
  myProc.usingCtx = currUsingContext;
132829
132810
  proc = myProc;
132830
- recordAction(bin => bin.addProc(myProc));
132811
+ recordAddProc(bin, myProc, needsUsingInfo, currUsingContext);
132831
132812
  }
132832
132813
  proc.captured = locals;
132833
132814
  const initalizedFields = [];
@@ -134744,7 +134725,7 @@ ${lbl}: .short 0xffff
134744
134725
  this.numStmts = 0;
134745
134726
  }
134746
134727
  getTitle() {
134747
- const title = this.options.name || pxtc.U.lf("Untitled");
134728
+ const title = this.name || pxtc.U.lf("Untitled");
134748
134729
  if (title.length >= 90)
134749
134730
  return title.slice(0, 87) + "...";
134750
134731
  else
@@ -134832,6 +134813,36 @@ ${lbl}: .short 0xffff
134832
134813
  return !!(type.flags & (ts.TypeFlags.NumberLike | ts.TypeFlags.EnumLike | ts.TypeFlags.BooleanLike));
134833
134814
  }
134834
134815
  }
134816
+ function recordAction(bin, needsUsingInfo, currUsingContext, f) {
134817
+ const r = f(bin);
134818
+ if (needsUsingInfo)
134819
+ bin.recordAction(currUsingContext, f);
134820
+ return r;
134821
+ }
134822
+ function recordAddProc(bin, proc, needsUsingInfo, currUsingContext) {
134823
+ recordAction(bin, needsUsingInfo, currUsingContext, b => b.addProc(proc));
134824
+ }
134825
+ function recordGetInterfaceId(bin, name, markUsed, needsUsingInfo, currUsingContext) {
134826
+ return recordAction(bin, needsUsingInfo, currUsingContext, bin => {
134827
+ if (markUsed) {
134828
+ if (!pxtc.U.lookup(bin.explicitlyUsedIfaceMembers, name)) {
134829
+ pxtc.U.assert(!bin.finalPass);
134830
+ bin.explicitlyUsedIfaceMembers[name] = true;
134831
+ }
134832
+ }
134833
+ let v = pxtc.U.lookup(bin.ifaceMemberMap, name);
134834
+ if (v != null)
134835
+ return v;
134836
+ pxtc.U.assert(!bin.finalPass);
134837
+ // this gets renumbered before the final pass
134838
+ v = bin.ifaceMemberMap[name] = -1;
134839
+ bin.emitString(name);
134840
+ return v;
134841
+ });
134842
+ }
134843
+ function recordEmitAndMarkString(bin, str, needsUsingInfo, currUsingContext) {
134844
+ return recordAction(bin, needsUsingInfo, currUsingContext, b => b.emitString(str));
134845
+ }
134835
134846
  })(pxtc = ts.pxtc || (ts.pxtc = {}));
134836
134847
  })(ts || (ts = {}));
134837
134848
  /// <reference path="../../localtypings/pxtarget.d.ts"/>
@@ -136855,7 +136866,7 @@ var ts;
136855
136866
  for (let i = 0; i < hd.length; ++i)
136856
136867
  pxt.HF2.write16(resbuf, i * 2 + ctx.jmpStartAddr, hd[i]);
136857
136868
  if (uf2 && !bin.target.switches.rawELF) {
136858
- let bn = bin.options.name || "pxt";
136869
+ let bn = bin.name || "pxt";
136859
136870
  bn = bn.replace(/[^a-zA-Z0-9\-\.]+/g, "_");
136860
136871
  uf2.filename = "Projects/" + bn + ".elf";
136861
136872
  pxtc.UF2.writeBytes(uf2, 0, resbuf);
@@ -137102,7 +137113,7 @@ ${lbl}: ${snippets.obj_header("pxt::number_vt")}
137102
137113
  }
137103
137114
  }
137104
137115
  pxtc.computeHashMultiplier = computeHashMultiplier;
137105
- function vtableToAsm(info, opts, bin) {
137116
+ function vtableToAsm(info, opts, bin, res) {
137106
137117
  /*
137107
137118
  uint16_t numbytes;
137108
137119
  ValType objectType;
@@ -137190,7 +137201,7 @@ ${hexfile.hexPrelude()}
137190
137201
  .hex 873266330af9dbdb ; replaced in binary by program hash
137191
137202
  `;
137192
137203
  }
137193
- function serialize(bin, opts) {
137204
+ function serialize(bin, opts, res) {
137194
137205
  let asmsource = `
137195
137206
  .short ${bin.globalsWords} ; num. globals
137196
137207
  .short 0 ; patched with number of 64 bit words resulting from assembly
@@ -137225,7 +137236,7 @@ ${hexfile.hexPrelude()}
137225
137236
  asmsource += snippets.arithmetic();
137226
137237
  asmsource += "_helpers_end:\n\n";
137227
137238
  bin.usedClassInfos.forEach(info => {
137228
- asmsource += vtableToAsm(info, opts, bin);
137239
+ asmsource += vtableToAsm(info, opts, bin, res);
137229
137240
  });
137230
137241
  asmsource += `\n.balign 4\n.object _pxt_iface_member_names\n_pxt_iface_member_names:\n`;
137231
137242
  asmsource += ` .word ${bin.ifaceMembers.length}\n`;
@@ -137237,7 +137248,7 @@ ${hexfile.hexPrelude()}
137237
137248
  asmsource += ` .word 0\n`;
137238
137249
  asmsource += "_vtables_end:\n\n";
137239
137250
  asmsource += `\n.balign 4\n.object _pxt_config_data\n_pxt_config_data:\n`;
137240
- const cfg = bin.res.configData || [];
137251
+ const cfg = res.configData || [];
137241
137252
  // asmsource += ` .word ${cfg.length}, 0 ; num. entries`
137242
137253
  for (let d of cfg) {
137243
137254
  asmsource += ` .word ${d.key}, ${d.value} ; ${d.name}=${d.value}\n`;
@@ -137506,7 +137517,7 @@ __flash_checksums:
137506
137517
  return elts.map(s => `"${s}"`).join(",");
137507
137518
  }
137508
137519
  function processorEmit(bin, opts, cres) {
137509
- const src = serialize(bin, opts);
137520
+ const src = serialize(bin, opts, cres);
137510
137521
  const opts0 = pxtc.U.flatClone(opts);
137511
137522
  // normally, this would already have been done, but if the main variant
137512
137523
  // is disabled, another variant may be set up
@@ -139699,14 +139710,13 @@ var ts;
139699
139710
  }
139700
139711
  service.snippetAddsDefinitions = snippetAddsDefinitions;
139701
139712
  function getSnippet(context, fn, decl, python, recursionDepth = 0) {
139702
- var _a;
139713
+ var _a, _b;
139703
139714
  // TODO: a lot of this is duplicate logic with blocklyloader.ts:buildBlockFromDef; we should
139704
139715
  // unify these approaches
139705
139716
  let { apis, takenNames, blocksInfo, screenSize, checker } = context;
139706
139717
  const PY_INDENT = pxt.py.INDENT;
139707
139718
  const fileType = python ? "python" : "typescript";
139708
139719
  let snippetPrefix = fn.namespace;
139709
- let isInstance = false;
139710
139720
  let addNamespace = false;
139711
139721
  let namespaceToUse = "";
139712
139722
  let functionCount = 0;
@@ -139756,6 +139766,11 @@ var ts;
139756
139766
  if (python && snippetPrefix)
139757
139767
  snippetPrefix = pxtc.U.snakify(snippetPrefix);
139758
139768
  }
139769
+ else if (((_b = params.thisParameter) === null || _b === void 0 ? void 0 : _b.shadowBlockId) === "variables_get") {
139770
+ snippetPrefix = params.thisParameter.defaultValue || params.thisParameter.definitionName;
139771
+ if (python && snippetPrefix)
139772
+ snippetPrefix = pxtc.U.snakify(snippetPrefix);
139773
+ }
139759
139774
  else if (element.namespace) { // some blocks don't have a namespace such as parseInt
139760
139775
  const nsInfo = apis.byQName[element.namespace];
139761
139776
  if (nsInfo.attributes.fixedInstances) {
@@ -139794,7 +139809,6 @@ var ts;
139794
139809
  if (namespaceToUse) {
139795
139810
  addNamespace = true;
139796
139811
  }
139797
- isInstance = true;
139798
139812
  }
139799
139813
  else if (element.kind == 1 /* Method */ || element.kind == 2 /* Property */) {
139800
139814
  if (params.thisParameter) {
@@ -139808,7 +139822,6 @@ var ts;
139808
139822
  if (python && snippetPrefix)
139809
139823
  snippetPrefix = pxtc.U.snakify(snippetPrefix);
139810
139824
  }
139811
- isInstance = true;
139812
139825
  }
139813
139826
  else if (nsInfo.kind === 8 /* Class */) {
139814
139827
  return undefined;
@@ -161739,11 +161752,6 @@ async function testSnippetsAsync(snippets, re, pyStrictSyntaxCheck) {
161739
161752
  }
161740
161753
  return;
161741
161754
  }
161742
- if (++codeSnippetCount % 40 == 0) {
161743
- // clean up cache every once in a while to speed up / clear up mem
161744
- // TODO probably this should be handled in the service host as it does become a perf concern
161745
- cleanService();
161746
- }
161747
161755
  const isPy = snippet.ext === "py";
161748
161756
  const inFiles = Object.assign({ [pxt.MAIN_TS]: isPy ? "" : snippet.code, [pxt.MAIN_PY]: isPy ? snippet.code : "", [pxt.MAIN_BLOCKS]: "" }, (snippet.extraFiles || {}));
161749
161757
  const { pkg, opts } = await getCompileResources(inFiles, snippet.packages);
@@ -156,7 +156,7 @@ declare namespace ts.pxtc {
156
156
  declare namespace ts.pxtc {
157
157
  function isBuiltinSimOp(name: string): boolean;
158
158
  function shimToJs(shimName: string): string;
159
- function jsEmit(bin: Binary): void;
159
+ function jsEmit(bin: Binary, cres: CompileResult): void;
160
160
  }
161
161
  declare namespace ts.pxtc {
162
162
  const thumbCmpMap: pxt.Map<string>;
@@ -203,7 +203,7 @@ declare namespace ts.pxtc {
203
203
  }
204
204
  }
205
205
  declare namespace ts.pxtc {
206
- function vmEmit(bin: Binary, opts: CompileOptions): void;
206
+ function vmEmit(bin: Binary, opts: CompileOptions, cres: CompileResult): void;
207
207
  }
208
208
  declare namespace ts.pxtc.decompiler {
209
209
  export enum DecompileParamKeys {
@@ -709,8 +709,9 @@ declare namespace ts.pxtc {
709
709
  finalPass: boolean;
710
710
  target: CompileTarget;
711
711
  writeFile: (fn: string, cont: string) => void;
712
- res: CompileResult;
713
- options: CompileOptions;
712
+ trace: boolean;
713
+ breakpoints: boolean;
714
+ name: string;
714
715
  usedClassInfos: ClassInfo[];
715
716
  checksumBlock: number[];
716
717
  numStmts: number;
@@ -833,7 +834,7 @@ declare namespace ts.pxtc {
833
834
  mapping: Uint16Array;
834
835
  size: number;
835
836
  };
836
- function vtableToAsm(info: ClassInfo, opts: CompileOptions, bin: Binary): string;
837
+ function vtableToAsm(info: ClassInfo, opts: CompileOptions, bin: Binary, res: CompileResult): string;
837
838
  function processorInlineAssemble(target: CompileTarget, src: string): number[];
838
839
  function assemble(target: CompileTarget, bin: Binary, src: string): {
839
840
  src: string;