static void first_and_last_instructions(word**first, word **last, mlval codepointer) { mlval codeobject = FOLLOWBACK(codepointer); mlval ancillaries = CCVANCILLARY(codeobject); mlval profiles = FIELD(ancillaries,ANC_PROFILES); size_t length = NFIELDS(profiles); unsigned int codenumber = CCODENUMBER(codepointer); *first = (word*) (codepointer-POINTER+8); *last = NULL; if (length == codenumber+1) { mlval header = *(mlval*)(codeobject-POINTER); *last = ((word*) (codeobject-POINTER))+LENGTH(header)-1; } else { word *p = *first; size_t offset = (codepointer-codeobject+8); for(; p+=2, offset += 8; ) { word w = *p; if (SECONDARY(w) == BACKPTR && LENGTH(w) == offset) { *last = p-1; break; } } if (*last == NULL) error ("no backptr found!\n"); } }
extern int pc_in_closure(word pc, mlval clos) { mlval code = FIELD(clos,0); word code_start = (word)CCODESTART(code); /* is it after the start of this function ? */ if (pc >= code_start) { mlval codeobj = FOLLOWBACK(code); word code_end = ((word)OBJECT(codeobj)) + (LENGTH(OBJECT(codeobj)[0]) << 2); /* is it before the end of this code object ? */ if (pc < code_end) { int codenum = CCODENUMBER(code); int codes = NFIELDS(FIELD(CCVANCILLARY(codeobj), ANC_NAMES)); if (codes != codenum+1) { if (FIELD(clos,1) == 0) { /* so we are in a shared closure; not the case for stub_c */ mlval nextcode = FIELD(clos,2); if (nextcode > code) { code_end = (word)CCODESTART(nextcode); /* is it after the end of this code item ? */ if (pc >= code_end) return 0; } else { error("code vectors in wrong order"); } } } return 1; } } return 0; }
extern void ml2c_tuple(MLvalue val, MLvalue *result) { int i, len; mlval tup; tup = TO_mlval(val); len = NFIELDS(tup); for (i=0; i < len; i++){ result[i] = TO_MLvalue(FIELD(tup,i)); }; }
mxArray * hikm_to_matlab (VlHIKMTree * tree) { int K = vl_hikm_get_K (tree) ; int depth = vl_hikm_get_depth (tree) ; mwSize dims [2] = {1, 1} ; mxArray *mtree ; const char *field_names[] = {"K", "depth", "centers", "sub"} ; /* Create the main struct array */ mtree = mxCreateStructArray (2, dims, NFIELDS(field_names), field_names) ; mxSetField (mtree, 0, "K", mxCreateDoubleScalar (K)) ; mxSetField (mtree, 0, "depth", mxCreateDoubleScalar (depth)) ; if (tree->root) xcreate (mtree, 0, tree->root) ; return mtree; }
extern int ml2c_tuple_length(MLvalue val) { return( NFIELDS(TO_mlval(val)) ); }