pxt-core 8.2.4 → 8.2.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/built/pxtlib.d.ts CHANGED
@@ -878,6 +878,10 @@ declare namespace pxt.cloud {
878
878
  };
879
879
  }
880
880
  declare namespace pxt.commands {
881
+ interface RecompileOptions {
882
+ recompile: boolean;
883
+ useVariants: string[];
884
+ }
881
885
  interface DeployOptions {
882
886
  reportError: (e: string) => void;
883
887
  showNotification: (msg: string) => void;
@@ -899,6 +903,7 @@ declare namespace pxt.commands {
899
903
  helpUrl: string;
900
904
  };
901
905
  let showUploadInstructionsAsync: (fn: string, url: string, confirmAsync: (options: any) => Promise<number>, saveonly?: boolean) => Promise<void>;
906
+ let showProgramTooLargeErrorAsync: (variants: string[], confirmAsync: (options: any) => Promise<number>) => Promise<RecompileOptions>;
902
907
  let saveProjectAsync: (project: pxt.cpp.HexFile) => Promise<void>;
903
908
  let electronDeployAsync: (r: ts.pxtc.CompileResult) => Promise<void>;
904
909
  let webUsbPairDialogAsync: (pairAsync: () => Promise<boolean>, confirmAsync: (options: any) => Promise<number>) => Promise<number>;
@@ -3400,6 +3405,7 @@ declare namespace ts.pxtc.assembler {
3400
3405
  opcode: number;
3401
3406
  stack: number;
3402
3407
  isLong: boolean;
3408
+ ldlitLabel: string;
3403
3409
  constructor(bin: File, text: string);
3404
3410
  getOpExt(): string;
3405
3411
  getOp(): string;
@@ -3437,10 +3443,17 @@ declare namespace ts.pxtc.assembler {
3437
3443
  disablePeepHole: boolean;
3438
3444
  stackAtLabel: pxt.Map<number>;
3439
3445
  private prevLabel;
3446
+ codeSizeStats: boolean;
3447
+ private labelToObject;
3448
+ private idToObject;
3449
+ private objSuspendStart;
3450
+ private currObject;
3451
+ private labelsToObjectDone;
3440
3452
  protected emitShort(op: number): void;
3441
3453
  protected emitOpCode(op: number): void;
3442
3454
  location(): number;
3443
3455
  pc(): number;
3456
+ useLabel(name: string): void;
3444
3457
  parseOneInt(s: string): number;
3445
3458
  private looksLikeLabel;
3446
3459
  private scopedName;
@@ -3461,6 +3474,7 @@ declare namespace ts.pxtc.assembler {
3461
3474
  private prepLines;
3462
3475
  private iterLines;
3463
3476
  getSourceMap(): pxt.Map<number[]>;
3477
+ getCodeSizeStats(): string;
3464
3478
  getSource(clean: boolean, numStmts?: number, flashSize?: number): string;
3465
3479
  private peepHole;
3466
3480
  private clearLabels;
package/built/pxtlib.js CHANGED
@@ -8713,6 +8713,7 @@ var pxt;
8713
8713
  docs.prepTemplate = prepTemplate;
8714
8714
  function setupRenderer(renderer) {
8715
8715
  renderer.image = function (href, title, text) {
8716
+ var _a, _b;
8716
8717
  const endpointName = "makecodeprodmediaeastus-usea";
8717
8718
  if (href.startsWith("youtube:")) {
8718
8719
  let out = '<div class="tutorial-video-embed"><iframe class="yt-embed" src="https://www.youtube.com/embed/' + href.split(":").pop()
@@ -8720,7 +8721,24 @@ var pxt;
8720
8721
  return out;
8721
8722
  }
8722
8723
  else if (href.startsWith("azuremedia:")) {
8723
- let out = `<div class="tutorial-video-embed"><video class="ams-embed" controls src="https://${endpointName}.streaming.media.azure.net/` + href.split(":").pop() + '/manifest(format=mpd-time-cmaf)" /></div>';
8724
+ let videoID = href.split(":")[1];
8725
+ const flagsSplit = videoID.split("?");
8726
+ let startTime;
8727
+ let endTime;
8728
+ if (flagsSplit[1]) {
8729
+ videoID = flagsSplit[0];
8730
+ const passedParameters = flagsSplit[1];
8731
+ startTime = (_a = /start(?:time)?=(\d+)/i.exec(passedParameters)) === null || _a === void 0 ? void 0 : _a[1];
8732
+ endTime = (_b = /end(?:time)?=(\d+)/i.exec(passedParameters)) === null || _b === void 0 ? void 0 : _b[1];
8733
+ }
8734
+ const url = new URL(`https://${endpointName}.streaming.media.azure.net/${videoID}/manifest(format=mpd-time-csf).mpd`);
8735
+ if (startTime) {
8736
+ url.hash = `t=${startTime}`;
8737
+ }
8738
+ if (endTime) {
8739
+ url.searchParams.append("endTime", endTime);
8740
+ }
8741
+ let out = `<div class="tutorial-video-embed"><video class="ams-embed" controls src="${url.toString()}" /></div>`;
8724
8742
  return out;
8725
8743
  }
8726
8744
  else {
@@ -14275,7 +14293,7 @@ var pxt;
14275
14293
  // and pulls from master
14276
14294
  const modtag = (modid === null || modid === void 0 ? void 0 : modid.tag) || ((_a = mod.config) === null || _a === void 0 ? void 0 : _a.version);
14277
14295
  const vertag = verid.tag;
14278
- // if there is no tag on the current dependency,
14296
+ // if there is no tag on the current dependency,
14279
14297
  // assume same as existing module version if any
14280
14298
  if (modtag && !vertag) {
14281
14299
  pxt.debug(`unversioned ${ver}, using ${modtag}`);
@@ -14734,6 +14752,8 @@ var pxt;
14734
14752
  opts.otherMultiVariants.push(etarget);
14735
14753
  }
14736
14754
  else {
14755
+ etarget.target.isNative = opts.target.isNative;
14756
+ opts.target = etarget.target;
14737
14757
  ext = einfo;
14738
14758
  opts.otherMultiVariants = [];
14739
14759
  }
@@ -15689,7 +15709,12 @@ var ts;
15689
15709
  const left = param.substr(0, dotIdx);
15690
15710
  let right = param.substr(dotIdx + 1);
15691
15711
  right = pxtc.U.snakify(right).toUpperCase();
15692
- return `${left}.${right}`;
15712
+ if (left) {
15713
+ return `${left}.${right}`;
15714
+ }
15715
+ else {
15716
+ return right;
15717
+ }
15693
15718
  }
15694
15719
  return param;
15695
15720
  }
@@ -21603,6 +21628,18 @@ var ts;
21603
21628
  }
21604
21629
  }
21605
21630
  assembler.Line = Line;
21631
+ const MAX_OBJ_USERS = 5;
21632
+ class AsmObject {
21633
+ constructor(id, description) {
21634
+ this.id = id;
21635
+ this.description = description;
21636
+ this.sizeAdj = 0;
21637
+ this.users = [];
21638
+ }
21639
+ get size() {
21640
+ return (this.endLocation - this.startLocation) - this.sizeAdj;
21641
+ }
21642
+ }
21606
21643
  // File is the center of the action: parsing a file into a sequence of Lines
21607
21644
  // and also emitting the binary (buf)
21608
21645
  class File {
@@ -21627,6 +21664,11 @@ var ts;
21627
21664
  this.throwOnError = false;
21628
21665
  this.disablePeepHole = false;
21629
21666
  this.stackAtLabel = {};
21667
+ this.codeSizeStats = false;
21668
+ this.labelToObject = {};
21669
+ this.idToObject = {};
21670
+ this.objSuspendStart = 0;
21671
+ this.labelsToObjectDone = false;
21630
21672
  this.currLine = new Line(this, "<start>");
21631
21673
  this.currLine.lineNo = 0;
21632
21674
  this.ei = ei;
@@ -21646,6 +21688,15 @@ var ts;
21646
21688
  pc() {
21647
21689
  return this.location() + this.baseOffset;
21648
21690
  }
21691
+ useLabel(name) {
21692
+ if (!this.currObject || name[0] == '.' || this.objSuspendStart)
21693
+ return;
21694
+ const obj = pxtc.U.lookup(this.labelToObject, name);
21695
+ if (!obj || obj == this.currObject)
21696
+ return;
21697
+ if (obj.users.length < MAX_OBJ_USERS && obj.users.indexOf(this.currObject) < 0)
21698
+ obj.users.push(this.currObject);
21699
+ }
21649
21700
  // parsing of an "integer", well actually much more than
21650
21701
  // just that
21651
21702
  parseOneInt(s) {
@@ -21775,6 +21826,7 @@ var ts;
21775
21826
  return name;
21776
21827
  }
21777
21828
  lookupLabel(name, direct = false) {
21829
+ this.useLabel(name);
21778
21830
  let v = null;
21779
21831
  let scoped = this.scopedName(name);
21780
21832
  if (this.labels.hasOwnProperty(scoped)) {
@@ -21933,6 +21985,37 @@ var ts;
21933
21985
  };
21934
21986
  let num0;
21935
21987
  switch (words[0]) {
21988
+ case ".object":
21989
+ if (!this.codeSizeStats) {
21990
+ // do nothing
21991
+ }
21992
+ else if (words[1] == "PUSH") {
21993
+ this.objSuspendStart = this.location();
21994
+ }
21995
+ else if (words[1] == "POP") {
21996
+ if (this.objSuspendStart)
21997
+ this.currObject.sizeAdj += this.location() - this.objSuspendStart;
21998
+ this.objSuspendStart = 0;
21999
+ }
22000
+ else {
22001
+ if (this.currObject)
22002
+ this.currObject.endLocation = this.location();
22003
+ this.currObject = pxtc.U.lookup(this.idToObject, words[1]);
22004
+ if (!this.currObject) {
22005
+ const str = l.text.replace(/^[^"]*/, "");
22006
+ let parsed = words[1];
22007
+ if (words.length > 2) {
22008
+ parsed = parseString(str.trim());
22009
+ if (parsed == null)
22010
+ this.directiveError(lf("expecting string in .object"));
22011
+ }
22012
+ this.currObject = new AsmObject(words[1], parsed);
22013
+ this.idToObject[words[1]] = this.currObject;
22014
+ }
22015
+ this.currObject.sizeAdj = 0;
22016
+ this.currObject.startLocation = this.location();
22017
+ }
22018
+ break;
21936
22019
  case ".ascii":
21937
22020
  case ".asciz":
21938
22021
  case ".string":
@@ -22127,6 +22210,8 @@ var ts;
22127
22210
  }
22128
22211
  }
22129
22212
  handleOneInstruction(ln, instr) {
22213
+ if (this.codeSizeStats && ln.ldlitLabel)
22214
+ this.useLabel(ln.ldlitLabel);
22130
22215
  let op = instr.emit(ln);
22131
22216
  if (!op.error) {
22132
22217
  this.stack += op.stack;
@@ -22235,6 +22320,8 @@ var ts;
22235
22320
  if (l.words.length == 0)
22236
22321
  return;
22237
22322
  if (l.type == "label") {
22323
+ if (this.currObject && !this.labelsToObjectDone && l.words[0][0] != '.')
22324
+ this.labelToObject[l.words[0]] = this.currObject;
22238
22325
  let lblname = this.scopedName(l.words[0]);
22239
22326
  this.prevLabel = lblname;
22240
22327
  if (this.finalEmit) {
@@ -22275,6 +22362,8 @@ var ts;
22275
22362
  pxtc.oops();
22276
22363
  }
22277
22364
  });
22365
+ this.labelsToObjectDone = true;
22366
+ this.currObject = null;
22278
22367
  }
22279
22368
  getSourceMap() {
22280
22369
  const sourceMap = {};
@@ -22307,6 +22396,22 @@ var ts;
22307
22396
  }
22308
22397
  return sourceMap;
22309
22398
  }
22399
+ getCodeSizeStats() {
22400
+ if (!this.codeSizeStats)
22401
+ return "";
22402
+ const objs = pxtc.U.values(this.idToObject);
22403
+ objs.sort((a, b) => b.size - a.size);
22404
+ let r = ";\n; Code size:\n;\n";
22405
+ for (const obj of objs) {
22406
+ r += `; ${(" " + obj.size).slice(-6)} ${obj.description} [${obj.id}]\n`;
22407
+ if (obj.users.length >= MAX_OBJ_USERS)
22408
+ r += `; by many, including ${obj.users[0].description}\n`;
22409
+ else
22410
+ for (const x of obj.users)
22411
+ r += `; by ${x.description} [${x.id}]\n`;
22412
+ }
22413
+ return r;
22414
+ }
22310
22415
  getSource(clean, numStmts = 1, flashSize = 0) {
22311
22416
  let lenPrev = 0;
22312
22417
  let size = (lbl) => {
@@ -22322,8 +22427,11 @@ var ts;
22322
22427
  let lenLiterals = size("_literals_end");
22323
22428
  let lenAllCode = lenPrev;
22324
22429
  let totalSize = (lenTotal + this.baseOffset) & 0xffffff;
22325
- if (flashSize && totalSize > flashSize)
22326
- pxtc.U.userError(lf("program too big by {0} bytes!", totalSize - flashSize));
22430
+ if (flashSize && totalSize > flashSize) {
22431
+ const e = new Error(lf("program too big by {0} bytes!", totalSize - flashSize));
22432
+ e.ksErrorCode = 9283;
22433
+ throw e;
22434
+ }
22327
22435
  flashSize = flashSize || 128 * 1024;
22328
22436
  let totalInfo = lf("; total bytes: {0} ({1}% of {2}k flash with {3} free)", totalSize, (100 * totalSize / flashSize).toFixed(1), (flashSize / 1024).toFixed(1), flashSize - totalSize);
22329
22437
  let res =
@@ -22331,7 +22439,7 @@ var ts;
22331
22439
  lf("; generated code sizes (bytes): {0} (incl. {1} user, {2} helpers, {3} vtables, {4} lits); src size {5}\n", lenAllCode, lenCode, lenHelpers, lenVtables, lenLiterals, lenTotal - lenAllCode) +
22332
22440
  lf("; assembly: {0} lines; density: {1} bytes/stmt; ({2} stmts)\n", this.lines.length, Math.round(100 * lenCode / numStmts) / 100, numStmts) +
22333
22441
  totalInfo + "\n" +
22334
- this.stats + "\n\n";
22442
+ this.stats + this.getCodeSizeStats() + "\n\n";
22335
22443
  let skipOne = false;
22336
22444
  this.lines.forEach((ln, i) => {
22337
22445
  if (ln.words[0] == "_stored_program") {