224#define DT(dt) (ut->types[ dt ])
225#define SERIES_DT(dt) ((const USeriesType*) (ut->types[ dt ]))
226#define bitIsSet(mem,n) (mem[(n)>>3] & 1<<((n)&7))
228#define block_destroy ur_arrFree
229#define string_destroy ur_arrFree
230#define context_markBuf block_markBuf
250 ord->secondLarger = 0;
256 ord->secondLarger = 1;
288static const char* operatorNames[] =
290 "add",
"sub",
"mul",
"div",
"mod",
"and",
"or",
"xor"
298 operatorNames[ op & 7 ],
328void unset_destroy(
UBuffer* buf )
333void unset_toShared(
UCell* cell )
346#define unset_recycle 0
347#define unset_markBuf 0
353 unset_make, unset_make, unset_copy,
354 unset_compare, unset_operate, unset_select,
355 unset_toString, unset_toString,
356 unset_recycle, unset_mark, unset_destroy,
357 unset_markBuf, unset_toShared, unset_bind
427 mask = 1 << (type - 32);
432 mask = 1 << (type - 64);
452 type = ur_atom(cell);
471 case UR_COMPARE_SAME:
481 case UR_COMPARE_EQUAL:
482 case UR_COMPARE_EQUAL_CASE:
490 case UR_COMPARE_ORDER:
491 case UR_COMPARE_ORDER_CASE:
522 for( mask = 1; dtBits; ++dt, mask <<= 1 )
547 datatype_make, datatype_make, unset_copy,
548 datatype_compare, unset_operate, unset_select,
549 datatype_toString, datatype_toString,
550 unset_recycle, unset_mark, unset_destroy,
551 unset_markBuf, unset_toShared, unset_bind
573 case UR_COMPARE_SAME:
574 case UR_COMPARE_EQUAL:
575 case UR_COMPARE_EQUAL_CASE:
594 none_make, none_make, unset_copy,
595 none_compare, unset_operate, unset_select,
596 none_toString, none_toString,
597 unset_recycle, unset_mark, unset_destroy,
598 unset_markBuf, unset_toShared, unset_bind
616 ur_logic(res) = ur_logic(from);
620 ur_logic(res) = ur_int(from) ? 1 : 0;
623 ur_logic(res) = ur_double(from) ? 1 : 0;
638 case UR_COMPARE_SAME:
639 return ur_logic(a) == ur_logic(b);
641 case UR_COMPARE_EQUAL:
642 case UR_COMPARE_EQUAL_CASE:
644 return ur_logic(a) == ur_logic(b);
662 int la = ur_is(a, UT_LOGIC) ? ur_logic(a) : 0;
663 int lb = ur_is(b, UT_LOGIC) ? ur_logic(b) : 0;
669 ur_logic(res) = la & lb;
672 ur_logic(res) = la | lb;
675 ur_logic(res) = la ^ lb;
678 return unset_operate( ut, a, b, res, op );
687 logic_make, logic_make, unset_copy,
688 logic_compare, logic_operate, unset_select,
689 logic_toString, logic_toString,
690 unset_recycle, unset_mark, unset_destroy,
691 unset_markBuf, unset_toShared, unset_bind,
701 if( ur_is(from, UT_INT) || ur_is(from, UT_CHAR) )
704 ur_int(res) = ur_int(from);
707 else if( ur_is(from, UT_STRING) )
711 SERIES_DT( UT_STRING )->pick( si.
buf, si.
it, res );
715 "make char! expected char!/int!/string!" );
719extern int copyUcs2ToUtf8( uint8_t* dest,
const uint16_t* src,
int srcLen );
720extern char _hexDigits[];
726 uint16_t n = ur_int(cell);
732 if( str->
form == UR_ENC_UCS2 )
748 if( str->
form == UR_ENC_UTF8 )
750 cp += copyUcs2ToUtf8( cp, &n, 1 );
758 *cp++ = _hexDigits[ ((n >> 12) & 0xf) ];
759 *cp++ = _hexDigits[ ((n >> 8) & 0xf) ];
761 *cp++ = _hexDigits[ ((n >> 4) & 0xf) ];
762 *cp++ = _hexDigits[ (n & 0xf) ];
782 n += ((n < 11) ?
'0' : (
'A' - 10));
790 if( n ==
'^' || n ==
'\'' )
816 char_make, char_make, unset_copy,
817 int_compare, int_operate, unset_select,
818 char_toString, char_toText,
819 unset_recycle, unset_mark, unset_destroy,
820 unset_markBuf, unset_toShared, unset_bind
828extern int64_t str_toInt64(
const uint8_t*,
const uint8_t*,
const uint8_t** );
829extern int64_t str_hexToInt64(
const uint8_t*,
const uint8_t*,
const uint8_t**);
831#define MAKE_NO_UCS2(tn) \
832 ur_error(ut,UR_ERR_INTERNAL,"make %s does not handle UCS2 strings",tn)
843 ur_int(res) = ur_logic(from);
847 ur_int(res) = ur_int(from);
852 ur_int(res) = ur_double(from);
859 if( ur_strIsUcs2(si.
buf) && ur_is(from, UT_STRING) )
861 return MAKE_NO_UCS2(
"int!" );
865 const uint8_t* cp = si.
buf->
ptr.
b + si.
it;
867 if( (si.
end - si.
it) > 2 && (cp[0] ==
'0') && (cp[1] ==
'x') )
869 ur_int(res) = str_hexToInt64( cp + 2, end, 0 );
873 ur_int(res) = str_toInt64( cp, end, 0 );
879 "make int! expected number or none!/logic!/char!/string!" );
885#define MASK_CHAR_INT ((1 << UT_CHAR) | (1 << UT_INT))
886#define ur_isIntType(T) ((1 << T) & MASK_CHAR_INT)
892 if( test == UR_COMPARE_SAME )
893 return ur_int(a) == ur_int(b);
899 case UR_COMPARE_EQUAL:
900 case UR_COMPARE_EQUAL_CASE:
901 return ur_int(a) == ur_int(b);
903 case UR_COMPARE_ORDER:
904 case UR_COMPARE_ORDER_CASE:
905 if( ur_int(a) > ur_int(b) )
907 if( ur_int(a) < ur_int(b) )
925 ur_int(res) = ur_int(a) + ur_int(b);
928 ur_int(res) = ur_int(a) - ur_int(b);
931 ur_int(res) = ur_int(a) * ur_int(b);
936 ur_int(res) = ur_int(a) / ur_int(b);
941 ur_int(res) = ur_int(a) % ur_int(b);
944 ur_int(res) = ur_int(a) & ur_int(b);
947 ur_int(res) = ur_int(a) | ur_int(b);
950 ur_int(res) = ur_int(a) ^ ur_int(b);
953 return unset_operate( ut, a, b, res, op );
957 else if( ur_is(a, UT_LOGIC) || ur_is(b, UT_LOGIC) )
959 int va = ur_is(a, UT_LOGIC) ? ur_logic(a) : ur_int(a);
960 int vb = ur_is(b, UT_LOGIC) ? ur_logic(b) : ur_int(b);
966 ur_int(res) = va & vb;
969 ur_int(res) = va | vb;
972 ur_int(res) = va ^ vb;
975 return unset_operate( ut, a, b, res, op );
980 "int! operator exepected logic!/char!/int!" );
994 int64_t n = ur_int(cell);
1006 int_make, int_make, unset_copy,
1007 int_compare, int_operate, unset_select,
1008 int_toString, int_toString,
1009 unset_recycle, unset_mark, unset_destroy,
1010 unset_markBuf, unset_toShared, unset_bind
1018extern double str_toDouble(
const uint8_t*,
const uint8_t*,
const uint8_t** );
1026 ur_double(res) = 0.0;
1029 ur_double(res) = (double) ur_logic(from);
1033 ur_double(res) = (double) ur_int(from);
1038 ur_double(res) = ur_double(from);
1044 if( ur_strIsUcs2(si.
buf) )
1045 return MAKE_NO_UCS2(
"double!" );
1047 ur_double(res) = str_toDouble( si.
buf->
ptr.
b + si.
it,
1053 "make double! expected number or none!/logic!/char!/string!" );
1059#define MASK_DECIMAL ((1 << UT_DOUBLE) | (1 << UT_TIME) | (1 << UT_DATE))
1060#define ur_isDecimalType(T) ((1 << T) & MASK_DECIMAL)
1062#define FLOAT_EPSILON (0.00000005960464477539062 * 2.0)
1065static int float_equal(
double a,
double b )
1067 return a >= (b - FLOAT_EPSILON) && a <= (b + FLOAT_EPSILON);
1077 case UR_COMPARE_SAME:
1078 return ur_double(a) == ur_double(b);
1080 case UR_COMPARE_EQUAL:
1081 case UR_COMPARE_EQUAL_CASE:
1082 if( ur_isDecimalType(
ur_type(a) ) )
1084 if( ur_isDecimalType(
ur_type(b) ) )
1085 return float_equal( ur_double(a), ur_double(b) );
1086 else if( ur_isIntType(
ur_type(b) ) )
1087 return float_equal( ur_double(a), ur_int(b) );
1091 if( ur_isIntType(
ur_type(a) ) )
1092 return float_equal( (
double) ur_int(a), ur_double(b) );
1096 case UR_COMPARE_ORDER:
1097 case UR_COMPARE_ORDER_CASE:
1098 if( ur_isDecimalType(
ur_type(a) ) )
1100 if( ur_isDecimalType(
ur_type(b) ) )
1102 if( ur_double(a) > ur_double(b) )
1104 if( ur_double(a) < ur_double(b) )
1107 else if( ur_isIntType(
ur_type(b) ) )
1109 if( ur_double(a) > ur_int(b) )
1111 if( ur_double(a) < ur_int(b) )
1117 if( ur_isIntType(
ur_type(a) ) )
1119 if( ((
double) ur_int(a)) > ur_double(b) )
1121 if( ((
double) ur_int(a)) < ur_double(b) )
1139 if( ur_isDecimalType( t ) )
1141 else if( ur_isIntType( t ) )
1146 if( ur_isDecimalType(
ur_type(b) ) )
1152 else if( ur_isIntType(
ur_type(b) ) )
1161 ur_double(res) = da + db;
1164 ur_double(res) = da - db;
1167 ur_double(res) = da * db;
1172 ur_double(res) = da / db;
1177 ur_double(res) = fmod(da, db);
1182 ur_double(res) = 0.0;
1185 return unset_operate( ut, a, b, res, op );
1192 "double! operator exepected char!/int!/double!/time!/date!" );
1211 decimal_make, decimal_make, unset_copy,
1212 decimal_compare, decimal_operate, unset_select,
1213 decimal_toString, decimal_toString,
1214 unset_recycle, unset_mark, unset_destroy,
1215 unset_markBuf, unset_toShared, unset_bind
1223double str_toTime(
const uint8_t*,
const uint8_t*,
const uint8_t** );
1231 ur_double(res) = (double) ur_int(from);
1237 ur_double(res) = ur_double(from);
1243 if( ur_strIsUcs2(si.
buf) )
1245 return MAKE_NO_UCS2(
"time!" );
1249 const uint8_t* cp = si.
buf->
ptr.
b;
1251 ur_double(res) = str_toTime( cp + si.
it, cp + si.
end, 0 );
1257 "make time! expected int!/double!/time!/date!/string!" );
1269 case UR_COMPARE_SAME:
1270 return ur_double(a) == ur_double(b);
1272 case UR_COMPARE_EQUAL:
1273 case UR_COMPARE_EQUAL_CASE:
1275 return float_equal( ur_double(a), ur_double(b) );
1278 case UR_COMPARE_ORDER:
1279 case UR_COMPARE_ORDER_CASE:
1282 if( ur_double(a) > ur_double(b) )
1284 if( ur_double(a) < ur_double(b) )
1293extern int fpconv_ftoa(
double,
char* );
1298 double n = ur_double(cell);
1310 seg = (int) (n / 3600.0);
1317 seg = (int) (n / 60.0);
1334 int len = fpconv_ftoa( n, buf );
1347 time_make, time_make, unset_copy,
1348 time_compare, decimal_operate, unset_select,
1349 time_toString, time_toString,
1350 unset_recycle, unset_mark, unset_destroy,
1351 unset_markBuf, unset_toShared, unset_bind
1360extern double ur_stringToDate(
const uint8_t*,
const uint8_t*,
const uint8_t**);
1370 ur_double(res) = ur_double(from);
1376 if( ur_strIsUcs2(si.
buf) )
1378 return MAKE_NO_UCS2(
"date!" );
1382 const uint8_t* cp = si.
buf->
ptr.
b;
1384 ur_double(res) = ur_stringToDate(cp + si.
it, cp + si.
end, 0);
1390 "make date! expected time!/date!/string!" );
1401 if( ur_is(a, UT_INT) )
1403 ur_int(&tmp) = ur_int(a);
1407 else if( ur_is(b, UT_INT) )
1409 ur_int(&tmp) = ur_int(b);
1413 ur_int(&tmp) *= 86400;
1415 return decimal_operate( ut, a, b, res, op );
1422 date_make, date_make, unset_copy,
1423 time_compare, date_operate, unset_select,
1424 date_toString, date_toString,
1425 unset_recycle, unset_mark, unset_destroy,
1426 unset_markBuf, unset_toShared, unset_bind
1434static void vec3_setf(
UCell* res,
float n )
1437 f[0] = f[1] = f[2] = n;
1441extern int vector_pickFloatV(
const UBuffer*,
UIndex n,
float* fv,
int count );
1449 vec3_setf( res, 0.0f );
1452 vec3_setf( res, (
float) ur_logic(from) );
1455 vec3_setf( res, (
float) ur_int(from) );
1458 vec3_setf( res, (
float) ur_double(from) );
1464 (
float) from->
coord.
n[2] : 0.0;
1479 if( ur_is(bi.
it, UT_WORD) )
1486 else if( ur_is(bi.
it, UT_PATH) )
1488 if( ! ur_pathCell( ut, bi.
it, res ) )
1497 if( ur_is(cell, UT_INT) )
1498 num = (float) ur_int(cell);
1499 else if( ur_is(cell, UT_DOUBLE) )
1500 num = (float) ur_double(cell);
1509 res->
vec3.
xyz[ len++ ] = 0.0f;
1518 res->
vec3.
xyz[ len++ ] = 0.0f;
1523 "make vec3! expected none!/logic!/int!/double!/block!" );
1532 for( depth = 0; depth < 3; ++depth )
1542void vec3_pick(
const UCell* cell,
int index,
UCell* res )
1544 if( (index < 0) || (index >= 3) )
1551 ur_double(res) = cell->
vec3.
xyz[ index ];
1561 if( (index < 0) || (index >= 3) )
1564 if( ur_is(src, UT_DOUBLE) )
1565 num = (float) ur_double(src);
1566 else if( ur_is(src, UT_INT) )
1567 num = (float) ur_int(src);
1571 cell->
vec3.
xyz[ index ] = num;
1581 case UR_COMPARE_EQUAL:
1582 case UR_COMPARE_EQUAL_CASE:
1587 case UR_COMPARE_SAME:
1589 const float* pa = a->
vec3.
xyz;
1590 const float* pb = b->
vec3.
xyz;
1591 if( (pa[0] != pb[0]) || (pa[1] != pb[1]) || (pa[2] != pb[2]) )
1597 case UR_COMPARE_ORDER:
1598 case UR_COMPARE_ORDER_CASE:
1601 const float* pa = a->
vec3.
xyz;
1602 const float* aend = pa + 3;
1603 const float* pb = b->
vec3.
xyz;
1620static const float* _load3f(
const UCell* cell,
float* tmp )
1625 tmp[0] = tmp[1] = tmp[2] = (float) ur_int(cell);
1629 tmp[0] = tmp[1] = tmp[2] = (float) ur_double(cell);
1633 tmp[0] = (float) cell->
coord.
n[0];
1634 tmp[1] = (float) cell->
coord.
n[1];
1635 tmp[2] = (cell->
coord.
len > 2) ? (
float) cell->
coord.
n[2] : 0.0f;
1648#define OPER_V3(OP) \
1649 res->vec3.xyz[0] = va[0] OP vb[0]; \
1650 res->vec3.xyz[1] = va[1] OP vb[1]; \
1651 res->vec3.xyz[2] = va[2] OP vb[2]
1660 va = _load3f( a, tmp );
1663 vb = _load3f( b, tmp );
1683 return unset_operate( ut, a, b, res, op );
1690 "vec3! operator exepected int!/double!/coord!/vec3!" );
1698 if( ur_is(sel, UT_INT) )
1700 vec3_pick( cell, ur_int(sel) - 1, tmp );
1711 vec3_make, vec3_make, unset_copy,
1712 vec3_compare, vec3_operate, vec3_select,
1713 vec3_toString, vec3_toString,
1714 unset_recycle, unset_mark, unset_destroy,
1715 unset_markBuf, unset_toShared, unset_bind
1723extern uint8_t charset_word[32];
1726static UAtom word_intern(
UThread* ut,
const char* str,
const char* end )
1728 const char* it = str;
1733 if( bitIsSet(charset_word, ch) )
1736 return UR_INVALID_ATOM;
1747 if( ur_isWordType( type ) )
1753 else if( type == UT_STRING )
1758 if( si.
buf->
form == UR_ENC_LATIN1 )
1760 atom = word_intern( ut, si.
buf->
ptr.
c + si.
it,
1768 atom = word_intern( ut, tmp.
ptr.
c, tmp.
ptr.
c + tmp.
used );
1771 if( atom == UR_INVALID_ATOM )
1775 ur_setWordUnbound(res, atom);
1778 else if( type == UT_DATATYPE )
1790 return word_makeType( ut, from, res, UT_WORD );
1798static int word_atomOrType(
const UCell* cell )
1801 if( ur_isWordType(type) )
1802 return ur_atom(cell);
1803 if( type == UT_DATATYPE )
1813int compare_ic_uint8_t(
const uint8_t*,
const uint8_t*,
1814 const uint8_t*,
const uint8_t* );
1820 case UR_COMPARE_SAME:
1821 return ((ur_atom(a) == ur_atom(b)) &&
1822 (ur_binding(a) == ur_binding(b)) &&
1825 case UR_COMPARE_EQUAL:
1826 case UR_COMPARE_EQUAL_CASE:
1828 int atomA = word_atomOrType( a );
1829 if( (atomA > -1) && (atomA == word_atomOrType(b)) )
1834 case UR_COMPARE_ORDER:
1835 case UR_COMPARE_ORDER_CASE:
1838#define ATOM_LEN(str) strLen((const char*) str)
1839 const uint8_t* strA = (
const uint8_t*) ur_wordCStr(a);
1840 const uint8_t* strB = (
const uint8_t*) ur_wordCStr(b);
1841 int (*func)(
const uint8_t*,
const uint8_t*,
1842 const uint8_t*,
const uint8_t* );
1843 func = (test == UR_COMPARE_ORDER) ? compare_ic_uint8_t
1845 return func( strA, strA + ATOM_LEN(strA),
1846 strB, strB + ATOM_LEN(strB) );
1872void word_toShared(
UCell* cell )
1890 word_make, word_make, unset_copy,
1891 word_compare, unset_operate, unset_select,
1892 word_toString, word_toString,
1893 unset_recycle, word_mark, unset_destroy,
1894 unset_markBuf, word_toShared, unset_bind
1904 return word_makeType( ut, from, res, UT_LITWORD );
1919 litword_make, litword_make, unset_copy,
1920 word_compare, unset_operate, unset_select,
1921 litword_toString, word_toString,
1922 unset_recycle, word_mark, unset_destroy,
1923 unset_markBuf, word_toShared, unset_bind
1933 return word_makeType( ut, from, res, UT_SETWORD );
1948 setword_make, setword_make, unset_copy,
1949 word_compare, unset_operate, unset_select,
1950 setword_toString, word_toString,
1951 unset_recycle, word_mark, unset_destroy,
1952 unset_markBuf, word_toShared, unset_bind
1962 return word_makeType( ut, from, res, UT_GETWORD );
1977 getword_make, getword_make, unset_copy,
1978 word_compare, unset_operate, unset_select,
1979 getword_toString, word_toString,
1980 unset_recycle, word_mark, unset_destroy,
1981 unset_markBuf, word_toShared, unset_bind
2000 unset_make, unset_make, unset_copy,
2001 word_compare, unset_operate, unset_select,
2002 option_toString, option_toString,
2003 unset_recycle, word_mark, unset_destroy,
2004 unset_markBuf, word_toShared, unset_bind
2019 len = bi.end - bi.it;
2025 ur_initSeries( res,
ur_type(from), n );
2032 if( type == UT_INT )
2037 else if( type == UT_BINARY )
2039 binary_copy( ut, from, res );
2042 else if( ur_isStringType(type) || (type == UT_VECTOR) )
2053 "make binary! expected int!/binary!/string!/file!" );
2061 case UR_COMPARE_SAME:
2066 case UR_COMPARE_EQUAL:
2067 case UR_COMPARE_EQUAL_CASE:
2068 if( ! ur_is(a, UT_BINARY) || ! ur_is(b, UT_BINARY) )
2085 pos = match_pattern_8( ai.
buf->
ptr.
b + ai.
it,
2093 case UR_COMPARE_ORDER:
2094 case UR_COMPARE_ORDER_CASE:
2095 if( ur_is(a, UT_BINARY) && ur_is(b, UT_BINARY) )
2103 return compare_uint8_t( ai.
buf->
ptr.
b + ai.
it,
2114static const char* binaryEncStart[ UR_BENC_COUNT ] = {
"#{",
"2#{",
"64#{" };
2131 if( n > UR_INVALID_BUF )
2136void binary_toShared(
UCell* cell )
2139 if( n > UR_INVALID_BUF )
2146 if( n > -1 && n < buf->used )
2149 ur_int(res) = buf->
ptr.
b[ n ];
2158 if( n > -1 && n < buf->used )
2160 if( ur_is(val, UT_CHAR) || ur_is(val, UT_INT) )
2161 buf->
ptr.
b[ n ] = ur_int(val);
2166static int _errorStaticBinary(
UThread* ut )
2177 return _errorStaticBinary(ut);
2180 if( (vt == UT_BINARY) || ur_isStringType(vt) )
2186 len = si.
end - si.
it;
2189 if( (vt != UT_BINARY) && ur_strIsUcs2(si.
buf) )
2198 else if( (vt == UT_CHAR) || (vt == UT_INT) )
2201 buf->
ptr.
b[ buf->
used++ ] = ur_int(val);
2204 else if( vt == UT_BLOCK )
2210 if( ! binary_append( ut, buf, bi.
it ) )
2216 "append binary! expected char!/int!/binary!/string!/block!" );
2226 return _errorStaticBinary(ut);
2229 if( (vt == UT_BINARY) || ur_isStringType(vt) )
2235 len = si.
end - si.
it;
2240 if( (vt != UT_BINARY) && ur_strIsUcs2(si.
buf) )
2254 else if( (vt == UT_CHAR) || (vt == UT_INT) )
2257 buf->
ptr.
b[ index ] = ur_int(val);
2261 "insert binary! expected char!/int!/binary!/string!" );
2265int binary_change(
UThread* ut, USeriesIterM* si,
const UCell* val,
2272 return _errorStaticBinary(ut);
2275 if( type == UT_CHAR || type == UT_INT )
2277 if( si->it == buf->
used )
2279 buf->
ptr.
b[ si->it++ ] = ur_int(val);
2284 else if( type == UT_BINARY )
2291 rlen = ri.end - ri.it;
2299 newUsed = (buf->
used < rlen) ? rlen : buf->used;
2305 newUsed = buf->
used;
2310 newUsed = si->it + rlen;
2311 if( newUsed < buf->used )
2312 newUsed = buf->
used;
2320 buf->
used = newUsed;
2325 "change binary! expected char!/int!/binary!" );
2329void binary_remove(
UThread* ut, USeriesIterM* si,
UIndex part )
2332 ur_binErase( si->buf, si->it, (part > 0) ? part : 1 );
2336void binary_reverse(
const USeriesIterM* si )
2338 uint8_t* it = si->buf->
ptr.
b;
2339 reverse_uint8_t( it + si->it, it + si->end );
2346 const uint8_t* it = buf->
ptr.
b;
2347 const uint8_t* ba = it + si->
it;
2348 const uint8_t* bb = it + si->
end;
2351 if( (vt == UT_CHAR) || (vt == UT_INT) )
2353 if( opt & UR_FIND_LAST )
2354 it = find_last_uint8_t( ba, bb, ur_int(val) );
2356 it = find_uint8_t( ba, bb, ur_int(val) );
2359 return it - buf->
ptr.
b;
2361 else if( ur_isStringType( vt ) || (vt == UT_BINARY) )
2368 if( (vt != UT_BINARY) && ur_strIsUcs2(siV.
buf) )
2373 it = find_pattern_8( ba, bb, itV + siV.
it, itV + siV.
end );
2376 else if( vt == UT_BITSET )
2379 if( opt & UR_FIND_LAST )
2380 it = find_last_charset_uint8_t( ba, bb, bbuf->
ptr.
b, bbuf->
used );
2382 it = find_charset_uint8_t( ba, bb, bbuf->
ptr.
b, bbuf->
used );
2419 ur_sizeOrder( &ord, biA.end - biA.it, biB.end - biB.it );
2425 ord.large -= ord.small;
2429 while( ord.small-- )
2430 *bp++ = *biA.it++ & *biB.it++;
2431 memSet( bp, 0, ord.large );
2435 while( ord.small-- )
2436 *bp++ = *biA.it++ | *biB.it++;
2440 while( ord.small-- )
2441 *bp++ = *biA.it++ ^ *biB.it++;
2443 memCpy( bp, ord.secondLarger ? biB.it : biA.it,
2452 return unset_operate( ut, a, b, res, op );
2459 if( ur_is(sel, UT_INT) )
2462 binary_pick( buf, cell->
series.
it + ur_int(sel) - 1, tmp );
2474 binary_make, binary_make, binary_copy,
2475 binary_compare, binary_operate, binary_select,
2476 binary_toString, binary_toString,
2478 unset_markBuf, binary_toShared, unset_bind
2480 binary_pick, binary_poke, binary_append,
2481 binary_insert, binary_change, binary_remove,
2482 binary_reverse, binary_find
2493 int bytes = (bitCount + 7) / 8;
2496 buf->
type = UT_BITSET;
2500 memSet( buf->
ptr.
b, 0, buf->
used );
2506#define setBit(mem,n) (mem[(n)>>3] |= 1<<((n)&7))
2507#define clrBit(mem,n) (mem[(n)>>3] &= ~(1<<((n)&7)))
2511 if( ur_is(from, UT_INT) )
2513 ur_makeBitsetCell( ut, ur_int(from), res );
2516 else if( ur_is(from, UT_CHAR) )
2518 int n = ur_int(from);
2519 UBuffer* buf = ur_makeBitsetCell( ut, n + 1, res );
2520 setBit( buf->
ptr.
b, n );
2523 else if( ur_is(from, UT_BINARY) )
2525 binary_copy( ut, from, res );
2530 else if( ur_is(from, UT_STRING) )
2536 bits = ur_makeBitsetCell( ut, 256, res )->ptr.b;
2539 if( si.buf->
form != UR_ENC_LATIN1 )
2542 "FIXME: make bitset! only handles Latin-1 strings" );
2553 "make bitset! expected int!/char!/binary!/string!" );
2561 case UR_COMPARE_SAME:
2564 case UR_COMPARE_EQUAL:
2565 case UR_COMPARE_EQUAL_CASE:
2566 if( ! ur_is(a, UT_BITSET) || ! ur_is(b, UT_BITSET) )
2575 ur_sizeOrder( &ord, ba->
used, bb->
used );
2579 const uint8_t* end = bb->
ptr.
b + ord.small;
2580 pos = match_pattern_8( ba->
ptr.
b, ba->
ptr.
b + ord.small,
2585 pos = ord.secondLarger ? bb->
ptr.
b : ba->
ptr.
b;
2586 end = pos + ord.large;
2597 case UR_COMPARE_ORDER:
2598 case UR_COMPARE_ORDER_CASE:
2621 if( n > -1 && n < (buf->
used * 8) )
2624 if( bitIsSet( buf->
ptr.
b, n ) )
2634 if( n > -1 && n < (buf->
used * 8) )
2638 if( ur_is(val, UT_INT) )
2640 if( ur_int(val) == 0 )
2643 else if( ur_is(val, UT_DOUBLE) )
2645 if( ur_double(val) == 0.0 )
2648 setBit( buf->
ptr.
b, n );
2653 clrBit( buf->
ptr.
b, n );
2659void bitset_reverse(
const USeriesIterM* si )
2672 if( (vt == UT_CHAR) || (vt == UT_INT) )
2675 if( ((n >> 3) < buf->
used) && bitIsSet( buf->
ptr.
b, n ) )
2678 else if( vt == UT_BLOCK )
2685 if( ur_is(bi.
it, UT_CHAR) || ur_is(bi.
it, UT_INT) )
2688 if( ((n >> 3) >= buf->
used) || ! bitIsSet( buf->
ptr.
b, n ) )
2702 bitset_make, bitset_make, binary_copy,
2703 bitset_compare, binary_operate, unset_select,
2704 bitset_toString, bitset_toString,
2706 unset_markBuf, binary_toShared, unset_bind
2708 bitset_pick, bitset_poke, binary_append,
2709 binary_insert, binary_change, binary_remove,
2710 bitset_reverse, bitset_find
2725 len = si.
end - si.
it;
2736 if( ur_isStringType(type) )
2738 string_copy( ut, from, res );
2740 else if( type == UT_BINARY )
2748 ur_initSeries( res, UT_STRING, n );
2752 DT( type )->toString( ut, from,
2761 if( ur_is(from, UT_INT) )
2766 else if( ur_is(from, UT_WORD) )
2768 UAtom atom = ur_atom(from);
2769 int enc = atom - UR_ATOM_LATIN1;
2770 if (enc < UR_ENC_LATIN1 || enc > UR_ENC_UCS2)
2776 return string_convert( ut, from, res );
2780#define COMPARE_IC(T) \
2781int compare_ic_ ## T( const T* it, const T* end, \
2782 const T* itB, const T* endB ) { \
2784 int lenA = end - it; \
2785 int lenB = endB - itB; \
2786 while( it < end && itB < endB ) { \
2787 ca = ur_charLowercase( *it++ ); \
2788 cb = ur_charLowercase( *itB++ ); \
2809 case UR_COMPARE_SAME:
2814 case UR_COMPARE_EQUAL:
2815 case UR_COMPARE_EQUAL_CASE:
2816 if( ! ur_isStringType(
ur_type(a)) || ! ur_isStringType(
ur_type(b)) )
2829 len = ai.
end - ai.
it;
2831 if( (bi.
end - bi.
it) == len )
2834 (
ur_strMatch( &ai, &bi, (test == UR_COMPARE_EQUAL_CASE) )
2841 case UR_COMPARE_ORDER:
2842 case UR_COMPARE_ORDER_CASE:
2843 if( ! ur_isStringType(
ur_type(a)) || ! ur_isStringType(
ur_type(b)) )
2855 if( ur_strIsUcs2(ai.
buf) )
2857 int (*func)(
const uint16_t*,
const uint16_t*,
2858 const uint16_t*,
const uint16_t* );
2859 func = (test == UR_COMPARE_ORDER) ? compare_ic_uint16_t
2868 int (*func)(
const uint8_t*,
const uint8_t*,
2869 const uint8_t*,
const uint8_t* );
2870 func = (test == UR_COMPARE_ORDER) ? compare_ic_uint8_t
2885static uint8_t _strLongChars[5] = { 0x00, 0x00, 0x00, 0x00, 0x04 };
2887static uint8_t _strEscapeChars[16] = {
2888 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2889 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x28
2893static inline int nibbleToChar(
int n )
2895 return (n < 10) ? n +
'0' : n +
'A' - 10;
2900 const int longLen = 40;
2907 len = si.
end - si.
it;
2915 if( (len > longLen) ||
2917 _strLongChars,
sizeof(_strLongChars) ) > -1) )
2931 _strEscapeChars,
sizeof(_strEscapeChars) );
2938 if( escPos != si.
it )
2942 depth = ur_strIsUcs2(si.
buf) ? si.
buf->
ptr.
u16[ escPos ]
2997 if( n > -1 && n < buf->used )
3000 ur_int(res) = ur_strIsUcs2(buf) ? buf->
ptr.
u16[ n ]
3010 if( n > -1 && n < buf->used )
3012 if( ur_is(val, UT_CHAR) || ur_is(val, UT_INT) )
3014 if( ur_strIsUcs2(buf) )
3015 buf->
ptr.
u16[ n ] = ur_int(val);
3017 buf->
ptr.
b[ n ] = ur_int(val);
3023static int _errorStaticString(
UThread* ut )
3034 return _errorStaticString(ut);
3037 if( ur_isStringType(type) )
3043 else if( type == UT_CHAR )
3047 else if( type == UT_BLOCK )
3060 DT( type )->toText( ut, val, buf, 0 );
3072 return _errorStaticString(ut);
3075 if( ur_isStringType(type) )
3082 len = si.
end - si.
it;
3089 saveUsed = buf->
used;
3092 buf->
used = saveUsed;
3096 else if( type == UT_CHAR )
3099 if( ur_strIsUcs2(buf) )
3100 buf->
ptr.
u16[ index ] = ur_int(val);
3102 buf->
ptr.
c[ index ] = ur_int(val);
3120 int rlen = ri->
end - ri->
it;
3130 newUsed = (buf->
used < rlen) ? rlen : buf->used;
3136 newUsed = buf->
used;
3141 newUsed = si->it + rlen;
3142 if( newUsed < buf->used )
3143 newUsed = buf->
used;
3151 buf->
used = newUsed;
3156int string_change(
UThread* ut, USeriesIterM* si,
const UCell* val,
3164 return _errorStaticString(ut);
3167 if( type == UT_CHAR )
3169 if( si->it == buf->
used )
3172 if( ur_strIsUcs2(buf) )
3173 buf->
ptr.
u16[ si->it ] = ur_int(val);
3175 buf->
ptr.
b[ si->it ] = ur_int(val);
3181 else if( ur_isStringType(type) )
3184 ur_strChange( si, &siV, part );
3191 DT( type )->toString( ut, val, &tmp, 0 );
3197 ur_strChange( si, &siV, part );
3204void string_remove(
UThread* ut, USeriesIterM* si,
UIndex part )
3207 ur_arrErase( si->buf, si->it, (part > 0) ? part : 1 );
3211void string_reverse(
const USeriesIterM* si )
3214 assert( buf->
form != UR_ENC_UTF8 );
3215 if( ur_strIsUcs2(buf) )
3216 reverse_uint16_t( buf->
ptr.
u16 + si->it, buf->
ptr.
u16 + si->end );
3218 reverse_uint8_t( buf->
ptr.
b + si->it, buf->
ptr.
b + si->end );
3239 return find( si, &pi, opt & UR_FIND_CASE );
3247 return find( buf, si->
it, si->
end, bbuf->
ptr.
b, bbuf->
used );
3257 if( ur_is(sel, UT_INT) )
3260 string_pick( buf, cell->
series.
it + ur_int(sel) - 1, tmp );
3272 string_make, string_convert, string_copy,
3273 string_compare, unset_operate, string_select,
3274 string_toString, string_toText,
3275 unset_recycle, binary_mark, string_destroy,
3276 unset_markBuf, binary_toShared, unset_bind
3278 string_pick, string_poke, string_append,
3279 string_insert, string_change, string_remove,
3280 string_reverse, string_find
3290 int ok = string_make( ut, from, res );
3299 int ok = string_convert( ut, from, res );
3308 string_copy( ut, from, res );
3314static uint8_t _fileQuoteChars[12] =
3316 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x08,
3317 0x00, 0x00, 0x00, 0x28
3328 sizeof(_fileQuoteChars) ) > -1 )
3346 file_make, file_convert, file_copy,
3347 string_compare, unset_operate, string_select,
3348 file_toString, string_toText,
3349 unset_recycle, binary_mark, string_destroy,
3350 unset_markBuf, binary_toShared, unset_bind
3352 string_pick, string_poke, string_append,
3353 string_insert, string_change, string_remove,
3354 string_reverse, string_find
3369 len = bi.
end - bi.
it;
3382 if( type == UT_INT )
3387 else if( type == UT_STRING )
3392 if( si.
it == si.
end )
3414 else if( ur_isBlockType(type) )
3417 block_copy( ut, from, res );
3421 else if( ur_isPathType(type) )
3423 if( from->
word.selType )
3432 "make block! expected int!/string!/block!/path!" );
3440 if( type == UT_STRING || ur_isPathType(type) )
3442 return block_make( ut, from, res );
3444 else if( ur_isBlockType( type ) )
3446 block_copy( ut, from, res );
3462 case UR_COMPARE_SAME:
3467 case UR_COMPARE_EQUAL:
3468 case UR_COMPARE_EQUAL_CASE:
3492 if( ! dt[ t ]->compare( ut, ai.
it, bi.
it, test ) )
3501 case UR_COMPARE_ORDER:
3502 case UR_COMPARE_ORDER_CASE:
3509#define BLOCK_OP_INT(OP) \
3511 if( ur_isIntType(ur_type(bi.it)) ) \
3512 n = n OP ur_int(bi.it); \
3513 else if( ur_isDecimalType(ur_type(bi.it)) ) \
3514 n = n OP (int) ur_double(bi.it); \
3517#define BLOCK_OP_DEC(OP) \
3519 if( ur_isDecimalType(ur_type(bi.it)) ) \
3520 n = n OP ur_double(bi.it); \
3521 else if( ur_isIntType(ur_type(bi.it)) ) \
3522 n = n OP (double) ur_int(bi.it); \
3530 if( ur_isIntType(
ur_type(a) ) )
3555 return unset_operate( ut, a, b, res, op );
3561 else if( ur_isDecimalType(
ur_type(a) ) )
3563 double n = ur_double(a);
3577 return unset_operate( ut, a, b, res, op );
3584 "block! operator exepected char!/int!/double!" );
3590 UBuffer* bs = &ut->blocksSeen;
3607 if (_blockRecursion(ut, cell->
series.
buf))
3625#ifdef UR_CONFIG_MACROS
3645 else if( bi.
it != start )
3653 ut->blocksSeen.
used--;
3673 if (_blockRecursion(ut, cell->
series.
buf))
3684 if( bi.
it != start )
3689 ut->blocksSeen.
used--;
3701 if( t >= UT_REFERENCE_BUF )
3703 DT( t )->mark( ut, it );
3713 if( n > UR_INVALID_BUF )
3721void block_toShared(
UCell* cell )
3724 if( n > UR_INVALID_BUF )
3731 if( n > -1 && n < buf->used )
3740 if( n > -1 && n < buf->used )
3747 if( ur_is(val, UT_BLOCK) || ur_is(val, UT_PAREN) )
3770 if( ur_is(val, UT_BLOCK) || ur_is(val, UT_PAREN) )
3777 len = bi.
end - bi.
it;
3790 len *
sizeof(
UCell) );
3807int block_change(
UThread* ut, USeriesIterM* si,
const UCell* val,
3810 if( ur_isBlockType(
ur_type(val) ) )
3818 rlen = ri.
end - ri.
it;
3827 newUsed = (buf->
used < rlen) ? rlen : buf->used;
3833 newUsed = buf->
used;
3838 newUsed = si->it + rlen;
3839 if( newUsed < buf->used )
3840 newUsed = buf->
used;
3848 buf->
used = newUsed;
3854 if( si->it == buf->
used )
3856 buf->
ptr.
cell[ si->it++ ] = *val;
3864void block_remove(
UThread* ut, USeriesIterM* si,
UIndex part )
3867 ur_arrErase( si->buf, si->it, (part > 0) ? part : 1 );
3871void block_reverse(
const USeriesIterM* si )
3873 if( si->end > si->it )
3899 if( opt & UR_FIND_LAST )
3901 while( bi.
it != bi.
end )
3904 if( equal( ut, val, bi.
end ) )
3912 if( equal( ut, val, bi.
it ) )
3925 if( ur_is(sel, UT_INT) )
3928 int n = cell->
series.
it + ur_int(sel) - 1;
3929 if( n > -1 && n < buf->used )
3935 else if( ur_is(sel, UT_WORD) )
3938 UAtom atom = ur_atom(sel);
3945 if( ur_isWordType(
ur_type(wi.
it) ) && (ur_atom(wi.
it) == atom) )
3947 if( ++wi.
it == wi.
end )
3963 block_make, block_convert, block_copy,
3964 block_compare, block_operate, block_select,
3965 block_toString, block_toText,
3966 unset_recycle, block_mark, block_destroy,
3967 block_markBuf, block_toShared, unset_bind
3969 block_pick, block_poke, block_append,
3970 block_insert, block_change, block_remove,
3971 block_reverse, block_find
3981 int ok = block_make( ut, from, res );
3990 int ok = block_convert( ut, from, res );
4001 paren_make, paren_convert, block_copy,
4002 block_compare, unset_operate, block_select,
4003 block_toString, block_toString,
4004 unset_recycle, block_mark, block_destroy,
4005 block_markBuf, block_toShared, unset_bind
4007 block_pick, block_poke, block_append,
4008 block_insert, block_change, block_remove,
4009 block_reverse, block_find
4019 if( from->
word.selType )
4022 block_copy( ut, from, res );
4028 int typeMask = 1 <<
ur_type(from);
4029 if( typeMask & ((1<<UT_BLOCK) | (1<<UT_PAREN)) )
4035 len = bi.
end - bi.
it;
4039 if( (1 <<
ur_type(bi.
it)) & ((1<<UT_WORD) | (1<<UT_LITWORD)) )
4046 "path! must start with word!/lit-word!" );
4048 else if( typeMask & ((1<<UT_PATH) | (1<<UT_LITPATH) | (1<<UT_SETPATH)) )
4050 path_copy( ut, from, res );
4060 return path_makeT( ut, from, res, UT_PATH );
4068 if( ur_is(cell, UT_LITPATH) )
4071 if( (stype = cell->
word.selType) )
4073 const UAtom* sel = cell->
word.sel;
4079 if( (stype & 3) == UR_SELECT_ATOM )
4097 if( bi.
it != start )
4103 if( ur_is(cell, UT_SETPATH) )
4110 const int pathMask = 1<<UT_PATH | 1<<UT_LITPATH | 1<<UT_SETPATH;
4114 if( (1<<ta & pathMask) && (1<<tb & pathMask) )
4116 if( a->
word.selType && b->
word.selType )
4120 case UR_COMPARE_SAME:
4125 case UR_COMPARE_EQUAL:
4126 case UR_COMPARE_EQUAL_CASE:
4127 if( a->
word.selType == b->
word.selType )
4131 case UR_COMPARE_ORDER:
4132 case UR_COMPARE_ORDER_CASE:
4136 else if( ! (a->
word.selType || b->
word.selType) )
4138 return block_compare( ut, a, b, test );
4150 if( ! ur_is(sel, UT_INT) )
4155 path_pick(ut, cell, ur_int(sel) - 1, tmp);
4162 if( cell->
word.selType )
4163 word_mark( ut, cell );
4165 block_mark( ut, cell );
4169void path_toShared(
UCell* cell )
4171 if( cell->
word.selType )
4172 word_toShared( cell );
4174 block_toShared( cell );
4181 path_make, path_make, path_copy,
4182 path_compare, unset_operate, path_select,
4183 path_toString, path_toString,
4184 unset_recycle, path_mark, block_destroy,
4185 block_markBuf, path_toShared, unset_bind
4195 return path_makeT( ut, from, res, UT_LITPATH );
4202 litpath_make, litpath_make, path_copy,
4203 path_compare, unset_operate, path_select,
4204 path_toString, path_toString,
4205 unset_recycle, path_mark, block_destroy,
4206 block_markBuf, path_toShared, unset_bind
4216 return path_makeT( ut, from, res, UT_SETPATH );
4223 setpath_make, setpath_make, path_copy,
4224 path_compare, unset_operate, path_select,
4225 path_toString, path_toString,
4226 unset_recycle, path_mark, block_destroy,
4227 block_markBuf, path_toShared, unset_bind
4237 if( ur_is(from, UT_BLOCK) )
4252 else if( ur_is(from, UT_CONTEXT) )
4272 case UR_COMPARE_SAME:
4275 case UR_COMPARE_EQUAL:
4276 case UR_COMPARE_EQUAL_CASE:
4284 case UR_COMPARE_ORDER:
4285 case UR_COMPARE_ORDER_CASE:
4307 di.end = di.it + used;
4310 atoms = ait = ((UAtom*) di.end) - used;
4313 if( ctxN == UR_INVALID_BUF )
4321 ur_setBinding( di.it, bindType );
4327 di.buf->
used = used;
4338 if( ur_is(sel, UT_WORD) )
4343 if( ur_atom(sel) == UR_ATOM_SELF )
4363#define ASTACK_SIZE 8
4366 UAtom stack[ ASTACK_SIZE ];
4374 if( buf->
used > ASTACK_SIZE )
4377 atoms.heap = ait = (UAtom*) memAlloc(
sizeof(UAtom) * buf->
used );
4391 DT(
ur_type(it) )->toString( ut, it, str, depth );
4397 memFree( atoms.heap );
4401#define ur_ctxRecursion(buf) (buf)->elemSize
4403#define ur_printRecurseEnd(cell,ctxb) \
4404 if( ! ur_isShared(cell->context.buf) ) \
4405 ur_ctxRecursion((UBuffer*) ctxb) = 0
4416 if( ur_ctxRecursion(buf) )
4418 unset_toString( ut, cell, str, 0 );
4422 ur_ctxRecursion((
UBuffer*) buf) = 1;
4429 const UBuffer* buf = ur_printRecurse( ut, cell, str );
4432 context_print( ut, buf, str, depth );
4433 ur_printRecurseEnd( cell, buf );
4445 context_toText( ut, cell, str, 0 );
4449 const UBuffer* buf = ur_printRecurse( ut, cell, str );
4453 context_print( ut, buf, str, depth + 1 );
4456 ur_printRecurseEnd( cell, buf );
4462void context_destroy(
UBuffer* buf )
4471 context_make, context_make, context_copy,
4472 context_compare, unset_operate, context_select,
4473 context_toString, context_toText,
4474 unset_recycle, block_mark, context_destroy,
4475 context_markBuf, block_toShared, unset_bind
4485 if( ur_is(from, UT_STRING) )
4487 uint8_t type = UT_BLOCK;
4506 case UR_COMPARE_EQUAL:
4507 case UR_COMPARE_EQUAL_CASE:
4512 case UR_COMPARE_SAME:
4519 case UR_COMPARE_ORDER:
4520 case UR_COMPARE_ORDER_CASE:
4533 return string_compare( ut, &strA, &strB, test );
4542static const char* errorTypeStr[] =
4570 if( end < bc->series.it )
4573 bi.end = bi.buf->
ptr.
cell + end;
4576 if( bi.it == bi.end )
4580 if( bi.it != bi.end )
4592 while( start != bi.buf->
ptr.
cell )
4603 if( bi.it != start )
4607 if( ur_is(bi.it, UT_BLOCK) || ur_is(bi.it, UT_PAREN) )
4623 if( et < UR_ERR_COUNT )
4644 bi.end = bi.it + bi.buf->
used;
4652 _lineToString( ut, bi.it, str );
4666 if( n > UR_INVALID_BUF )
4674void error_toShared(
UCell* cell )
4678 if( n > UR_INVALID_BUF )
4681 if( n > UR_INVALID_BUF )
4689 error_make, error_make, unset_copy,
4690 error_compare, unset_operate, unset_select,
4691 error_toString, error_toString,
4692 unset_recycle, error_mark, unset_destroy,
4693 unset_markBuf, error_toShared, unset_bind
void ur_binErase(UBuffer *, int start, int count)
Remove bytes from the binary.
Definition binary.c:171
void ur_binAppendData(UBuffer *, const uint8_t *data, int len)
Append data to binary buffer.
Definition binary.c:213
UBuffer * ur_makeBinaryCell(UThread *, int size, UCell *cell)
Generate a single binary and set cell to reference it.
Definition binary.c:74
void ur_binReserve(UBuffer *, int size)
Allocates enough memory to hold size bytes.
Definition binary.c:138
void ur_binFree(UBuffer *)
Free binary data.
Definition binary.c:120
void ur_binSlice(UThread *, UBinaryIter *, const UCell *cell)
Set UBinaryIter to binary slice.
Definition binary.c:423
void ur_binAppendArray(UBuffer *, const USeriesIter *si)
Append array slice to binary buffer.
Definition binary.c:227
void ur_binExpand(UBuffer *, int index, int count)
Create space in the binary for count bytes starting at index.
Definition binary.c:194
UIndex ur_makeBinary(UThread *, int size)
Generate and initialize a single binary buffer.
Definition binary.c:56
void ur_blkInsert(UBuffer *, UIndex it, const UCell *cells, int count)
Insert cells into block.
Definition block.c:143
void ur_blkPush(UBuffer *, const UCell *cell)
Copy cell to end of block.
Definition block.c:153
UStatus ur_blkSliceM(UThread *, UBlockIterM *, const UCell *cell)
Set UBlockIterM to block slice.
Definition block.c:224
void ur_blkAppendCells(UBuffer *, const UCell *cells, int count)
Append cells to block.
Definition block.c:125
UBuffer * ur_makeBlockCell(UThread *, int type, int size, UCell *cell)
Generate a single block and set cell to reference it.
Definition block.c:76
UBuffer * ur_ctxClone(UThread *, const UBuffer *src, UCell *cell)
Clone a new context and set cell to reference it.
Definition context.c:220
void ur_ctxFree(UBuffer *)
Free context data.
Definition context.c:316
int ur_ctxLookup(const UBuffer *, UAtom atom)
Find word in context by atom.
Definition context.c:579
#define ur_ctxCell(c, n)
Get pointer of UCell in context by index.
Definition urlan.h:668
void ur_ctxSetWords(UBuffer *, const UCell *it, const UCell *end)
Add the set-word! values in a series of cells to the words in a context.
Definition context.c:283
UBuffer * ur_makeContextCell(UThread *, int size, UCell *cell)
Generate a single context and set cell to reference it.
Definition context.c:111
UBuffer * ur_ctxSort(UBuffer *)
Sort the internal context search table so ur_ctxLookup() is faster.
Definition context.c:510
void ur_ctxWordAtoms(const UBuffer *, UAtom *atoms)
Get word atoms in order.
Definition context.c:334
void ur_bind(UThread *, UBuffer *blk, const UBuffer *ctx, int bindType)
Bind block to context.
Definition context.c:690
const UBuffer * ur_sortedContext(UThread *, const UCell *)
Get context and make sure it is fully sorted for minimal ur_ctxLookup() time.
Definition context.c:547
UBuffer * ur_makePathCell(UThread *, const UCell *nodes, int size, UCell *cell)
Initialize path cell and generate block if needed.
Definition path.c:65
int ur_pathSelectCells(const UCell *selC, UCell *dest)
Definition path.c:204
#define ur_strFree
A string is a simple array.
Definition urlan.h:629
UBuffer * ur_makeStringCell(UThread *, int enc, int size, UCell *cell)
Generate a single string and set cell to reference it.
Definition string.c:104
UIndex ur_strFindCharsRev(const UBuffer *, UIndex start, UIndex end, const uint8_t *charSet, int len)
Find the last character of a set in a string.
Definition string.c:1388
void ur_strAppendBinary(UBuffer *, const uint8_t *it, const uint8_t *end, enum UrlanBinaryEncoding enc)
Append binary data as text of the specified encoding.
Definition string.c:998
void ur_strAppendChar(UBuffer *, int)
Append a single UCS2 character to a string.
Definition string.c:611
UIndex ur_strFindChars(const UBuffer *, UIndex start, UIndex end, const uint8_t *charSet, int len)
Find the first character of a set in a string.
Definition string.c:1353
void ur_strAppendIndent(UBuffer *, int depth)
Append tabs to a string.
Definition string.c:851
UIndex ur_strFindRev(const USeriesIter *, const USeriesIter *, int matchCase)
Find last string in another string or binary series.
Definition string.c:1531
UIndex ur_makeStringUtf8(UThread *, const uint8_t *it, const uint8_t *end)
Generate and initialize a single string buffer from memory holding a UTF-8 string.
Definition string.c:415
void ur_strAppendHex(UBuffer *, uint32_t n, uint32_t hi)
Append a hexidecimal integer to a string.
Definition string.c:765
UIndex ur_strMatch(const USeriesIter *, const USeriesIter *, int matchCase)
Compare characters in two string or binary series.
Definition string.c:1584
void ur_strAppendInt(UBuffer *, int32_t)
Append an integer to a string.
Definition string.c:706
void ur_strInit(UBuffer *, int enc, int size)
Initialize buffer to type UT_STRING.
Definition string.c:430
UIndex ur_strFindChar(const UBuffer *, UIndex, UIndex, int ch, int opt)
Find the first instance of a character in a string.
Definition string.c:1292
void ur_strAppend(UBuffer *, const UBuffer *strB, UIndex itB, UIndex endB)
Append another string buffer to this string.
Definition string.c:899
void ur_strAppendDouble(UBuffer *, double)
Append a double to a string.
Definition string.c:787
UIndex ur_strFind(const USeriesIter *, const USeriesIter *, int matchCase)
Find string in another string or binary series.
Definition string.c:1451
void ur_strAppendFloat(UBuffer *, float)
Append a float to a string.
Definition string.c:813
void ur_strAppendInt64(UBuffer *, int64_t)
Append an 64-bit integer to a string.
Definition string.c:725
void ur_strAppendCStr(UBuffer *, const char *)
Append a null-terminated UTF-8 string to a string buffer.
Definition string.c:641
void ur_seriesSlice(const UThread *, USeriesIter *si, const UCell *cell)
Set USeriesIter to series slice.
Definition env.c:1338
#define ur_bufferSer(c)
Convenience macro for ur_bufferSeries().
Definition urlan.h:752
#define ur_setId(c, t)
Set type and initialize the other 24 bits of UCellId to zero.
Definition urlan.h:701
@ UT_TYPEMASK
Used in UCellDatatype to declare a multi-type datatype!.
Definition urlan.h:73
const char * ur_atomCStr(UThread *, UAtom atom)
Get name of atom.
Definition atoms.c:47
UIndex it
Start position.
Definition urlan.h:338
UStatus ur_error(UThread *, int errorType, const char *fmt,...)
Create error! exception.
Definition env.c:964
const UCell * ur_wordCell(UThread *, const UCell *cell)
Get word value for read-only operations.
Definition env.c:1132
UAtom ur_internAtom(UThread *, const char *it, const char *end)
Add a single atom to the shared environment.
Definition env.c:612
const UCell * end
End position.
Definition urlan.h:388
void ur_toText(UThread *, const UCell *cell, UBuffer *str)
Append textual representation of cell to a string.
Definition env.c:1118
UStatus ur_tokenizeB(UThread *, UIndex blkN, int inputEncoding, const uint8_t *start, const uint8_t *end)
Parse UTF-8 or Latin1 data into block.
Definition tokenize.c:654
UIndex end
End position.
Definition urlan.h:339
const UCell * it
Start position.
Definition urlan.h:387
@ UR_THROW
Returned to indicate an evaluation exception occured.
Definition urlan.h:117
@ UR_OK
Returned to indicate successful evaluation/operation.
Definition urlan.h:118
#define ur_foreach(bi)
Loop over all members of an iterator struct.
Definition urlan.h:760
UBuffer * ur_generate(UThread *, int count, UIndex *index, const uint8_t *)
Generate and initialize buffers of given types.
Definition env.c:771
int ur_true(const UCell *cell)
Check if a value is "true".
Definition env.c:1029
const UBuffer * ur_blockIt(const UThread *ut, UBlockIt *bi, const UCell *blkCell)
Set UBlockIt to the start and end of a block slice.
Definition env.c:1388
int ur_equal(UThread *, const UCell *a, const UCell *b)
Definition env.c:1053
const UBuffer * buf
Buffer pointer.
Definition urlan.h:337
int ur_datatypeCount(UThread *)
Get number of datatypes installed in the environment.
Definition env.c:580
#define ur_isShared(n)
True if buffer number refers to a buffer in the shared environment.
Definition urlan.h:726
#define ur_buffer(n)
Macro to get buffer known to be in thread dataStore.
Definition urlan.h:750
int ur_equalCase(UThread *, const UCell *a, const UCell *b)
Case-sensitive equality test.
Definition env.c:1066
#define ur_type(c)
Return UrlanDataType of cell.
Definition urlan.h:695
void ur_toStr(UThread *, const UCell *cell, UBuffer *str, int depth)
Append data representation of cell to a string.
Definition env.c:1107
#define ur_bufferE(n)
Convenience macro for ur_bufferEnv().
Definition urlan.h:751
Holds information for binding functions.
Definition urlan.h:402
Iterator for const UCell array.
Definition urlan.h:386
The UBuffer struct holds information about a resource, usually a chunk of memory.
Definition urlan.h:266
uint8_t * b
bytes
Definition urlan.h:277
uint8_t form
This can indicate a specific form of the data (such as a string encoding).
Definition urlan.h:269
char * c
chars
Definition urlan.h:276
uint32_t * u32
uint32_t
Definition urlan.h:282
UIndex used
This typically holds the number of elements in the buffer.
Definition urlan.h:271
uint16_t * u16
uint16_t
Definition urlan.h:279
uint8_t type
UrlanDataType identifier.
Definition urlan.h:267
uint8_t flags
Indicates special features of the buffer (UR_STATIC, UR_STRING_ENC_UP).
Definition urlan.h:270
UCell * cell
Array of cells.
Definition urlan.h:275
union UBuffer::@312146223224040072236377336057316010374162171270 ptr
This typically holds a pointer to a chunk of memory.
uint8_t elemSize
This typically holds the byte size of each element.
Definition urlan.h:268
int16_t n[UR_COORD_MAX]
Holds six, 16-bit integers.
Definition urlan.h:195
uint16_t len
Number of integers used in array n.
Definition urlan.h:194
uint8_t n
The UrlanDataType.
Definition urlan.h:167
uint32_t mask0
Low 32 bits of type mask.
Definition urlan.h:169
uint32_t mask1
Middle 32 bits of type mask.
Definition urlan.h:170
UIndex messageStr
Index of message string! buffer.
Definition urlan.h:240
uint16_t exType
The UrlanErrorType.
Definition urlan.h:239
UIndex traceBlk
Index of block! buffer where error occurred.
Definition urlan.h:241
uint8_t flags
Bit field for type-specific properties.
Definition urlan.h:157
UIndex end
Slice end index.
Definition urlan.h:230
UIndex buf
Buffer id.
Definition urlan.h:228
UIndex it
Iterator index.
Definition urlan.h:229
float xyz[3]
The three float values.
Definition urlan.h:203
uint16_t index
Normally the word index into a context.
Definition urlan.h:218
UAtom atom
The name of the word.
Definition urlan.h:219
UIndex ctx
Normally the buffer id of a context.
Definition urlan.h:217
The UDatatype struct holds methods for a specific class of data.
Definition urlan.h:439
void(* toText)(UThread *, const UCell *cell, UBuffer *str, int depth)
Convert cell to its string textual representation.
Definition urlan.h:450
Iterator for const series of any type.
Definition urlan.h:336
The USeriesType struct holds extra methods for series datatypes.
Definition urlan.h:469
The UThread struct stores the data specific to a thread of execution.
Definition urlan.h:309
const UDatatype ** types
Pointer to the datatypes.
Definition urlan.h:322
A cell holds a single value of a simple type or a reference (often to a UBuffer) for a complex type.
Definition urlan.h:248
UCellWord word
For word!, lit-word!, set-word!, get-word! types.
Definition urlan.h:251
UCellError error
For error! type.
Definition urlan.h:258
UCellVec3 vec3
For vec3! type.
Definition urlan.h:254
UCellCoord coord
For coord! type.
Definition urlan.h:253
UCellSeries series
For binary!, bitset!, string!, file!, block!, paren!, path! types.
Definition urlan.h:255
UCellId id
Basic type identification.
Definition urlan.h:249
UCellDatatype datatype
For datatype! type.
Definition urlan.h:250
#define UR_STATIC
This UBuffer::flags bit is set when the UBuffer::ptr points to memory outside of the Urlan datatype s...
Definition urlan.h:292
#define UR_FLAG_SOL
This UCellId::flags bit indicates that the cell starts a new line of code.
Definition urlan.h:82
void ur_arrAppendInt32(UBuffer *, int32_t)
Append int32_t to array.
Definition array.c:180
UStatus
Definition urlan.h:116
void ur_arrExpand(UBuffer *, int index, int count)
Create space in the array for count elements starting at index.
Definition array.c:161
void ur_makeDatatype(UCell *cell, int type)
Initialize cell to be a UT_DATATYPE value of the given type.
Definition datatypes.c:389
#define ur_datatype(c)
Access the UrlanDataType that a UCellDatatype represents.
Definition urlan.h:711
@ UR_ERR_SCRIPT
General script evaluation error.
Definition urlan.h:126
@ UR_ERR_INTERNAL
Fatal internal problem.
Definition urlan.h:129
@ UR_ERR_TYPE
Invalid argument/parameter datatype.
Definition urlan.h:125
void ur_datatypeAddType(UCell *cell, int type)
Add type to multi-type UT_DATATYPE cell.
Definition datatypes.c:414
int ur_isDatatype(const UCell *cell, const UCell *datatype)
Test if cell is of a certain datatype.
Definition datatypes.c:376
#define UR_FLAG_INT_HEX
This UCellId::flags bit indicates that an UR_INT value is printed as hexidecimal.
Definition urlan.h:80
int ur_markBuffer(UThread *, UIndex bufN)
Makes sure the buffer is marked as used.
Definition gc.c:326
@ UR_BIND_THREAD
Bound to buffer in thread dataStore.
Definition urlan.h:88
@ UR_BIND_USER
Start of user defined bindings.
Definition urlan.h:93
@ UR_BIND_UNBOUND
ur_setId() zeros binding so this is default.
Definition urlan.h:87
@ UR_BIND_ENV
Bound to buffer in shared env dataStore.
Definition urlan.h:89
@ UR_BIND_SELF
Evaluate to bound context rather than value.
Definition urlan.h:91
int32_t UIndex
This is an index into an array.
Definition urlan.h:150
void ur_arrErase(UBuffer *, int start, int count)
Remove elements from the array.
Definition array.c:137
void ur_arrReserve(UBuffer *, int count)
Allocates enough memory to hold count elements.
Definition array.c:98
This header provides fixed atoms which are always present.