Skip to content

Commit 04d49ec

Browse files
committed
more ++ rewrite
1 parent 5219cdd commit 04d49ec

File tree

4 files changed

+80
-81
lines changed

4 files changed

+80
-81
lines changed

TODO

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
- makeing print lazy would probably be hard
3939

40+
- remove trace stuff from reduce
41+
4042
- add multiple definitions, finish function argument destructuring
4143

4244
sym has a field for "next definition", initially NULL

src/action.c

Lines changed: 72 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -808,76 +808,6 @@ action_proc_notequal(Reduce *rc, Compile *compile,
808808
}
809809
}
810810

811-
static void *
812-
action_proc_join_sub(Reduce *rc, PElement *pe,
813-
PElement *a, PElement *b, PElement *out)
814-
{
815-
if (PEISMANAGEDSTRING(a)) {
816-
PElement tail;
817-
818-
// expand the static string into a list
819-
reduce_clone_list(rc, a, pe);
820-
PEPUTPE(&tail, b);
821-
}
822-
else if (PEISELIST(a)) {
823-
}
824-
else if (PEISNODE(a) && PEGETVAL(a)->type == TAG_CONS) {
825-
HeapNode *cons = PEGETVAL(a);
826-
PElement hd;
827-
PEPOINTLEFT(hn, &hd);
828-
PElement tl;
829-
PEPOINTRIGHT(hn, &tl);
830-
831-
PElement t;
832-
if (!heap_list_add(rc->heap, &tl, &t))
833-
reduce_throw(rc);
834-
PEPUTP(&t,
835-
}
836-
else
837-
g_assert(FALSE);
838-
839-
840-
if (!heap_list_cat(rc, a, b, pe))
841-
return a;
842-
843-
PEPUTPE(out, pe);
844-
845-
return NULL;
846-
}
847-
848-
static void
849-
action_proc_join(Reduce *rc, Compile *compile,
850-
int op, const char *name, HeapNode **arg, PElement *out)
851-
{
852-
PElement left, right;
853-
PElement *a = &left;
854-
PElement *b = &right;
855-
856-
PEPOINTRIGHT(arg[1], &left);
857-
PEPOINTRIGHT(arg[0], &right);
858-
859-
if (PEISIMAGE(a) && PEISIMAGE(b)) {
860-
g_autoptr(VipsArrayImage) c =
861-
vips_array_image_newv(2, PEGETIMAGE(a), PEGETIMAGE(b));
862-
863-
vo_callva(rc, out, "bandjoin", c);
864-
}
865-
else if (PEISLIST(a) && PEISLIST(b)) {
866-
if (reduce_safe_pointer(rc,
867-
(reduce_safe_pointer_fn) action_proc_join_sub,
868-
a, b, out, NULL))
869-
action_boperror(rc, compile, error_get_sub(), op, name, a, b);
870-
}
871-
else if (PEISIMAGE(a) && PEISELIST(b)) {
872-
PEPUTPE(out, a);
873-
}
874-
else if (PEISIMAGE(b) && PEISELIST(a)) {
875-
PEPUTPE(out, b);
876-
}
877-
else
878-
action_boperror(rc, compile, NULL, op, name, a, b);
879-
}
880-
881811
static void
882812
action_proc_index(Reduce *rc, Compile *compile,
883813
int op, const char *name, HeapNode **arg, PElement *out)
@@ -932,6 +862,74 @@ action_proc_exp(Reduce *rc, Compile *compile,
932862
action_boperror(rc, compile, NULL, op, name, a, b);
933863
}
934864

865+
static void *
866+
action_proc_join_sub(Reduce *rc, PElement *pe,
867+
PElement *a, PElement *b, PElement *out)
868+
{
869+
if (PEISELIST(a))
870+
PEPUTPE(pe, b);
871+
else if (PEISMANAGEDSTRING(a)) {
872+
PElement new_list = *pe;
873+
874+
// expand the static string into a list
875+
reduce_clone_list(rc, a, &new_list);
876+
// and overwrite the terminating [] with b
877+
PEPUTPE(&new_list, b);
878+
}
879+
else if (PEISNODE(a) && PEGETVAL(a)->type == TAG_CONS) {
880+
/*
881+
HeapNode *cons = PEGETVAL(a);
882+
PElement hd;
883+
PEPOINTLEFT(hn, &hd);
884+
PElement tl;
885+
PEPOINTRIGHT(hn, &tl);
886+
887+
PElement t;
888+
if (!heap_list_add(rc->heap, &tl, &t))
889+
reduce_throw(rc);
890+
891+
PEPUTP(&t,
892+
893+
// we were using this
894+
if (!heap_list_cat(rc, a, b, pe))
895+
return a;
896+
897+
*/
898+
}
899+
else
900+
g_assert(FALSE);
901+
902+
PEPUTPE(out, pe);
903+
904+
return NULL;
905+
}
906+
907+
static void
908+
action_proc_join(Reduce *rc, Compile *compile, int op, const char *name,
909+
PElement *a, PElement *b, PElement *out)
910+
{
911+
if (PEISIMAGE(a) && PEISIMAGE(b)) {
912+
g_autoptr(VipsArrayImage) c =
913+
vips_array_image_newv(2, PEGETIMAGE(a), PEGETIMAGE(b));
914+
915+
vo_callva(rc, out, "bandjoin", c);
916+
}
917+
else if (PEISLIST(a) && PEISLIST(b)) {
918+
if (reduce_safe_pointer(rc,
919+
(reduce_safe_pointer_fn) action_proc_join_sub,
920+
a, b, out, NULL))
921+
action_boperror(rc, compile, error_get_sub(), op, name, a, b);
922+
}
923+
else if (PEISIMAGE(a) && PEISELIST(b)) {
924+
PEPUTPE(out, a);
925+
}
926+
else if (PEISIMAGE(b) && PEISELIST(a)) {
927+
PEPUTPE(out, b);
928+
}
929+
else
930+
action_boperror(rc, compile, NULL, op, name, a, b);
931+
}
932+
935933
/* Left shift.
936934
*/
937935
static void
@@ -1268,10 +1266,6 @@ action_proc_bop_strict(Reduce *rc, Compile *compile,
12681266
action_proc_index(rc, compile, op, name, arg, out);
12691267
break;
12701268

1271-
case BI_JOIN:
1272-
action_proc_join(rc, compile, op, name, arg, out);
1273-
break;
1274-
12751269
case BI_EQ:
12761270
action_proc_equal(rc, compile, op, name, arg, out);
12771271
break;
@@ -1314,6 +1308,10 @@ action_proc_bop_strict(Reduce *rc, Compile *compile,
13141308
action_proc_exp(rc, compile, op, name, a, b, out);
13151309
break;
13161310

1311+
case BI_JOIN:
1312+
action_proc_join(rc, compile, op, name, a, b, out);
1313+
break;
1314+
13171315
case BI_LSHIFT:
13181316
action_proc_lshift(rc, compile, op, name, a, b, out);
13191317
break;

src/path.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
*/
2222

2323
/* just load .defs/.wses from "."
24-
#define DEBUG_LOCAL
2524
*/
25+
#define DEBUG_LOCAL
2626

2727
/* show path searches
2828
#define DEBUG_SEARCH

src/reduce.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
*/
3535

3636
/* trace each reduction
37-
#define DEBUG_TRACE
3837
*/
38+
#define DEBUG_TRACE
3939

4040
/* trace copies of code from compile heap to main heap.
4141
#define DEBUG_COPY
@@ -46,12 +46,12 @@
4646
*/
4747

4848
/* Turn on WHNF tests.
49-
#define WHNF_DEBUG
5049
*/
50+
#define WHNF_DEBUG
5151

5252
/* regular tests that we stay in weak head normal form
53-
#define WHNF_DEBUG
5453
*/
54+
#define WHNF_DEBUG
5555

5656
/* State of the reduction engine.
5757
*/
@@ -752,7 +752,7 @@ reduce_is_realvec(Reduce *rc, PElement *base)
752752
return TRUE;
753753
}
754754

755-
/* Test for 1st sz elements are reals. Init sz < 0 for unlimited test.
755+
/* Test for 1st sz elements are images. Init sz < 0 for unlimited test.
756756
*/
757757
static void *
758758
reduce_test_image(Reduce *rc, PElement *base, int *sz)
@@ -1814,8 +1814,7 @@ reduce_spine(Reduce *rc, PElement *out)
18141814

18151815
/* Write to node above.
18161816
*/
1817-
PEPUTP(&np,
1818-
GETRT(arg[0]), GETRIGHT(arg[0]));
1817+
PEPUTP(&np, GETRT(arg[0]), GETRIGHT(arg[0]));
18191818

18201819
/* Loop again with new np.
18211820
*/

0 commit comments

Comments
 (0)