#define L2_BITSET_H | #define L2_BITSET_H | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdint.h> | |||||
typedef long long int l2_bitset_entry; | typedef long long int l2_bitset_entry; | ||||
#ifndef L2_GEN_H | |||||
#define L2_GEN_H | |||||
#include "../io.h" | |||||
void l2_gen_stack_frame(struct l2_bufio_writer *writer); | |||||
#endif |
void l2_bufio_writer_init(struct l2_bufio_writer *b, struct l2_io_writer *w); | void l2_bufio_writer_init(struct l2_bufio_writer *b, struct l2_io_writer *w); | ||||
void l2_bufio_flush(struct l2_bufio_writer *b); | void l2_bufio_flush(struct l2_bufio_writer *b); | ||||
static inline void l2_bufio_put(struct l2_bufio_writer *b, char ch); | static inline void l2_bufio_put(struct l2_bufio_writer *b, char ch); | ||||
static inline void l2_bufio_put_n(struct l2_bufio_writer *b, const char *ptr, size_t len); | |||||
static inline void l2_bufio_put_n(struct l2_bufio_writer *b, const void *ptr, size_t len); | |||||
/* | /* | ||||
* Useful readers and writers | * Useful readers and writers | ||||
b->buf[b->idx++] = ch; | b->buf[b->idx++] = ch; | ||||
} | } | ||||
static inline void l2_bufio_put_n(struct l2_bufio_writer *b, const char *ptr, size_t len) { | |||||
static inline void l2_bufio_put_n(struct l2_bufio_writer *b, const void *ptr, size_t len) { | |||||
size_t freespace = sizeof(b->buf) - b->idx; | size_t freespace = sizeof(b->buf) - b->idx; | ||||
if (len < freespace) { | if (len < freespace) { | ||||
memcpy(b->buf + b->idx, ptr, len); | memcpy(b->buf + b->idx, ptr, len); |
#ifndef L2_PARSE_LEX_H | #ifndef L2_PARSE_LEX_H | ||||
#define L2_PARSE_LEX_H | #define L2_PARSE_LEX_H | ||||
#include "io.h" | |||||
#include "../io.h" | |||||
enum l2_token_kind { | enum l2_token_kind { | ||||
L2_TOK_OPEN_PAREN, | L2_TOK_OPEN_PAREN, |
#define L2_PARSE_H | #define L2_PARSE_H | ||||
#include "lex.h" | #include "lex.h" | ||||
#include "../io.h" | |||||
void l2_parse(); | |||||
struct l2_parse_state { | |||||
struct l2_lexer *lexer; | |||||
struct l2_bufio_writer writer; | |||||
}; | |||||
void l2_parse_program(struct l2_parse_state *state); | |||||
#endif | #endif |
#include <stdlib.h> | #include <stdlib.h> | ||||
#include "bytecode.h" | |||||
#include "bitset.h" | |||||
#include "../bytecode.h" | |||||
#include "../bitset.h" | |||||
struct l2_vm_value { | struct l2_vm_value { | ||||
enum l2_value_flags { | enum l2_value_flags { |
#include "gen/gen.h" | |||||
#include "bytecode.h" | |||||
static void put(struct l2_bufio_writer *writer, l2_word word) { | |||||
l2_bufio_put_n(writer, &word, sizeof(word)); | |||||
} | |||||
void l2_gen_stack_frame(struct l2_bufio_writer *writer) { | |||||
put(writer, L2_OP_ALLOC_NAMESPACE); | |||||
} |
#include "parse/parse.h" | |||||
#include "gen/gen.h" | |||||
void l2_parse_program(struct l2_parse_state *state) { | |||||
l2_gen_stack_frame(&state->writer); | |||||
} |