1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include "Compiler.h"
- #include "Test.h"
- #include "libraries/Math.h"
- #include "libraries/Time.h"
- #include "tokenizer/Tokenizer.h"
- #include "utils/Functions.h"
- #include "vm/Script.h"
- static long getNanos(void) {
- struct timespec time;
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time);
- return time.tv_nsec + time.tv_sec * 1000000000l;
- }
- static void start(int argAmount, const char** args) {
- if(argAmount >= 3 && strcmp(args[1], "test") == 0) {
- tsStart(args[2]);
- } else if(argAmount >= 2) {
- Error e;
- tTokenize(args[1], &e);
- if(eHasError(&e)) {
- puts(e.message);
- printf("line: %d\n", e.line);
- printf("path: %s\n", e.paths);
- return;
- }
- ByteCode* code = cCompile(&e);
- if(code == NULL) {
- puts(e.message);
- printf("line: %d\n", e.line);
- printf("path: %s\n", e.paths);
- return;
- }
- Script* sc = sInit(code);
- long time = -getNanos();
- sRun(sc);
- time += getNanos();
- printf("----------------\n%ld ns\n", time);
- sDelete(sc);
- }
- }
- int main(int argAmount, const char** args) {
- gfsInit();
- gstsInit();
- lTimeRegister();
- lMathRegister();
- start(argAmount, args);
- gstsDelete();
- gfsDelete();
- return 0;
- }
|