Example #1
0
void Patron::onRegisterProvider(Handler< ::donut::Heap> const& heap)
{
	Handler<Universe> universe = this->universe_.lock();
	if( unlikely(!universe) ){
		DONUT_EXCEPTION(Exception, "[BUG] Failed to lock universe.");
	}
	Handler<World> world = this->world_.lock();
	if( unlikely(!world) ){
		DONUT_EXCEPTION(Exception, "[BUG] Failed to lock world.");
	}
	//world
	heap->registerProvider(this->worldProvider_ = Handler<WorldProvider>( new WorldProvider(heap, world) ));
	// heaven
	heap->registerProvider(this->heavenProvider_ = Handler<HeavenProvider>( new HeavenProvider(heap, world->heaven()) ));
	// angel
	heap->registerProvider(this->loneAngelProvider_ = Handler<LoneAngelProvider>( new LoneAngelProvider(heap, world->heaven()) ));
	heap->registerProvider(this->twinAngelProvider_ = Handler<TwinAngelProvider>( new TwinAngelProvider(heap, world->heaven()) ));
	// angel target
	heap->registerProvider(this->angelElementTargetProvider_ = Handler<AngelElementTargetProvider>( new AngelElementTargetProvider(heap, world->heaven()) ));
	heap->registerProvider(this->angelWidgetTargetProvider_ = Handler<AngelWidgetTargetProvider>( new AngelWidgetTargetProvider(heap, world->heaven()) ));
	// servant
	heap->registerProvider(this->haloServantProvider_ = Handler<HaloServantProvider>( new HaloServantProvider(heap, world->heaven()) ));
	heap->registerProvider(this->contentUnderlineServantProvider_ = Handler<ContentUnderlineServantProvider>( new ContentUnderlineServantProvider(heap, world->heaven()) ));
	heap->registerProvider(this->elementServantProvider_ = Handler<ElementServantProvider>( new ElementServantProvider(heap, world->heaven()) ));
	//ウィジットのプロバイダを設定
	world->elementFactory()->registerDonutProvider(heap);
	world->widgetFactory()->registerDonutProvider(heap);

	universe->hexe()->registerGeistProvider(heap);

}
Example #2
0
	void setup()
	{
		this->lexer = DonutLexerNew(this->stream);
		if(!this->lexer){
			DONUT_EXCEPTION(Exception, "Failed to read stream for %s", filename_.c_str());
		}
		this->tokenStream = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lexer));
		if(!this->tokenStream){
			DONUT_EXCEPTION(Exception, "Failed to create token stream for %s", filename_.c_str());
		}
		this->parser = DonutParserNew(tokenStream);
		if(!this->parser){
			DONUT_EXCEPTION(Exception, "Failed to create parser for %s", filename_.c_str());
		}
	}
Example #3
0
inline Handler<ObjectT> HeapProvider::newInstance(ProviderT* self, Args... args)
{
    Handler<Heap> heap(self->heap().lock());
    if( unlikely(!heap) ) {
        DONUT_EXCEPTION(Exception, "[BUG] Heap is already dead.");
    }
    return heap->createObject<ObjectT>(self, args...);
}
Example #4
0
PureNativeClosureObject::Signature const& Provider::findPureNativeClosureEntry( std::string const& name )
{
	auto it = pureNativeClosures_.find(name);
	if(it == this->pureNativeClosures_.end()){
		DONUT_EXCEPTION(Exception, "Pure Native Closure \"%s\" not found in \"%s\"!!", name.c_str(), this->name().c_str());
	}
	VectorMap<std::string, PureNativeClosureObject::Signature>::Pair const& p = *it;
	return p.second;
}
Example #5
0
	ParserImpl& fromFile(std::string const& filename)
	{
		this->filename_ = filename;
		stream = antlr3FileStreamNew((ANTLR3_UINT8*)filename.c_str(), ANTLR3_ENC_UTF8);
		if(!stream){
			DONUT_EXCEPTION(Exception, "Failed to create ANTLR3 File Stream for %s", filename.c_str());
		}
		setup();
		return *this;
	}
