modelica_metatype boxptr_stringUpdateStringChar(threadData_t *threadData,metamodelica_string str, metamodelica_string c, modelica_metatype iix) { int ix = MMC_UNTAGFIXNUM(iix); int length = 0; unsigned header = MMC_GETHDR(str); unsigned nwords = MMC_HDRSLOTS(header) + 1; struct mmc_string *p = NULL; void *res = NULL; MMC_CHECK_STRING(str); MMC_CHECK_STRING(c); /* fprintf(stderr, "stringUpdateStringChar(%s,%s,%ld)\n", MMC_STRINGDATA(str),MMC_STRINGDATA(c),ix); */ if (ix < 1 || MMC_STRLEN(c) != 1) MMC_THROW_INTERNAL(); length = MMC_STRLEN(str); if (ix > length) MMC_THROW_INTERNAL(); p = (struct mmc_string *) mmc_alloc_words_atomic(nwords); p->header = header; memcpy(p->data, MMC_STRINGDATA(str), length+1 /* include NULL */); p->data[ix-1] = MMC_STRINGDATA(c)[0]; res = MMC_TAGPTR(p); MMC_CHECK_STRING(res); return res; }
modelica_real nobox_stringReal(threadData_t *threadData,metamodelica_string s) { modelica_real res; char *endptr,*str=MMC_STRINGDATA(s); MMC_CHECK_STRING(s); errno = 0; res = strtod(str,&endptr); if (errno != 0 || str == endptr) MMC_THROW_INTERNAL(); if (*endptr != '\0') MMC_THROW_INTERNAL(); return res; }
modelica_metatype nobox_getGlobalRoot(threadData_t *threadData, modelica_integer ix) { void *val = 0; if (ix < 0 || ix >= MMC_GC_GLOBAL_ROOTS_SIZE) { MMC_THROW_INTERNAL(); } else if (ix > 8) { val = mmc_GC_state->global_roots[ix]; } else { val = threadData->localRoots[ix]; } if (!val) { MMC_THROW_INTERNAL(); } return val; }
modelica_integer nobox_stringInt(threadData_t *threadData,metamodelica_string s) { long res; char *endptr,*str=MMC_STRINGDATA(s); MMC_CHECK_STRING(s); errno = 0; res = strtol(str,&endptr,10); if (errno != 0 || str == endptr) MMC_THROW_INTERNAL(); if (*endptr != '\0') MMC_THROW_INTERNAL(); if (res > INT_MAX || res < INT_MIN) MMC_THROW_INTERNAL(); return res; }
modelica_metatype boxptr_listGet(threadData_t *threadData,modelica_metatype lst, modelica_metatype ii) { modelica_metatype res; int i = mmc_unbox_integer(ii); if (i < 1) MMC_THROW_INTERNAL(); while (!MMC_NILTEST(lst)) { if (i == 1) { return MMC_CAR(lst); } lst = MMC_CDR(lst); i--; } MMC_THROW_INTERNAL(); /* List was not long enough */ }
void boxptr_listSetFirst(threadData_t *threadData, modelica_metatype cellToDestroy, modelica_metatype newContent) { if (MMC_NILTEST(cellToDestroy)) { MMC_THROW_INTERNAL(); } MMC_CAR(cellToDestroy) = newContent; }
modelica_metatype boxptr_listHead(threadData_t *threadData, modelica_metatype lst) { if (!MMC_NILTEST(lst)) { return MMC_CAR(lst); } MMC_THROW_INTERNAL(); }
void boxptr_equality(threadData_t *threadData,modelica_metatype in1, modelica_metatype in2) { if (!valueEq(in1, in2)) { /* fprintf(stderr, "%s != %s\n", anyString(in1), anyString(in2)); */ MMC_THROW_INTERNAL(); } }
void omc_throw_function(threadData_t *threadData) { if (threadData) { MMC_THROW_INTERNAL(); } else { MMC_THROW(); } }
modelica_integer nobox_stringCharInt(threadData_t *threadData,metamodelica_string chr) { unsigned char c; if (MMC_STRLEN(chr) != 1) MMC_THROW_INTERNAL(); MMC_CHECK_STRING(chr); return (unsigned char) MMC_STRINGDATA(chr)[0]; }
static void omc_assert_compiler(threadData_t *threadData, FILE_INFO info, const char *msg, ...) { va_list args; va_start(args, msg); omc_assert_compiler_common(threadData, ErrorLevel_error, info, msg, args); va_end(args); MMC_THROW_INTERNAL(); }
modelica_metatype boxptr_stringHashDjb2Mod(threadData_t *threadData,modelica_metatype v,modelica_metatype mod) { modelica_integer modunbox = mmc_unbox_integer(mod); if (modunbox < 1) { MMC_THROW_INTERNAL(); } return mmc_mk_icon(stringHashDjb2Mod(v,modunbox)); }
metamodelica_string nobox_intStringChar(threadData_t *threadData,modelica_integer ix) { char chr[2]; if (ix < 1 || ix > 255) MMC_THROW_INTERNAL(); chr[0] = (char) ix; chr[1] = '\0'; return mmc_mk_scon(chr); }
modelica_metatype boxptr_stringGetStringChar(threadData_t *threadData,metamodelica_string str, modelica_metatype iix) { modelica_metatype res; int ix = MMC_UNTAGFIXNUM(iix); MMC_CHECK_STRING(str); if (ix < 1 || ix > (long) MMC_STRLEN(str)) MMC_THROW_INTERNAL(); return mmc_strings_len1[(size_t)MMC_STRINGDATA(str)[ix-1]]; }
void boxptr_setGlobalRoot(threadData_t *threadData, modelica_metatype i, modelica_metatype val) { int ix = mmc_unbox_integer(i); if (ix < 0 || ix >= MMC_GC_GLOBAL_ROOTS_SIZE) { MMC_THROW_INTERNAL(); } else if (ix > 8) { mmc_GC_state->global_roots[ix] = val; } else { threadData->localRoots[ix] = val; } }
modelica_metatype boxptr_listDelete(threadData_t *threadData, modelica_metatype lst, modelica_metatype iix) { /* TODO: If we assume the index exists we can do this in a much better way */ int ix = mmc_unbox_integer(iix); modelica_metatype *tmpArr = NULL; int i = 0; if (ix <= 0) { MMC_THROW_INTERNAL(); } tmpArr = (modelica_metatype *) GC_malloc(sizeof(modelica_metatype)*(ix-1)); /* We know the size of the first part of the list */ if (tmpArr == NULL) { fprintf(stderr, "%s:%d: malloc failed", __FILE__, __LINE__); EXIT(1); } for (i=0; i<ix-1; i++) { if (listEmpty(lst)) { if (tmpArr) { GC_free(tmpArr); } MMC_THROW_INTERNAL(); } tmpArr[i] = MMC_CAR(lst); lst = MMC_CDR(lst); } if (listEmpty(lst)) { GC_free(tmpArr); MMC_THROW_INTERNAL(); } lst = MMC_CDR(lst); for (i=ix-2; i>=0; i--) { lst = mmc_mk_cons(tmpArr[i], lst); } GC_free(tmpArr); return lst; }
void omc_assert_function(threadData_t* threadData, FILE_INFO info, const char *msg, ...) { va_list ap; va_start(ap,msg); printInfo(stderr, info); fputs("Modelica Assert: ", stderr); vfprintf(stderr,msg,ap); fputs("!\n", stderr); va_end(ap); fflush(NULL); if (threadData) { MMC_THROW_INTERNAL(); } else { MMC_THROW(); } }
modelica_metatype boxptr_substring(threadData_t *threadData, metamodelica_string_const str, modelica_metatype boxstart, modelica_metatype boxstop) { unsigned header = 0, nwords; long start = MMC_UNTAGFIXNUM(boxstart) - 1; long stop = MMC_UNTAGFIXNUM(boxstop) - 1; long totalLen = MMC_STRLEN(str), len = stop-start+1; struct mmc_string *res; char *tmp; modelica_metatype p; /* Bad indexes */ if (start < 0 || start >= totalLen || stop < start || stop >= totalLen) { MMC_THROW_INTERNAL(); } header = MMC_STRINGHDR(len); nwords = MMC_HDRSLOTS(header) + 1; res = (struct mmc_string *) mmc_alloc_words_atomic(nwords); res->header = header; tmp = (char*) res->data; memcpy(tmp, MMC_STRINGDATA(str) + start, len); tmp[len] = '\0'; p = MMC_TAGPTR(res); MMC_CHECK_STRING(p); return p; }
modelica_integer nobox_stringGet(threadData_t *threadData,metamodelica_string str, modelica_integer ix) { if (ix < 1 || ix > (long) MMC_STRLEN(str)) MMC_THROW_INTERNAL(); return ((unsigned char*)MMC_STRINGDATA(str))[ix-1]; }