diff --git a/WL.c b/WL.c index a75a240..485b39e 100644 --- a/WL.c +++ b/WL.c @@ -379,6 +379,7 @@ struct Node { Node *params; Node *child; + bool no_body; Node *cond; @@ -1006,6 +1007,7 @@ Node *parse_html(Parser *p) parent->tagname = tagname; parent->params = param_head; parent->child = head; + parent->no_body = no_body; return parent; } @@ -2801,40 +2803,49 @@ void assemble_html_2(Assembler *a, HTMLAssembler *ha, Node *node) if (value) { append_u8(&ha->tmp, '='); + append_u8(&ha->tmp, '"'); if (value->type == NODE_VALUE_STR) { - append_u8(&ha->tmp, '"'); append_mem(&ha->tmp, value->sval.ptr, // TODO: escape value->sval.len ); - append_u8(&ha->tmp, '"'); } else { write_buffered_html(a, ha); assemble_statement(a, value, false); } + + append_u8(&ha->tmp, '"'); } attr = attr->next; } - append_u8(&ha->tmp, '>'); - Node *child = node->child; - while (child) { - if (child->type == NODE_VALUE_STR) - append_mem(&ha->tmp, child->sval.ptr, child->sval.len); - else if (child->type == NODE_VALUE_HTML) - assemble_html_2(a, ha, child); - else { - write_buffered_html(a, ha); - assemble_statement(a, child, false); + if (node->no_body) { + append_u8(&ha->tmp, ' '); + append_u8(&ha->tmp, '/'); + append_u8(&ha->tmp, '>'); + } else { + + append_u8(&ha->tmp, '>'); + + Node *child = node->child; + while (child) { + if (child->type == NODE_VALUE_STR) + append_mem(&ha->tmp, child->sval.ptr, child->sval.len); + else if (child->type == NODE_VALUE_HTML) + assemble_html_2(a, ha, child); + else { + write_buffered_html(a, ha); + assemble_statement(a, child, false); + } + child = child->next; } - child = child->next; - } - append_u8(&ha->tmp, '<'); - append_u8(&ha->tmp, '/'); - append_mem(&ha->tmp, node->tagname.ptr, node->tagname.len); - append_u8(&ha->tmp, '>'); + append_u8(&ha->tmp, '<'); + append_u8(&ha->tmp, '/'); + append_mem(&ha->tmp, node->tagname.ptr, node->tagname.len); + append_u8(&ha->tmp, '>'); + } } void assemble_html(Assembler *a, Node *node) @@ -3337,6 +3348,7 @@ void assemble_statement(Assembler *a, Node *node, bool pop_expr) assert(off == idx); + idx++; arg = arg->next; } @@ -4218,7 +4230,7 @@ Value *array_select(Value array, int key) int cursor = 0; while (batch) { - int num = ITEMS_PER_MAP_BATCH; + int num = ITEMS_PER_ARRAY_BATCH; if (batch->next == NULL) num = p->tail_count; @@ -4235,7 +4247,7 @@ Value *array_select(Value array, int key) int array_append(WL_Arena *a, Value array, Value val) { ArrayValue *p = get_array(array); - if (p->tail_count == ITEMS_PER_MAP_BATCH) { + if (p->tail_count == ITEMS_PER_ARRAY_BATCH) { ArrayItems *batch = alloc(a, (int) sizeof(ArrayItems), _Alignof(ArrayItems)); if (batch == NULL) @@ -5210,7 +5222,12 @@ int step(WL_State *state) if (type_of(set) == TYPE_ARRAY) { - Value *dst = array_select(set, key); + if (type_of(key) != TYPE_INT) { + assert(0); // TODO + } + int64_t idx = get_int(key); + + Value *dst = array_select(set, idx); if (dst == NULL) { eval_report(state, "Index out of range"); return -1; @@ -5241,7 +5258,12 @@ int step(WL_State *state) if (type_of(set) == TYPE_ARRAY) { - Value *dst = array_select(set, key); + if (type_of(key) != TYPE_INT) { + assert(0); // TODO + } + int64_t idx = get_int(key); + + Value *dst = array_select(set, idx); if (dst == NULL) { eval_report(state, "Index out of range"); return -1; @@ -5272,7 +5294,12 @@ int step(WL_State *state) Value r; if (type_of(set) == TYPE_ARRAY) { - Value *src = array_select(set, key); + if (type_of(key) != TYPE_INT) { + assert(0); // TODO + } + int64_t idx = get_int(key); + + Value *src = array_select(set, idx); if (src == NULL) { eval_report(state, "Index out of range"); return -1; diff --git a/src/assemble.c b/src/assemble.c index 441f73d..7d03332 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -441,40 +441,49 @@ void assemble_html_2(Assembler *a, HTMLAssembler *ha, Node *node) if (value) { append_u8(&ha->tmp, '='); + append_u8(&ha->tmp, '"'); if (value->type == NODE_VALUE_STR) { - append_u8(&ha->tmp, '"'); append_mem(&ha->tmp, value->sval.ptr, // TODO: escape value->sval.len ); - append_u8(&ha->tmp, '"'); } else { write_buffered_html(a, ha); assemble_statement(a, value, false); } + + append_u8(&ha->tmp, '"'); } attr = attr->next; } - append_u8(&ha->tmp, '>'); - Node *child = node->child; - while (child) { - if (child->type == NODE_VALUE_STR) - append_mem(&ha->tmp, child->sval.ptr, child->sval.len); - else if (child->type == NODE_VALUE_HTML) - assemble_html_2(a, ha, child); - else { - write_buffered_html(a, ha); - assemble_statement(a, child, false); + if (node->no_body) { + append_u8(&ha->tmp, ' '); + append_u8(&ha->tmp, '/'); + append_u8(&ha->tmp, '>'); + } else { + + append_u8(&ha->tmp, '>'); + + Node *child = node->child; + while (child) { + if (child->type == NODE_VALUE_STR) + append_mem(&ha->tmp, child->sval.ptr, child->sval.len); + else if (child->type == NODE_VALUE_HTML) + assemble_html_2(a, ha, child); + else { + write_buffered_html(a, ha); + assemble_statement(a, child, false); + } + child = child->next; } - child = child->next; - } - append_u8(&ha->tmp, '<'); - append_u8(&ha->tmp, '/'); - append_mem(&ha->tmp, node->tagname.ptr, node->tagname.len); - append_u8(&ha->tmp, '>'); + append_u8(&ha->tmp, '<'); + append_u8(&ha->tmp, '/'); + append_mem(&ha->tmp, node->tagname.ptr, node->tagname.len); + append_u8(&ha->tmp, '>'); + } } void assemble_html(Assembler *a, Node *node) @@ -977,6 +986,7 @@ void assemble_statement(Assembler *a, Node *node, bool pop_expr) assert(off == idx); + idx++; arg = arg->next; } diff --git a/src/eval.c b/src/eval.c index dfdcbe8..22efdfb 100644 --- a/src/eval.c +++ b/src/eval.c @@ -723,7 +723,12 @@ int step(WL_State *state) if (type_of(set) == TYPE_ARRAY) { - Value *dst = array_select(set, key); + if (type_of(key) != TYPE_INT) { + assert(0); // TODO + } + int64_t idx = get_int(key); + + Value *dst = array_select(set, idx); if (dst == NULL) { eval_report(state, "Index out of range"); return -1; @@ -754,7 +759,12 @@ int step(WL_State *state) if (type_of(set) == TYPE_ARRAY) { - Value *dst = array_select(set, key); + if (type_of(key) != TYPE_INT) { + assert(0); // TODO + } + int64_t idx = get_int(key); + + Value *dst = array_select(set, idx); if (dst == NULL) { eval_report(state, "Index out of range"); return -1; @@ -785,7 +795,12 @@ int step(WL_State *state) Value r; if (type_of(set) == TYPE_ARRAY) { - Value *src = array_select(set, key); + if (type_of(key) != TYPE_INT) { + assert(0); // TODO + } + int64_t idx = get_int(key); + + Value *src = array_select(set, idx); if (src == NULL) { eval_report(state, "Index out of range"); return -1; diff --git a/src/parse.c b/src/parse.c index 8eaa54e..62efabe 100644 --- a/src/parse.c +++ b/src/parse.c @@ -592,6 +592,7 @@ Node *parse_html(Parser *p) parent->tagname = tagname; parent->params = param_head; parent->child = head; + parent->no_body = no_body; return parent; } diff --git a/src/parse.h b/src/parse.h index 73b8cb2..bf5bd77 100644 --- a/src/parse.h +++ b/src/parse.h @@ -58,6 +58,7 @@ struct Node { Node *params; Node *child; + bool no_body; Node *cond; diff --git a/src/value.c b/src/value.c index 480df12..3eb0d48 100644 --- a/src/value.c +++ b/src/value.c @@ -253,7 +253,7 @@ Value *array_select(Value array, int key) int cursor = 0; while (batch) { - int num = ITEMS_PER_MAP_BATCH; + int num = ITEMS_PER_ARRAY_BATCH; if (batch->next == NULL) num = p->tail_count; @@ -270,7 +270,7 @@ Value *array_select(Value array, int key) int array_append(WL_Arena *a, Value array, Value val) { ArrayValue *p = get_array(array); - if (p->tail_count == ITEMS_PER_MAP_BATCH) { + if (p->tail_count == ITEMS_PER_ARRAY_BATCH) { ArrayItems *batch = alloc(a, (int) sizeof(ArrayItems), _Alignof(ArrayItems)); if (batch == NULL)