bool express_calcu(string express) {
    trim(express);
    if (execute_calculation_express(express)) {
        copy_variant(JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT,JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT);
        return true;
    } else if (execute_function_call(express)) {
        copy_variant(JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT,JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT);
        return true;
    }/* else if (execute_calculation_term(express)) {  //  WARNING ,it will crash because of STL lib ..
        copy_variant(JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT,JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT);
        return true;
    }*/
    express_type express_type_=get_express_type(express);
    if (EXPRESSION_UNKNOW!=express_type_) {
        if (EXPRESSION_NUMBER_DECIMAL==express_type_) {
            set_variant(JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT,(void*)atoi(express.c_str()),NUMBER);
        } else if (EXPRESSION_NUMBER_HEX==express_type_) {
            set_variant(JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT,(void*)hex_string_to_number(express),NUMBER);
        } else if (EXPRESSION_STRING==express_type_) {
            set_variant(JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT,(void*)(express.substr(1,express.length()-2)).c_str(),STRING);
        } else if (EXPRESSION_ARRAY==express_type_) {
            string variant_name(express.substr(0,express.find('[')));
            express_calcu(express.substr(express.find('[')+1,express.find(']')-express.find('[')-1));
            unsigned long array_index=0;
            support_javascript_variant_type array_type=NONE;
            get_variant(JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT,(void*)&array_index,&array_type);
            if (NUMBER!=array_index)
                return false;
            get_variant_array(variant_name,array_index,&array_index,&array_type);
            set_variant(JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT,(void*)array_index,array_type);
        }
        return true;
    }
    return false;
}
Beispiel #2
0
/** execute_statement   	Execute a Cx statement
 *
 * @param p_function_id : ptr to the routine symtab node
 */
void cx_executor::execute_statement(cx_symtab_node *p_function_id) {
    if (token != tc_left_bracket) {
        ++statement_count;
        trace_statement();
    }

    switch (token) {
        case tc_identifier:
        {
            if (p_node->defn.how == dc_function) {
                execute_function_call(p_node);
            } else {
                cx_symtab_node *p_var = p_node;
                get_token();
                if (token_in(token, tokenlist_assign_ops)) {
                    execute_assignment(p_var);
                } else {
                    execute_variable(p_var, false);
                    pop();
                }
            }
        }
            break;
        case tc_DO: execute_DO(p_function_id);
            break;
        case tc_WHILE: execute_WHILE(p_function_id);
            break;
        case tc_IF: execute_IF(p_function_id);
            break;
        case tc_FOR: execute_FOR(p_function_id);
            break;
        case tc_SWITCH: //parse_SWITCH();
            break;
        case tc_CASE:
        case tc_DEFAULT://parse_case_label();
            break;
        case tc_BREAK:
            get_token();
            break_loop = true;
            break;
        case tc_left_bracket: execute_compound(p_function_id);
            break;
        case tc_RETURN: execute_RETURN(p_function_id);
            break;
        default:
            break;
    }
}
Beispiel #3
0
void interpretert::step()
{
  if(PC==function->second.body.instructions.end())
  {
    if(call_stack.empty())
      done=true;
    else
    {
      PC=call_stack.top().return_PC;
      function=call_stack.top().return_function;
      stack_pointer=call_stack.top().old_stack_pointer;
      call_stack.pop();
    }

    return;
  }
  
  next_PC=PC;
  next_PC++;  

  switch(PC->type)
  {
  case GOTO:
    execute_goto();
    break;
  
  case ASSUME:
    execute_assume();
    break;
  
  case ASSERT:
    execute_assert();
    break;
  
  case OTHER:
    execute_other();
    break;
  
  case DECL:
    execute_decl();
    break;
  
  case SKIP:
  case LOCATION:
  case END_FUNCTION:
    break;
  
  case RETURN:
    if(call_stack.empty())
      throw "RETURN without call";

    if(PC->code.operands().size()==1 &&
       call_stack.top().return_value_address!=0)
    {
      std::vector<mp_integer> rhs;
      evaluate(PC->code.op0(), rhs);
      assign(call_stack.top().return_value_address, rhs);
    }

    next_PC=function->second.body.instructions.end();
    break;
    
  case ASSIGN:
    execute_assign();
    break;
    
  case FUNCTION_CALL:
    execute_function_call();
    break;
  
  case START_THREAD:
    throw "START_THREAD not yet implemented";
  
  case END_THREAD:
    throw "END_THREAD not yet implemented";
    break;

  case ATOMIC_BEGIN:
    throw "ATOMIC_BEGIN not yet implemented";
    
  case ATOMIC_END:
    throw "ATOMIC_END not yet implemented";
    
  case DEAD:
    throw "DEAD not yet implemented";
  
  default:
    throw "encountered instruction with undefined instruction type";
  }
  
  PC=next_PC;
}