shithub: hammer

ref: e01f61f0d55b37630264e8d74107199752a6e76f
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 {
	Tunkn,
	Tvoid,
	Tchar,
	Tuchar,
	Tshort,
	Tushort,
	Tlong,
	Tulong,
	Tvlong,
	Tuvlong,
	Tarray,
	Tslice,
	Tfunc,
	Tstruct,
};

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

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

enum {
	Lint,
	Lstr,
	Lfloat,
};

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 {
			int	t;
			union {
				vlong	i;
				double	d;
				char	*s;
			};
		} 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 {
			char	*name;
			Nlst	args;
			Typ	*type;
			Nod	*body;
		} func;
		struct {
			char	*name;
			Nlst	args;
		} call;
	};
};
#pragma	   varargck    type  "N"   Nod*
#pragma	   varargck    type  "O"   Nod*
#pragma	   varargck    type  "L"   Nlst
#pragma	   varargck    type  "M"   Nlst

extern int	lexline;
extern char*	lexfile;