|
@@ -136,6 +136,90 @@ ResultType vm_quit(O_FUNC){
|
|
|
return R_error;
|
|
|
}
|
|
|
|
|
|
+ResultType vm_exec(O_FUNC){
|
|
|
+ ArgumentParser ap[] = {{.type=name_value, .name=L"cm", .must=1, .long_arg=false},
|
|
|
+ {.type=name_value, .name=L"var", .must=0, .long_arg=false},
|
|
|
+ {.type=name_value, .name=L"out", .must=0, .long_arg=false},
|
|
|
+ {.must=-1}};
|
|
|
+ LinkValue *str;
|
|
|
+ LinkValue *var;
|
|
|
+ LinkValue *out;
|
|
|
+ bool out_;
|
|
|
+ Statement *new_st;
|
|
|
+ VarList *run;
|
|
|
+
|
|
|
+ setResultCore(result);
|
|
|
+ parserArgumentUnion(ap, arg, CNEXT_NT);
|
|
|
+ if (!CHECK_RESULT(result))
|
|
|
+ return result->type;
|
|
|
+ freeResult(result);
|
|
|
+
|
|
|
+ str = ap[0].value;
|
|
|
+ var = ap[1].value;
|
|
|
+ out = ap[2].value;
|
|
|
+ if (str->value->type != V_str) {
|
|
|
+ setResultError(E_TypeException, ONLY_ACC(cm, str), LINEFILE, true, CNEXT_NT);
|
|
|
+ return result->type;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (var != NULL && var->value->type != V_dict) {
|
|
|
+ setResultError(E_TypeException, ONLY_ACC(var, dict), LINEFILE, true, CNEXT_NT);
|
|
|
+ return R_error;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (out != NULL) {
|
|
|
+ if (out->value->type != V_bool) {
|
|
|
+ setResultError(E_TypeException, ONLY_ACC(out, bool), LINEFILE, true, CNEXT_NT);
|
|
|
+ return R_error;
|
|
|
+ } else if (var == NULL) {
|
|
|
+ setResultError(E_TypeException, L"missing parameters: var", LINEFILE, true, CNEXT_NT);
|
|
|
+ return R_error;
|
|
|
+ }
|
|
|
+ out_ = out->value->data.bool_.bool_;
|
|
|
+ } else
|
|
|
+ out = false;
|
|
|
+
|
|
|
+ {
|
|
|
+ ParserMessage *pm = makeParserMessageStr(str->value->data.str.str);
|
|
|
+ new_st = makeStatement(0, "exec");
|
|
|
+ parserCommandList(pm, inter, true, false, new_st);
|
|
|
+
|
|
|
+ if (pm->status == int_error) {
|
|
|
+ setResultError(E_KeyInterrupt, KEY_INTERRUPT, LINEFILE, true, CNEXT_NT);
|
|
|
+ return R_error;
|
|
|
+ }
|
|
|
+ else if (pm->status != success) {
|
|
|
+ wchar_t *wcs_message = memStrToWcs(pm->status_message, false);
|
|
|
+ setResultError(E_TypeException, wcs_message, LINEFILE, true, CNEXT_NT);
|
|
|
+ memFree(wcs_message);
|
|
|
+ return R_error;
|
|
|
+ }
|
|
|
+
|
|
|
+ freeParserMessage(pm, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (var != NULL) {
|
|
|
+ run = makeVarList(inter, false);
|
|
|
+ run->hashtable = var->value->data.dict.dict;
|
|
|
+ if (out)
|
|
|
+ run->next = var_list;
|
|
|
+ else
|
|
|
+ gc_freeze(inter, var_list, run, true);
|
|
|
+ } else
|
|
|
+ run = var_list;
|
|
|
+
|
|
|
+ includeSafeInterStatement(CFUNC(new_st, run, result, belong));
|
|
|
+ freeStatement(new_st);
|
|
|
+
|
|
|
+ if (var != NULL) {
|
|
|
+ if (!out)
|
|
|
+ gc_freeze(inter, var_list, run, false);
|
|
|
+ freeVarList(run);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result->type;
|
|
|
+}
|
|
|
+
|
|
|
void registeredSysFunction(R_FUNC){
|
|
|
NameFunc tmp[] = {{L"super", vm_super, free_},
|
|
|
{L"freemethod", vm_freemethod, free_},
|
|
@@ -151,6 +235,7 @@ void registeredSysFunction(R_FUNC){
|
|
|
{L"isnowrun", vm_isnowrun, free_},
|
|
|
{L"disnowrun", vm_disnowrun, free_},
|
|
|
{L"quit", vm_quit, free_},
|
|
|
+ {L"exec", vm_exec, free_},
|
|
|
{NULL, NULL}};
|
|
|
iterBaseNameFunc(tmp, belong, CFUNC_CORE(var_list));
|
|
|
}
|