diff --git a/libs/core/linux.cpp b/libs/core/linux.cpp index 68caa628..5e7bcfa4 100644 --- a/libs/core/linux.cpp +++ b/libs/core/linux.cpp @@ -13,14 +13,35 @@ #include #include #include +#include #define THREAD_DBG(...) +#define MALLOC_LIMIT (8 * 1024 * 1024) +#define MALLOC_CHECK_PERIOD (1024 * 1024) + +void *xmalloc(size_t sz) { + static size_t allocBytes = 0; + allocBytes += sz; + if (allocBytes >= MALLOC_CHECK_PERIOD) { + allocBytes = 0; + auto info = mallinfo(); + DMESG("malloc used: %d kb", info.uordblks / 1024); + if (info.uordblks > MALLOC_LIMIT) { + target_panic(904); + } + } + auto r = malloc(sz); + if (r == NULL) + target_panic(905); // shouldn't happen + return r; +} + void *operator new(size_t size) { - return malloc(size); + return xmalloc(size); } void *operator new[](size_t size) { - return malloc(size); + return xmalloc(size); } void operator delete(void *p) { diff --git a/libs/core/png.cpp b/libs/core/png.cpp index 90674728..9932a6bc 100644 --- a/libs/core/png.cpp +++ b/libs/core/png.cpp @@ -88,7 +88,7 @@ Image unpackPNG(Buffer png) { uint32_t byteW = (hd.width + 7) >> 3; uint32_t expSize = (byteW + 1) * hd.height; unsigned long sz = expSize; - uint8_t *tmp = (uint8_t *)malloc(sz); + uint8_t *tmp = (uint8_t *)xmalloc(sz); int code = uncompress(tmp, &sz, png->data + sizeof(hd), hd.lenIDAT); if (code != 0) { DMESG("PNG: zlib failed: %d", code); diff --git a/libs/core/pxt.h b/libs/core/pxt.h index 0c62ad43..8bd3b92c 100644 --- a/libs/core/pxt.h +++ b/libs/core/pxt.h @@ -3,6 +3,8 @@ #include "pxtbase.h" +void *xmalloc(size_t sz); + namespace pxt { void raiseEvent(int id, int event); int allocateNotifyEvent(); diff --git a/libs/core/test.ts b/libs/core/test.ts index 056e7c43..2147a5ba 100644 --- a/libs/core/test.ts +++ b/libs/core/test.ts @@ -1,51 +1,36 @@ screen.clear() -screen.print("PXT!", 10, 30, Draw.Quad) +brick.print("PXT!", 10, 30, Draw.Quad) -screen.drawRect(40, 40, 20, 10, Draw.Fill) -motors.setStatusLight(LightsPattern.Orange) +brick.drawRect(40, 40, 20, 10, Draw.Fill) +brick.setStatusLight(LightsPattern.Orange) -screen.heart.doubled().draw(100, 50, Draw.Double | Draw.Transparent) +brick.heart.doubled().draw(100, 50, Draw.Double | Draw.Transparent) -sensors.buttonEnter.onEvent(ButtonEvent.Click, () => { +brick.buttonEnter.onEvent(ButtonEvent.Click, () => { screen.clear() }) -sensors.buttonLeft.onEvent(ButtonEvent.Click, () => { - screen.drawRect(10, 70, 20, 10, Draw.Fill) - motors.setStatusLight(LightsPattern.Red) - screen.setFont(screen.microbitFont()) +brick.buttonLeft.onEvent(ButtonEvent.Click, () => { + brick.drawRect(10, 70, 20, 10, Draw.Fill) + brick.setStatusLight(LightsPattern.Red) + brick.setFont(brick.microbitFont()) }) -sensors.buttonRight.onEvent(ButtonEvent.Click, () => { - screen.print("Right!", 10, 60) +brick.buttonRight.onEvent(ButtonEvent.Click, () => { + brick.print("Right!", 10, 60) }) -sensors.buttonDown.onEvent(ButtonEvent.Click, () => { - screen.print("Down! ", 10, 60) +brick.buttonDown.onEvent(ButtonEvent.Click, () => { + brick.print("Down! ", 10, 60) }) -sensors.buttonUp.onEvent(ButtonEvent.Click, () => { - screen.print("Up! ", 10, 60) +brick.buttonUp.onEvent(ButtonEvent.Click, () => { + brick.print("Up! ", 10, 60) }) let num = 0 -sensors.touchSensor1.onEvent(TouchSensorEvent.Bumped, () => { - screen.print("Click! " + num, 10, 60) - num++ -}) - -sensors.remoteButtonTopLeft.onEvent(ButtonEvent.Click, () => { - screen.print("TOPLEFT " + num, 10, 60) - num++ -}) - -sensors.remoteButtonTopRight.onEvent(ButtonEvent.Down, () => { - screen.print("TOPRIGH " + num, 10, 60) - num++ -}) - loops.forever(() => { serial.writeDmesg() loops.pause(100) diff --git a/package.json b/package.json index 3fec37d6..0087de27 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "semantic-ui-less": "^2.2.4", "@types/bluebird": "2.0.33", "@types/jquery": "3.2.16", + "@types/marked": "0.3.0", "@types/node": "8.0.53" }, "dependencies": { diff --git a/pxtarget.json b/pxtarget.json index b9f7d928..1b2c1bf9 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -137,5 +137,6 @@ "monacoColors": { "editor.background": "#ecf6ff" } - } + }, + "ignoreDocsErrors": true } diff --git a/sim/instructions.ts b/sim/instructions.ts deleted file mode 100644 index b0f872a0..00000000 --- a/sim/instructions.ts +++ /dev/null @@ -1,91 +0,0 @@ -/// -/// - -//HACK: allows instructions.html to access pxtblocks without requiring simulator.html to import blocks as well -if (!(window).pxt) (window).pxt = {}; -import pxtrunner = pxt.runner; -import pxtdocs = pxt.docs; - -namespace pxsim.instructions { - export function drawInstructions() { - pxsim.visuals.mkBoardView = (opts: pxsim.visuals.BoardViewOptions): pxsim.visuals.BoardView => { - return new visuals.EV3BoardSvg({ - runtime: runtime, - theme: visuals.randomTheme(), - disableTilt: false, - wireframe: opts.wireframe, - }); - } - - let getQsVal = parseQueryString(); - - //project name - let name = getQsVal("name") || "Untitled"; - - // board def - const boardDef = JSON.parse(getQsVal("board")) as pxsim.BoardDefinition; - - //parts list - let parts = (getQsVal("parts") || "").split(" "); - parts.sort(); - - // parts definitions - let partDefinitions = JSON.parse(getQsVal("partdefs") || "{}") as pxsim.Map - - //fn args - let fnArgs = JSON.parse((getQsVal("fnArgs") || "{}")); - - //project code - let tsCode = getQsVal("code"); - let tsPackage = getQsVal("package") || ""; - let codeSpinnerDiv = document.getElementById("proj-code-spinner"); - let codeContainerDiv = document.getElementById("proj-code-container"); - if (tsCode) { - //we use the docs renderer to decompile the code to blocks and render it - //TODO: render the blocks code directly - let md = - `\`\`\`blocks -${tsCode} -\`\`\` -\`\`\`package -${tsPackage} -\`\`\` -` - - pxtdocs.requireMarked = function () { return (window).marked; } - pxtrunner.renderMarkdownAsync(codeContainerDiv, md) - .done(function () { - let codeSvg = $("#proj-code-container svg"); - if (codeSvg.length > 0) { - //code rendered successfully as blocks - codeSvg.css("width", "inherit"); - codeSvg.css("height", "inherit"); - //takes the svg out of the wrapper markdown - codeContainerDiv.innerHTML = ""; - codeContainerDiv.appendChild(codeSvg[0]); - } else { - //code failed to convert to blocks, display as typescript instead - codeContainerDiv.innerText = tsCode; - } - $(codeContainerDiv).show(); - $(codeSpinnerDiv).hide(); - }); - } - - - if (name) - $("#proj-title").text(name); - - //init runtime - if (!pxsim.initCurrentRuntime) - pxsim.initCurrentRuntime = initRuntimeWithDalBoard; - - renderParts({ - name, - boardDef, - parts, - partDefinitions, - fnArgs - }) - } -} \ No newline at end of file diff --git a/sim/public/siminstructions.html b/sim/public/siminstructions.html deleted file mode 100644 index e5fbdd60..00000000 --- a/sim/public/siminstructions.html +++ /dev/null @@ -1,201 +0,0 @@ - - - - - - Assembly Instructions - - - - - -
-
-
- - - - - - - - - - - - - - - - - - -
-

- - -
- -
-
-
-
- - \ No newline at end of file