-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from KennyOliver/issue-211
Issue 211: Add Import/Export Support
- Loading branch information
Showing
19 changed files
with
409 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "module_cache.h" | ||
|
||
ModuleCacheEntry *lookup_module_cache(const char *module_path) { | ||
ModuleCacheEntry *entry = moduleCacheHead; | ||
while (entry) { | ||
if (strcmp(entry->module_path, module_path) == 0) { | ||
return entry; | ||
} | ||
entry = entry->next; | ||
} | ||
return NULL; | ||
} | ||
|
||
void store_module_cache(const char *module_path, Environment *export_env) { | ||
ModuleCacheEntry *entry = calloc(1, sizeof(ModuleCacheEntry)); | ||
if (!entry) { | ||
fatal_error("Memory allocation failed in store_module_cache.\n"); | ||
} | ||
entry->module_path = strdup(module_path); | ||
entry->export_env = | ||
export_env; // might want to copy export table in the future | ||
entry->next = moduleCacheHead; | ||
moduleCacheHead = entry; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef MODULE_CACHE_H | ||
#define MODULE_CACHE_H | ||
|
||
#include "../lexer/lexer.h" | ||
#include "../parser/parser.h" | ||
#include "interpreter_types.h" | ||
#include "utils.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
// Simple struct to hold cached module exports | ||
typedef struct ModuleCacheEntry { | ||
char *module_path; // key | ||
Environment *export_env; // pointer to an environment holding exports | ||
struct ModuleCacheEntry *next; | ||
} ModuleCacheEntry; | ||
|
||
static ModuleCacheEntry *moduleCacheHead = NULL; | ||
|
||
ModuleCacheEntry *lookup_module_cache(const char *module_path); | ||
void store_module_cache(const char *module_path, Environment *export_env); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.