RML_END_LABEL /* misc_tick.c */ RML_BEGIN_LABEL(RML__tick) { static rml_sint_t counter; rmlA0 = RML_IMMEDIATE(RML_TAGFIXNUM(counter)); ++counter; RML_TAILCALLK(rmlSC); }
RML_END_LABEL RML_BEGIN_LABEL(External__strcmp) { char *str1 = RML_STRINGDATA(rmlA0); char *str2 = RML_STRINGDATA(rmlA1); int result = strcmp(str1, str2); rmlA0 = RML_IMMEDIATE(RML_TAGFIXNUM(result)); RML_TAILCALLK(rmlSC); }
RML_END_LABEL /* list_length.c */ RML_BEGIN_LABEL(RML__list_5flength) { void *lst = rmlA0; rml_uint_t len = 0; for(; RML_GETHDR(lst) == RML_CONSHDR; ++len, lst = RML_CDR(lst)) ; rmlA0 = RML_IMMEDIATE(RML_TAGFIXNUM(len)); RML_TAILCALLK(rmlSC); }
RML_END_LABEL /* list-delete.c */ RML_BEGIN_LABEL(RML__list_5fdelete) { rml_sint_t nelts = RML_UNTAGFIXNUM(rmlA1); if( nelts < 0 ) RML_TAILCALLK(rmlFC); else if( nelts == 0 ) { if( RML_GETHDR(rmlA0) == RML_CONSHDR ) rmlA0 = RML_CDR(rmlA0); else RML_TAILCALLK(rmlFC); } else { /* nelts > 0 */ void **chunk = (void**)rml_prim_alloc(3*nelts, 1); void *lst = rmlA0; rmlA0 = RML_TAGPTR(chunk); for(;;) { if( RML_GETHDR(lst) == RML_CONSHDR ) { if( nelts == 0 ) { chunk[-1] = RML_CDR(lst); break; } else { chunk[0] = RML_IMMEDIATE(RML_CONSHDR); chunk[1] = RML_CAR(lst); chunk[2] = RML_TAGPTR(chunk + 3); lst = RML_CDR(lst); chunk += 3; --nelts; continue; } } else /* NIL */ RML_TAILCALLK(rmlFC); } } /* return resulting list */ RML_TAILCALLK(rmlSC); }
RML_END_LABEL RML_BEGIN_LABEL(RML__list_5fmap) { rml_uint_t nelts; void *lst = rmlA0; void *function = rmlA1; /* count the number of elements in the first list */ nelts = 0; while( RML_GETHDR(lst) == RML_CONSHDR ) { lst = RML_CDR(lst); ++nelts; } /* call the relation, to build the second list */ if( nelts == 0 ) { /* do nothing, return nil */ } else { void **chunk = (void**)rml_prim_alloc(3*nelts, 2); lst = rmlA0; rmlA0 = RML_TAGPTR(chunk); do { chunk[0] = RML_IMMEDIATE(RML_CONSHDR); rmlA0 = RML_CAR(lst); /* element */; RML_TAILCALL(rmlA1 /* fn */,1); chunk[1] = rmlA0; chunk[2] = RML_TAGPTR(chunk + 3); lst = RML_CDR(lst); chunk += 3; } while( --nelts != 0 ); } /* return resulting list */ RML_TAILCALLK(rmlSC); }
void *mk_icon(int i) { return RML_IMMEDIATE(RML_TAGFIXNUM((rml_sint_t)i)); }