Skip to content

Commit db3aa3c

Browse files
committed
start adding lazy print of main
1 parent c522f90 commit db3aa3c

File tree

4 files changed

+34
-66
lines changed

4 files changed

+34
-66
lines changed

src/heap.c

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,28 +2588,23 @@ graph_pointer(PElement *root)
25882588

25892589
/* Fwd ref.
25902590
*/
2591-
static gboolean shell_pelement(PElement *base);
2591+
static gboolean shell_pelement(Reduce *rc, PElement *base);
25922592

2593-
/* Print a graph shell-style. TRUE for node is a concrete, printable or
2594-
* saveable thing.
2593+
/* Print a graph shell-style. FALSE for compute error.
25952594
*/
25962595
static gboolean
2597-
shell_node(HeapNode *hn)
2596+
shell_node(Reduce *rc, HeapNode *hn)
25982597
{
25992598
PElement p1, p2;
26002599

26012600
/* Have we printed this node before?
26022601
*/
26032602
if (hn->flgs & FLAG_PRINT) {
2604-
printf("<*circular*>");
2603+
printf("<circular>");
26052604
return TRUE;
26062605
}
26072606
hn->flgs |= FLAG_PRINT;
26082607

2609-
gboolean concrete;
2610-
2611-
concrete = FALSE;
2612-
26132608
switch (hn->type) {
26142609
case TAG_CLASS:
26152610
case TAG_APPL:
@@ -2618,70 +2613,52 @@ shell_node(HeapNode *hn)
26182613
case TAG_GEN:
26192614
break;
26202615

2621-
case TAG_CONS: {
2622-
gboolean string_mode;
2623-
2624-
PEPOINTLEFT(hn, &p1);
2625-
string_mode = PEISCHAR(&p1);
2626-
2616+
case TAG_CONS:
26272617
for (;;) {
2628-
if (string_mode) {
2629-
printf("%c", PEGETCHAR(&p1));
2630-
concrete = TRUE;
2631-
}
2632-
else
2633-
concrete = shell_pelement(&p1);
2618+
PEPOINTLEFT(hn, &p1);
2619+
if (!reduce_pelement(rc, reduce_spine, &p1) ||
2620+
shell_pelement(rc, &p1))
2621+
return FALSE;
26342622

26352623
PEPOINTRIGHT(hn, &p2);
2624+
if (!reduce_pelement(rc, reduce_spine, &p2))
2625+
return FALSE;
26362626
if (PEISMANAGEDSTRING(&p2)) {
26372627
printf("%s\n", PEGETMANAGEDSTRING(&p2)->string);
2638-
concrete = TRUE;
26392628
break;
26402629
}
26412630
else if (PEISELIST(&p2))
26422631
break;
2643-
2644-
if (!string_mode)
2645-
printf("\n");
2646-
hn = PEGETVAL(&p2);
2647-
PEPOINTLEFT(hn, &p1);
2648-
if (string_mode && !PEISCHAR(&p1))
2649-
string_mode = FALSE;
2632+
else if (PEISNODE(&p2))
2633+
hn = PEGETVAL(&p2);
2634+
else
2635+
break;
26502636
}
2651-
}
26522637
break;
26532638

26542639
case TAG_DOUBLE:
26552640
printf("%g", hn->body.num);
2656-
concrete = TRUE;
26572641
break;
26582642

26592643
case TAG_COMPLEX:
26602644
printf("%g %g",
26612645
GETLEFT(hn)->body.num, GETRIGHT(hn)->body.num);
2662-
concrete = TRUE;
26632646
break;
26642647

26652648
case TAG_FREE:
26662649
default:
26672650
g_assert(FALSE);
26682651
}
26692652

2670-
return concrete;
2653+
return TRUE;
26712654
}
26722655