Example #6
0
	Handler<donut::Source> compile(){
		Handler<donut::Source> src = compiler->prog(compiler);
		// エラー自体は既に表示されているので、こちらでは例外を投げるだけ
		if(compiler->pTreeParser->rec->state->errorCount > 0)
		{
			//ANTLR3_EXCEPTION* ex = compiler->pTreeParser->rec->state->exception;
			DONUT_EXCEPTION(Exception, "Failed to compile.");
		}
		return src;
	}
Example #7
0
	ParserImpl& fromString(std::string const& src, std::string const& filename, int line)
	{
		this->src = src;
		this->filename_ = filename;
		stream = antlr3StringStreamNew((pANTLR3_UINT8)this->src.c_str(), ANTLR3_ENC_UTF8, src.size(), (pANTLR3_UINT8)this->filename_.c_str());
		if(!stream){
			DONUT_EXCEPTION(Exception, "Failed to create ANTLR3 String Stream for %s", filename.c_str());
		}
		stream->line=line;
		setup();
		return *this;
	}
Example #8
0
Parser::Parser(ParserImpl* pimpl)
:parserImpl(nullptr), compilerImpl(nullptr)
{
	if(!pimpl){
		DONUT_EXCEPTION(Exception, "[BUG] Invalid parser impl pointer.");
	}
	this->parserImpl = pimpl;
	pANTLR3_BASE_TREE tree = pimpl->parseProgram();
//	std::string treeStr(createStringFromString(tree->toStringTree(tree)));
//	std::cout << treeStr << std::endl;
	this->compilerImpl = new CompilerImpl(pimpl->filename(), tree);
}
Example #9
0
	pANTLR3_BASE_TREE parseProgram()
	{
		pANTLR3_BASE_TREE t = parser->source(parser).tree;

		// エラー自体は既に表示されているので、こちらでは例外を投げるだけ
		if(parser->pParser->rec->state->errorCount > 0)
		{
			//ANTLR3_EXCEPTION* ex = parser->pParser->rec->state->exception;
			DONUT_EXCEPTION(Exception, "Failed to parse.");
		}
		return t;
	}
Example #10
0
void ReactiveProviderAspectT<__AntiSideEffect>::bootstrap(ReactiveProvider& self) {
    Handler<Heap> heap = self.heap().lock();
    if( unlikely(!heap) ) {
        DONUT_EXCEPTION(Exception, "[BUG] Heap is already dead.");
    }
    for( std::pair<std::string, typename ReactiveNativeClosureBaseT<__AntiSideEffect>::Signature> const& p : this->reactiveNativeClosures_ ) {
        self.prototype()->set(
            heap,
            p.first,
            heap->createReactiveNativeClosureObject< __AntiSideEffect >(self.name(), p.first, p.second));
    }
}
Example #11
0
HomuraProvider::HomuraProvider(Handler<Heap> const& heap)
:Super(heap, "Homura")
{
	this->registerPureNativeClosure("tick", [&](HomuraObject* hom) {
		Handler<Heap> heap = this->heap().lock();
		if(!heap){
			DONUT_EXCEPTION(Exception, "[BUG] Heap is already dead.");
		}
		Handler<Clock> clk(heap->clock());
		timestamp_t const t = clk->now();
		clk->tickFromMachine();
		return t;
	});
	this->registerPureNativeClosure("now", [&](HomuraObject* hom) {
		Handler<Heap> heap = this->heap().lock();
		if(!heap){
			DONUT_EXCEPTION(Exception, "[BUG] Heap is already dead.");
		}
		return heap->clock()->now();
	});
	this->registerPureNativeClosure("seek", [&](HomuraObject* hom, timestamp_t t) {
		Handler<Heap> heap = this->heap().lock();
		if(!heap){
			DONUT_EXCEPTION(Exception, "[BUG] Heap is already dead.");
		}
		Handler<Clock> clk(heap->clock());
		clk->seekFromMachine(t);
		return t;
	});
	this->registerPureNativeClosure("discardHistory", [&](HomuraObject* hom) {
		Handler<Heap> heap = this->heap().lock();
		if(!heap){
			DONUT_EXCEPTION(Exception, "[BUG] Heap is already dead.");
		}
		Handler<Clock> clk(heap->clock());
		clk->discardHistoryFromMachine();
		return clk->now();
	});
}