/** * 'Does-not-equals' opcode handler. * * See also: ECMA-262 v5, 11.9.2 * * @return completion value * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t opfunc_not_equal_value (vm_instr_t instr, /**< instruction */ vm_frame_ctx_t *frame_ctx_p) /**< interpreter context */ { const idx_t dst_var_idx = instr.data.not_equal_value.dst; const idx_t left_var_idx = instr.data.not_equal_value.var_left; const idx_t right_var_idx = instr.data.not_equal_value.var_right; //ilyushin printf("not_equal_value,"); //ilyushin ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); ECMA_TRY_CATCH (left_value, get_variable_value (frame_ctx_p, left_var_idx, false), ret_value); ECMA_TRY_CATCH (right_value, get_variable_value (frame_ctx_p, right_var_idx, false), ret_value); ECMA_TRY_CATCH (compare_result, ecma_op_abstract_equality_compare (left_value, right_value), ret_value); JERRY_ASSERT (ecma_is_value_boolean (compare_result)); bool is_equal = ecma_is_value_true (compare_result); ret_value = set_variable_value (frame_ctx_p, frame_ctx_p->pos, dst_var_idx, ecma_make_simple_value (is_equal ? ECMA_SIMPLE_VALUE_FALSE : ECMA_SIMPLE_VALUE_TRUE)); ECMA_FINALIZE (compare_result); ECMA_FINALIZE (right_value); ECMA_FINALIZE (left_value); frame_ctx_p->pos++; return ret_value; } /* opfunc_not_equal_value */
/** * 'Greater-than-or-equal' opcode handler. * * See also: ECMA-262 v5, 11.8.4 * * @return completion value * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t opfunc_greater_or_equal_than (vm_instr_t instr, /**< instruction */ vm_frame_ctx_t *frame_ctx_p) /**< interpreter context */ { const idx_t dst_var_idx = instr.data.greater_or_equal_than.dst; const idx_t left_var_idx = instr.data.greater_or_equal_than.var_left; const idx_t right_var_idx = instr.data.greater_or_equal_than.var_right; //ilyushin printf("greater_or_equal_than,"); //ilyushin ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); ECMA_TRY_CATCH (left_value, get_variable_value (frame_ctx_p, left_var_idx, false), ret_value); ECMA_TRY_CATCH (right_value, get_variable_value (frame_ctx_p, right_var_idx, false), ret_value); ECMA_TRY_CATCH (compare_result, ecma_op_abstract_relational_compare (left_value, right_value, true), ret_value); ecma_simple_value_t res; if (ecma_is_value_undefined (compare_result)) { res = ECMA_SIMPLE_VALUE_FALSE; } else { JERRY_ASSERT (ecma_is_value_boolean (compare_result)); if (ecma_is_value_true (compare_result)) { res = ECMA_SIMPLE_VALUE_FALSE; } else { res = ECMA_SIMPLE_VALUE_TRUE; } } ret_value = set_variable_value (frame_ctx_p, frame_ctx_p->pos, dst_var_idx, ecma_make_simple_value (res)); ECMA_FINALIZE (compare_result); ECMA_FINALIZE (right_value); ECMA_FINALIZE (left_value); frame_ctx_p->pos++; return ret_value; } /* opfunc_greater_or_equal_than */
void get_variable_value(const frontend::stache_variant &model, const std::string &key, variable_sink &sink) { auto m = boost::get<frontend::stache_model>(&model); if (m) get_variable_value(*m, key, sink); }
static value_object eval_aux(expr* node) { if (node == NULL) return make_null(); if (node->type == EXP_ASSIGN) return assign_value(node->left, node->right); value_object left = eval_aux(node->left); value_object right = eval_aux(node->right); switch (node->type) { case EXP_PLUS: return add_values(left, right); case EXP_MINUS: return sub_values(left, right); case EXP_TIMES: return mul_values(left, right); case EXP_DIV: return div_values(left, right); case EXP_INT: return make_int(atoi(node->text)); case EXP_FLOAT: return make_float(to_float64(node->text)); case EXP_NATIVE: return make_native(atof(node->text)); case EXP_CALL: return eval_function(node->text, node->args); case EXP_ID: return get_variable_value(node->text); case EXP_UNMINUS: return negate_value(left); } }
/** * 'Greater-than-or-equal' opcode handler. * * See also: ECMA-262 v5, 11.8.4 * * @return completion value * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t opfunc_greater_or_equal_than (opcode_t opdata, /**< operation data */ int_data_t *int_data) /**< interpreter context */ { const idx_t dst_var_idx = opdata.data.greater_or_equal_than.dst; const idx_t left_var_idx = opdata.data.greater_or_equal_than.var_left; const idx_t right_var_idx = opdata.data.greater_or_equal_than.var_right; ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); ECMA_TRY_CATCH (left_value, get_variable_value (int_data, left_var_idx, false), ret_value); ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value); ECMA_TRY_CATCH (compare_result, ecma_op_abstract_relational_compare (left_value, right_value, true), ret_value); ecma_simple_value_t res; if (ecma_is_value_undefined (compare_result)) { res = ECMA_SIMPLE_VALUE_FALSE; } else { JERRY_ASSERT (ecma_is_value_boolean (compare_result)); if (ecma_is_value_true (compare_result)) { res = ECMA_SIMPLE_VALUE_FALSE; } else { res = ECMA_SIMPLE_VALUE_TRUE; } } ret_value = set_variable_value (int_data, int_data->pos, dst_var_idx, ecma_make_simple_value (res)); ECMA_FINALIZE (compare_result); ECMA_FINALIZE (right_value); ECMA_FINALIZE (left_value); int_data->pos++; return ret_value; } /* opfunc_greater_or_equal_than */
/** * Fill arguments' list * * @return empty completion value if argument list was filled successfully, * otherwise - not normal completion value indicating completion type * of last expression evaluated */ ecma_completion_value_t fill_varg_list (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */ ecma_length_t args_number, /**< number of arguments */ ecma_value_t arg_values[], /**< out: arguments' values */ ecma_length_t *out_arg_number_p) /**< out: number of arguments successfully read */ { ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); ecma_length_t arg_index; for (arg_index = 0; arg_index < args_number && ecma_is_completion_value_empty (ret_value); ) { ecma_completion_value_t evaluate_arg_completion = vm_loop (frame_ctx_p, NULL); if (ecma_is_completion_value_empty (evaluate_arg_completion)) { vm_instr_t next_instr = vm_get_instr (frame_ctx_p->instrs_p, frame_ctx_p->pos); JERRY_ASSERT (next_instr.op_idx == VM_OP_META); JERRY_ASSERT (next_instr.data.meta.type == OPCODE_META_TYPE_VARG); const idx_t varg_var_idx = next_instr.data.meta.data_1; ecma_completion_value_t get_arg_completion = get_variable_value (frame_ctx_p, varg_var_idx, false); if (ecma_is_completion_value_normal (get_arg_completion)) { arg_values[arg_index++] = ecma_get_completion_value_value (get_arg_completion); } else { JERRY_ASSERT (ecma_is_completion_value_throw (get_arg_completion)); ret_value = get_arg_completion; } } else { JERRY_ASSERT (ecma_is_completion_value_throw (evaluate_arg_completion)); ret_value = evaluate_arg_completion; } frame_ctx_p->pos++; } *out_arg_number_p = arg_index; return ret_value; } /* fill_varg_list */
void putbackvariable(char* var) { char* a=NULL; char* v=strdup(var); char* subst_begin=strstr(v,"@@{"); char* subst_end=strstr(subst_begin,"}"); char* tmp=(char*)malloc((subst_end-subst_begin)+1); tmp = strncpy(tmp,subst_begin+3,subst_end-subst_begin-3); tmp[subst_end-subst_begin-3]='\0'; conf_put_token(subst_end+1); if((a=get_variable_value(tmp))!=NULL){ conf_put_token(a); } else { error(230,_("Variable %s not defined\n"),tmp); /* * We can use nondefined variable */ } subst_begin[0]='\0'; conf_put_token(v); conf_put_token("\n"); free(v); free(tmp); }
/** * 'for-in' opcode handler * * See also: * ECMA-262 v5, 12.6.4 * * @return completion value * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t opfunc_for_in (vm_instr_t instr, /**< instruction */ vm_frame_ctx_t *int_data_p) /**< interpreter context */ { const idx_t expr_idx = instr.data.for_in.expr; const idx_t block_end_oc_idx_1 = instr.data.for_in.oc_idx_1; const idx_t block_end_oc_idx_2 = instr.data.for_in.oc_idx_2; const vm_instr_counter_t for_in_end_oc = (vm_instr_counter_t) ( vm_calc_instr_counter_from_idx_idx (block_end_oc_idx_1, block_end_oc_idx_2) + int_data_p->pos); ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); /* 1., 2. */ ECMA_TRY_CATCH (expr_value, get_variable_value (int_data_p, expr_idx, false), ret_value); int_data_p->pos++; vm_instr_t meta_instr = vm_get_instr (int_data_p->instrs_p, for_in_end_oc); JERRY_ASSERT (meta_instr.op_idx == VM_OP_META); JERRY_ASSERT (meta_instr.data.meta.type == OPCODE_META_TYPE_END_FOR_IN); /* 3. */ if (!ecma_is_value_undefined (expr_value) && !ecma_is_value_null (expr_value)) { /* 4. */ ECMA_TRY_CATCH (obj_expr_value, ecma_op_to_object (expr_value), ret_value); ecma_object_t *obj_p = ecma_get_object_from_value (obj_expr_value); ecma_collection_iterator_t names_iterator; ecma_collection_header_t *names_p = vm_helper_for_in_enumerate_properties_names (obj_p); if (names_p != NULL) { ecma_collection_iterator_init (&names_iterator, names_p); const vm_instr_counter_t for_in_body_begin_oc = int_data_p->pos; const vm_instr_counter_t for_in_body_end_oc = for_in_end_oc; while (ecma_collection_iterator_next (&names_iterator)) { ecma_value_t name_value = *names_iterator.current_value_p; ecma_string_t *name_p = ecma_get_string_from_value (name_value); if (ecma_op_object_get_property (obj_p, name_p) != NULL) { ecma_completion_value_t completion = set_variable_value (int_data_p, int_data_p->pos, OPCODE_REG_SPECIAL_FOR_IN_PROPERTY_NAME, name_value); JERRY_ASSERT (ecma_is_completion_value_empty (completion)); vm_run_scope_t run_scope_for_in = { for_in_body_begin_oc, for_in_body_end_oc }; ecma_completion_value_t for_in_body_completion = vm_loop (int_data_p, &run_scope_for_in); if (ecma_is_completion_value_empty (for_in_body_completion)) { JERRY_ASSERT (int_data_p->pos == for_in_body_end_oc); int_data_p->pos = for_in_body_begin_oc; } else { JERRY_ASSERT (ecma_is_completion_value_throw (for_in_body_completion) || ecma_is_completion_value_return (for_in_body_completion) || ecma_is_completion_value_jump (for_in_body_completion)); JERRY_ASSERT (int_data_p->pos <= for_in_body_end_oc); ret_value = for_in_body_completion; break; } } } ecma_free_values_collection (names_p, true); } ECMA_FINALIZE (obj_expr_value); } int_data_p->pos = (vm_instr_counter_t) (for_in_end_oc + 1u); ECMA_FINALIZE (expr_value); return ret_value; } /* opfunc_for_in */
int symbol_to_value(char *str, int *ret, double *value) { if(!strcmp(str, "quit")) { exit(0); } else if(!strcmp(str, "sin")) { *ret = SIN; } else if(!strcmp(str, "cos")) { *ret = COS; } else if(!strcmp(str, "tan")) { *ret = TAN; } else if(!strcmp(str, "asin")) { *ret = ASIN; } else if(!strcmp(str, "acos")) { *ret = ACOS; } else if(!strcmp(str, "atan")) { *ret = ATAN; } else if(!strcmp(str, "sinh")) { *ret = SINH; } else if(!strcmp(str, "cosh")) { *ret = COSH; } else if(!strcmp(str, "tanh")) { *ret = TANH; } else if(!strcmp(str, "sqrt")) { *ret = SQRT; } else if(!strcmp(str, "exp")) { *ret = EXP; } else if(!strcmp(str, "log")) { *ret = LOG; } else if(!strcmp(str, "ln")) { *ret = LN; } else if(!strcmp(str, "abs")) { *ret = ABS; } else if(!strcmp(str, "help") || !(strcmp(str, "?"))) { f_was_calc = 0; show_usage(); *ret = UNKNOWN; } else if(!strcmp(str, "list")) { f_was_calc = 0; list_of_functions(); *ret = UNKNOWN; } else if(!strcmp(str, "matrix")) { f_was_calc = 0; matrix_mode(); *ret = UNKNOWN; } else if(!strcmp(str, "degree")) { f_was_calc = 0; set_angle_unit(DEGREE); printf("degree mode\n"); *ret = UNKNOWN; } else if(!strcmp(str, "radian")) { f_was_calc = 0; set_angle_unit(RADIAN); printf("radian mode\n"); *ret = UNKNOWN; } else if(!strcmp(str, "pi") || !strcmp(str, "PI")) { *value = M_PI; return 2; // number } else if(!strncmp(str, "$", 1)) { *value = get_variable_value(str + 1); return 2; // number } else { f_was_calc = 0; *ret = UNKNOWN; } return 1; // symbol }
* See also: ECMA-262 v5, 11.8.6 * * @return completion value * returned value must be freed with ecma_free_completion_value. */ ecma_completion_value_t opfunc_instanceof (opcode_t opdata __attr_unused___, /**< operation data */ int_data_t *int_data __attr_unused___) /**< interpreter context */ { const idx_t dst_idx = opdata.data.instanceof.dst; const idx_t left_var_idx = opdata.data.instanceof.var_left; const idx_t right_var_idx = opdata.data.instanceof.var_right; ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); ECMA_TRY_CATCH (left_value, get_variable_value (int_data, left_var_idx, false), ret_value); ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value); if (!ecma_is_value_object (right_value)) { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { ecma_object_t *right_value_obj_p = ecma_get_object_from_value (right_value); ECMA_TRY_CATCH (is_instance_of, ecma_op_object_has_instance (right_value_obj_p, left_value), ret_value); ret_value = set_variable_value (int_data, int_data->pos, dst_idx, is_instance_of);
* @return completion value * returned value must be freed with ecma_free_completion_value. */ ecma_completion_value_t opfunc_instanceof (vm_instr_t instr __attr_unused___, /**< instruction */ vm_frame_ctx_t *frame_ctx_p __attr_unused___) /**< interpreter context */ { const idx_t dst_idx = instr.data.instanceof.dst; const idx_t left_var_idx = instr.data.instanceof.var_left; const idx_t right_var_idx = instr.data.instanceof.var_right; //ilyushin printf("instanceof,"); //ilyushin ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); ECMA_TRY_CATCH (left_value, get_variable_value (frame_ctx_p, left_var_idx, false), ret_value); ECMA_TRY_CATCH (right_value, get_variable_value (frame_ctx_p, right_var_idx, false), ret_value); if (!ecma_is_value_object (right_value)) { ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); } else { ecma_object_t *right_value_obj_p = ecma_get_object_from_value (right_value); ECMA_TRY_CATCH (is_instance_of, ecma_op_object_has_instance (right_value_obj_p, left_value), ret_value); ret_value = set_variable_value (frame_ctx_p, frame_ctx_p->pos, dst_idx, is_instance_of);
bool PNPActionServer::GetVariableValue(pnp_msgs::PNPGetVariableValue::Request &req, pnp_msgs::PNPGetVariableValue::Response &res){ res.answer = get_variable_value(req.variable); return true; }
sexp eval_object(sexp object, sexp environment) { tail_loop: if (is_quote_form(object)) return quotation_text(object); if (is_variable_form(object)) return get_variable_value(object, environment); if (is_define_form(object)) { /* sexp value = eval_object(definition_value(object), environment); */ /* add_binding(definition_variable(object), value, environment); */ /* return value; */ return eval_object(define2set(object), environment); } if (is_assignment_form(object)) { sexp value = eval_object(assignment_value(object), environment); set_binding(assignment_variable(object), value, environment); return value; } if (is_if_form(object)) { sexp test_part = if_test_part(object); sexp then_part = if_then_part(object); sexp else_part = if_else_part(object); if (!is_false(eval_object(test_part, environment))) { object = then_part; } else { object = else_part; } goto tail_loop; } if (is_lambda_form(object)) { sexp parameters = lambda_parameters(object); sexp body = lambda_body(object); return make_lambda_procedure(parameters, body, environment); } if (is_begin_form(object)) { return eval_begin(object, environment); } if (is_cond_form(object)) { object = cond2if(object); goto tail_loop; } if (is_let_form(object)) { object = let2lambda(object); goto tail_loop; } if (is_and_form(object)) { sexp tests = and_tests(object); if (is_null(tests)) return make_true(); while (is_pair(pair_cdr(tests))) { sexp result = eval_object(pair_car(tests), environment); if (is_false(result)) return make_false(); tests = pair_cdr(tests); } return eval_object(pair_car(tests), environment); } if (is_or_form(object)) { sexp tests = or_tests(object); if (is_null(tests)) return make_false(); while (is_pair(pair_cdr(tests))) { sexp result = eval_object(pair_car(tests), environment); if (!is_false(result)) return result; tests = pair_cdr(tests); } return eval_object(pair_car(tests), environment); } if (is_macro_form(object)) { sexp pars = macro_parameters(object); sexp body = macro_body(object); return make_macro_procedure(pars, body, environment); } if (is_application_form(object)) { sexp operator = application_operator(object); sexp operands = application_operands(object); operator = eval_object(operator, environment); if (!is_function(operator) && !is_macro(operator)) { fprintf(stderr, "Illegal functional object "); write_object(operator, make_file_out_port(stderr)); fprintf(stderr, " from "); write_object(pair_car(object), make_file_out_port(stderr)); fputc('\n', stderr); exit(1); } /* Expand the macro before evaluating arguments */ if (is_macro(operator)) { sexp body = macro_proc_body(operator); sexp vars = macro_proc_pars(operator); sexp def_env = macro_proc_env(operator); sexp object = make_pair(S("begin"), body); sexp env = extend_environment(vars, operands, def_env); sexp exp = eval_object(object, env); return eval_object(exp, environment); } operands = eval_arguments(operands, environment); /* if (is_apply(operator)) { */ /* operator = pair_car(operands); */ /* operands = apply_operands_conc(pair_cdr(operands)); */ /* } */ if (is_eval(operator)) { environment = pair_cadr(operands); object = pair_car(operands); goto tail_loop; } return eval_application(operator, operands); } else return object; }