Clean up a bit. Initial scanner code.

master
Josh K 5 years ago
parent d6281d2f5c
commit 9461ea8323
  1. 6
      Makefile
  2. 4
      compiler.c
  3. 45
      main.c
  4. 7
      scanner.c
  5. 7
      scanner.h

@ -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
@ -28,13 +28,13 @@ SRCS := $(wildcard *.c)
OBJS_g := $(SRCS:.c=.o)
# include dirs
CFLAGS_g +=
CFLAGS_g +=
# libs
ifdef ISWIN
LDFLAGS_g +=
else
CFLAGS_g +=
CFLAGS_g +=
LDFLAGS_g +=
endif

@ -1,7 +1,7 @@
#include "compiler.h"
//#include "scanner.h"
#include "scanner.h"
void compile( VM* vm, const char* src ) {
//initScanner( src );
initScanner( src );
}

@ -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 );
}
/*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 );
//exit( EXIT_FAILURE );
}
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 ) {
}

@ -0,0 +1,7 @@
#ifndef __SCANNER_H
#define __SCANNER_H
void initScanner( const char* src );
#endif
Loading…
Cancel
Save