create executable function which identifies and loads a cache if available
This commit is contained in:
@@ -31,6 +31,8 @@ add_custom_target(GenerateLexer DEPENDS ${LEXER_C} ${LEXER_H})
|
||||
|
||||
# Step 3: Add executable
|
||||
add_executable(argon external/xxhash/xxhash.c external/cwalk/src/cwalk.c ${CFILES} ${LEXER_C})
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
target_include_directories(argon PRIVATE ${CMAKE_SOURCE_DIR}/external/cwalk/include)
|
||||
|
||||
# Step 4: Build order
|
||||
add_dependencies(argon GenerateLexer)
|
||||
@@ -44,7 +46,7 @@ set_target_properties(argon PROPERTIES
|
||||
find_package(BDWgc REQUIRED)
|
||||
find_package(gmp REQUIRED)
|
||||
|
||||
target_compile_options(argon PRIVATE -O3 -Wall -Wextra -Wno-unused-function -Iexternal/cwalk/include -s)
|
||||
target_compile_options(argon PRIVATE -O3 -Wall -Wextra -Wno-unused-function -s)
|
||||
target_link_options(argon PRIVATE -static)
|
||||
|
||||
target_link_libraries(argon PRIVATE
|
||||
@@ -55,4 +57,6 @@ target_link_libraries(argon PRIVATE
|
||||
|
||||
target_include_directories(argon PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/lexer
|
||||
)
|
||||
)
|
||||
|
||||
add_custom_command(TARGET argon POST_BUILD COMMAND ${CMAKE_STRIP} $<TARGET_FILE:argon>)
|
||||
@@ -55,7 +55,9 @@ void resize_hashmap(struct hashmap *t) {
|
||||
while (temp) {
|
||||
hashmap_insert(t, temp->hash, temp->key, temp->val,
|
||||
temp->order); // Will increment count
|
||||
struct node *temp_temp = temp;
|
||||
temp = temp->next;
|
||||
free(temp_temp);
|
||||
}
|
||||
}
|
||||
free(old_list);
|
||||
|
||||
54
src/main.c
54
src/main.c
@@ -160,34 +160,24 @@ FAILED:
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
generate_siphash_key(siphash_key);
|
||||
ArgonObject *execute(char*absolute_path) {
|
||||
clock_t start, end;
|
||||
double time_spent, total_time_spent = 0;
|
||||
setlocale(LC_ALL, "");
|
||||
if (argc <= 1)
|
||||
return -1;
|
||||
ar_memory_init();
|
||||
char *CWD = get_current_directory();
|
||||
char *path_non_absolute = argv[1];
|
||||
char path[FILENAME_MAX];
|
||||
cwk_path_get_absolute(CWD, path_non_absolute, path,
|
||||
sizeof(path));
|
||||
|
||||
const char *basename_ptr;
|
||||
size_t basename_length;
|
||||
cwk_path_get_basename(path, &basename_ptr, &basename_length);
|
||||
cwk_path_get_basename(absolute_path, &basename_ptr, &basename_length);
|
||||
|
||||
if (!basename_ptr) return -1;
|
||||
if (!basename_ptr) return NULL;
|
||||
|
||||
char basename[FILENAME_MAX];
|
||||
memcpy(basename, basename_ptr, basename_length);
|
||||
|
||||
size_t parent_directory_length;
|
||||
cwk_path_get_dirname(path, &parent_directory_length);
|
||||
cwk_path_get_dirname(absolute_path, &parent_directory_length);
|
||||
|
||||
char parent_directory[FILENAME_MAX];
|
||||
memcpy(parent_directory, path, parent_directory_length);
|
||||
memcpy(parent_directory, absolute_path, parent_directory_length);
|
||||
parent_directory[parent_directory_length] = '\0';
|
||||
|
||||
char cache_folder_path[FILENAME_MAX];
|
||||
@@ -197,9 +187,9 @@ int main(int argc, char *argv[]) {
|
||||
cwk_path_join(cache_folder_path, basename, cache_file_path, sizeof(cache_file_path));
|
||||
cwk_path_change_extension(cache_file_path, BYTECODE_EXTENTION, cache_file_path, sizeof(cache_file_path));
|
||||
|
||||
FILE *file = fopen(path, "r");
|
||||
FILE *file = fopen(absolute_path, "r");
|
||||
if (!file) {
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
XXH3_state_t *hash_state = XXH3_createState();
|
||||
@@ -223,7 +213,7 @@ int main(int argc, char *argv[]) {
|
||||
DArray tokens;
|
||||
darray_init(&tokens, sizeof(Token));
|
||||
|
||||
LexerState state = {path, file, 0, 0, &tokens};
|
||||
LexerState state = {absolute_path, file, 0, 0, &tokens};
|
||||
start = clock();
|
||||
lexer(state);
|
||||
end = clock();
|
||||
@@ -237,7 +227,7 @@ int main(int argc, char *argv[]) {
|
||||
darray_init(&ast, sizeof(ParsedValue));
|
||||
|
||||
start = clock();
|
||||
parser(path, &ast, &tokens, false);
|
||||
parser(absolute_path, &ast, &tokens, false);
|
||||
end = clock();
|
||||
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
|
||||
total_time_spent += time_spent;
|
||||
@@ -277,10 +267,9 @@ int main(int argc, char *argv[]) {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
init_types();
|
||||
|
||||
start = clock();
|
||||
runtime(translated);
|
||||
RuntimeState state = init_runtime_state(translated);
|
||||
ArgonObject *resp = runtime(translated,state);
|
||||
|
||||
end = clock();
|
||||
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
|
||||
@@ -289,6 +278,23 @@ int main(int argc, char *argv[]) {
|
||||
printf("total time taken: %f seconds\n", total_time_spent);
|
||||
|
||||
free_translator(&translated);
|
||||
free(CWD);
|
||||
return 0;
|
||||
return resp;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
setlocale(LC_ALL, "");
|
||||
ar_memory_init();
|
||||
generate_siphash_key(siphash_key);
|
||||
init_types();
|
||||
char *CWD = get_current_directory();
|
||||
if (argc <= 1)
|
||||
return -1;
|
||||
char *path_non_absolute = argv[1];
|
||||
char path[FILENAME_MAX];
|
||||
cwk_path_get_absolute(CWD, path_non_absolute, path,
|
||||
sizeof(path));
|
||||
free(CWD);
|
||||
ArgonObject *resp = execute(path);
|
||||
if (resp) return 0;
|
||||
return -1;
|
||||
}
|
||||
@@ -79,13 +79,18 @@ void run_instruction(Translated *translated, RuntimeState *state,
|
||||
}
|
||||
}
|
||||
|
||||
void runtime(Translated translated) {
|
||||
RuntimeState init_runtime_state(Translated translated) {
|
||||
RuntimeState state = {
|
||||
checked_malloc(translated.registerCount * sizeof(ArgonObject *)), 0};
|
||||
struct Stack stack = {};
|
||||
return state;
|
||||
}
|
||||
|
||||
ArgonObject *runtime(Translated translated, RuntimeState state) {
|
||||
struct Stack stack = {NULL,NULL};
|
||||
state.head = 0;
|
||||
while (state.head < translated.bytecode.size) {
|
||||
run_instruction(&translated, &state, stack);
|
||||
}
|
||||
free(state.registers);
|
||||
return stack.scope;
|
||||
}
|
||||
@@ -19,6 +19,8 @@ uint64_t pop_bytecode(Translated *translated, RuntimeState *state);
|
||||
|
||||
void run_instruction(Translated *translated, RuntimeState *state, struct Stack stack);
|
||||
|
||||
void runtime(Translated translated);
|
||||
RuntimeState init_runtime_state(Translated translated);
|
||||
|
||||
ArgonObject *runtime(Translated translated, RuntimeState state);
|
||||
|
||||
#endif // RUNTIME_H
|
||||
@@ -1 +0,0 @@
|
||||
null
|
||||
Reference in New Issue
Block a user