blob: 9342a12e470324c7491b33d251a0913f87312b20 [file] [log] [blame]
#pragma once
#include "lisp.h"
#include <stdbool.h>
struct function
{
char *name;
int nargs; // number of arguments
union {
struct value (*def0) ();
struct value (*def1) (struct value);
struct value (*def2) (struct value, struct value);
struct value (*def3) (struct value, struct value, struct value);
void *code_ptr;
unsigned long code_addr;
};
struct function *prev;
};
struct environment
{
struct function *first;
};
struct variable
{
char *name;
int number;
struct variable *prev;
};
// local environment
struct local
{
// temps are accessed at ebp - 8 * (num_vars + temp)
bool temps[ 64 ];
int num_vars;
struct variable *first;
};
// First pass populates local
void firstpass (struct value val, struct environment *env, struct local *local);
// Second pass generates code
void secondpass (struct value val, struct environment *env,
struct local *local);
void toplevel (struct value val, struct environment *env);
void compile (struct istream *is);
struct function *find_function (struct environment *env, char *name);