shithub: hammer

ref: 0c8cf4098baef78d7c3da9d3c029cdce5bd8ebb2
dir: /dat.h/

View raw version
typedef struct Nod Nod;
typedef struct Nlst Nlst;
typedef struct Typ Typ;
typedef struct Loc Loc;

#define ZL	(Nlst){nil, 0, 0}

struct Typ {
	int	t;
	char	linear;
	char	*name;
	Typ	*base;
	Typ	**args;
	int	nargs;
	Nod	*size;
};

struct Nlst {
	Nod	**v;
	int	nv;
	int	cap;
};

struct Loc {
	int	line;
	char	*file;
};

enum {
	Tvoid,
	Tarray,
	Tslice,
	Tfunc,
};

enum {
	Nexpr,
	Nif,
	Nfor,
	Niter,
	Nblk,
	Nlit,
	Nsym,
	Ndcl,
	Nfunc,
};

enum {
	Olit,
	Ovar,
	Oasn,
	Oadd,
	Osub,
	Omul,
	Odiv,
	Omod,
	Oshl,
	Oshr,
	Olor,
	Oland,
	Ogt,
	Olt,
	Oge,
	Ole,
	Oeq,
	One,
	Oinc,
	Odec,
	Orcv,
};

struct Nod {
	int	t;
	Loc	loc;
	union {
		struct {
			int	nsub;
			Nod	*sub;
		} top;
		struct {
			int	op;
			Nod	*lhs;
			Nod	*rhs;
			Typ	*type;
		} expr;
		struct {
			Nod	*idx;
			Nod	*arg;
			Nod	*body;
		} iter;
		struct {
			Nod	*init;
			Nod	*cond;
			Nod	*step;
			Nod	*body;
		} nfor;
		struct {
			Nod	*cond;
			Nod	*t;
			Nod	*f;
		} nif;
		struct {
			vlong	val;
		} lit;
		struct {
			char	*sym;
		} sym;
		struct {
			char	*name;
			Nlst	arg;
			Nod	*body;
		} fndef;
		struct {
			char	*name;
			char	*pkg;
			Typ	*type;
			Nod	*init;
		} dcl;
		struct {
			Nlst	body;
		} blk;
		struct {
			Nlst	args;
			Typ	*type;
			Nod	*body;
		} func;
	};
};

extern int	lexline;
extern char*	lexfile;