Clean up a bit. Initial scanner code.
This commit is contained in:
parent
d6281d2f5c
commit
9461ea8323
2
Makefile
2
Makefile
|
@ -14,7 +14,7 @@ RM ?= rm -f
|
|||
RMDIR ?= rm -rf
|
||||
MKDIR ?= mkdir -p
|
||||
|
||||
WARFLAGS := -Wall -Wextra -pedantic
|
||||
WARFLAGS := -Wall #-Wextra -pedantic
|
||||
|
||||
CFLAGS_g := $(WARFLAGS) -std=gnu11 -O2 -msse2 -ffast-math -mfpmath=sse -DNDEBUG \
|
||||
-MMD
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "compiler.h"
|
||||
//#include "scanner.h"
|
||||
#include "scanner.h"
|
||||
|
||||
void compile( VM* vm, const char* src ) {
|
||||
//initScanner( src );
|
||||
initScanner( src );
|
||||
}
|
||||
|
||||
|
|
45
main.c
45
main.c
|
@ -4,6 +4,7 @@
|
|||
#include "vm.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
static void repl( VM* vm ) {
|
||||
char line[512];
|
||||
|
@ -13,6 +14,7 @@ static void repl( VM* vm ) {
|
|||
if ( !fgets( line, sizeof(line), stdin ) ) {
|
||||
printf( "\n" ); break;
|
||||
}
|
||||
printf( "= %s", line );
|
||||
interpret( vm, line );
|
||||
}
|
||||
}
|
||||
|
@ -56,12 +58,6 @@ int main( int argc, char** argv ) {
|
|||
(void)argc; (void)argv;
|
||||
srand( time( NULL ) );
|
||||
|
||||
double dfp = 22.0 / 7.0;
|
||||
printf( "DFP: %.64g\n", dfp );
|
||||
|
||||
float ffp = 22.0f / 7.0f;
|
||||
printf( "FFP: %.64f\n", ffp );
|
||||
|
||||
VM vm;
|
||||
initVM( &vm );
|
||||
|
||||
|
@ -71,44 +67,9 @@ int main( int argc, char** argv ) {
|
|||
runFile( &vm, argv[1] );
|
||||
} else {
|
||||
fprintf( stderr, "Usage: clox [path]\n" );
|
||||
exit( EXIT_FAILURE );
|
||||
//exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
/*Chunk c;
|
||||
initChunk( &c );
|
||||
//c.bDebug = false;
|
||||
|
||||
writeConstant( &c, 4.2f, 1 );
|
||||
writeConstant( &c, rand()/(float)RAND_MAX, 2 );
|
||||
|
||||
//for ( int i = 0; i < 10; ++i )
|
||||
// writeChunk( &c, rand() % NUM_OP, 5 );
|
||||
|
||||
// const overload
|
||||
for ( int i = 2; i < 6; ++i ) {
|
||||
writeConstant( &c, (float)rand()/RAND_MAX, 6 );
|
||||
}
|
||||
|
||||
writeConstant( &c, 69069, 9 );
|
||||
writeChunk( &c, OP_NEGATE, 9 );
|
||||
|
||||
writeConstant( &c, 22, 9 );
|
||||
writeChunk( &c, OP_ADD, 9 );
|
||||
|
||||
writeConstant( &c, 42, 9 );
|
||||
writeChunk( &c, OP_DIVIDE, 9 );
|
||||
|
||||
writeChunk( &c, OP_RETURN, 10 );
|
||||
|
||||
//disassembleChunk( &c, "test" );
|
||||
|
||||
interpret( &vm, &c );
|
||||
printChunkInfo( &c, "test" );
|
||||
|
||||
printf( "vm %u chunk %u valar %u\n", sizeof(VM), sizeof(Chunk), sizeof(ValueArray) );
|
||||
|
||||
freeChunk( &c );*/
|
||||
|
||||
freeVM( &vm );
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#include "scanner.h"
|
||||
|
||||
void initScanner( const char* src ) {
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue