diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2024-09-25 19:47:29 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2024-09-25 19:47:29 +0330 |
commit | c409b8aaf6b6f63bd68a3356e146ab80b2ec8c4b (patch) | |
tree | 65ea5801fd910fc6bcff3f2e8f06b5fd7d249c78 /src/main.c | |
parent | f79290084948f3cf140395c270c07cf29ca58e8d (diff) |
fixed multiple variable definition bug
tried to implement import
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 75 |
1 files changed, 27 insertions, 48 deletions
@@ -1,22 +1,19 @@ +#include <compiler/tree_parser/tree_parser.h> #include <stdlib.h> #include <string.h> #include <utils/file.h> #include <utils/time.h> +#include <utils/types.h> #include <vm/runner/runner.h> -#include "compiler/tree_parser/tree_parser.h" -#include "utils/types.h" +#include "compiler/source_code/source_code.h" -static const char *codes[] = { - "print(\"Hello\\n\");", -}; - -Clock runWithPrint(char const *restrict code) { +Clock runWithPrint(SourceCode *code) { Clock sum = 0; Clock diff = 0; - fprintf(stderr, "----code:\n%s\n----\n", code); + fprintf(stderr, "----code:\n%s\n----\n", code->codes[0]->code); Clock start = getTimeInNano(); - const Nodes nodes = lexer(code); + const Nodes nodes = lexer(code, 0); diff += getTimeInNano() - start; sum += diff; if (nodes.size != ERROR_SIZE) { @@ -70,53 +67,35 @@ Clock runWithPrint(char const *restrict code) { 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]); + SourceCode sourceCode = makeSourceCode(); + const char *const filePath = argv[1]; + + Code *code; + code = read_whole_file("std/builtins.felan"); + if (code == NULL) { + goto RETURN_ERROR; + } + pushToSourceCode(&sourceCode, code); + + code = read_whole_file(filePath); if (code == NULL) { - return 1; + goto RETURN_ERROR; } - char *import = read_whole_file("stdlib/builtins.felan"); - if (import == NULL) { - return 1; + pushToSourceCode(&sourceCode, code); + + if (!runner(&sourceCode)) { + goto RETURN_ERROR; } - 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); + deleteSourceCodeInners(sourceCode); + return 0; - free(code); - if (ret) { - return 0; - } else { - return 1; - } +RETURN_ERROR: + deleteSourceCodeInners(sourceCode); + return 1; } |