--- /dev/null
+#include "cerise.h"
+#include <limits.h>
+#include <assert.h>
+
+Type BoolType = {
+ .form = FORM_BOOL,
+ .size = sizeof(bool)
+};
+
+Type IntType = {
+ .form = FORM_INT,
+ .size = sizeof(long)
+};
+
+Type RealType = {
+ .form = FORM_REAL,
+ .size = sizeof(double)
+};
+
+Type StringType = {
+ .form = FORM_STRING,
+ .size = -1
+};
+
+
+static size_t MaxBlocks = 0;
+static size_t NumBlocks = 0;
+static Block* Blocks = NULL;
+
+static size_t block_new(void)
+{
+ if (NumBlocks == MaxBlocks)
+ {
+ MaxBlocks = (MaxBlocks ? 16u : (MaxBlocks << 1u));
+ Blocks = realloc(Blocks, MaxBlocks * sizeof(Block));
+ }
+ memset(&Blocks[NumBlocks], 0, sizeof(Block));
+ NumBlocks++;
+ return (NumBlocks-1);
+}
+
+static void put_op(size_t blkid, Operation* op)
+{
+ assert(blkid < NumBlocks);
+ Block* block = &Blocks[blkid];
+ if (block->nops == block->mops)
+ {
+ block->mops = (block->mops ? 4u : (block->mops << 1u));
+ block->ops = realloc(block->ops, block->mops * sizeof(Operation));
+ }
+ block->ops[block->nops++] = *op;
+}
+
+
+void codegen_startmod(Parser* p)
+{
+ (void)p;
+}
+
+void codegen_endmod(Parser* p)
+{
+ (void)p;
+}
+
+void codegen_setint(Item* item, Type* type, long long val)
+{
+ item->mode = ITEM_CONST;
+ item->type = type;
+ item->reg = 0;
+ item->imm.i = val;
+}
+
+void codegen_setreal(Item* item, double val)
+{
+ item->mode = ITEM_CONST;
+ item->type = &RealType;
+ item->reg = 0;
+ item->imm.f = val;
+}
+
+void codegen_setstr(Item* item, char* val)
+{
+ item->mode = ITEM_CONST;
+ item->type = &StringType;
+ item->reg = 0;
+ item->imm.s = val;
+}
+
+void codegen_imports(Parser* p)
+{
+ (void)p;
+}
+
+void codegen_var(Parser* p, Symbol* sym)
+{
+ (void)p, (void)sym;
+}
+
+void codegen_main(Parser* p)
+{
+ (void)p;
+}
+
+void codegen_startproc(Parser* p, Symbol* proc)
+{
+ (void)p, (void)proc;
+ printf("func %s(){\n", (proc ? proc->name : p->name));
+ printf("L%lu:\n", block_new());
+}
+
+void codegen_endproc(Parser* p)
+{
+ (void)p;
+ printf("}\n");
+}
+
+void codegen_unop(Parser* p, int op, Item* a)
+{
+ (void)p, (void)op, (void)a;
+}
+
+void codegen_binop(Parser* p, int op, Item* a, Item* b)
+{
+ (void)p, (void)op, (void)a, (void)b;
+}
+
+void codegen_store(Parser* p, Item* a, Item* b)
+{
+ (void)p, (void)a, (void)b;
+}
+
+void codegen_if(Parser* p, Item* item)
+{
+ (void)p, (void)item;
+}
+
+void codegen_else(Parser* p, Item* item)
+{
+ (void)p, (void)item;
+}
+
+void codegen_endif(Parser* p, long elsifs, Item* item)
+{
+ (void)p, (void)elsifs, (void)item;
+}
+
+void codegen_prepcall(Parser* p, Item* item)
+{
+ (void)p, (void)item;
+}
+
+void codegen_call(Parser* p, Item* item, Item* args)
+{
+ (void)p, (void)item, (void)args;
+}
+
+void codegen_setarg(Parser* p, Item* item, bool firstarg)
+{
+ (void)p, (void)item, (void)firstarg;
+}
+
+void codegen_return(Parser* p, Item* item)
+{
+ (void)p, (void)item;
+}
+
+void codegen_index(Parser* p, Item* array, Item* index)
+{
+ (void)p, (void)array, (void)index;
+}
+
+void codegen_field(Parser* p, Item* record, char* name)
+{
+ (void)p, (void)record, (void)name;
+}
+
typedef struct {
size_t nops;
size_t mops;
- Operation** ops;
+ Operation* ops;
} Block;
long ir_startblock(Parser* p);
void ir_binopf(Parser* p, int op, long dest, long arg, double imm);
void ir_unnopi(Parser* p, int op, long dest, long imm);
void ir_unopf(Parser* p, int op, long dest, double imm);
-
-/* <op> <reg>, <base>+<off> */
-/* <op> <base>+<off>, <reg> */
-/* <op> <reg>, <reg> */
-/* <op> <reg>, <reg>, <reg> */
-
-/*
-
-typedef struct AnfNode {
- enum {
- ANF_VAR, ANF_BEGIN, ANF_PROC, ANF_IF, ANF_SET, ANF_LET
- } form;
-} AnfNode;
-
-;; <prog> ::= <dec> ...
-
-;; <dec> ::= (define <var> <exp>)
-;; | (begin <dec> ...)
-;; | <exp>
-
-;; <aexp> ::= (λ (<name> ...) <exp>)
-;; | <number>
-;; | <boolean>
-;; | <string>
-;; | <var>
-;; | (void)
-
-;; <cexp> ::= (<aexp> <aexp> ...)
-;; | (if <aexp> <exp> <exp>)
-;; | (set! <var> <exp>)
-
-;; <exp> ::= (let ([<var> <cexp>]) <exp>)
-;; | <aexp>
-;; | <cexp>
-
-
-*/