shrub/g/z.c

110 lines
2.2 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
**
** This file is in the public domain.
*/
#include "all.h"
2014-09-06 00:13:24 +04:00
/* u3_cz_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
u3_cz_find(u3_mote 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-09-06 00:13:24 +04:00
val = u3_ch_get(u3R->cax.har_u, key);
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_weak
u3_cz_find_2(u3_mote 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-09-06 00:13:24 +04:00
val = u3_ch_get(u3R->cax.har_u, key);
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_weak
u3_cz_find_3(u3_mote 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-09-06 00:13:24 +04:00
val = u3_ch_get(u3R->cax.har_u, key);
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_weak
u3_cz_find_4(u3_mote 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-09-06 00:13:24 +04:00
val = u3_ch_get(u3R->cax.har_u, key);
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
/* u3_cz_save*(): save in memo cache.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cz_save(u3_mote 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-09-06 00:13:24 +04:00
u3_ch_put(u3R->cax.har_u, key, u3k(val));
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cz_save_2(u3_mote 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-09-06 00:13:24 +04:00
u3_ch_put(u3R->cax.har_u, key, u3k(val));
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cz_save_3(u3_mote 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-09-06 00:13:24 +04:00
u3_ch_put(u3R->cax.har_u, key, u3k(val));
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cz_save_4(u3_mote fun,
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-09-06 00:13:24 +04:00
u3_ch_put(u3R->cax.har_u, key, u3k(val));
u3z(key);
2014-09-05 23:55:16 +04:00
return val;
}
2014-09-06 00:13:24 +04:00
/* u3_cz_uniq(): uniquify with memo cache.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cz_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));
u3_noun val = u3_ch_get(u3R->cax.har_u, key);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_none != val ) {
u3z(key); u3z(som); return val;
2014-09-05 23:55:16 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_ch_put(u3R->cax.har_u, key, u3k(som));
2014-09-05 23:55:16 +04:00
return som;
}
}