Skip to content
Snippets Groups Projects
bc_compiler.h 1021 B
Newer Older
typedef struct String {
  u32 len;
  u32 capacity;
  u8 * str; 
} String;

typedef struct Function {
  Str name;
  u8 parameters;
  u16 locals;
  String bc;
} Function;

typedef struct Class {
  u16 fields;
  u16 * indexes;
} Class;

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 );

typedef struct Constants {
  Str * strings;
  i32 * integers;
  bool bools [2];
  i32 null_pos;
  Function * functions;
  Class * classes;
} Constants;

typedef struct Globals {
  Str * names;
} Globals;

typedef struct LocalScope {
  LocalScope * prev;
  Str * names;
  u16 * locals;
} LocalScope;

typedef struct BCCompilerState {
  Constants constants;
  Globals globals;
  LocalScope scope;
} BCCompilerState;

void ast_to_bc   ( Ast * ast, String * bc );
void generate_bc ( Ast * ast, String * bc );