Compare commits
No commits in common. "2d01b09ee9701fe92f775a345ee4d76ce662ffe8" and "c2f2658e9c8e3c3c44f60699a0449345c132bf64" have entirely different histories.
2d01b09ee9
...
c2f2658e9c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "include/ast.h"
|
||||
#include "include/dstr.h"
|
||||
#include "include/scope.h"
|
||||
#include "include/htab.h"
|
||||
#include "include/util.h"
|
||||
|
||||
extern AST* root;
|
||||
@ -28,7 +28,7 @@ AST* ast_init(ASTType type, void* data) {
|
||||
return ast;
|
||||
}
|
||||
|
||||
AST* ast_init_scope(ASTType type, void* data, Scope* scope) {
|
||||
AST* ast_init_scope(ASTType type, void* data, HTab* scope) {
|
||||
AST* ast = malloc(sizeof(AST));
|
||||
|
||||
ast->type = type;
|
||||
@ -53,8 +53,8 @@ void ast_destroy(AST* ast) {
|
||||
log_dbgf("Unknown ast type %d (max: %d)", ast->type, AST_TYPE_MAX);
|
||||
}
|
||||
|
||||
scope_destroy_psv(ast->scope);
|
||||
free(ast);
|
||||
htab_destroy(ast->scope);
|
||||
}
|
||||
|
||||
void ast_print(AST* ast) { ast_print_i(ast, 0); }
|
||||
|
13
src/exec.c
13
src/exec.c
@ -9,11 +9,12 @@
|
||||
#include "include/stack.h"
|
||||
#include "include/util.h"
|
||||
|
||||
extern AST* root;
|
||||
|
||||
AST* exec_find(char* name);
|
||||
|
||||
AST* exec_start(AST* ast) {
|
||||
log_dbg("Started execution.");
|
||||
|
||||
Stack* scope = stack_init();
|
||||
|
||||
HTab* global = htab_init();
|
||||
@ -46,13 +47,13 @@ AST* exec_block(AST* ast) {
|
||||
ASTBlockData* block = (ASTBlockData*)ast->data;
|
||||
|
||||
HTab* local = htab_init();
|
||||
// stack_push(scope, local);
|
||||
//stack_push(scope, local);
|
||||
|
||||
// Loop through all but last ast.
|
||||
for (int i = 0; i < block->ln - 1; i++) exec_exp(block->inside[i]);
|
||||
AST* last = exec_exp(block->inside[block->ln - 1]);
|
||||
|
||||
// stack_pop(scope);
|
||||
//stack_pop(scope);
|
||||
htab_destroy(local);
|
||||
|
||||
return last;
|
||||
@ -87,7 +88,7 @@ AST* exec_cf(AST* ast, size_t argc, AST** argv) {
|
||||
for (int i = 0; i < argc; i++) {
|
||||
char* key = ((ASTArgData*)fdef->argv[i]->data)->name;
|
||||
AST* val = argv[i];
|
||||
// htab_ins(scope->buf[scope->ln - 1], key, val);
|
||||
//htab_ins(scope->buf[scope->ln - 1], key, val);
|
||||
}
|
||||
|
||||
return exec_exp(fdef->body);
|
||||
@ -110,7 +111,7 @@ AST* exec_vdef(AST* ast) {
|
||||
ASTVDefData* data = (ASTVDefData*)ast->data;
|
||||
AST* val = data->val;
|
||||
char* key = data->name;
|
||||
// htab_ins(scope->buf[scope->ln - 1], key, val);
|
||||
//htab_ins(scope->buf[scope->ln - 1], key, val);
|
||||
return exec_exp(val);
|
||||
}
|
||||
|
||||
@ -137,7 +138,7 @@ AST* exec_fdef(AST* ast) {
|
||||
ASTFDefData* fdef = (ASTFDefData*)ast->data;
|
||||
AST* val = fdef->body;
|
||||
char* key = fdef->name;
|
||||
// htab_ins(scope->buf[scope->ln - 1], key, val);
|
||||
//htab_ins(scope->buf[scope->ln - 1], key, val);
|
||||
return val; // Function definitions return function body.
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define AST_H
|
||||
|
||||
#include "htab.h"
|
||||
#include "scope.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
// The type of an `AST`.
|
||||
@ -33,13 +32,13 @@ typedef enum {
|
||||
typedef struct {
|
||||
ASTType type; // The type of the `AST`.
|
||||
void* data; // The data of the `AST`.
|
||||
Scope* scope; // The scope of the `AST`.
|
||||
HTab* scope; // The scope of the `AST`.
|
||||
} AST;
|
||||
|
||||
// Create a new `AST`.
|
||||
AST* ast_init(ASTType type, void* data);
|
||||
// Create a new `AST` with a specified scope.
|
||||
AST* ast_init_scope(ASTType type, void* data, Scope* scope);
|
||||
AST* ast_init_scope(ASTType type, void* data, HTab* scope);
|
||||
// Destroy an `AST`, recursively.
|
||||
void ast_destroy(AST* ast);
|
||||
// Print an `AST`, recursively.
|
||||
|
@ -1,19 +0,0 @@
|
||||
#ifndef SCOPE_H
|
||||
#define SCOPE_H
|
||||
|
||||
#include "htab.h"
|
||||
|
||||
// Represents the reverse linked tree of scope.
|
||||
typedef struct SCOPE_T {
|
||||
HTab* here;
|
||||
struct SCOPE_T* inherit;
|
||||
} Scope;
|
||||
|
||||
// Create a new `Scope`.
|
||||
Scope* scope_init(HTab* here, Scope* inherit);
|
||||
// Destroy all linked `Scope`s this inherits from.
|
||||
void scope_destroy(Scope* scope);
|
||||
// Destroy the current `Scope` only.
|
||||
void scope_destroy_psv(Scope *scope);
|
||||
|
||||
#endif
|
24
src/scope.c
24
src/scope.c
@ -1,24 +0,0 @@
|
||||
#include "include/scope.h"
|
||||
#include "include/htab.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
Scope* scope_init(HTab* here, Scope* inherit) {
|
||||
Scope* scope = malloc(sizeof(Scope));
|
||||
|
||||
scope->here = here;
|
||||
scope->inherit = inherit;
|
||||
|
||||
return scope;
|
||||
}
|
||||
|
||||
void scope_destroy(Scope* scope) {
|
||||
htab_destroy(scope->here);
|
||||
if (scope->inherit != NULL) scope_destroy(scope->inherit);
|
||||
free(scope);
|
||||
}
|
||||
|
||||
void scope_destroy_psv(Scope* scope) {
|
||||
htab_destroy(scope->here);
|
||||
scope->inherit = NULL;
|
||||
free(scope);
|
||||
}
|
@ -1 +1 @@
|
||||
Subproject commit 73237c5d224169c7b4d2ec8321f9ac92e8071708
|
||||
Subproject commit cdf1d0297effc2736ee847e557b4275b4f02310b
|
Loading…
x
Reference in New Issue
Block a user