#include #include #include #include #include #include "compiler/tree_parser/tree_parser.h" #include "utils/types.h" static const char *codes[] = { "print(\"Hello\\n\");", }; Clock runWithPrint(char const *restrict code) { Clock sum = 0; Clock diff = 0; fprintf(stderr, "----code:\n%s\n----\n", code); Clock start = getTimeInNano(); const Nodes nodes = lexer(code); diff += getTimeInNano() - start; sum += diff; if (nodes.size != ERROR_SIZE) { printNodes(nodes); fprintf(stderr, "----lexing in %ldns\n", diff); start = getTimeInNano(); ParsedNode *parsedNode = _parser(nodes, code); diff = getTimeInNano() - start; sum += diff; if (parsedNode != NULL) { printParsedNode(parsedNode); fprintf(stderr, "----node parsing in %ldns\n", diff); start = getTimeInNano(); ParsedTree *parsedTree = _treeParser(parsedNode, code); diff = getTimeInNano() - start; sum += diff; if (parsedTree != NULL) { printParsedTreeNode(parsedTree); fprintf(stderr, "----tree parsing in %ldns\n", diff); start = getTimeInNano(); Instructions instructions = _codeGenerator(parsedTree, code); diff = getTimeInNano() - start; sum += diff; if (instructions.size != ERROR_SIZE) { printInstructions(instructions); fprintf(stderr, "----code_generator in %ldns\n", diff); start = getTimeInNano(); bool ranSuccess = _runner(instructions); diff = getTimeInNano() - start; sum += diff; fprintf(stderr, "----runner in %ldns\n", diff); fprintf(stderr, "ran sucessfully = %s\n", ranSuccess ? "true" : "false"); fprintf(stderr, "----sum %ldns\n", sum); deleteInstructions(instructions); } else { fprintf(stderr, "----returned error"); } deleteParsedTree(parsedTree); } else { fprintf(stderr, "----returned error"); } deleteParsedNode(parsedNode); } else { fprintf(stderr, "----returned error"); } } else { fprintf(stderr, "----returned error"); } deleteNodes(nodes); return sum; } Clock process() { Clock sumAll = 0; for (size_t i = 0; i < sizeof(codes) / sizeof(char *); ++i) { Clock start = getTimeInNano(); runWithPrint(codes[i]); sumAll += getTimeInNano() - start; } return sumAll; } void runBenchmark() { Clock sum = 0; const int times = 100; for (int i = 0; i < times; ++i) { sum += process(); } printf("\n\navg = %fns", ((float)sum) / times); } int main(int argc, char *argv[]) { /*runBenchmark();*/ if (argc < 2) { fprintf(stderr, "no file"); return 1; } char *code = read_whole_file(argv[1]); if (code == NULL) { return 1; } char *import = read_whole_file("stdlib/builtins.felan"); if (import == NULL) { return 1; } char *lastCode = code; code = a404m_malloc(strlen(code) + strlen(import) + 2); strcpy(code, import); strcat(code, "\n"); strcat(code, lastCode); free(lastCode); free(import); bool ret = runner(code); free(code); if (ret) { return 0; } else { return 1; } }