示例#1
0
static BOOL TestStream_Fill(void)
{
	BOOL rc = FALSE;
	const BYTE fill[7] = "XXXXXXX";
	const BYTE data[] = "someteststreamdata";
	wStream* s = Stream_New(NULL, sizeof(data));
	if (!s)
		goto out;

	Stream_Write(s, data, sizeof(data));
	if (memcmp(Stream_Buffer(s), data, sizeof(data)) != 0)
		goto out;
	Stream_SetPosition(s, 0);
	if (s->pointer != s->buffer)
		goto out;
	Stream_Fill(s, fill[0], sizeof(fill));
	if (s->pointer != s->buffer + sizeof(fill))
		goto out;
	if (memcmp(Stream_Pointer(s), data+sizeof(fill), sizeof(data)-sizeof(fill)) != 0)
		goto out;
	Stream_SetPosition(s, 0);
	if (s->pointer != s->buffer)
		goto out;
	if (memcmp(Stream_Pointer(s), fill, sizeof(fill)) != 0)
		goto out;

	rc = TRUE;
out:
	Stream_Free(s, TRUE);
	return rc;
}
示例#2
0
int main( int argc, char * argv[] )
{
    /*TreeNode * syntaxTree = NULL;*/

    char pgm[255]; /* source code file name */
#ifdef DEBUG
    source = fopen("J:\\pure_c\\story\\src\\bin\\Debug\\test.str", "rb");
#else
    if (argc != 2)
    {
        fprintf(stderr, "usage: %s <filename>\n", argv[0]);
        exit(1);
    }

    strcpy(pgm, argv[1]);
    if (strchr (pgm, '.') == NULL)
        strcat(pgm, ".str");

    source = fopen(pgm, "rb");
#endif // DEBUG

    if (source == NULL)
    {
        fprintf(stderr, "File %s not found\n", pgm);
        exit(1);
    }

    listing = stdout; /* send listing to screen */
    /*fprintf(listing, "\nSTORY COMPILATION: %s\n", pgm);*/
    /*GlobalState *gs;
    gs.GCdebt = 0;
    gs.totalBytes = 0;
    gs.gcoList = NULL;*/

    StState *st = StState_Create(ReallocateMemory, NULL);
    /*st.globalState = &gs;
    gs.stringTable = StringTable_Create(&st, 20);*/

    LexState scanState;
    scanState.appState = st;
    scanState.lineNumber = 0;
    scanState.lookAhead.token = TK_EOS;
    scanState.currentChar = 0;
    FileInputBuffer fib;
    fib.inputFile = source;
    fib.length = 0;

    MemoryStream ms;
    Stream_CreateFileMemoryStream(&ms, &fib);
    scanState.stream = &ms;
    MemoryBuffer mbuff;
    MemoryBuffer* pmbuff = &mbuff;
    MemoryBuffer_Create(st, pmbuff);
    scanState.tokenBuffer = pmbuff;
#if NO_PARSE
    Stream_Fill(scanState.stream);
    scanState.currentChar = *scanState.stream->currentPosition++;
    Lexer_ScanNextToken(&scanState);
    while(TRUE)
    {
        /*st_debug("token type: %d\n", scanState.currentToken.token);*/
        PrintToken(&scanState.currentToken, scanState.tokenBuffer->buffer);
        if (scanState.currentToken.token == TK_EOS) break;
        Lexer_ScanNextToken(&scanState);
    }

    /*fclose(source);*/
    MemoryBuffer_Free(st, pmbuff);

    /*while (getToken(&scanState) != EOS);*/
#else
    syntaxTree = parse();
    if (TraceParse)
    {
        fprintf(listing, "\nSyntax tree:\n");
        printTree(syntaxTree);
    }
#if !NO_ANALYZE
    if (!Error)
    {
        if (TraceAnalyze) fprintf(listing,"\nBuilding Symbol Table...\n");
        buildSymtab(syntaxTree);
        if (TraceAnalyze) fprintf(listing, "\nChecking Types...\n");
        typeCheck(syntaxTree);
        if (TraceAnalyze) fprintf(listing, "\nType Checking Finished\n");
    }
#if !NO_CODE
    if (! Error)
    {
        char * codefile;
        int fnlen = strcspn(pgm, ".");
        codefile = (char *) calloc(fnlen+4, sizeof(char));
        strncpy(codefile, pgm, fnlen);
        strcat(codefile, ".tm");
        code = fopen(codefile,"w");
        if (code == NULL)
        {
            printf("Unable to open %s\n",codefile);
            exit(1);
        }
        codeGen(syntaxTree,codefile);
        fclose(code);
    }
#endif
#endif
#endif
    fclose(source);
    return 0;
}