shrub/noun/zave.c

109 lines
2.1 KiB
C
Raw Normal View History

2014-09-11 04:01:32 +04:00
/* g/z.c
2014-09-05 23:55:16 +04:00
**
*/
#include "all.h"
2014-11-06 03:20:01 +03:00
/* u3z_find(): find in memo cache. Arguments retained.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_weak
2014-11-06 06:10:22 +03:00
u3z_find(c3_m fun, u3_noun one)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun key = u3nc(fun, u3k(one));
u3_noun val;
2014-09-05 23:55:16 +04:00
2014-11-06 03:20:01 +03:00
val = u3h_get(u3R->cax.har_p, key);
2014-09-06 00:13:24 +04:00
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_weak
2014-11-06 06:10:22 +03:00
u3z_find_2(c3_m fun, u3_noun one, u3_noun two)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun key = u3nt(fun, u3k(one), u3k(two));
u3_noun val;
2014-09-05 23:55:16 +04:00
2014-11-06 03:20:01 +03:00
val = u3h_get(u3R->cax.har_p, key);
2014-09-06 00:13:24 +04:00
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_weak
2014-11-06 06:10:22 +03:00
u3z_find_3(c3_m fun, u3_noun one, u3_noun two, u3_noun tri)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun key = u3nq(fun, u3k(one), u3k(two), u3k(tri));
u3_noun val;
2014-09-05 23:55:16 +04:00
2014-11-06 03:20:01 +03:00
val = u3h_get(u3R->cax.har_p, key);
2014-09-06 00:13:24 +04:00
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_weak
2014-11-06 06:10:22 +03:00
u3z_find_4(c3_m fun, u3_noun one, u3_noun two, u3_noun tri, u3_noun qua)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun key = u3nc(fun, u3nq(u3k(one), u3k(two), u3k(tri), u3k(qua)));
u3_noun val;
2014-09-05 23:55:16 +04:00
2014-11-06 03:20:01 +03:00
val = u3h_get(u3R->cax.har_p, key);
2014-09-06 00:13:24 +04:00
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-11-06 03:20:01 +03:00
/* u3z_save*(): save in memo cache.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 06:10:22 +03:00
u3z_save(c3_m fun, u3_noun one, u3_noun val)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun key = u3nc(fun, u3k(one));
2014-09-05 23:55:16 +04:00
2014-11-06 03:20:01 +03:00
u3h_put(u3R->cax.har_p, key, u3k(val));
2014-09-06 00:13:24 +04:00
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 06:10:22 +03:00
u3z_save_2(c3_m fun, u3_noun one, u3_noun two, u3_noun val)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun key = u3nt(fun, u3k(one), u3k(two));
2014-09-05 23:55:16 +04:00
2014-11-06 03:20:01 +03:00
u3h_put(u3R->cax.har_p, key, u3k(val));
2014-09-06 00:13:24 +04:00
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 06:10:22 +03:00
u3z_save_3(c3_m fun, u3_noun one, u3_noun two, u3_noun tri, u3_noun val)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun key = u3nq(fun, u3k(one), u3k(two), u3k(tri));
2014-09-05 23:55:16 +04:00
2014-11-06 03:20:01 +03:00
u3h_put(u3R->cax.har_p, key, u3k(val));
2014-09-06 00:13:24 +04:00
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 06:10:22 +03:00
u3z_save_4(c3_m fun,
2014-09-06 00:13:24 +04:00
u3_noun one,
u3_noun two,
u3_noun tri,
u3_noun qua,
u3_noun val)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun key = u3nc(fun, u3nq(u3k(one), u3k(two), u3k(tri), u3k(qua)));
2014-09-05 23:55:16 +04:00
2014-11-06 03:20:01 +03:00
u3h_put(u3R->cax.har_p, key, u3k(val));
2014-09-06 00:13:24 +04:00
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-11-06 03:20:01 +03:00
/* u3z_uniq(): uniquify with memo cache.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 03:20:01 +03:00
u3z_uniq(u3_noun som)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun key = u3nc(c3__uniq, u3k(som));
2014-11-06 03:20:01 +03:00
u3_noun val = u3h_get(u3R->cax.har_p, key);
2014-09-05 23:55:16 +04:00
2014-11-06 02:36:30 +03:00
if ( u3_none != val ) {
2014-09-06 00:13:24 +04:00
u3z(key); u3z(som); return val;
2014-09-05 23:55:16 +04:00
}
else {
2014-11-06 03:20:01 +03:00
u3h_put(u3R->cax.har_p, key, u3k(som));
2014-09-05 23:55:16 +04:00
return som;
}
}