Skip to content

Commit

Permalink
🎨 this commit is to big
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed May 6, 2024
1 parent 7e09034 commit 30cd26a
Show file tree
Hide file tree
Showing 9 changed files with 408 additions and 28 deletions.
7 changes: 4 additions & 3 deletions include/env/type.h
Expand Up @@ -50,9 +50,10 @@ struct Type_ {
m_str name;
Nspc nspc;
struct TypeInfo_ *info;
uint32_t size;
uint32_t actual_size;
uint32_t array_depth; // TODO: encode in array type
uint64_t size;
uint64_t actual_size;
// struct Vector_ effects; // pre-ctor effects
uint32_t array_depth;
uint16_t ref;
uint16_t weight;
ae_flag flag;
Expand Down
20 changes: 5 additions & 15 deletions src/emit/emit.c
Expand Up @@ -255,12 +255,7 @@ ANN void emit_pop_scope(const Emitter emit) {
ANN void emit_push_scope(const Emitter emit) {
frame_push(emit->code->frame);
vector_add(&emit->info->pure, 0);
//if (emit->info->debug) emit_add_instr(emit, DebugPush);
if (emit->info->debug) {

const Instr instr = emit_add_instr(emit, DebugPush);
instr->m_val = emit->status.line;
}
if (emit->info->debug) emit_add_instr(emit, DebugPush);
}

ANN m_uint emit_code_offset(const Emitter emit) {
Expand Down Expand Up @@ -989,11 +984,9 @@ static INSTR(UsedBy) {
}

ANN static void used_by(const Emitter emit, const Value v) {
puts("emit used by");
MP_Vector *vec = new_mp_vector(emit->gwion->mp, Func, 0);
for(uint32_t i = 0; i < v->used_by->len; i++) {
const Func f = *mp_vector_at(v->used_by, Func, i);
if(f->_wait) puts("Adding to wait list");
if(f->_wait) mp_vector_add(emit->gwion->mp, &vec, Func, f);
}
free_mp_vector(emit->gwion->mp, Func, v->used_by);
Expand Down Expand Up @@ -1922,13 +1915,11 @@ ANN2(1) /*static */ bool emit_exp(const Emitter emit, /* const */ Exp* e) {
Exp* exp = e;
do {
if (emit->info->debug){

printf("debug line: %i\n", e->loc.first.line);
if(emit->status.line < e->loc.first.line) {
const Instr instr = emit_add_instr(emit, DebugLine);
instr->m_val = emit->status.line = e->loc.first.line;
}
emit->status.line = e->loc.first.line;
const Instr instr = emit_add_instr(emit, DebugLine);
instr->m_val = emit->status.line = e->loc.first.line;
}
emit->status.line = e->loc.first.line;
}
CHECK_B(emit_exp_func[exp->exp_type](emit, &exp->d));
if (exp->cast_to) CHECK_B(emit_implicit_cast(emit, exp, exp->cast_to));
Expand Down Expand Up @@ -2615,7 +2606,6 @@ ANN static bool emit_exp_dot(const Emitter emit, const Exp_Dot *member) {
ANN static inline void emit_func_def_init(const Emitter emit, const Func func) {
emit_push_code(emit, func->name);
if(mp_vector_len(func->_wait)) {
puts("wait");
const Instr instr = emit_add_instr(emit, FuncWait);
instr->m_val = (m_uint) func;
}
Expand Down
6 changes: 3 additions & 3 deletions src/env/func.c
Expand Up @@ -61,10 +61,10 @@ ANN void builtin_func(const Gwion gwion, const Func f, void *func_ptr) {

ANN void print_signature(const Gwion gwion, const Func f) {
struct GwfmtState ls = {.minimize=true, .ppa = gwion->ppa};
// gwfmt_state_init(&ls);
gwfmt_state_init(&ls);
text_init(&ls.text, gwion->mp);
Gwfmt l = {.mp = gwion->mp, .st = gwion->st, .ls = &ls, .line = 1, .last = cht_nl };
gwfmt_func_def(&l, f->def);
Gwfmt gwfmter = {.mp = gwion->mp, .st = gwion->st, .ls = &ls, .line = 1, .last = cht_nl };
gwfmt_func_def(&gwfmter, f->def);
gwlog_related_from(ls.text.str, f->value_ref->from);
text_release(&ls.text);
}
Expand Down
6 changes: 5 additions & 1 deletion src/env/type.c
Expand Up @@ -35,14 +35,18 @@ Type new_type(MemPool p, const m_str name, const Type parent) {
type->name = name;
type->info = mp_calloc(p, TypeInfo);
type->info->parent = parent;
if (parent) type->size = parent->size;
if (parent) {
type->size = parent->size;
type->actual_size = parent->actual_size;
}
type->ref = 1;
return type;
}

ANN Type type_copy(MemPool p, const Type type) {
const Type a = new_type(p, type->name, type->info->parent);
a->size = type->size;
a->actual_size = type->actual_size;
a->array_depth = type->array_depth;
a->info->gack = type->info->gack;
return a;
Expand Down
97 changes: 97 additions & 0 deletions src/gwion_parse.c
@@ -0,0 +1,97 @@
#include "gwion_util.h"
#include "gwion_ast.h"
#include "gwion_env.h"
#include "vm.h"
#include "gwion.h"
#include "gwion_parse.h"

ANN Ast gwion_parse_ast(const Gwion gwion, const char *data) {
FILE *file = fmemopen((void*)data, strlen(data), "r");
struct AstGetter_ arg = {gwion->env->name, file, gwion->st, .ppa = gwion->ppa};
return parse(&arg);
}


ANN static Ast gwion_parse_ast1(const Gwion gwion, const char *data, const loc_t loc) {
DECL_O(const Ast, ast, = gwion_parse_ast(gwion, data));
if(ast->len != 1) {
gwlog_error("more than one section", NULL, gwion->env->name, loc, 0);
free_ast(gwion->mp, ast);
return NULL;
}
return ast;
}

ANN Func_Def gwion_parse_func_def(const Gwion gwion, const char *data, const loc_t loc) {
DECL_O(const Ast, ast, = gwion_parse_ast1(gwion, data, loc));
Section *section = mp_vector_at(ast, Section, 0);
if(section->section_type != ae_section_func) {
gwlog_error("invalid section type", NULL, gwion->env->name, loc, 0);
free_ast(gwion->mp, ast);
return NULL;
}
Func_Def fdef = section->d.func_def;
free_ast(gwion->mp, ast);
return fdef;
}

ANN Stmt_List gwion_parse_stmt_list(const Gwion gwion, const char *data, const loc_t loc) {
DECL_O(const Ast, ast, = gwion_parse_ast1(gwion, data, loc));
Section *section = mp_vector_at(ast, Section, 0);
if(section->section_type != ae_section_stmt) {
gwlog_error("invalid section type", NULL, gwion->env->name, loc, 0);
free_ast(gwion->mp, ast);
return NULL;
}
Stmt_List stmts = section->d.stmt_list;
free_mp_vector(gwion->mp, Section, ast);
return stmts;
}

ANN Exp *gwion_parse_expression(const Gwion gwion, const char *data, const loc_t loc) {
char* str = NULL;
gw_asprintf(gwion->mp, &str, "%s;", data);
Stmt_List stmts = gwion_parse_stmt_list(gwion, str, loc);
free_mstr(gwion->mp, str);
if(!stmts) return NULL;
if(stmts->len != 1) {
gwlog_error("invalid number of statements", NULL, gwion->env->name, loc, 0);
return NULL;
}
Stmt *stmt = mp_vector_at(stmts, Stmt, 0);
if(stmt->stmt_type != ae_stmt_exp) {
gwlog_error("invalid statement type", NULL, gwion->env->name, loc, 0);
return NULL;
}
Exp *exp = stmt->d.stmt_exp.val;
free_mp_vector(gwion->mp, Stmt, stmts);
return exp;
}

ANN Type_Decl *gwion_parse_type_decl(const Gwion gwion, const char *data, const loc_t loc) {
char* str = NULL;
gw_asprintf(gwion->mp, &str, "var %s A;", data);
Stmt_List stmts = gwion_parse_stmt_list(gwion, str, loc);
if(!stmts) {
return NULL;
}
// free_mstr(gwion->mp, str);
if(stmts->len != 1) {
gwlog_error("invalid number of statements", NULL, gwion->env->name, loc, 0);
return NULL;
}
Stmt *stmt = mp_vector_at(stmts, Stmt, 0);
if(stmt->stmt_type != ae_stmt_exp) {
gwlog_error("invalid statement type", NULL, gwion->env->name, loc, 0);
return NULL;
}
Exp *exp = stmt->d.stmt_exp.val;
free_mp_vector(gwion->mp, Stmt, stmts);
if(exp->exp_type != ae_exp_decl) {
gwlog_error("invalid expression type", NULL, gwion->env->name, loc, 0);
return NULL;
}
Type_Decl *td = cpy_type_decl(gwion->mp, exp->d.exp_decl.var.td);
free_exp(gwion->mp, exp);
return td;
}
6 changes: 3 additions & 3 deletions src/import/import_checker.c
Expand Up @@ -359,10 +359,10 @@ ANEW ANN m_str type2str(const Gwion gwion, const Type t,
ANEW ANN m_str tl2str(const Gwion gwion, const TmplArg_List tl,
const loc_t loc NUSED) {
struct GwfmtState ls = {.minimize=true, .ppa = gwion->ppa};
// gwfmt_state_init(&ls);
gwfmt_state_init(&ls);
text_init(&ls.text, gwion->mp);
Gwfmt l = {.mp = gwion->mp, .st = gwion->st, .ls = &ls, .line = 1, .last = cht_nl };
struct td_info info = {.tl = tl, .fmt = &l };
Gwfmt gwfmter = {.mp = gwion->mp, .st = gwion->st, .ls = &ls, .line = 1, .last = cht_nl };
struct td_info info = {.tl = tl, .fmt = &gwfmter };
CHECK_O(td_info_run(gwion->env, &info));
return ls.text.str;
}
Expand Down
4 changes: 2 additions & 2 deletions src/import/import_internals.c
Expand Up @@ -31,9 +31,9 @@ ANN void gwi_reset(const Gwi gwi) {

ANN static bool run_with_doc(const Gwi gwi, bool (*f)(const Gwi)) {
struct GwfmtState ls = {.builtin = true, .nindent = 4};
// gwfmt_state_init(&ls);
gwfmt_state_init(&ls);
text_init(&ls.text, gwi->gwion->mp);
Gwfmt gwfmter = {.mp = gwi->gwion->mp, .ls = &ls, .st = gwi->gwion->st };
Gwfmt gwfmter = {.mp = gwi->gwion->mp, .ls = &ls, .st = gwi->gwion->st };
gwfmt_indent(&gwfmter);
gwfmt_util(&gwfmter, "{-}#!+ %s{0}\n", gwi->gwion->env->name);
gwi->gwfmt = &gwfmter;
Expand Down

0 comments on commit 30cd26a

Please sign in to comment.