summaryrefslogtreecommitdiff
path: root/test/dump.h
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2022-11-26 14:06:43 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2022-11-26 14:06:43 +0000
commit6d58bc4e0278c971ba7fc9623367d8ea241689ee (patch)
tree14e5e408ca1613e769d7c4c943467767dbf72be2 /test/dump.h
parentad87e675c59bc76a64c445cc89b8cc4522e6f761 (diff)
downloadlibcss-6d58bc4e0278c971ba7fc9623367d8ea241689ee.tar.gz
libcss-6d58bc4e0278c971ba7fc9623367d8ea241689ee.tar.bz2
(calc): Update bytecode for calc() to be in an lwc_stringdsilvers/calc
In order to permit us to share calc expressions between styles and computed styles, without copying, we embed the calc expression bytecode into an lwc string. This is effectively using lwc_string as an interned byte buffer, there may be a nicer way to do this in the future. Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'test/dump.h')
-rw-r--r--test/dump.h29
1 files changed, 18 insertions, 11 deletions
diff --git a/test/dump.h b/test/dump.h
index a1fdd1f..eac0a9f 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -803,15 +803,23 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
} else if (getFlagValue(opv) == FLAG_VALUE_UNSET) {
*ptr += sprintf(*ptr, "unset");
} else if (isCalc(opv)) {
+ lwc_string *calc_expr = NULL;
+ const uint8_t *codeptr = NULL;
+ css_code_t calc_opcode;
+ uint32_t unit, snum;
/* First entry is a unit */
- uint32_t unit = *((uint32_t *)bytecode);
+ unit = *((uint32_t *)bytecode);
ADVANCE(sizeof(unit));
+ /* Second entry is an lwc_string of the expression */
+ snum = *((uint32_t *)bytecode);
+ ADVANCE(sizeof(snum));
+ css__stylesheet_string_get(style->sheet, snum, &calc_expr);
+ codeptr = (const uint8_t *)lwc_string_data(calc_expr);
*ptr += sprintf(*ptr, "/* -> ");
dump_unit(0, unit, ptr);
*ptr += sprintf(*ptr, " */ calc(");
- css_code_t calc_opcode;
- while ((calc_opcode = *((css_code_t *)bytecode)) != CALC_FINISH) {
- ADVANCE(sizeof(calc_opcode));
+ while ((calc_opcode = *((css_code_t *)codeptr)) != CALC_FINISH) {
+ codeptr += sizeof(calc_opcode);
switch (calc_opcode) {
case CALC_ADD:
*ptr += sprintf(*ptr, "+ ");
@@ -826,17 +834,17 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
*ptr += sprintf(*ptr, "/ ");
break;
case CALC_PUSH_VALUE: {
- css_fixed num = *((css_fixed *)bytecode);
- ADVANCE(sizeof(num));
- uint32_t unit = *((uint32_t *)bytecode);
- ADVANCE(sizeof(unit));
+ css_fixed num = *((css_fixed *)codeptr);
+ codeptr += sizeof(num);
+ uint32_t unit = *((uint32_t *)codeptr);
+ codeptr += sizeof(unit);
dump_unit(num, unit, ptr);
*ptr += sprintf(*ptr, " ");
break;
}
case CALC_PUSH_NUMBER: {
- css_fixed num = *((css_fixed *)bytecode);
- ADVANCE(sizeof(num));
+ css_fixed num = *((css_fixed *)codeptr);
+ codeptr += sizeof(num);
dump_number(num, ptr);
*ptr += sprintf(*ptr, " ");
break;
@@ -846,7 +854,6 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth)
break;
}
}
- ADVANCE(sizeof(calc_opcode));
*ptr += sprintf(*ptr, "=)");
} else {
value = getValue(opv);