Clean up a bit. Initial scanner code.
This commit is contained in:
parent
d6281d2f5c
commit
9461ea8323
6
Makefile
6
Makefile
|
@ -14,7 +14,7 @@ RM ?= rm -f
|
||||||
RMDIR ?= rm -rf
|
RMDIR ?= rm -rf
|
||||||
MKDIR ?= mkdir -p
|
MKDIR ?= mkdir -p
|
||||||
|
|
||||||
WARFLAGS := -Wall -Wextra -pedantic
|
WARFLAGS := -Wall #-Wextra -pedantic
|
||||||
|
|
||||||
CFLAGS_g := $(WARFLAGS) -std=gnu11 -O2 -msse2 -ffast-math -mfpmath=sse -DNDEBUG \
|
CFLAGS_g := $(WARFLAGS) -std=gnu11 -O2 -msse2 -ffast-math -mfpmath=sse -DNDEBUG \
|
||||||
-MMD
|
-MMD
|
||||||
|
@ -28,13 +28,13 @@ SRCS := $(wildcard *.c)
|
||||||
OBJS_g := $(SRCS:.c=.o)
|
OBJS_g := $(SRCS:.c=.o)
|
||||||
|
|
||||||
# include dirs
|
# include dirs
|
||||||
CFLAGS_g +=
|
CFLAGS_g +=
|
||||||
|
|
||||||
# libs
|
# libs
|
||||||
ifdef ISWIN
|
ifdef ISWIN
|
||||||
LDFLAGS_g +=
|
LDFLAGS_g +=
|
||||||
else
|
else
|
||||||
CFLAGS_g +=
|
CFLAGS_g +=
|
||||||
LDFLAGS_g +=
|
LDFLAGS_g +=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
//#include "scanner.h"
|
#include "scanner.h"
|
||||||
|
|
||||||
void compile( VM* vm, const char* src ) {
|
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 "vm.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
static void repl( VM* vm ) {
|
static void repl( VM* vm ) {
|
||||||
char line[512];
|
char line[512];
|
||||||
|
@ -13,6 +14,7 @@ static void repl( VM* vm ) {
|
||||||
if ( !fgets( line, sizeof(line), stdin ) ) {
|
if ( !fgets( line, sizeof(line), stdin ) ) {
|
||||||
printf( "\n" ); break;
|
printf( "\n" ); break;
|
||||||
}
|
}
|
||||||
|
printf( "= %s", line );
|
||||||
interpret( vm, line );
|
interpret( vm, line );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,12 +58,6 @@ int main( int argc, char** argv ) {
|
||||||
(void)argc; (void)argv;
|
(void)argc; (void)argv;
|
||||||
srand( time( NULL ) );
|
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;
|
VM vm;
|
||||||
initVM( &vm );
|
initVM( &vm );
|
||||||
|
|
||||||
|
@ -71,44 +67,9 @@ int main( int argc, char** argv ) {
|
||||||
runFile( &vm, argv[1] );
|
runFile( &vm, argv[1] );
|
||||||
} else {
|
} else {
|
||||||
fprintf( stderr, "Usage: clox [path]\n" );
|
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 );
|
freeVM( &vm );
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "scanner.h"
|
||||||
|
|
||||||
|
void initScanner( const char* src ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue