Scheme<T>& operator+=(Scheme<T> const &a) { for (auto i =0; i < a.ind.size(); ++i) { push_pair(a.ind[i], a.val[i]); } push_constant(a.c); return *this; }
void Parse::do_get_xxx(Node* obj, ciField* field, bool is_field) { // Does this field have a constant value? If so, just push the value. if (field->is_constant()) { if (field->is_static()) { // final static field if (push_constant(field->constant_value())) return; } else { // final non-static field of a trusted class (classes in // java.lang.invoke and sun.invoke packages and subpackages). if (obj->is_Con()) { const TypeOopPtr* oop_ptr = obj->bottom_type()->isa_oopptr(); ciObject* constant_oop = oop_ptr->const_oop(); ciConstant constant = field->constant_value_of(constant_oop); if (push_constant(constant, true)) return; } } } ciType* field_klass = field->type(); bool is_vol = field->is_volatile(); // Compute address and memory type. int offset = field->offset_in_bytes(); const TypePtr* adr_type = C->alias_type(field)->adr_type(); Node *adr = basic_plus_adr(obj, obj, offset); BasicType bt = field->layout_type(); // Build the resultant type of the load const Type *type; bool must_assert_null = false; if( bt == T_OBJECT ) { if (!field->type()->is_loaded()) { type = TypeInstPtr::BOTTOM; must_assert_null = true; } else if (field->is_constant() && field->is_static()) { // This can happen if the constant oop is non-perm. ciObject* con = field->constant_value().as_object(); // Do not "join" in the previous type; it doesn't add value, // and may yield a vacuous result if the field is of interface type. type = TypeOopPtr::make_from_constant(con)->isa_oopptr(); assert(type != NULL, "field singleton type must be consistent"); } else { type = TypeOopPtr::make_from_klass(field_klass->as_klass()); } } else { type = Type::get_const_basic_type(bt); } // Build the load. Node* ld = make_load(NULL, adr, type, bt, adr_type, is_vol); // Adjust Java stack if (type2size[bt] == 1) push(ld); else push_pair(ld); if (must_assert_null) { // Do not take a trap here. It's possible that the program // will never load the field's class, and will happily see // null values in this field forever. Don't stumble into a // trap for such a program, or we might get a long series // of useless recompilations. (Or, we might load a class // which should not be loaded.) If we ever see a non-null // value, we will then trap and recompile. (The trap will // not need to mention the class index, since the class will // already have been loaded if we ever see a non-null value.) // uncommon_trap(iter().get_field_signature_index()); #ifndef PRODUCT if (PrintOpto && (Verbose || WizardMode)) { method()->print_name(); tty->print_cr(" asserting nullness of field at bci: %d", bci()); } #endif if (C->log() != NULL) { C->log()->elem("assert_null reason='field' klass='%d'", C->log()->identify(field->type())); } // If there is going to be a trap, put it at the next bytecode: set_bci(iter().next_bci()); do_null_assert(peek(), T_OBJECT); set_bci(iter().cur_bci()); // put it back } // If reference is volatile, prevent following memory ops from // floating up past the volatile read. Also prevents commoning // another volatile read. if (field->is_volatile()) { // Memory barrier includes bogus read of value to force load BEFORE membar insert_mem_bar(Op_MemBarAcquire, ld); } }
static void op_push_constant(int byte, struct thread *thread) { push_constant(thread, decode_arg(thread)); }
static void op_push_constant_immed(int byte, struct thread *thread) { push_constant(thread, byte & 0x0f); }
void test_scored_subexpression() { // Create a database with the default options. auto db = grnxx::open_db(""); // Create a table with the default options. auto table = db->create_table("Table"); constexpr size_t NUM_ROWS = 1 << 16; // Generate random values. grnxx::Array<grnxx::Float> float_values; grnxx::Array<grnxx::Int> ref_values; float_values.resize(NUM_ROWS); ref_values.resize(NUM_ROWS); for (size_t i = 0; i < NUM_ROWS; ++i) { float_values[i] = grnxx::Float(1.0 * rng() / rng.max()); // ref_values[i] = mersenne_twister() % NUM_ROWS; ref_values[i] = grnxx::Int(0); } // Create columns for Float and Int values. auto float_column = table->create_column("Float", GRNXX_FLOAT); grnxx::ColumnOptions options; options.reference_table_name = "Table"; auto ref_column = table->create_column("Ref", GRNXX_INT, options); // Store generated values into columns. for (size_t i = 0; i < NUM_ROWS; ++i) { grnxx::Int row_id = table->insert_row(); assert(row_id.match(grnxx::Int(i))); float_column->set(row_id, float_values[i]); } for (size_t i = 0; i < NUM_ROWS; ++i) { ref_column->set(grnxx::Int(i), ref_values[i]); } // Generate a list of records. grnxx::Array<grnxx::Record> records; auto cursor = table->create_cursor(); assert(cursor->read_all(&records) == table->num_rows()); // Set scores (Float). auto builder = grnxx::ExpressionBuilder::create(table); builder->push_column("Float"); auto expression = builder->release(); expression->adjust(&records); // Test an expression (Ref.(_score > 0.5)). builder->push_column("Ref"); builder->begin_subexpression(); builder->push_score(); builder->push_constant(grnxx::Float(0.5)); builder->push_operator(GRNXX_GREATER); builder->end_subexpression(); expression = builder->release(); expression->filter(&records); size_t count = 0; for (size_t i = 0; i < NUM_ROWS; ++i) { if (float_values[i].raw() > 0.5) { assert(records[count].row_id.match(grnxx::Int(i))); ++count; } } assert(records.size() == count); }
Status parse(const Token *tokens, Stack **operands, Stack **operators, Stack **functions) { Status status = OK; const Token *token, *previous, *next; for (token = tokens, previous = &NO_TOKEN, next = token + 1; token->type != TOKEN_NONE; previous = token, token = next++) { switch (token->type) { case TOKEN_OPEN_PARENTHESIS: { // Implicit multiplication: "(2)(2)". if (previous->type == TOKEN_CLOSE_PARENTHESIS) { status = push_multiplication(operands, operators); } stack_push(operators, get_operator('(', OPERATOR_OTHER)); break; } case TOKEN_CLOSE_PARENTHESIS: { // Apply operators until the previous open parenthesis is found. bool found_parenthesis = false; while (*operators && status == OK && !found_parenthesis) { const Operator *operator = stack_pop(operators); if (operator->symbol == '(') { found_parenthesis = true; } else { status = apply_operator(operator, operands); } } if (!found_parenthesis) { status = ERROR_CLOSE_PARENTHESIS; } else if (*functions) { status = apply_function(stack_pop(functions), operands); } break; } case TOKEN_OPERATOR: { status = push_operator( get_operator(*token->value, get_arity(*token->value, previous)), operands, operators); break; } case TOKEN_NUMBER: { if (previous->type == TOKEN_CLOSE_PARENTHESIS || previous->type == TOKEN_NUMBER || previous->type == TOKEN_IDENTIFIER) { status = ERROR_SYNTAX; } else { status = push_number(token->value, operands); // Implicit multiplication: "2(2)" or "2a". if (next->type == TOKEN_OPEN_PARENTHESIS || next->type == TOKEN_IDENTIFIER) { status = push_multiplication(operands, operators); } } break; } case TOKEN_IDENTIFIER: { // The identifier could be either a constant or function. status = push_constant(token->value, operands); if (status == ERROR_UNDEFINED_CONSTANT && next->type == TOKEN_OPEN_PARENTHESIS) { stack_push(functions, token->value); status = OK; } else if (next->type == TOKEN_OPEN_PARENTHESIS || next->type == TOKEN_IDENTIFIER) { // Implicit multiplication: "a(2)" or "a b". status = push_multiplication(operands, operators); } break; } default: { status = ERROR_UNRECOGNIZED; } } if (status != OK) { return status; } } // Apply all remaining operators. while (*operators && status == OK) { const Operator *operator = stack_pop(operators); if (operator->symbol == '(') { status = ERROR_OPEN_PARENTHESIS; } else { status = apply_operator(operator, operands); } } return status; }
int push_transflag(lua_State *L, pmtransflag_t f) { return push_constant(L, f, transflag_constants); }