示例#1
0
/*time_t lastmodtime;*/
int recompile()
{
	/*
	struct stat file_stat;
	int err = stat("update.c", &file_stat);

	if( !g_tcc )
	{
	lastmodtime = file_stat.st_mtime;		
	}
	else
	{
	if( lastmodtime == file_stat.st_mtime )
	return 0;
	lastmodtime = file_stat.st_mtime;
	}
	*/
	printf("recompile\n");
	FILE* f = fopen( "update.c", "rb" );	// MUST be "rb" on windows - othersize CRLF will be converted to \n, and file size will be wrong (CRLF:2bytes, \n:1bytes)
	fseek(f, 0L, SEEK_END);
	long sz = ftell(f);
	fseek(f, 0L, SEEK_SET);
	char* program = (char*)malloc( sz+1 );
	fread( program, sz, 1, f ); 
	program[sz] = '\0';
	fclose(f);

	TCCState* s = tcc_new();
	tcc_set_output_type(s, TCC_OUTPUT_MEMORY);

	int n;
	tcc_set_error_func(s, &n, compile_err);

	addSymbols(s);

	int compileResult = tcc_compile_string(s, program);
	free( program );

	if ( compileResult == -1)
	{
		return 1;
	}
	
	tcc_add_library_path(s,".");
	
	/* relocate the code */
	if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
		return 1;

	/* get entry symbol */
	update = (updatefp_t)tcc_get_symbol(s, "update");
	if (!update)
		return 1;

	if( g_tcc ) tcc_delete(g_tcc);
	g_tcc = s;

	printf("recompile ok\n");
	return 0;
}
示例#2
0
// pre: the state 'lastState' is a newly created state that has only a lambda transition coming in to it.
// post: lastState is updated to a new state that has the property that only lambda transitions go to it.
void addSymbols(ParseNode::iterator_type begin, ParseNode::iterator_type end, FaSymbolTable &symTab, FaRuleIr &ruleIr, FaNfa *nfa, unsigned &lastState)
{
	for(ParseNode::iterator_type i = begin; i != end; ++i)
	{
		assert((*i)->getToken() == RULE_rcsymbol);
		unsigned symbolHeadToken = (*(*i)->begin())->getToken();
	
		if(symbolHeadToken == RULE_rcitem)
		{
			ParseNode *item = *(*i)->begin();
			assert(item->getToken() == RULE_rcitem);
			
			ParseNode *item2 = *item->begin();
			std::string item2Text = item2->getTokenText();
			unsigned newState = ruleIr.addState(*nfa);
			
			bool ok = ruleIr.addEdge(*nfa, lastState, newState, item2Text);
			if(!ok)
			{
				std::string msg = "error adding NFA transition (check that keywords and tokens are defined before use)";
				throw ParseSpecificError((*i)->getLine(), (*i)->getFile(), msg);
			}
			
			lastState = newState;
		}
		else
		if(symbolHeadToken == '{' || symbolHeadToken == '[')
		{
			unsigned q0 = ruleIr.addState(*nfa);
			ruleIr.addLambda(*nfa, lastState, q0);
			lastState = q0;
			ParseNode::iterator_type j = (*i)->begin();
			ParseNode *alternate = *++j;
			assert(alternate->getToken() == RULE_rcalternate);
			addSymbols(alternate->begin(), alternate->end(), symTab, ruleIr, nfa, lastState);
			
			if(symbolHeadToken == '{')
				ruleIr.addLambda(*nfa, lastState, q0);
			ruleIr.addLambda(*nfa, q0, lastState);
			unsigned qf = ruleIr.addState(*nfa);
			ruleIr.addLambda(*nfa, lastState, qf);
			lastState = qf;
		}
	}
	
	unsigned newState = ruleIr.addState(*nfa);
	ruleIr.addLambda(*nfa, lastState, newState);
	lastState = newState;
}
示例#3
0
// This is called when the atlernate rule in the statement rule is encountered.
void parseAlternate(FaSymbolTable &symTab, FaRuleIr &ruleIr, ParseNode *alternate, std::string ruleName)
{
	// alternate ::= symbol { symbol } ;
	//
	// symbol ::=
	// item |
	// '{' alternate '}' |
	// '[' alternate ']' ;
	//
	// item ::= LITCHAR | LITSTRING | IDENT ;
	
	unsigned firstState;	// 1st state of this alternate
	FaNfa *nfa = ruleIr.addProduction(ruleName, firstState);
	unsigned lastState = firstState;
	
	addSymbols(alternate->begin(), alternate->end(), symTab, ruleIr, nfa, lastState);
	ruleIr.makeFinal(*nfa, lastState);
}
示例#4
0
void
ImageModule::load()
{
    USING_MU_FUNCTION_SYMBOLS

    MuLangContext* c = (MuLangContext*)globalModule()->context();

    addSymbols( new ImageType(c),  
                new PixelsType(c),

                new Function(c, "resize", resize, None,
                             Return, "image.image",
                             Parameters,
                             new Param(c, "img", "image.image"),
                             new Param(c, "newWidth", "int"),
                             new Param(c, "newHeight", "int"),
                             End),

		EndArguments );

}
示例#5
0
char *WLoadSymbols( WRHashTable **table, char *file_name, HWND parent, bool prompt )
{
    char                *name;
    int                 c;
    unsigned            flags;
    char                *inc_path;
    WGetFileStruct      gf;
    bool                ret;
    bool                ok;

    name = NULL;

    ok = (table != NULL);

    if( ok ) {
        if( file_name == NULL || prompt ) {
            gf.file_name = file_name;
            gf.title = AllocRCString( W_LOADSYMTITLE );
            gf.filter = AllocRCString( W_SYMFILTER );
            WMassageFilter( gf.filter );
            name = WGetOpenFileName( parent, &gf );
            if( gf.title != NULL ) {
                FreeRCString( gf.title );
            }
            if( gf.filter != NULL ) {
                FreeRCString( gf.filter );
            }
        } else {
            name = WStrDup( file_name );
        }
        ok = (name != NULL);
    }

    WSetWaitCursor( parent, TRUE );

    if( ok ) {
        flags = PPFLAG_IGNORE_INCLUDE | PPFLAG_EMIT_LINE;
        inc_path = NULL;
        ret = setjmp( SymEnv ) != 0;
        if( ret ) {
            PP_Fini();
            WDisplayErrorMsg( W_SYMOUTOFMEM );
            ok = false;
        }
    }

    if( ok ) {
        ok = !PP_Init( name, flags, inc_path );
        if( !ok ) {
            WDisplayErrorMsg( W_NOOPENSYMFILE );
        }
    }

    if( ok ) {
        do {
            c = PP_Char();
        } while( c != EOF );
        if( *table == NULL ) {
            *table = WRInitHashTable();
        }
        addSymbols( *table );
        WRMakeHashTableClean( *table );
        PP_Fini();
    }

    if( !ok ) {
        if( name != NULL ) {
            WRMemFree( name );
            name = NULL;
        }
    }

    WSetWaitCursor( parent, FALSE );

    return( name );
}
示例#6
0
void
StreamType::load()
{
    USING_MU_FUNCTION_SYMBOLS;

    Symbol *s = scope();
    MuLangContext* context = (MuLangContext*)globalModule()->context();
    Context* c = context;

    String tname = fullyQualifiedName();
    String rname = tname + "&";

    const char* tn = tname.c_str();
    const char* rn = rname.c_str();
		  
    s->addSymbols( new ReferenceType(c, "stream&", this), 

		   new Function(c, "stream", BaseFunctions::dereference, Cast,
				Return, tn,
				Args, rn, End),

		   EndArguments);

    globalScope()->addSymbols(

		   new Function(c, "print", StreamType::print, None,
				Return, "void", 
				Args, tn, End),

		   new Function(c, "=", BaseFunctions::assign, AsOp,
				Return, rn, 
				Args, rn, tn, End),

                   new Function(c, "!", StreamType::eval, None,
                                Return, "bool",
                                Args, tn, End),

                   new Function(c, "bool", StreamType::toBool, None,
                                Return, "bool",
                                Args, tn, End),

                   EndArguments);

    addSymbols( 

               new SymbolicConstant(c, "GoodBit", "int", Value(int(ios::goodbit))),
                new SymbolicConstant(c, "BadBit", "int", Value(int(ios::badbit))),
                new SymbolicConstant(c, "FailBit", "int", Value(int(ios::failbit))),
                new SymbolicConstant(c, "EofBit", "int", Value(int(ios::eofbit))),

                new SymbolicConstant(c, "Beginning", "int", Value(int(ios::beg))),
                new SymbolicConstant(c, "Current", "int", Value(int(ios::cur))),
                new SymbolicConstant(c, "End", "int", Value(int(ios::end))),

                new SymbolicConstant(c, "Append", "int", Value(int(ios::app))),
                new SymbolicConstant(c, "AtEnd", "int", Value(int(ios::ate))),
                new SymbolicConstant(c, "Binary", "int", Value(int(ios::binary))),
                new SymbolicConstant(c, "In", "int", Value(int(ios::in))),
                new SymbolicConstant(c, "Out", "int", Value(int(ios::out))),
                new SymbolicConstant(c, "Truncate", "int", Value(int(ios::trunc))),

                new Function(c, "bad", StreamType::bad, None,
                             Return, "bool",
                             Args, tn, End),

                new Function(c, "eof", StreamType::eof, None,
                             Return, "bool",
                             Args, tn, End),

                new Function(c, "fail", StreamType::fail, None,
                             Return, "bool",
                             Args, tn, End),

                new Function(c, "good", StreamType::good, None,
                             Return, "bool",
                             Args, tn, End),

                new Function(c, "clear", StreamType::clear, None,
                             Return, "void",
                             Args, tn, End),

                new Function(c, "clear", StreamType::clear, None,
                             Return, "void",
                             Args, tn, "int", End),

                new Function(c, "rdstate", StreamType::rdstate, None,
                             Return, "int",
                             Args, tn, End),

                new Function(c, "setstate", StreamType::setstate, None,
                             Return, "void",
                             Args, tn, "int", End),

		EndArguments );

}