8. Channels in Scheme and Janet
8.1. Worgle Constructs
<<gfx_scheme_functions>>=
<<chan_scheme_functions>>
<<gfx_scheme_entries>>=
<<chan_scheme_entries>>
8.2. Channel Scheme Functions
The two functions needed here are monolith:chan-get
and monolith:chan-set
.
<<chan_scheme_entries>>=
{"monolith:chan-get", pp_chan_get, 1, 1, {INT,___,___}},
<<chan_scheme_functions>>=
static cell pp_chan_get(cell x)
{
GFFLT val;
int pos;
monolith_d *m;
unsigned int ival;
char name[] = "monolith:chan-get";
pos = integer_value(name, car(x));
m = monolith_data_get();
val = monolith_chan_get(m, pos);
/* get non-decimal part */
ival = floor(val);
/* get 4 decimal places */
val = floor(1e4 * (ival + (val - ival)));
return s9_make_real(1, -4, s9_make_integer(val));
}
<<chan_scheme_entries>>=
{"monolith:chan-set", pp_chan_set, 2, 2, {INT,REA,___}},
<<chan_scheme_functions>>=
static cell pp_chan_set(cell x)
{
GFFLT val;
int pos;
monolith_d *m;
char name[] = "monolith:chan-set";
int mantissa;
int exponent;
cell real;
pos = integer_value(name, car(x));
x = cdr(x);
m = monolith_data_get();
real = car(x);
mantissa = s9_bignum_to_int(s9_real_mantissa(real));
exponent = s9_real_exponent(real);
val = mantissa * pow(10, exponent);
monolith_chan_set(m, pos, val);
return UNSPECIFIC;
}
8.3. Channel Janet Functions
Identical in functionality to scheme functions.
monolith/chan-get
and monolith/chan-set
.
<<gfx_janet>>=
static Janet j_chan_get(int32_t argc, Janet *argv)
{
GFFLT val;
int pos;
monolith_d *m;
janet_fixarity(argc, 1);
pos = janet_unwrap_integer(argv[0]);
m = monolith_data_get();
val = monolith_chan_get(m, pos);
return janet_wrap_number(val);
}
<<gfx_janet_entries>>=
{
"monolith/chan-get",
j_chan_get,
"get a channel\n"
},
<<gfx_janet>>=
static Janet j_chan_set(int32_t argc, Janet *argv)
{
GFFLT val;
int pos;
monolith_d *m;
janet_fixarity(argc, 2);
pos = janet_unwrap_integer(argv[0]);
val = janet_unwrap_number(argv[1]);
m = monolith_data_get();
monolith_chan_set(m, pos, val);
return janet_wrap_nil();
}
<<gfx_janet_entries>>=
{
"monolith/chan-set",
j_chan_set,
"setting a channel value\n"
},
prev | home | next