2026-02-16 02:08:54 +01:00
|
|
|
#include "vm/eval.h"
|
2026-02-15 20:57:19 +01:00
|
|
|
|
2026-02-16 02:08:54 +01:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
if (argc != 2) {
|
|
|
|
|
printf("usage: %s <path to .j file>\n", argv[0]);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2026-02-16 00:33:02 +01:00
|
|
|
// Creamos un allocator
|
2026-02-15 20:57:19 +01:00
|
|
|
JLANG_memory_allocator *allocPtr = JLANG_CreateAllocator();
|
|
|
|
|
|
2026-02-16 02:08:54 +01:00
|
|
|
// Read file from argv
|
|
|
|
|
FILE *fptr = fopen(argv[1], "r");
|
|
|
|
|
if (fptr == NULL) {
|
|
|
|
|
printf("error leyendo: %s\n", argv[1]);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2026-02-15 20:57:19 +01:00
|
|
|
|
2026-02-16 02:08:54 +01:00
|
|
|
fseek(fptr, 0, SEEK_END); // ir al final
|
|
|
|
|
long length = ftell(fptr); // cuántos bytes tiene
|
|
|
|
|
fseek(fptr, 0, SEEK_SET); // volver al inicio
|
|
|
|
|
char *buff = malloc(length + 1);
|
|
|
|
|
size_t bytesRead = fread(buff, 1, length, fptr);
|
|
|
|
|
buff[bytesRead] = '\0';
|
2026-02-16 01:36:41 +01:00
|
|
|
|
2026-02-16 02:08:54 +01:00
|
|
|
fclose(fptr);
|
2026-02-15 22:12:19 +01:00
|
|
|
|
2026-02-16 02:08:54 +01:00
|
|
|
printf("%s\n", buff);
|
2026-02-16 00:33:02 +01:00
|
|
|
|
2026-02-16 01:36:41 +01:00
|
|
|
// Lexer test
|
|
|
|
|
int totalTokens = 0;
|
2026-02-16 02:08:54 +01:00
|
|
|
Token *tokens = tokenize(buff, &totalTokens);
|
2026-02-16 01:36:41 +01:00
|
|
|
printf("totalTokens=%d\n", totalTokens);
|
2026-02-16 02:08:54 +01:00
|
|
|
ASTNode *block = parse(tokens, totalTokens);
|
2026-02-16 01:36:41 +01:00
|
|
|
ast_debug(block);
|
2026-02-16 02:08:54 +01:00
|
|
|
|
|
|
|
|
Environment env = {0};
|
Add while loops, GC mark-and-sweep, and malloc block reuse
- Lexer: add INDENT/DEDENT tokens, <, >, : operators, while keyword,
closing DEDENT emission, include guards
- Parser: add NODE_WHILE with while_loop union, parse while/cond/body
blocks, include guards
- Eval: add while loop evaluation, GC integration with roots from env,
debug and gc flags, <, > comparison operators
- GC: implement mark-and-sweep collector with 3 stages (mark roots,
sweep unmarked, join free blocks)
- Allocator: block reuse via first-fit search with splitting, exponential
heap growth, NULL check on malloc, include guards, marked field in metadata
- Object: add include guards, fix include to use allocator.h
2026-02-16 04:55:52 +01:00
|
|
|
eval(block, &env, allocPtr, 0, 1);
|
|
|
|
|
|
|
|
|
|
printf("heapSize=%zu\n", allocPtr->size);
|
2026-02-16 17:39:52 +01:00
|
|
|
JLANG_visualize(allocPtr);
|
2026-02-16 01:36:41 +01:00
|
|
|
|
2026-02-15 20:57:19 +01:00
|
|
|
return 0;
|
2026-02-15 20:48:01 +01:00
|
|
|
}
|