void Kontext::createInteger() { std::vector<llvm::Type*> types(1, llvm::Type::getInt32Ty(this->getContext())); auto leType = llvm::StructType::create(this->getContext(), makeArrayRef(types), "Integer", false); std::vector<KObjectAttr> attributes(1, KObjectAttr("innerInt", nullptr)); auto o = KObject("Integer", leType, std::move(attributes)); this->addType("Integer", o); this->setObject("Integer"); std::vector<llvm::Type *> argTypes; argTypes.emplace_back(leType->getPointerTo()); argTypes.emplace_back(llvm::Type::getInt32Ty(this->getContext())); auto fType = llvm::FunctionType::get(llvm::Type::getVoidTy(this->getContext()), makeArrayRef(argTypes), false); auto func = llvm::Function::Create(fType, llvm::GlobalValue::ExternalLinkage, "_KN7IntegerC1E", this->module()); auto bBlock = llvm::BasicBlock::Create(this->getContext(), "entry", func, nullptr); this->pushBlock(bBlock); auto argIter = func->arg_begin(); auto obj = InstanciatedObject::Create("self", &(*argIter), *this, KCallArgList()); (*argIter).setName("self"); obj->store(*this); argIter++; (*argIter).setName("leValue"); auto leBlock = KBlock(); auto decl = std::make_shared<KVarDecl>("innerInt", llvm::Type::getInt32Ty(this->getContext()), &(*argIter)); decl->setInObj(); leBlock.emplaceStatement(std::move(decl)); leBlock.codeGen(*this); llvm::ReturnInst::Create(this->getContext(), _blocks.top()->returnValue, bBlock); this->popBlock(); this->createIntegerAdd(); this->createIntegerPrint(); this->popObject(); }
bool LinkedBag<ItemType>::remove(const ItemType& anEntry) { Node<ItemType>* entryNodePtr = getPointerTo(anEntry); bool canRemoveItem = !isEmpty() && (entryNodePtr != nullptr); if (canRemoveItem) { // Copy data from first node to located node entryNodePtr->setItem(headPtr->getItem()); // Delete first node Node<ItemType>* nodeToDeletePtr = headPtr; headPtr = headPtr->getNext(); // Return node to the system nodeToDeletePtr->setNext(nullptr); delete nodeToDeletePtr; nodeToDeletePtr = nullptr; itemCount--; } // end if return canRemoveItem; } // end remove
bool LinkedBag<ItemType>::contains(const ItemType& anEntry) const { return (getPointerTo(anEntry) != nullptr); } // end contains
void initGlobalFuncs(GlobalState& g) { g.llvm_opaque_type = llvm::StructType::create(g.context, "opaque"); g.llvm_clfunction_type_ptr = lookupFunction("boxCLFunction")->arg_begin()->getType(); g.llvm_module_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedModule")->getPointerTo(); assert(g.llvm_module_type_ptr); g.llvm_bool_type_ptr = lookupFunction("boxBool")->getReturnType(); g.llvm_value_type_ptr = lookupFunction("getattr")->getReturnType(); g.llvm_value_type = g.llvm_value_type_ptr->getSequentialElementType(); // g.llvm_class_type_ptr = llvm::cast<llvm::StructType>(g.llvm_value_type)->getElementType(0); // g.llvm_class_type = g.llvm_class_type_ptr->getSequentialElementType(); g.llvm_class_type = g.stdlib_module->getTypeByName("class.pyston::BoxedClass"); assert(g.llvm_class_type); g.llvm_class_type_ptr = g.llvm_class_type->getPointerTo(); g.llvm_flavor_type = g.stdlib_module->getTypeByName("class.pyston::ObjectFlavor"); assert(g.llvm_flavor_type); g.llvm_flavor_type_ptr = g.llvm_flavor_type->getPointerTo(); g.llvm_str_type_ptr = lookupFunction("boxStringPtr")->arg_begin()->getType(); auto vector_type = g.stdlib_module->getTypeByName("class.std::vector"); assert(vector_type); g.vector_ptr = vector_type->getPointerTo(); g.llvm_closure_type_ptr = g.stdlib_module->getTypeByName("class.pyston::BoxedClosure")->getPointerTo(); assert(g.llvm_closure_type_ptr); #define GET(N) g.funcs.N = getFunc((void*)N, STRINGIFY(N)) g.funcs.printf = addFunc((void*)printf, g.i8_ptr, true); g.funcs.my_assert = getFunc((void*)my_assert, "my_assert"); g.funcs.malloc = addFunc((void*)malloc, g.i8_ptr, g.i64); g.funcs.free = addFunc((void*)free, g.void_, g.i8_ptr); g.funcs.allowGLReadPreemption = addFunc((void*)threading::allowGLReadPreemption, g.void_); GET(boxCLFunction); GET(unboxCLFunction); GET(createUserClass); GET(boxInt); GET(unboxInt); GET(boxFloat); GET(unboxFloat); GET(boxStringPtr); GET(boxInstanceMethod); GET(boxBool); GET(unboxBool); GET(createTuple); GET(createList); GET(createDict); GET(createSlice); GET(createClosure); GET(getattr); GET(setattr); GET(getitem); GET(setitem); GET(delitem); GET(getGlobal); GET(binop); GET(compare); GET(augbinop); GET(nonzero); GET(print); GET(unboxedLen); GET(getclsattr); GET(unaryop); GET(import); GET(repr); GET(isinstance); GET(checkUnpackingLength); GET(raiseAttributeError); GET(raiseAttributeErrorStr); GET(raiseNotIterableError); GET(assertNameDefined); GET(assertFail); GET(printFloat); GET(listAppendInternal); g.funcs.runtimeCall = getFunc((void*)runtimeCall, "runtimeCall"); g.funcs.runtimeCall0 = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32); g.funcs.runtimeCall1 = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32, g.llvm_value_type_ptr); g.funcs.runtimeCall2 = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32, g.llvm_value_type_ptr, g.llvm_value_type_ptr); g.funcs.runtimeCall3 = addFunc((void*)runtimeCall, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.i32, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr); g.funcs.callattr = getFunc((void*)callattr, "callattr"); g.funcs.callattr0 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr, g.i1, g.i32); g.funcs.callattr1 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr, g.i1, g.i32, g.llvm_value_type_ptr); g.funcs.callattr2 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr, g.i1, g.i32, g.llvm_value_type_ptr, g.llvm_value_type_ptr); g.funcs.callattr3 = addFunc((void*)callattr, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_str_type_ptr, g.i1, g.i32, g.llvm_value_type_ptr, g.llvm_value_type_ptr, g.llvm_value_type_ptr); g.funcs.reoptCompiledFunc = addFunc((void*)reoptCompiledFunc, g.i8_ptr, g.i8_ptr); g.funcs.compilePartialFunc = addFunc((void*)compilePartialFunc, g.i8_ptr, g.i8_ptr); GET(__cxa_begin_catch); g.funcs.__cxa_end_catch = addFunc((void*)__cxa_end_catch, g.void_); g.funcs.__cxa_allocate_exception = addFunc((void*)__cxa_allocate_exception, g.i8_ptr, g.i64); g.funcs.__cxa_throw = addFunc((void*)__cxa_throw, g.void_, g.i8_ptr, g.i8_ptr, g.i8_ptr); g.funcs.div_i64_i64 = getFunc((void*)div_i64_i64, "div_i64_i64"); g.funcs.mod_i64_i64 = getFunc((void*)mod_i64_i64, "mod_i64_i64"); g.funcs.pow_i64_i64 = getFunc((void*)pow_i64_i64, "pow_i64_i64"); GET(div_float_float); GET(mod_float_float); GET(pow_float_float); }