Skip to content

Commit f2bd61d

Browse files
committed
Revert "start adding multiple RHS"
This reverts commit 95590a2.
1 parent 4d4319f commit f2bd61d

File tree

8 files changed

+1042
-1102
lines changed

8 files changed

+1042
-1102
lines changed

TODO

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- remove remove prefs workspace stuff?
2+
3+
things like max heap size should be settable ... maybe pres are useful?
14

25
- add multiple definitions, finish function argument destructuring
36

@@ -29,46 +32,6 @@
2932
- error if defs don't all have the same number of args
3033
- error if a def with no destructuring isn't the last def
3134

32-
test code:
33-
34-
fact 1 = 1;
35-
fact n = n * fact (n - 1);
36-
main = fact 3;
37-
38-
parses to:
39-
40-
fact $$arg0 = 1
41-
{
42-
$$patt0 = 1;
43-
}
44-
45-
$$fact_rhs0 n = n * fact (n - 1);
46-
47-
main = fact 3;
48-
49-
next:
50-
51-
- secret_build() needs to loop over next_rhs as well
52-
53-
- compile_heap() need to work for multiple RHS
54-
55-
- check set of RHSes follow rules above
56-
57-
- final one needs to have no patterns, or we synthesise a default rhs
58-
which flags a "pattern match failed" error
59-
60-
- generate pattern match test def
61-
62-
see compile_pattern_condition(), compile_pattern_error()
63-
64-
- chain RHSes together with pattern match tests
65-
66-
where do we make the code for "does object match pattern?"
67-
68-
- remove remove prefs workspace stuff?
69-
70-
things like max heap size should be settable ... maybe pres are useful?
71-
7235
- try < > in the image titlebar
7336

7437
seems to get stuck on eg. mp3 files

src/compile.c

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,29 @@
2828
*/
2929

3030
/*
31-
*/
3231
#define DEBUG_RESOLVE
32+
*/
3333

3434
/* regular (and very slow) sanity checks on symbols ... needs DEBUG in
3535
* symbol.c as well
36-
*/
3736
#define DEBUG_SANITY
37+
*/
3838

3939
/* count how many nodes we find with common sub-expression removal.
40-
*/
4140
#define DEBUG_COMMON
41+
*/
4242

4343
/* show what everything compiled to
44-
*/
4544
#define DEBUG_RESULT
45+
*/
4646

4747
/* trace list comp compile
48-
*/
4948
#define DEBUG_LCOMP
49+
*/
5050

5151
/* trace pattern LHS generation
52-
*/
5352
#define DEBUG_PATTERN
53+
*/
5454

5555
/*
5656
#define DEBUG
@@ -1468,29 +1468,6 @@ compile_remove_subexpr(Compile *compile, PElement *root)
14681468
return TRUE;
14691469
}
14701470

1471-
/* This is a def with multiple RHS. Check that:
1472-
*
1473-
* - all defs hjave the same number of args
1474-
* - no more then def RHS has no pattern matching args
1475-
* - if there is a no-pattern def, it must be the last one
1476-
*/
1477-
static gboolean
1478-
compile_check_rhs(Compile *compile)
1479-
{
1480-
g_assert(!compile->sym->generated);
1481-
g_assert(compile->sym->next_rhs);
1482-
1483-
int nargs = -1;
1484-
for (Symbol *p = compile->sym; p; p = p->next_rhs)
1485-
if (nargs == -1)
1486-
nargs = p->nargs;
1487-
else if (nargs != p->nargs) {
1488-
error ...
1489-
}
1490-
1491-
return TRUE;
1492-
}
1493-
14941471
/* Top-level compiler driver.
14951472
*/
14961473

@@ -1506,14 +1483,6 @@ compile_heap(Compile *compile)
15061483
if (compile->sym->placeholder)
15071484
return NULL;
15081485

1509-
/* There could be multiple RHS ... if this is the first RHS, check the
1510-
* rules around parameters and patterns.
1511-
*/
1512-
if (!compile->sym->generated &&
1513-
compile->sym->next_rhs &&
1514-
!compile_check_rhs(compile))
1515-
return compile->sym;
1516-
15171486
PEPOINTE(&base, &compile->base);
15181487

15191488
/* Is there an existing function base? GC it away.
@@ -1601,8 +1570,7 @@ compile_symbol_sub(Symbol *sym)
16011570
{
16021571
Compile *compile;
16031572

1604-
if (sym->expr &&
1605-
(compile = sym->expr->compile))
1573+
if (sym->expr && (compile = sym->expr->compile))
16061574
if (compile_object_sub(compile))
16071575
return sym;
16081576

@@ -1684,12 +1652,14 @@ compile_check_i18n(Compile *compile, ParseNode *pn)
16841652
static GHashTable *msgid = NULL;
16851653

16861654
if (!msgid)
1687-
msgid = g_hash_table_new(g_str_hash, g_str_equal);
1655+
msgid = g_hash_table_new(
1656+
g_str_hash, g_str_equal);
16881657

16891658
if (!g_hash_table_lookup(msgid, text)) {
16901659
char buf[MAX_STRSIZE];
16911660

1692-
g_hash_table_insert(msgid, (void *) text, NULL);
1661+
g_hash_table_insert(msgid,
1662+
(void *) text, NULL);
16931663
my_strecpy(buf, text, TRUE);
16941664
printf("msgid \"%s\"\n", buf);
16951665
printf("msgstr \"\"\n\n");
@@ -2488,9 +2458,11 @@ compile_pattern_access(Compile *compile,
24882458
* item in the trail in the list of elements.
24892459
*/
24902460
c.type = PARSE_CONST_NUM;
2491-
c.val.num = g_slist_index(trail[i]->elist, trail[i + 1]);
2461+
c.val.num = g_slist_index(trail[i]->elist,
2462+
trail[i + 1]);
24922463
right = tree_const_new(compile, c);
2493-
node = tree_binop_new(compile, BI_SELECT, node, right);
2464+
node = tree_binop_new(compile,
2465+
BI_SELECT, node, right);
24942466
break;
24952467

