123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011 |
- #include "__run.h"
- static bool checkNumber(INTER_FUNCTIONSIG){
- if (!isType(result->value->value, number)) {
- setResultErrorSt(E_TypeException, "Don't get a number value", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
- return false;
- }
- return true;
- }
- static bool checkString(INTER_FUNCTIONSIG){
- if (!isType(result->value->value, string)) {
- setResultErrorSt(E_TypeException, "Don't get a string value", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
- return false;
- }
- return true;
- }
- static bool checkBool(Value *value){
- switch (value->type) {
- case number:
- return value->data.num.num != 0;
- case string:
- return memStrlen(value->data.str.str) > 0;
- case bool_:
- return value->data.bool_.bool_;
- case pass_:
- case none:
- return false;
- case list:
- return value->data.list.size > 0;
- case dict:
- return value->data.dict.size > 0;
- default:
- return true;
- }
- }
- void newBranchYield(Statement *branch_st, Statement *node, StatementList *sl_node, VarList *new_var, enum StatementInfoStatus status, Inter *inter){
- if (new_var != NULL)
- new_var->next = NULL;
- gc_freeze(inter, new_var, NULL, true);
- branch_st->info.var_list = new_var;
- branch_st->info.node = node->type == yield_code ? node->next : node;
- branch_st->info.branch.sl_node = sl_node;
- branch_st->info.branch.status = status;
- branch_st->info.have_info = true;
- }
- void newWithBranchYield(Statement *branch_st, Statement *node, StatementList *sl_node, VarList *new_var, enum StatementInfoStatus status,
- Inter *inter, LinkValue *value, LinkValue *_exit_, LinkValue *_enter_){
- newBranchYield(branch_st, node, sl_node, new_var, status, inter);
- branch_st->info.branch.with_.value = value;
- branch_st->info.branch.with_._exit_ = _exit_;
- branch_st->info.branch.with_._enter_ = _enter_;
- }
- void newForBranchYield(Statement *branch_st, Statement *node, StatementList *sl_node, VarList *new_var, enum StatementInfoStatus status,
- Inter *inter, LinkValue *iter){
- newBranchYield(branch_st, node, sl_node, new_var, status, inter);
- branch_st->info.branch.for_.iter = iter;
- }
- void updateBranchYield(Statement *branch_st, Statement *node, StatementList *sl_node, enum StatementInfoStatus status){
- branch_st->info.node = node->type == yield_code ? node->next : node;
- branch_st->info.branch.sl_node = sl_node;
- branch_st->info.branch.status = status;
- branch_st->info.have_info = true;
- }
- ResultType ifBranch(INTER_FUNCTIONSIG) {
- StatementList *if_list = st->u.if_branch.if_list;
- Statement *else_st = st->u.if_branch.else_list;
- Statement *finally = st->u.if_branch.finally;
- Statement *info_vl = NULL;
- bool set_result = true;
- bool is_rego = false;
- bool yield_run = false;
- enum StatementInfoStatus result_from = info_vl_branch;
- Result finally_tmp;
- setResultCore(result);
- setResultCore(&finally_tmp);
- yield_run = popStatementVarList(st, &var_list, var_list, inter);
- if (yield_run && st->info.branch.status == info_vl_branch){
- if_list = st->info.branch.sl_node;
- info_vl = st->info.node;
- }
- else if (yield_run && st->info.branch.status == info_else_branch){
- if_list = NULL;
- else_st = st->info.node;
- }
- else if (yield_run && st->info.branch.status == info_finally_branch){
- finally = st->info.node;
- goto not_else;
- }
- for (PASS; if_list != NULL; if_list = if_list->next){
- freeResult(result);
- if (info_vl != NULL){
- if (ifBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(info_vl, var_list, result, belong))){
- set_result = false;
- goto not_else;
- }
- if (result->type == rego_return)
- is_rego = true;
- freeResult(result);
- info_vl = NULL;
- }
- else if (if_list->type == if_b){
- LinkValue *condition_value = NULL;
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(if_list->condition, var_list, result, belong))){
- set_result = false;
- goto not_else;
- }
- condition_value = result->value;
- freeResult(result);
- if (if_list->var != NULL) {
- assCore(if_list->var, condition_value, false, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
- if (!CHECK_RESULT(result)){
- set_result = false;
- goto not_else;
- }
- freeResult(result);
- }
- bool condition = is_rego ? true : checkBool(condition_value->value); // 若是rego则不执行checkbool的判断了
- if (condition){
- is_rego = false;
- if (ifBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(if_list->code, var_list, result, belong))){
- set_result = false;
- goto not_else;
- }
- if (result->type == rego_return)
- is_rego = true;
- else {
- freeResult(result);
- goto not_else;
- }
- freeResult(result);
- }
- }
- else{
- if (ifBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(if_list->code, var_list, result, belong))){
- set_result = false;
- goto not_else;
- }
- if (result->type == rego_return)
- is_rego = true;
- freeResult(result);
- }
- }
- if (else_st != NULL && ifBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(else_st, var_list, result, belong))) {
- set_result = false;
- result_from = info_else_branch;
- }
- else
- freeResult(result);
- not_else:
- if (finally != NULL && ifBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(finally, var_list, &finally_tmp, belong))){
- if (!set_result)
- freeResult(result);
- set_result = false;
- result_from = info_finally_branch;
- *result = finally_tmp;
- }
- else
- freeResult(&finally_tmp);
- if (yield_run)
- if (result->type == yield_return)
- updateBranchYield(st, result->node, if_list, result_from);
- else
- freeRunInfo(st);
- else
- if (result->type == yield_return)
- newBranchYield(st, result->node, if_list, var_list, result_from, inter);
- else
- var_list = popVarList(var_list);
- if (set_result)
- setResult(result, inter, belong);
- return result->type;
- }
- ResultType whileBranch(INTER_FUNCTIONSIG) {
- StatementList *while_list = st->u.while_branch.while_list;
- Statement *first = st->u.while_branch.first;
- Statement *after = st->u.while_branch.after;
- Statement *else_st = st->u.while_branch.else_list;
- Statement *finally = st->u.while_branch.finally;
- Statement *info_vl = NULL;
- Statement *after_vl = NULL;
- bool set_result = true;
- bool is_break = false;
- bool do_while = st->u.while_branch.type == do_while_;
- int yield_run = false;
- enum StatementInfoStatus result_from = info_vl_branch;
- Result finally_tmp;
- setResultCore(result);
- setResultCore(&finally_tmp);
- yield_run = popStatementVarList(st, &var_list, var_list, inter);
- if (yield_run && st->info.branch.status == info_first_do)
- first = st->info.node;
- else if (yield_run && st->info.branch.status == info_vl_branch){
- first = NULL;
- info_vl = st->info.node;
- }
- else if (yield_run && st->info.branch.status == info_after_do){
- first = NULL;
- after_vl = st->info.node;
- }
- else if (yield_run && st->info.branch.status == info_else_branch){
- else_st = st->info.node;
- goto run_else;
- }
- else if (yield_run && st->info.branch.status == info_finally_branch){
- finally = st->info.node;
- goto not_else;
- }
- if (first != NULL && cycleBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(first, var_list, result, belong))) {
- result_from = info_first_do;
- set_result = false;
- }
- else
- freeResult(result);
- while (!is_break){
- LinkValue *condition_value = NULL;
- Statement *after_st = after;
- Statement *while_st = while_list->code;
- bool condition = false;
- freeResult(result);
- if (info_vl != NULL){
- while_st = info_vl;
- info_vl = NULL;
- goto do_while_st;
- }
- else if (after_vl != NULL){
- after_st = after_vl;
- after_vl = NULL;
- goto do_after;
- }
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(while_list->condition, var_list, result, belong))){
- set_result = false;
- goto not_else;
- }
- condition_value = result->value;
- freeResult(result);
- if (while_list->var != NULL){
- assCore(while_list->var, condition_value, false, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
- if (!CHECK_RESULT(result)){
- set_result = false;
- goto not_else;
- }
- freeResult(result); // 赋值的返回值被丢弃
- }
- condition = do_while || checkBool(condition_value->value);
- do_while = false;
- if (condition){
- do_while_st:
- if (cycleBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(while_st, var_list, result, belong))){
- set_result = false;
- goto not_else;
- }
- else if (result->type == break_return)
- is_break = true;
- freeResult(result);
- }
- else
- break;
- do_after:
- if (after_st == NULL)
- continue;
- if (cycleBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(after_st, var_list, result, belong))){
- result_from = info_after_do;
- set_result = false;
- goto not_else;
- }
- else if (result->type == break_return) {
- freeResult(result);
- goto not_else;
- }
- freeResult(result);
- }
- run_else:
- if (!is_break && else_st != NULL && cycleBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(else_st, var_list, result, belong))) {
- result_from = info_else_branch;
- set_result = false;
- }
- else
- freeResult(result);
- not_else:
- if (finally != NULL && cycleBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(finally, var_list, &finally_tmp, belong))){
- if (!set_result)
- freeResult(result);
- set_result = false;
- result_from = info_finally_branch;
- *result = finally_tmp;
- }
- else
- freeResult(&finally_tmp);
- if (yield_run)
- if (result->type == yield_return)
- updateBranchYield(st, result->node, while_list, result_from);
- else
- freeRunInfo(st);
- else
- if (result->type == yield_return)
- newBranchYield(st, result->node, while_list, var_list, result_from, inter);
- else
- var_list = popVarList(var_list);
- if (set_result)
- setResult(result, inter, belong);
- return result->type;
- }
- ResultType forBranch(INTER_FUNCTIONSIG) {
- StatementList *for_list = st->u.for_branch.for_list;
- Statement *first = st->u.for_branch.first_do;
- Statement *after = st->u.for_branch.after_do;
- Statement *else_st = st->u.for_branch.else_list;
- Statement *finally = st->u.for_branch.finally;
- LinkValue *iter = NULL;
- Statement *info_vl = NULL;
- Statement *after_vl = NULL;
- bool set_result = true;
- bool is_break = false;
- bool do_while = st->u.while_branch.type == do_while_;
- int yield_run = false;
- enum StatementInfoStatus result_from = info_vl_branch;
- Result finally_tmp;
- setResultCore(result);
- setResultCore(&finally_tmp);
- yield_run = popStatementVarList(st, &var_list, var_list, inter);
- if (yield_run && st->info.branch.status == info_first_do)
- first = st->info.node;
- else if (yield_run && st->info.branch.status == info_vl_branch){
- first = NULL;
- info_vl = st->info.node;
- iter = st->info.branch.for_.iter;
- goto do_for;
- }
- else if (yield_run && st->info.branch.status == info_after_do){
- first = NULL;
- after_vl = st->info.node;
- iter = st->info.branch.for_.iter;
- goto do_for;
- }
- else if (yield_run && st->info.branch.status == info_else_branch){
- else_st = st->info.node;
- goto run_else;
- }
- else if (yield_run && st->info.branch.status == info_finally_branch){
- finally = st->info.node;
- goto not_else;
- }
- if (first != NULL && cycleBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(first, var_list, result, belong))) {
- result_from = info_first_do;
- set_result = false;
- }
- else if (first != NULL)
- freeResult(result);
- {
- LinkValue *tmp = NULL; // TODD-szh 要释放
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(for_list->condition, var_list, result, belong))){
- set_result = false;
- goto not_else;
- }
- tmp = result->value;
- result->value = NULL;
- freeResult(result);
- getIter(tmp, 1, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
- gc_freeTmpLink(&tmp->gc_status);
- if (!CHECK_RESULT(result)) {
- set_result = false;
- goto not_else;
- }
- iter = result->value;
- result->value = NULL;
- }
- do_for:
- while (!is_break){
- Statement *for_st = for_list->code;
- Statement *after_st = after;
- freeResult(result);
- if (info_vl != NULL){
- for_st = info_vl;
- info_vl = NULL;
- goto do_for_st;
- }
- else if (after_vl != NULL){
- after_st = after_vl;
- after_vl = NULL;
- goto do_after;
- }
- {
- LinkValue *element = NULL;
- getIter(iter, 0, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
- if (!CHECK_RESULT(result)) {
- if (result->value->value == inter->data.iterstop_exc || checkAttribution(result->value->value, inter->data.iterstop_exc)){
- freeResult(result);
- break;
- } else {
- set_result = false;
- goto not_else;
- }
- }
- element = result->value;
- result->value = NULL;
- freeResult(result);
- assCore(for_list->var, element, false, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
- gc_freeTmpLink(&element->gc_status);
- if (!CHECK_RESULT(result)){
- set_result = false;
- goto not_else;
- }
- freeResult(result);
- }
- do_for_st:
- if (cycleBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(for_st, var_list, result, belong))){
- result_from = info_vl_branch;
- set_result = false;
- goto not_else;
- }
- else if (result->type == break_return)
- is_break = true;
- freeResult(result);
- if (after_st == NULL)
- continue;
- do_after:
- if (cycleBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(after_st, var_list, result, belong))){
- result_from = info_after_do;
- set_result = false;
- goto not_else;
- }
- else if (result->type == break_return) {
- freeResult(result);
- goto not_else;
- }
- freeResult(result);
- }
- run_else:
- if (!is_break && else_st != NULL && cycleBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(else_st, var_list, result, belong))) {
- result_from = info_else_branch;
- set_result = false;
- }
- else
- freeResult(result);
- not_else:
- if (finally != NULL && cycleBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(finally, var_list, &finally_tmp, belong))){
- if (!set_result)
- freeResult(result);
- set_result = false;
- result_from = info_finally_branch;
- *result = finally_tmp;
- }
- else
- freeResult(&finally_tmp);
- if (yield_run) {
- if (result->type == yield_return)
- if (result_from == info_finally_branch) {
- freeRunInfo(st);
- newBranchYield(st, result->node, for_list, var_list, result_from, inter);
- } else
- updateBranchYield(st, result->node, for_list, result_from);
- else
- freeRunInfo(st);
- iter = NULL;
- } else {
- if (result->type == yield_return)
- if (result_from == info_finally_branch)
- newBranchYield(st, result->node, for_list, var_list, result_from, inter);
- else {
- newForBranchYield(st, result->node, for_list, var_list, result_from, inter, iter);
- iter = NULL;
- }
- else {
- popVarList(var_list);
- }
- }
- if (iter != NULL)
- gc_freeTmpLink(&iter->gc_status);
- if (set_result)
- setResult(result, inter, belong);
- return result->type;
- }
- ResultType withBranch(INTER_FUNCTIONSIG) {
- StatementList *with_list = st->u.with_branch.with_list;
- Statement *else_st = st->u.with_branch.else_list;
- Statement *finally = st->u.with_branch.finally;
- Statement *vl_info = NULL;
- VarList *new = NULL;
- LinkValue *_enter_ = NULL;
- LinkValue *_exit_ = NULL;
- LinkValue *value = NULL;
- LinkValue *with_belong = belong;
- bool set_result = true;
- bool yield_run;
- enum StatementInfoStatus result_from = info_vl_branch;
- Result finally_tmp;
- Result else_tmp;
- Result exit_tmp;
- setResultCore(result);
- setResultCore(&finally_tmp);
- setResultCore(&else_tmp);
- setResultCore(&exit_tmp);
- if ((yield_run = st->info.have_info)){
- value = st->info.branch.with_.value;
- _enter_ = st->info.branch.with_._enter_;
- _exit_ = st->info.branch.with_._exit_;
- if (st->info.var_list != NULL) {
- new = st->info.var_list;
- new->next = var_list;
- }
- if (st->info.branch.status == info_vl_branch)
- vl_info = st->info.node;
- else if (st->info.branch.status == info_else_branch) {
- else_st = st->info.node;
- goto run_else;
- }
- else if (st->info.branch.status == info_finally_branch){
- finally = st->info.node;
- goto run_finally;
- }
- }
- else {
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(with_list->condition, var_list, result, belong))) {
- set_result = false;
- goto run_finally;
- }
- if (with_list->var == NULL) {
- with_belong = result->value;
- new = copyVarListCore(result->value->value->object.var, inter);
- new->next = var_list;
- freeResult(result);
- } else {
- LinkValue *enter_value = NULL;
- value = result->value;
- result->value = NULL;
- _enter_ = findAttributes(inter->data.object_enter, false, value, inter);
- _exit_ = findAttributes(inter->data.object_exit, false, value, inter);
- freeResult(result);
- if (_enter_ == NULL || _exit_ == NULL) {
- gc_freeTmpLink(&value->gc_status);
- _enter_ = NULL;
- _exit_ = NULL;
- value = NULL;
- setResultErrorSt(E_TypeException, "Get Not Support Value to Enter with", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
- set_result = false;
- goto run_finally;
- }
- gc_addTmpLink(&_enter_->gc_status);
- gc_addTmpLink(&_exit_->gc_status);
- callBackCore(_enter_, NULL, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, value));
- if (!CHECK_RESULT(result)) {
- set_result = false;
- gc_freeTmpLink(&value->gc_status);
- gc_freeTmpLink(&_enter_->gc_status);
- gc_freeTmpLink(&_exit_->gc_status);
- goto run_finally;
- }
- new = pushVarList(var_list, inter);
- enter_value = result->value;
- freeResult(result);
- assCore(with_list->var, enter_value, false, false, CALL_INTER_FUNCTIONSIG_NOT_ST(new, result, belong));
- if (!CHECK_RESULT(result)) {
- set_result = false;
- popVarList(new);
- gc_freeTmpLink(&value->gc_status);
- gc_freeTmpLink(&_enter_->gc_status);
- gc_freeTmpLink(&_exit_->gc_status);
- goto run_finally;
- }
- freeResult(result);
- }
- }
- gc_freeze(inter, new, var_list, true);
- if (vl_info == NULL)
- vl_info = with_list->code;
- if (tryBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(vl_info, new, result, with_belong))) {
- set_result = false;
- if (result->type == yield_return)
- goto run_finally;
- }
- else
- freeResult(result);
- run_else:
- if (else_st != NULL && tryBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(else_st, new, &else_tmp, with_belong))) {
- if (!set_result)
- freeResult(result);
- set_result = false;
- *result = else_tmp;
- result_from = info_else_branch;
- if (result->type == yield_return)
- goto run_finally;
- }
- else
- freeResult(&else_tmp);
- if (_exit_ != NULL) {
- callBackCore(_exit_, NULL, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, &exit_tmp, value));
- if (!RUN_TYPE(exit_tmp.type)) {
- if (!set_result)
- freeResult(result);
- set_result = false;
- *result = exit_tmp;
- }
- else
- freeResult(&exit_tmp);
- if (!yield_run){
- gc_freeTmpLink(&value->gc_status);
- gc_freeTmpLink(&_enter_->gc_status);
- gc_freeTmpLink(&_exit_->gc_status);
- }
- }
- run_finally:
- if (finally != NULL && tryBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(finally, var_list, &finally_tmp, belong))){
- if (!set_result)
- freeResult(result);
- set_result = false;
- *result = finally_tmp;
- result_from = info_finally_branch;
- }
- else
- freeResult(&finally_tmp);
- gc_freeze(inter, new, var_list, false);
- if (yield_run)
- if (result->type == yield_return)
- if (result_from == info_finally_branch) {
- freeRunInfo(st);
- newBranchYield(st, result->node, with_list, NULL, result_from, inter);
- }
- else
- updateBranchYield(st, result->node, with_list, result_from);
- else
- freeRunInfo(st);
- else {
- if (result->type == yield_return)
- if (result_from == info_finally_branch) {
- if (value != NULL) {
- gc_freeTmpLink(&value->gc_status);
- gc_freeTmpLink(&_enter_->gc_status);
- gc_freeTmpLink(&_exit_->gc_status);
- }
- newBranchYield(st, result->node, with_list, NULL, result_from, inter);
- popVarList(new);
- }
- else
- newWithBranchYield(st, result->node, with_list, new, result_from, inter, value, _exit_, _enter_);
- else
- popVarList(new);
- }
- if (set_result)
- setResult(result, inter, belong);
- return result->type;
- }
- ResultType tryBranch(INTER_FUNCTIONSIG) {
- StatementList *except_list = st->u.try_branch.except_list;
- Statement *try = st->u.try_branch.try;
- Statement *else_st = st->u.try_branch.else_list;
- Statement *finally = st->u.try_branch.finally;
- Statement *info_vl = NULL;
- LinkValue *error_value = NULL;
- bool set_result = true;
- bool yield_run;
- enum StatementInfoStatus result_from = info_first_do;
- Result finally_tmp;
- setResultCore(result);
- setResultCore(&finally_tmp);
- yield_run = popStatementVarList(st, &var_list, var_list, inter);
- if (yield_run && st->info.branch.status == info_first_do)
- try = st->info.node;
- else if (yield_run && st->info.branch.status == info_vl_branch){
- try = NULL;
- info_vl = st->info.node;
- goto run_except;
- }
- else if (yield_run && st->info.branch.status == info_else_branch){
- try = NULL;
- else_st = st->info.node;
- goto not_except;
- }
- else if (yield_run && st->info.branch.status == info_finally_branch){
- try = NULL;
- else_st = NULL;
- finally = st->info.node;
- goto not_else;
- }
- if (try == NULL || !tryBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(try, var_list, result, belong))){
- freeResult(result);
- goto not_except;
- }
- if (result->type == yield_return)
- goto not_else;
- if (except_list == NULL) {
- set_result = false;
- result_from = info_first_do;
- goto not_else;
- }
- error_value = result->value;
- freeResult(result);
- if (except_list->var != NULL){
- assCore(except_list->var, error_value, false, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
- if (!CHECK_RESULT(result)){
- set_result = false;
- goto not_else;
- }
- freeResult(result);
- }
- run_except:
- if (info_vl == NULL)
- info_vl = except_list->code;
- if (tryBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(info_vl, var_list, result, belong))) {
- result_from = info_vl_branch;
- set_result = false;
- }
- else
- freeResult(result);
- goto not_else;
- not_except:
- if (else_st != NULL && tryBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(else_st, var_list, result, belong))) {
- set_result = false;
- result_from = info_else_branch;
- }
- else
- freeResult(result);
- not_else:
- if (finally != NULL && tryBranchSafeInterStatement(CALL_INTER_FUNCTIONSIG(finally, var_list, &finally_tmp, belong))){
- if (!set_result)
- freeResult(result);
- set_result = false;
- *result = finally_tmp;
- result_from = info_finally_branch;
- }
- else
- freeResult(&finally_tmp);
- if (yield_run)
- if (result->type == yield_return)
- updateBranchYield(st, result->node, except_list, result_from);
- else
- freeRunInfo(st);
- else
- if (result->type == yield_return)
- newBranchYield(st, result->node, except_list, var_list, result_from, inter);
- else
- var_list = popVarList(var_list);
- if (set_result)
- setResult(result, inter, belong);
- return result->type;
- }
- ResultType breakCycle(INTER_FUNCTIONSIG){
- int times_int = 0;
- setResultCore(result);
- if (st->u.break_cycle.times == NULL)
- goto not_times;
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.break_cycle.times, var_list, result, belong)))
- return result->type;
- if (!checkNumber(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong)))
- return result->type;
- times_int = (int)result->value->value->data.num.num;
- freeResult(result);
- not_times:
- setResult(result, inter, belong);
- if (times_int >= 0) {
- result->type = break_return;
- result->times = times_int;
- }
- return result->type;
- }
- ResultType continueCycle(INTER_FUNCTIONSIG){
- int times_int = 0;
- setResultCore(result);
- if (st->u.continue_cycle.times == NULL)
- goto not_times;
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.continue_cycle.times, var_list, result, belong)))
- return result->type;
- if (!checkNumber(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong)))
- return result->type;
- times_int = (int)result->value->value->data.num.num;
- freeResult(result);
- not_times:
- setResult(result, inter, belong);
- if (times_int >= 0) {
- result->type = continue_return;
- result->times = times_int;
- }
- return result->type;
- }
- ResultType regoIf(INTER_FUNCTIONSIG){
- int times_int = 0;
- setResultCore(result);
- if (st->u.rego_if.times == NULL)
- goto not_times;
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.rego_if.times, var_list, result, belong)))
- return result->type;
- if (!checkNumber(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong)))
- return result->type;
- times_int = (int)result->value->value->data.num.num;
- freeResult(result);
- not_times:
- setResult(result, inter, belong);
- if (times_int >= 0) {
- result->type = rego_return;
- result->times = times_int;
- }
- return result->type;
- }
- ResultType restartCode(INTER_FUNCTIONSIG){
- int times_int = 0;
- setResultCore(result);
- if (st->u.restart.times == NULL)
- goto not_times;
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.restart.times, var_list, result, belong)))
- return result->type;
- if (!checkNumber(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong)))
- return result->type;
- times_int = (int)result->value->value->data.num.num;
- freeResult(result);
- not_times:
- setResult(result, inter, belong);
- if (times_int >= 0) {
- result->type = restart_return;
- result->times = times_int;
- }
- return result->type;
- }
- ResultType returnCode(INTER_FUNCTIONSIG){
- setResultCore(result);
- if (st->u.return_code.value == NULL) {
- setResult(result, inter, belong);
- goto set_result;
- }
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.return_code.value, var_list, result, belong)))
- return result->type;
- set_result:
- result->type = function_return;
- return result->type;
- }
- ResultType yieldCode(INTER_FUNCTIONSIG){
- setResultCore(result);
- if (st->u.yield_code.value == NULL) {
- setResult(result, inter, belong);
- goto set_result;
- }
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.yield_code.value, var_list, result, belong)))
- return result->type;
- set_result:
- result->type = yield_return;
- return result->type;
- }
- ResultType raiseCode(INTER_FUNCTIONSIG){
- setResultCore(result);
- if (st->u.raise_code.value == NULL) {
- setResult(result, inter, belong);
- goto set_result;
- }
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.raise_code.value, var_list, result, belong)))
- return result->type;
- set_result:
- result->type = error_return;
- result->error = connectError(makeError("RaiseException", "Exception was raise by user", st->line, st->code_file), result->error);
- return result->type;
- }
- ResultType assertCode(INTER_FUNCTIONSIG){
- setResultCore(result);
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.raise_code.value, var_list, result, belong)))
- return result->type;
- if (checkBool(result->value->value))
- setResult(result, inter, belong);
- else
- setResultErrorSt(E_AssertException, "Assertion check error", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
- return result->type;
- }
- ResultType gotoLabel(INTER_FUNCTIONSIG){
- int times_int = 0;
- char *label = NULL;
- setResultCore(result);
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.goto_.label, var_list, result, belong)))
- return result->type;
- if (!checkString(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong)))
- return result->type;
- label = memStrcpy(result->value->value->data.str.str);
- freeResult(result);
- if (st->u.goto_.times == NULL)
- goto not_times;
- if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.goto_.times, var_list, result, belong))) {
- memFree(label);
- return result->type;
- }
- if (!checkNumber(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong))) {
- memFree(label);
- return result->type;
- }
- times_int = (int)result->value->value->data.num.num;
- freeResult(result);
- not_times:
- if (st->u.goto_.return_ == NULL)
- setResult(result, inter, belong);
- else if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.goto_.return_, var_list, result, belong))) {
- memFree(label);
- return result->type;
- }
- result->times = times_int;
- result->type = goto_return;
- result->label = label;
- return result->type;
- }
- ResultType runLabel(INTER_FUNCTIONSIG) {
- // goto的值通过result传入
- LinkValue *goto_value = result->value;
- result->value = NULL;
- freeResult(result);
- var_list = pushVarList(var_list, inter);
- if (st->u.label_.as != NULL)
- assCore(st->u.label_.as, goto_value, false, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
- gc_freeTmpLink(&goto_value->gc_status);
- if (st->u.label_.as != NULL && !CHECK_RESULT(result))
- goto return_;
- freeResult(result);
- if (st->u.label_.command != NULL)
- operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.label_.command, var_list, result, belong));
- else
- setResult(result, inter, belong);
- return_:
- popVarList(var_list);
- return result->type;
- }
|