/* load executable name */ static int evalload(Xpost_Context *ctx) { int ret; if (_xpost_interpreter_is_tracing) { Xpost_Object s = xpost_name_get_string(ctx, xpost_stack_topdown_fetch(ctx->lo, ctx->es, 0)); XPOST_LOG_DUMP("evalload <name \"%*s\">", s.comp_.sz, xpost_string_get_pointer(ctx, s)); } if (!xpost_stack_push(ctx->lo, ctx->os, xpost_stack_pop(ctx->lo, ctx->es))) return stackoverflow; assert(ctx->gl->base); /*xpost_operator_exec(ctx, xpost_operator_cons(ctx, "load", NULL,0,0).mark_.padw); */ ret = xpost_operator_exec(ctx, ctx->opcode_shortcuts.load); if (ret) return ret; if (xpost_object_is_exe(xpost_stack_topdown_fetch(ctx->lo, ctx->os, 0))) { Xpost_Object q; q = xpost_stack_pop(ctx->lo, ctx->os); if (xpost_object_get_type(q) == invalidtype) return undefined; if (!xpost_stack_push(ctx->lo, ctx->es, q)) return ret; } return 0; }
/* any string cvs string convert any object to string representation */ static int AScvs (Xpost_Context *ctx, Xpost_Object any, Xpost_Object str) { char nostringval[] = "-nostringval-"; char strue[] = "true"; char sfalse[] = "false"; char smark[] = "-mark-"; char ssave[] = "-save-"; int n; int ret; switch(xpost_object_get_type(any)) { default: if (str.comp_.sz < sizeof(nostringval)-1) return rangecheck; memcpy(xpost_string_get_pointer(ctx, str), nostringval, sizeof(nostringval)-1); str.comp_.sz = sizeof(nostringval)-1; break; case savetype: if (str.comp_.sz < sizeof(ssave)-1) return rangecheck; memcpy(xpost_string_get_pointer(ctx, str), ssave, sizeof(ssave)-1); str.comp_.sz = sizeof(ssave)-1; break; case marktype: if (str.comp_.sz < sizeof(smark)-1) return rangecheck; memcpy(xpost_string_get_pointer(ctx, str), smark, sizeof(smark)-1); str.comp_.sz = sizeof(smark)-1; break; case booleantype: { if (any.int_.val) { if (str.comp_.sz < sizeof(strue)-1) return rangecheck; memcpy(xpost_string_get_pointer(ctx, str), strue, sizeof(strue)-1); str.comp_.sz = sizeof(strue)-1; } else { if (str.comp_.sz < sizeof(sfalse)-1) return rangecheck; memcpy(xpost_string_get_pointer(ctx, str), sfalse, sizeof(sfalse)-1); str.comp_.sz = sizeof(sfalse)-1; } } break; case integertype: { //n = conv_rad(any.int_.val, 10, xpost_string_get_pointer(ctx, str), str.comp_.sz); char *s = xpost_string_get_pointer(ctx, str); int sz = str.comp_.sz; n = 0; if (any.int_.val < 0) { s[n++] = '-'; any.int_.val = abs(any.int_.val); --sz; } n += conv_integ((real)any.int_.val, s + n, sz); if (n == -1) return rangecheck; if (n < str.comp_.sz) str.comp_.sz = n; break; } case realtype: n = conv_real(any.real_.val, xpost_string_get_pointer(ctx, str), str.comp_.sz); if (n == -1) return rangecheck; if (n < str.comp_.sz) str.comp_.sz = n; break; case operatortype: { unsigned int optadr; Xpost_Operator *optab; Xpost_Operator op; Xpost_Object_Mark nm; ret = xpost_memory_table_get_addr(ctx->gl, XPOST_MEMORY_TABLE_SPECIAL_OPERATOR_TABLE, &optadr); if (!ret) { XPOST_LOG_ERR("cannot load optab!"); return VMerror; } optab = (void *)(ctx->gl->base + optadr); op = optab[any.mark_.padw]; nm.tag = nametype | XPOST_OBJECT_TAG_DATA_FLAG_BANK; nm.pad0 = 0; nm.padw = op.name; any.mark_ = nm; } /*@fallthrough@*/ case nametype: any = xpost_name_get_string(ctx, any); /*@fallthrough@*/ case stringtype: if (any.comp_.sz > str.comp_.sz) return rangecheck; if (any.comp_.sz < str.comp_.sz) str.comp_.sz = any.comp_.sz; memcpy(xpost_string_get_pointer(ctx, str), xpost_string_get_pointer(ctx, any), any.comp_.sz); break; } xpost_stack_push(ctx->lo, ctx->os, str); return 0; }