24962468
default:
@@ -2529,27 +2501,34 @@ compile_pattern_condition(Compile *compile,
25292501
/* Generate is_complex x.
25302502
*/
25312503
left = tree_leaf_new(compile, "is_complex");
2532-
right = compile_pattern_access(compile, leaf, trail, i);
2504+
right = compile_pattern_access(compile,
2505+
leaf, trail, i);
25332506
node2 = tree_appl_new(compile, left, right);
25342507

2535-
node = tree_binop_new(compile, BI_LAND, node2, node);
2508+
node = tree_binop_new(compile,
2509+
BI_LAND, node2, node);
25362510
break;
25372511

25382512
case BI_CONS:
25392513
/* Generate is_list x && x != [].
25402514
*/
25412515
left = tree_leaf_new(compile, "is_list");
2542-
right = compile_pattern_access(compile, leaf, trail, i);
2516+
right = compile_pattern_access(compile,
2517+
leaf, trail, i);
25432518
node2 = tree_appl_new(compile, left, right);
25442519

2545-
node = tree_binop_new(compile, BI_LAND, node2, node);
2520+
node = tree_binop_new(compile,
2521+
BI_LAND, node2, node);
25462522

2547-
left = compile_pattern_access(compile, leaf, trail, i);
2523+
left = compile_pattern_access(compile,
2524+
leaf, trail, i);
25482525
n.type = PARSE_CONST_ELIST;
25492526
right = tree_const_new(compile, n);
2550-
node2 = tree_binop_new(compile, BI_NOTEQ, left, right);
2527+
node2 = tree_binop_new(compile,
2528+
BI_NOTEQ, left, right);
25512529

2552-
node = tree_binop_new(compile, BI_LAND, node, node2);
2530+
node = tree_binop_new(compile,
2531+
BI_LAND, node, node2);
25532532
break;
25542533

25552534
default:
@@ -2561,7 +2540,8 @@ compile_pattern_condition(Compile *compile,
25612540
/* Generate is_list x && is_list_len n x.
25622541
*/
25632542
left = tree_leaf_new(compile, "is_list");
2564-
right = compile_pattern_access(compile, leaf, trail, i);
2543+
right = compile_pattern_access(compile,
2544+
leaf, trail, i);
25652545
node2 = tree_appl_new(compile, left, right);
25662546

25672547
node = tree_binop_new(compile, BI_LAND, node2, node);
@@ -2571,7 +2551,8 @@ compile_pattern_condition(Compile *compile,
25712551
n.val.num = g_slist_length(trail[i]->elist);
25722552
right = tree_const_new(compile, n);
25732553
left = tree_appl_new(compile, left, right);
2574-
right = compile_pattern_access(compile, leaf, trail, i);
2554+
right = compile_pattern_access(compile,
2555+
leaf, trail, i);
25752556
node2 = tree_appl_new(compile, left, right);
25762557

25772558
node = tree_binop_new(compile, BI_LAND, node, node2);
@@ -2580,7 +2561,8 @@ compile_pattern_condition(Compile *compile,
25802561
case NODE_CONST:
25812562
/* Generate x == n.
25822563
*/
2583-
left = compile_pattern_access(compile, leaf, trail, i);
2564+
left = compile_pattern_access(compile,
2565+
leaf, trail, i);
25842566
right = tree_const_new(compile, trail[i]->con);
25852567
node2 = tree_binop_new(compile, BI_EQ, left, right);
25862568

@@ -2595,7 +2577,8 @@ compile_pattern_condition(Compile *compile,
25952577
n.val.str = g_strdup(trail[i]->tag);
25962578
right = tree_const_new(compile, n);
25972579
node2 = tree_appl_new(compile, left, right);
2598-
right = compile_pattern_access(compile, leaf, trail, i);
2580+
right = compile_pattern_access(compile,
2581+
leaf, trail, i);
25992582
node2 = tree_appl_new(compile, node2, right);
26002583

26012584
node = tree_binop_new(compile, BI_LAND, node2, node);

src/dump.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
*/
3535

3636
/*
37-
*/
3837
#define DEBUG
38+
*/
3939

4040
/* Dump a binary operator.
4141
*/
@@ -477,15 +477,6 @@ dump_symbol(Symbol *sym)
477477
IOBJECT(sym)->name, sym->ndirtychildren);
478478
printf("%s->leaf = %s\n",
479479
IOBJECT(sym)->name, bool_to_char(sym->leaf));
480-
printf("%s->generated = %s\n",
481-
IOBJECT(sym)->name, bool_to_char(sym->generated));
482-
483-
if (!sym->generated && sym->next_rhs) {
484-
printf("%s->next_rhs = ", IOBJECT(sym)->name);
485-
for (Symbol *p = sym->next_rhs; p; p = sym->next_rhs)
486-
printf("%s ", IOBJECT(sym)->name);
487-
printf("\n");
488-
}
489480

490481
printf("%s->tool = kit ", IOBJECT(sym)->name);
491482
if (sym->tool)

src/main-batch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ main(int argc, char **argv)
469469
main_error_exit("%s", _("no \"main\" found"));
470470
}
471471

472-
//main_shutdown();
472+
main_shutdown();
473473

474474
return 0;
475475
}

0 commit comments

Comments
 (0)