|
@@ -1535,6 +1535,8 @@ node_t *parse_primary(list_t *tokens, size_t *pos) {
|
|
|
node_t *cond = NULL;
|
|
|
|
|
|
if (MATCH(FOR)) {
|
|
|
+ int is_var = MATCH(VAR);
|
|
|
+
|
|
|
if (MATCH(LSB)) {
|
|
|
list_t *l = list_new();
|
|
|
|
|
@@ -1548,7 +1550,10 @@ node_t *parse_primary(list_t *tokens, size_t *pos) {
|
|
|
EXPECT(RSB, "]");
|
|
|
EXPECT(OF, "of");
|
|
|
|
|
|
- loop = NODE2l(FOROFUNPACK, parse_expr(tokens, pos), NODEL(LIST, a), l);
|
|
|
+ if (is_var)
|
|
|
+ loop = NODE2l(FOROFVARUNPACK, parse_expr(tokens, pos), NODEL(LIST, a), l);
|
|
|
+ else
|
|
|
+ loop = NODE2l(FOROFUNPACK, parse_expr(tokens, pos), NODEL(LIST, a), l);
|
|
|
} else {
|
|
|
if (!AT(NAME))
|
|
|
PARSE_ERROR("expected identifier");
|
|
@@ -1557,7 +1562,10 @@ node_t *parse_primary(list_t *tokens, size_t *pos) {
|
|
|
|
|
|
EXPECT(OF, "of");
|
|
|
|
|
|
- loop = NODE2t(FOROF, parse_expr(tokens, pos), NODEL(LIST, a), t);
|
|
|
+ if (is_var)
|
|
|
+ loop = NODE2t(FOROFVAR, parse_expr(tokens, pos), NODEL(LIST, a), t);
|
|
|
+ else
|
|
|
+ loop = NODE2t(FOROF, parse_expr(tokens, pos), NODEL(LIST, a), t);
|
|
|
}
|
|
|
|
|
|
if (MATCH(IF))
|
|
@@ -1594,6 +1602,8 @@ node_t *parse_primary(list_t *tokens, size_t *pos) {
|
|
|
node_t *cond = NULL;
|
|
|
|
|
|
if (MATCH(FOR)) {
|
|
|
+ int is_var = MATCH(VAR);
|
|
|
+
|
|
|
if (MATCH(LSB)) {
|
|
|
list_t *l = list_new();
|
|
|
|
|
@@ -1607,7 +1617,10 @@ node_t *parse_primary(list_t *tokens, size_t *pos) {
|
|
|
EXPECT(RSB, "]");
|
|
|
EXPECT(OF, "of");
|
|
|
|
|
|
- loop = NODE2l(FOROFUNPACK, parse_expr(tokens, pos), NODEL(LIST, pairs), l);
|
|
|
+ if (is_var)
|
|
|
+ loop = NODE2l(FOROFVARUNPACK, parse_expr(tokens, pos), NODEL(LIST, pairs), l);
|
|
|
+ else
|
|
|
+ loop = NODE2l(FOROFUNPACK, parse_expr(tokens, pos), NODEL(LIST, pairs), l);
|
|
|
} else {
|
|
|
if (!AT(NAME))
|
|
|
PARSE_ERROR("expected identifier");
|
|
@@ -1616,7 +1629,10 @@ node_t *parse_primary(list_t *tokens, size_t *pos) {
|
|
|
|
|
|
EXPECT(OF, "of");
|
|
|
|
|
|
- loop = NODE2t(FOROF, parse_expr(tokens, pos), NODEL(LIST, pairs), t);
|
|
|
+ if (is_var)
|
|
|
+ loop = NODE2t(FOROFVAR, parse_expr(tokens, pos), NODEL(LIST, pairs), t);
|
|
|
+ else
|
|
|
+ loop = NODE2t(FOROF, parse_expr(tokens, pos), NODEL(LIST, pairs), t);
|
|
|
}
|
|
|
|
|
|
if (MATCH(IF))
|
|
@@ -5411,6 +5427,9 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
|
|
|
|
|
|
buffer_t *bbuf = buffer_new();
|
|
|
|
|
|
+ CTXPUSH("scope");
|
|
|
+ buffer_fmt(tbuf, "qi_new_scope(state);\n");
|
|
|
+
|
|
|
if (node->b) {
|
|
|
buffer_fmt(bbuf, "if (_qi_truthy(state, ");
|
|
|
compile_node(gbuf, bbuf, ctx, ltab, lstk, sstk, lbl, node->b);
|
|
@@ -5432,6 +5451,9 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
|
|
|
|
|
|
compile_node(gbuf, tbuf, ctx, ltab, lstk, sstk, lbl, node->a);
|
|
|
|
|
|
+ CTXPOP();
|
|
|
+ buffer_fmt(tbuf, "qi_old_scope(state);\n");
|
|
|
+
|
|
|
buffer_fmt(tbuf, "return qi_make_list(state, list);\n}\n");
|
|
|
|
|
|
buffer_appendb(gbuf, tbuf);
|
|
@@ -5450,6 +5472,9 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
|
|
|
|
|
|
buffer_t *bbuf = buffer_new();
|
|
|
|
|
|
+ CTXPUSH("scope");
|
|
|
+ buffer_fmt(tbuf, "qi_new_scope(state);\n");
|
|
|
+
|
|
|
if (node->b) {
|
|
|
buffer_fmt(bbuf, "if (_qi_truthy(state, ");
|
|
|
compile_node(gbuf, bbuf, ctx, ltab, lstk, sstk, lbl, node->b);
|
|
@@ -5474,6 +5499,9 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab,
|
|
|
|
|
|
compile_node(gbuf, tbuf, ctx, ltab, lstk, sstk, lbl, node->a);
|
|
|
|
|
|
+ CTXPOP();
|
|
|
+ buffer_fmt(tbuf, "qi_old_scope(state);\n");
|
|
|
+
|
|
|
buffer_fmt(tbuf, "return qi_make_table(state, table);\n}\n");
|
|
|
|
|
|
buffer_appendb(gbuf, tbuf);
|