From 6a7d1bd95cd60bb8eddfd0cea2e39e388bd02c26 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Wed, 7 Sep 2016 16:27:28 +0100 Subject: [PATCH] Support for object literals bump pxt-microbit-core to 0.4.4 see https://github.com/Microsoft/pxt/issues/287 --- libs/microbit/core.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++ pxtarget.json | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/libs/microbit/core.cpp b/libs/microbit/core.cpp index 79bfc6b9..2ef9de04 100644 --- a/libs/microbit/core.cpp +++ b/libs/microbit/core.cpp @@ -308,6 +308,72 @@ namespace pxtrt { } } + //% + RefMap *mkMap() { + return new RefMap(); + } + + //% + uint32_t mapGet(RefMap *map, uint32_t key) { + int i = map->findIdx(key); + if (i < 0) { + map->unref(); + return 0; + } + uint32_t r = map->data[i].val; + map->unref(); + return r; + } + + //% + uint32_t mapGetRef(RefMap *map, uint32_t key) { + int i = map->findIdx(key); + if (i < 0) { + map->unref(); + return 0; + } + uint32_t r = incr(map->data[i].val); + map->unref(); + return r; + } + + //% + void mapSet(RefMap *map, uint32_t key, uint32_t val) { + int i = map->findIdx(key); + if (i < 0) { + map->data.push_back({ + key << 1, + val + }); + } else { + if (map->data[i].key & 1) { + decr(map->data[i].val); + map->data[i].key = key << 1; + } + map->data[i].val = val; + } + map->unref(); + } + + //% + void mapSetRef(RefMap *map, uint32_t key, uint32_t val) { + int i = map->findIdx(key); + if (i < 0) { + map->data.push_back({ + (key << 1) | 1, + val + }); + } else { + if (map->data[i].key & 1) { + decr(map->data[i].val); + } else { + map->data[i].key = (key << 1) | 1; + } + map->data[i].val = val; + } + map->unref(); + } + // // Debugger // diff --git a/pxtarget.json b/pxtarget.json index de3d6af8..11a27414 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -91,7 +91,7 @@ "yottaTarget": "bbc-microbit-classic-gcc", "yottaCorePackage": "pxt-microbit-core", "githubCorePackage": "microsoft/pxt-microbit-core", - "gittag": "v0.4.2", + "gittag": "v0.4.4", "serviceId": "ws" }, "serial": {