From cb955762a688857164e0e507dc4e3188a6c8b380 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 16 Aug 2021 10:32:25 +0200 Subject: [PATCH 1/5] Version bump to v9.5.0.6 Version bump to monitor possible HTTP issues releated to ``SetOption128`` --- CHANGELOG.md | 6 +++++- RELEASENOTES.md | 2 +- tasmota/tasmota_version.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 037d14613..f4a01c052 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,11 @@ All notable changes to this project will be documented in this file. ## [Unreleased] - Development -## [9.5.0.5] +## [9.5.0.6] +### Added +- Version bump to monitor possible HTTP issues releated to ``SetOption128`` + +## [9.5.0.5] 20210815 ### Added - Inital support for Wi-Fi extender (#12784) - Neopool commands ``NPPHRes``, ``NPCLRes`` and ``NPIonRes`` (#12813) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 9831112fc..828af7ac0 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -98,7 +98,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo [Complete list](BUILDS.md) of available feature and sensors. -## Changelog v9.5.0.5 +## Changelog v9.5.0.6 ### Added - Release of [Tasmota WebInstaller](https://arendst.github.io/Tasmota-firmware/) - Command ``SetOption127 1`` to force Wi-Fi in no-sleep mode even if ``Sleep 0`` is not enabled diff --git a/tasmota/tasmota_version.h b/tasmota/tasmota_version.h index bb18eec6f..51dc681e6 100644 --- a/tasmota/tasmota_version.h +++ b/tasmota/tasmota_version.h @@ -20,6 +20,6 @@ #ifndef _TASMOTA_VERSION_H_ #define _TASMOTA_VERSION_H_ -const uint32_t VERSION = 0x09050005; +const uint32_t VERSION = 0x09050006; #endif // _TASMOTA_VERSION_H_ From 0d9678eef6f5b645c8507b11d2026ca0909094c3 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 16 Aug 2021 11:11:46 +0200 Subject: [PATCH 2/5] Refactor trim --- tasmota/support.ino | 10 +++++----- tasmota/xdrv_59_influxdb.ino | 13 ++++++------- tasmota/xsns_53_sml.ino | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 2e17c7915..097bb1de8 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -316,7 +316,7 @@ float CharToFloat(const char *str) char *pt = strbuf; if (*pt == '\0') { return 0.0; } - while ((*pt != '\0') && isblank(*pt)) { pt++; } // Trim leading spaces + while ((*pt != '\0') && isspace(*pt)) { pt++; } // Trim leading spaces signed char sign = 1; if (*pt == '-') { sign = -1; } @@ -529,12 +529,12 @@ bool IsNumeric(const char* value) { return (*digit == '\0'); } -char* Trim(char* p) -{ +char* Trim(char* p) { + // Remove leading and trailing tab, \n, \v, \f, \r and space if (*p != '\0') { - while ((*p != '\0') && isblank(*p)) { p++; } // Trim leading spaces + while ((*p != '\0') && isspace(*p)) { p++; } // Trim leading spaces char* q = p + strlen(p) -1; - while ((q >= p) && isblank(*q)) { q--; } // Trim trailing spaces + while ((q >= p) && isspace(*q)) { q--; } // Trim trailing spaces q++; *q = '\0'; } diff --git a/tasmota/xdrv_59_influxdb.ino b/tasmota/xdrv_59_influxdb.ino index 9bc7f5510..a591321c8 100644 --- a/tasmota/xdrv_59_influxdb.ino +++ b/tasmota/xdrv_59_influxdb.ino @@ -84,7 +84,7 @@ struct { String _serverUrl; // Connection info String _writeUrl; // Cached full write url String _lastErrorResponse; // Server reponse or library error message for last failed request - uint32_t _lastRequestTime = 0; // Last time in ms we made are a request to server + uint32_t _lastRequestTime = 0; // Last time in ms we made a request to server int interval = 0; int _lastStatusCode = 0; // HTTP status code of last request to server int _lastRetryAfter = 0; // Store retry timeout suggested by server after last request @@ -161,7 +161,7 @@ void InfluxDbAfterRequest(int expectedStatusCode, bool modifyLastConnStatus) { IFDB._lastRequestTime = millis(); // AddLog(LOG_LEVEL_DEBUG, PSTR("IFX: HTTP status code %d"), IFDB._lastStatusCode); IFDB._lastRetryAfter = 0; - if (IFDB._lastStatusCode >= 429) { //retryable server errors + if (IFDB._lastStatusCode >= 429) { // Retryable server errors if (IFDBhttpClient->hasHeader(RetryAfter)) { IFDB._lastRetryAfter = IFDBhttpClient->header(RetryAfter).toInt(); AddLog(LOG_LEVEL_DEBUG, PSTR("IFX: Reply after %d"), IFDB._lastRetryAfter); @@ -171,12 +171,12 @@ void InfluxDbAfterRequest(int expectedStatusCode, bool modifyLastConnStatus) { IFDB._lastErrorResponse = ""; if (IFDB._lastStatusCode != expectedStatusCode) { if (IFDB._lastStatusCode > 0) { - IFDB._lastErrorResponse = IFDBhttpClient->getString(); - AddLog(LOG_LEVEL_INFO, PSTR("IFX: %s"), IFDB._lastErrorResponse.c_str()); // {"error":"database not found: \"db\""} + IFDB._lastErrorResponse = IFDBhttpClient->getString(); // {"error":"database not found: \"db\""}\n } else { IFDB._lastErrorResponse = IFDBhttpClient->errorToString(IFDB._lastStatusCode); - AddLog(LOG_LEVEL_INFO, PSTR("IFX: Error %s"), IFDB._lastErrorResponse.c_str()); } + IFDB._lastErrorResponse.trim(); // Remove trailing \n + AddLog(LOG_LEVEL_INFO, PSTR("IFX: Error %s"), IFDB._lastErrorResponse.c_str()); } } @@ -191,8 +191,6 @@ bool InfluxDbValidateConnection(void) { if (1 == Settings->influxdb_version) { url += InfluxDbAuth(); } - // on version 1.8.9 /health works fine -// String url = IFDB._serverUrl + "/health"; AddLog(LOG_LEVEL_INFO, PSTR("IFX: Validating connection to %s"), url.c_str()); if (!IFDBhttpClient->begin(*IFDBwifiClient, url)) { @@ -221,6 +219,7 @@ int InfluxDbPostData(const char *data) { return false; } + Trim((char*)data); // Remove trailing \n AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("IFX: Sending\n%s"), data); IFDBhttpClient->addHeader(F("Content-Type"), F("text/plain")); InfluxDbBeforeRequest(); diff --git a/tasmota/xsns_53_sml.ino b/tasmota/xsns_53_sml.ino index 184261771..5c3644d1f 100755 --- a/tasmota/xsns_53_sml.ino +++ b/tasmota/xsns_53_sml.ino @@ -1198,7 +1198,7 @@ double CharToDouble(const char *str) strlcpy(strbuf, str, sizeof(strbuf)); char *pt = strbuf; - while ((*pt != '\0') && isblank(*pt)) { pt++; } // Trim leading spaces + while ((*pt != '\0') && isspace(*pt)) { pt++; } // Trim leading spaces signed char sign = 1; if (*pt == '-') { sign = -1; } From 1ab2b2c8659f9e6f1086830a7fccf42a85c98052 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 16 Aug 2021 11:44:27 +0200 Subject: [PATCH 3/5] Fix influxdb id regression --- tasmota/support.ino | 1 + tasmota/xdrv_59_influxdb.ino | 46 +++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 097bb1de8..22ff91854 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -524,6 +524,7 @@ bool StrCaseStr_P(const char* source, const char* search) { } bool IsNumeric(const char* value) { + // Test for characters '-.0123456789' char *digit = (char*)value; while (isdigit(*digit) || *digit == '.' || *digit == '-') { digit++; } return (*digit == '\0'); diff --git a/tasmota/xdrv_59_influxdb.ino b/tasmota/xdrv_59_influxdb.ino index a591321c8..32ea3e076 100644 --- a/tasmota/xdrv_59_influxdb.ino +++ b/tasmota/xdrv_59_influxdb.ino @@ -293,36 +293,38 @@ void InfluxDbProcessJson(void) { } else { // Level 2 // { ... "ANALOG":{"Temperature":184.72},"DS18B20":{"Id":"01144A0CB2AA","Temperature":24.88},"HTU21":{"Temperature":25.32,"Humidity":49.2,"DewPoint":13.88},"Global":{"Temperature":24.88,"Humidity":49.2,"DewPoint":13.47}, ... } - bool isarray = value2.isArray(); - const char* value = InfluxDbNumber(number, (isarray) ? (value2.getArray())[0].getStr() : value2.getStr()); + LowerCase(type, key2.getStr()); + bool is_id = (!strcmp_P(type, PSTR("id"))); // Index for DS18B20 + bool is_array = value2.isArray(); + const char* value = nullptr; + if (is_id && !is_array) { + snprintf_P(sensor_id, sizeof(sensor_id), PSTR(",id=%s"), value2.getStr()); + } else { + value = InfluxDbNumber(number, (is_array) ? (value2.getArray())[0].getStr() : value2.getStr()); + } if (value != nullptr) { LowerCase(sensor, key1.getStr()); - LowerCase(type, key2.getStr()); // AddLog(LOG_LEVEL_DEBUG, PSTR("IFX2: sensor %s (%s), type %s (%s)"), key1.getStr(), sensor, key2.getStr(), type); - if (strcmp(type, "id") == 0) { // Index for DS18B20 - snprintf_P(sensor_id, sizeof(sensor_id), PSTR(",id=%s"), value); - } else { - if (isarray) { - JsonParserArray arr = value2.getArray(); - uint32_t i = 0; - for (auto val : arr) { - i++; - // power1,device=shelly25,sensor=energy value=0.00 - // power2,device=shelly25,sensor=energy value=4.12 - snprintf_P(linebuf, sizeof(linebuf), PSTR("%s%d,device=%s,sensor=%s%s value=%s\n"), - type, i, TasmotaGlobal.mqtt_topic, sensor, sensor_id, val.getStr()); - data += linebuf; - } - } else { - // temperature,device=demo,sensor=ds18b20,id=01144A0CB2AA value=22.63 - snprintf_P(linebuf, sizeof(linebuf), PSTR("%s,device=%s,sensor=%s%s value=%s\n"), - type, TasmotaGlobal.mqtt_topic, sensor, sensor_id, value); + if (is_array) { + JsonParserArray arr = value2.getArray(); + uint32_t i = 0; + for (auto val : arr) { + i++; + // power1,device=shelly25,sensor=energy value=0.00 + // power2,device=shelly25,sensor=energy value=4.12 + snprintf_P(linebuf, sizeof(linebuf), PSTR("%s%d,device=%s,sensor=%s%s value=%s\n"), + type, i, TasmotaGlobal.mqtt_topic, sensor, sensor_id, val.getStr()); data += linebuf; } - sensor_id[0] = '\0'; + } else { + // temperature,device=demo,sensor=ds18b20,id=01144A0CB2AA value=22.63 + snprintf_P(linebuf, sizeof(linebuf), PSTR("%s,device=%s,sensor=%s%s value=%s\n"), + type, TasmotaGlobal.mqtt_topic, sensor, sensor_id, value); + data += linebuf; } + sensor_id[0] = '\0'; } } } From 660698dc1003d1eaec4716b6b673aeff044a59db Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Mon, 16 Aug 2021 12:11:28 +0200 Subject: [PATCH 4/5] Fix Berry compiler bug #117 --- lib/libesp32/Berry/default/be_tasmotalib.c | 400 ++++++------------ .../Berry/default/embedded/Tasmota.be | 41 ++ lib/libesp32/Berry/src/be_code.c | 77 +++- lib/libesp32/Berry/src/be_code.h | 2 +- lib/libesp32/Berry/src/be_parser.c | 20 +- 5 files changed, 243 insertions(+), 297 deletions(-) diff --git a/lib/libesp32/Berry/default/be_tasmotalib.c b/lib/libesp32/Berry/default/be_tasmotalib.c index f14657f33..ec1aa8739 100644 --- a/lib/libesp32/Berry/default/be_tasmotalib.c +++ b/lib/libesp32/Berry/default/be_tasmotalib.c @@ -973,115 +973,61 @@ be_local_closure(set_timer, /* name */ ); /*******************************************************************/ - -/******************************************************************** - // run every 50ms tick - "def run_deferred() " - "if self._timers " - "var i=0 " - "while inot, NOT_EXPR) #define notmask(e) isset((e)->not, NOT_MASK) -#define exp2anyreg(f, e) exp2reg(f, e, (f)->freereg) -#define var2anyreg(f, e) var2reg(f, e, (f)->freereg) +#define exp2anyreg(f, e) exp2reg(f, e, -1) /* -1 means allocate a new register if needed */ +#define var2anyreg(f, e) var2reg(f, e, -1) /* -1 means allocate a new register if needed */ #define hasjump(e) ((e)->t != (e)->f || notexpr(e)) #define code_bool(f, r, b, j) codeABC(f, OP_LDBOOL, r, b, j) #define code_call(f, a, b) codeABC(f, OP_CALL, a, b, 0) @@ -321,9 +321,38 @@ static void free_suffix(bfuncinfo *finfo, bexpdesc *e) } } +static int suffix_destreg(bfuncinfo *finfo, bexpdesc *e1, int dst) +{ + int cand_dst = dst; /* candidate for new dst */ + int nlocal = be_list_count(finfo->local); + int reg1 = (e1->v.ss.tt == ETREG) ? e1->v.ss.obj : -1; /* check if obj is ETREG or -1 */ + int reg2 = (!isK(e1->v.ss.idx) && e1->v.ss.idx >= nlocal) ? e1->v.ss.idx : -1; /* check if idx is ETREG or -1 */ + + if (reg1 >= 0 && reg2 >= 0) { + /* both are ETREG, we keep the lowest and discard the other */ + if (reg1 != reg2) { + cand_dst = min(reg1, reg2); + be_code_freeregs(finfo, 1); /* and free the other one */ + } else { + cand_dst = reg1; /* both ETREG are equal, we return its value */ + } + } else if (reg1 >= 0) { + cand_dst = reg1; + } else if (reg2 >= 0) { + cand_dst = reg2; + } else { + // dst unchanged + } + + if (dst >= finfo->freereg) { + dst = cand_dst; /* if dst was allocating a new register, use the more precise candidate */ + } + return dst; +} + static int code_suffix(bfuncinfo *finfo, bopcode op, bexpdesc *e, int dst) { - free_suffix(finfo, e); /* free temporary registers */ + dst = suffix_destreg(finfo, e, dst); if (dst > finfo->freereg) { dst = finfo->freereg; } @@ -351,6 +380,9 @@ static bbool constint(bfuncinfo *finfo, bint i) static int var2reg(bfuncinfo *finfo, bexpdesc *e, int dst) { + if (dst < 0) { /* if unspecified, allocate a new register if needed */ + dst = finfo->freereg; + } be_assert(e != NULL); switch (e->type) { case ETINT: @@ -376,7 +408,7 @@ static int var2reg(bfuncinfo *finfo, bexpdesc *e, int dst) codeABx(finfo, OP_GETGBL, dst, e->v.idx); break; case ETNGLOBAL: - codeABC(finfo, OP_GETNGBL, dst, e->v.ss.idx, 0); + codeABC(finfo, OP_GETNGBL, dst, e->v.ss.obj, e->v.ss.idx); break; case ETUPVAL: codeABx(finfo, OP_GETUPV, dst, e->v.idx); @@ -420,28 +452,37 @@ static int exp2reg(bfuncinfo *finfo, bexpdesc *e, int dst) return reg; } -static int codedestreg(bfuncinfo *finfo, bexpdesc *e1, bexpdesc *e2) +static int codedestreg(bfuncinfo *finfo, bexpdesc *e1, bexpdesc *e2, int dst) { - int dst, con1 = e1->type == ETREG, con2 = e2->type == ETREG; + int cand_dst = dst; + int con1 = e1->type == ETREG, con2 = e2->type == ETREG; if (con1 && con2) { - dst = min(e1->v.idx, e2->v.idx); + cand_dst = min(e1->v.idx, e2->v.idx); be_code_freeregs(finfo, 1); } else if (con1) { - dst = e1->v.idx; + cand_dst = e1->v.idx; } else if (con2) { - dst = e2->v.idx; + cand_dst = e2->v.idx; } else { - dst = be_code_allocregs(finfo, 1); + if (dst >= finfo->freereg) { + cand_dst = be_code_allocregs(finfo, 1); + return cand_dst; + } + } + if (dst >= finfo->freereg) { + return cand_dst; + } else { + return dst; } - return dst; } -static void binaryexp(bfuncinfo *finfo, bopcode op, bexpdesc *e1, bexpdesc *e2) +static void binaryexp(bfuncinfo *finfo, bopcode op, bexpdesc *e1, bexpdesc *e2, int dst) { - int src1 = exp2anyreg(finfo, e1); + if (dst < 0) { dst = finfo->freereg; } + int src1 = exp2reg(finfo, e1, dst); /* potentially force the target for src1 reg */ int src2 = exp2anyreg(finfo, e2); - int dst = codedestreg(finfo, e1, e2); + dst = codedestreg(finfo, e1, e2, dst); codeABC(finfo, op, dst, src1, src2); e1->type = ETREG; e1->v.idx = dst; @@ -462,7 +503,7 @@ void be_code_prebinop(bfuncinfo *finfo, int op, bexpdesc *e) } } -void be_code_binop(bfuncinfo *finfo, int op, bexpdesc *e1, bexpdesc *e2) +void be_code_binop(bfuncinfo *finfo, int op, bexpdesc *e1, bexpdesc *e2, int dst) { switch (op) { case OptAnd: @@ -480,7 +521,7 @@ void be_code_binop(bfuncinfo *finfo, int op, bexpdesc *e1, bexpdesc *e2) case OptNE: case OptGT: case OptGE: case OptConnect: case OptBitAnd: case OptBitOr: case OptBitXor: case OptShiftL: case OptShiftR: - binaryexp(finfo, (bopcode)(op - OptAdd), e1, e2); + binaryexp(finfo, (bopcode)(op - OptAdd), e1, e2, dst); break; default: break; } @@ -560,7 +601,7 @@ static void setbgblvar(bfuncinfo *finfo, bopcode op, bexpdesc *e1, int src) code_move(finfo, finfo->freereg, src); src = finfo->freereg; } - codeABC(finfo, op, src, e1->v.idx, 0); + codeABC(finfo, op, src, 0, e1->v.idx); } static void setsupvar(bfuncinfo *finfo, bopcode op, bexpdesc *e1, int src) @@ -586,7 +627,7 @@ static void setsfxvar(bfuncinfo *finfo, bopcode op, bexpdesc *e1, int src) int be_code_setvar(bfuncinfo *finfo, bexpdesc *e1, bexpdesc *e2) { int src = exp2reg(finfo, e2, - e1->type == ETLOCAL ? e1->v.idx : finfo->freereg); + e1->type == ETLOCAL ? e1->v.idx : -1); if (e1->type != ETLOCAL || e1->v.idx != src) { free_expreg(finfo, e2); /* free source (only ETREG) */ diff --git a/lib/libesp32/Berry/src/be_code.h b/lib/libesp32/Berry/src/be_code.h index f7fdb2d55..54d0c317c 100644 --- a/lib/libesp32/Berry/src/be_code.h +++ b/lib/libesp32/Berry/src/be_code.h @@ -14,7 +14,7 @@ int be_code_allocregs(bfuncinfo *finfo, int count); void be_code_prebinop(bfuncinfo *finfo, int op, bexpdesc *e); -void be_code_binop(bfuncinfo *finfo, int op, bexpdesc *e1, bexpdesc *e2); +void be_code_binop(bfuncinfo *finfo, int op, bexpdesc *e1, bexpdesc *e2, int dst); int be_code_unop(bfuncinfo *finfo, int op, bexpdesc *e); int be_code_setvar(bfuncinfo *finfo, bexpdesc *e1, bexpdesc *e2); int be_code_nextreg(bfuncinfo *finfo, bexpdesc *e); diff --git a/lib/libesp32/Berry/src/be_parser.c b/lib/libesp32/Berry/src/be_parser.c index c19f83e9a..3090ca465 100644 --- a/lib/libesp32/Berry/src/be_parser.c +++ b/lib/libesp32/Berry/src/be_parser.c @@ -467,7 +467,6 @@ static int singlevaraux(bvm *vm, bfuncinfo *finfo, bstring *s, bexpdesc *var) static void singlevar(bparser *parser, bexpdesc *var) { - bexpdesc key; bstring *varname = next_token(parser).u.s; int type = singlevaraux(parser->vm, parser->finfo, varname, var); switch (type) { @@ -480,10 +479,13 @@ static void singlevar(bparser *parser, bexpdesc *var) var->v.idx = be_global_find(parser->vm, varname); break; case ETNGLOBAL: - init_exp(&key, ETSTRING, 0); - key.v.s = varname; - init_exp(var, ETNGLOBAL, 0); - var->v.idx = be_code_nglobal(parser->finfo, &key); + { + bexpdesc key; + init_exp(&key, ETSTRING, 0); + key.v.s = varname; + init_exp(var, ETNGLOBAL, 0); + var->v.idx = be_code_nglobal(parser->finfo, &key); + } break; default: break; @@ -610,7 +612,7 @@ static void list_nextmember(bparser *parser, bexpdesc *l) bfuncinfo *finfo = parser->finfo; expr(parser, &e); /* value */ check_var(parser, &e); - be_code_binop(finfo, OptConnect, &v, &e); + be_code_binop(finfo, OptConnect, &v, &e, -1); be_code_freeregs(finfo, 1); } @@ -823,9 +825,11 @@ static void suffix_alloc_reg(bparser *parser, bexpdesc *l) /* compound assignment */ static void compound_assign(bparser *parser, int op, bexpdesc *l, bexpdesc *r) { + int dst = -1; /* destination register in case of compound assignment */ if (op != OptAssign) { /* check left variable */ check_var(parser, l); /* cache the register of the object when continuously assigning */ + dst = parser->finfo->freereg; suffix_alloc_reg(parser, l); } expr(parser, r); /* right expression */ @@ -834,7 +838,7 @@ static void compound_assign(bparser *parser, int op, bexpdesc *l, bexpdesc *r) bexpdesc e = *l; op = op < OptAndAssign ? op - OptAddAssign + OptAdd : op - OptAndAssign + OptBitAnd; - be_code_binop(parser->finfo, op, &e, r); /* coding operation */ + be_code_binop(parser->finfo, op, &e, r, dst); /* coding operation */ *r = e; } } @@ -938,7 +942,7 @@ static void sub_expr(bparser *parser, bexpdesc *e, int prio) init_exp(&e2, ETVOID, 0); sub_expr(parser, &e2, binary_op_prio(op)); check_var(parser, &e2); - be_code_binop(finfo, op, e, &e2); /* encode binary op */ + be_code_binop(finfo, op, e, &e2, -1); /* encode binary op */ op = get_binop(parser); } if (prio == ASSIGN_OP_PRIO) { From b870ca1aa39556b8a452427e781f8c5b68e31060 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Mon, 16 Aug 2021 12:22:02 +0200 Subject: [PATCH 5/5] Fix --- lib/libesp32/Berry/src/be_code.c | 4 ++-- lib/libesp32/Berry/src/be_parser.c | 12 +++++------- lib/libesp32/Berry/src/berry.h | 11 +++++++++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/libesp32/Berry/src/be_code.c b/lib/libesp32/Berry/src/be_code.c index f6eb792ab..56bd9f530 100644 --- a/lib/libesp32/Berry/src/be_code.c +++ b/lib/libesp32/Berry/src/be_code.c @@ -408,7 +408,7 @@ static int var2reg(bfuncinfo *finfo, bexpdesc *e, int dst) codeABx(finfo, OP_GETGBL, dst, e->v.idx); break; case ETNGLOBAL: - codeABC(finfo, OP_GETNGBL, dst, e->v.ss.obj, e->v.ss.idx); + codeABC(finfo, OP_GETNGBL, dst, e->v.ss.idx, 0); break; case ETUPVAL: codeABx(finfo, OP_GETUPV, dst, e->v.idx); @@ -601,7 +601,7 @@ static void setbgblvar(bfuncinfo *finfo, bopcode op, bexpdesc *e1, int src) code_move(finfo, finfo->freereg, src); src = finfo->freereg; } - codeABC(finfo, op, src, 0, e1->v.idx); + codeABC(finfo, op, src, e1->v.idx, 0); } static void setsupvar(bfuncinfo *finfo, bopcode op, bexpdesc *e1, int src) diff --git a/lib/libesp32/Berry/src/be_parser.c b/lib/libesp32/Berry/src/be_parser.c index 3090ca465..4a32c189d 100644 --- a/lib/libesp32/Berry/src/be_parser.c +++ b/lib/libesp32/Berry/src/be_parser.c @@ -467,6 +467,7 @@ static int singlevaraux(bvm *vm, bfuncinfo *finfo, bstring *s, bexpdesc *var) static void singlevar(bparser *parser, bexpdesc *var) { + bexpdesc key; bstring *varname = next_token(parser).u.s; int type = singlevaraux(parser->vm, parser->finfo, varname, var); switch (type) { @@ -479,13 +480,10 @@ static void singlevar(bparser *parser, bexpdesc *var) var->v.idx = be_global_find(parser->vm, varname); break; case ETNGLOBAL: - { - bexpdesc key; - init_exp(&key, ETSTRING, 0); - key.v.s = varname; - init_exp(var, ETNGLOBAL, 0); - var->v.idx = be_code_nglobal(parser->finfo, &key); - } + init_exp(&key, ETSTRING, 0); + key.v.s = varname; + init_exp(var, ETNGLOBAL, 0); + var->v.idx = be_code_nglobal(parser->finfo, &key); break; default: break; diff --git a/lib/libesp32/Berry/src/berry.h b/lib/libesp32/Berry/src/berry.h index 52a557fd8..1637dc434 100644 --- a/lib/libesp32/Berry/src/berry.h +++ b/lib/libesp32/Berry/src/berry.h @@ -352,6 +352,17 @@ typedef struct bntvmodule { PROTO_VAR_INFO_BLOCK \ } +#define be_define_local_closure(_name) \ + const bclosure _name##_closure = { \ + NULL, /* bgcobject *next */ \ + BE_CLOSURE, /* type BE_CLOSURE */ \ + GC_CONST, /* marked GC_CONST */ \ + 0, /* nupvals */ \ + NULL, /* bgcobject *gray */ \ + (bproto*) &_name##_proto, /* proto */ \ + { NULL } /* upvals */ \ + } + /* new version for more compact literals */ #define be_local_closure(_name, _proto) \ static const bclosure _name##_closure = { \