Newer
Older
Michal Štěpánek
committed
#pragma once
#include "parser.h"
#include "heap.h"
#include "string.h"
#define INIT_STRING_LENGTH 512
#define MAX_SCOPE_VARIABLES 128
Michal Štěpánek
committed
typedef struct String {
u32 len;
u32 capacity;
u8 * str;
} String;
u8 parameters;
u16 locals;
String bc;
} BCClass;
typedef struct BCConstant {
ConstantType kind;
union {
i32 integer;
bool boolean;
Str string;
BCFunction function;
BCClass class;
};
} BCConstant;
void string_init ( String * str );
void string_destroy ( String * str );
void string_write_byte ( String * str, const u8 data );
void string_write_u16 ( String * str, const u16 data );
void string_write_i32 ( String * str, const i32 data );
void string_write_constant ( String * str, BCConstant constant );
BCConstant constants [ 256 * 256 ];
u16 constant_count;
} Constants;
typedef struct Globals {
} Globals;
typedef struct LocalScope {
u16 used_locals; // locals at use in this scope
u16 local_count; // locals at use at this time
} LocalScope;
typedef struct BCCompilerState {
Constants constants;
Globals globals;
LocalScope * scope;
u16 fp;
u16 ep;
BCConstant create_function ( u8 parameters );
LocalScope * create_function_scope ( u8 parameters );
u16 get_string_index ( BCCompilerState * state, Str str );
u16 get_local_index ( BCCompilerState * state, Str name );
void gen_bc_constant ( BCCompilerState * state, u16 index );
void insert_constant ( BCCompilerState * state, BCConstant constant );
void bc_state_init ( BCCompilerState * state );
void bc_state_destroy ( BCCompilerState * state );
void ast_to_bc ( BCCompilerState * state, Ast * ast );