2673-
/* Print a pelement shell-style.
2656+
/* Lazy print of a pelement, shell-style. Return FALSE for runtime error.
26742657
*/
26752658
static gboolean
2676-
shell_pelement(PElement *base)
2659+
shell_pelement(Reduce *rc, PElement *base)
26772660
{
2678-
gboolean concrete;
2679-
2680-
concrete = FALSE;
2681-
26822661
switch (PEGETTYPE(base)) {
2683-
/* Only allow concrete base types.
2684-
*/
26852662
case ELEMENT_SYMREF:
26862663
case ELEMENT_COMPILEREF:
26872664
case ELEMENT_CONSTRUCTOR:
@@ -2691,53 +2668,49 @@ shell_pelement(PElement *base)
26912668
case ELEMENT_TAG:
26922669
case ELEMENT_SYMBOL:
26932670
case ELEMENT_NOVAL:
2671+
printf("<function>");
26942672
break;
26952673

26962674
case ELEMENT_NODE:
2697-
concrete = shell_node(PEGETVAL(base));
2675+
shell_node(rc, PEGETVAL(base));
26982676
break;
26992677

27002678
case ELEMENT_CHAR:
27012679
printf("%c", (int) PEGETCHAR(base));
2702-
concrete = TRUE;
27032680
break;
27042681

27052682
case ELEMENT_BOOL:
27062683
printf("%s", bool_to_char(PEGETBOOL(base)));
2707-
concrete = TRUE;
27082684
break;
27092685

27102686
case ELEMENT_ELIST:
2711-
printf("[ ]");
2712-
concrete = TRUE;
27132687
break;
27142688

27152689
case ELEMENT_MANAGED:
27162690
if (PEISIMAGE(base))
27172691
printf("%s", PEGETIMAGE(base)->filename);
27182692
else if (PEISMANAGEDSTRING(base))
27192693
printf("%s", PEGETMANAGEDSTRING(base)->string);
2720-
concrete = TRUE;
27212694
break;
27222695

27232696
default:
27242697
g_assert(FALSE);
27252698
}
27262699

2727-
return concrete;
2700+
return TRUE;
27282701
}
27292702

27302703
/* Print a pelement shell-style.
27312704
*/
2732-
void
2705+
gboolean
27332706
graph_value(PElement *root)
27342707
{
27352708
Reduce *rc = reduce_context;
27362709

2737-
if (!reduce_pelement(rc, reduce_spine_strict, root))
2738-
error_alert(NULL);
2710+
heap_clear(rc->heap, FLAG_PRINT);
2711+
2712+
if (!reduce_pelement(rc, reduce_spine, root))
2713+
return FALSE;
27392714

2740-
heap_clear(reduce_context->heap, FLAG_PRINT);
2741-
if (shell_pelement(root))
2742-
printf("\n");
2715+
return shell_pelement(rc, root);
27432716
}

src/heap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,6 @@ void graph_pelement(Heap *heap, VipsBuf *buf, PElement *root, gboolean fn);
507507
void graph_element(Heap *heap, VipsBuf *buf, Element *root, gboolean fn);
508508
void graph_pointer(PElement *root);
509509

510-
/* Reduce and print, csh-style output.
510+
/* Reduce and print, shell-style output.
511511
*/
512-
void graph_value(PElement *root);
512+
gboolean graph_value(PElement *root);

src/main-batch.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,7 @@ main_save_item(PElement *item, char *filename)
205205
static void
206206
main_print_main(Symbol *sym)
207207
{
208-
PElement *root;
209-
210-
/* Strict reduction of this object, then print.
211-
*/
212-
root = &sym->expr->root;
213-
if (!symbol_recalculate_check(sym) ||
214-
!reduce_pelement(reduce_context, reduce_spine_strict, root))
215-
main_error_exit(_( "error calculating \"%s\""), symbol_name_scope(sym));
208+
PElement *root = &sym->expr->root;
216209

217210
if (main_option_output) {
218211
char filename[VIPS_PATH_MAX];
@@ -221,8 +214,9 @@ main_print_main(Symbol *sym)
221214
if (!main_save_item(root, filename))
222215
main_error_exit(_( "error saving \"%s\""), symbol_name_scope(sym));
223216
}
224-
225-
graph_value(root);
217+
else
218+
if (!graph_value(root))
219+
main_error_exit(NULL);
226220
}
227221

228222
static void

test/workspaces/x.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main = "......" ++ error "argh";

0 commit comments

Comments
 (0)