diff --git a/src/code.h b/src/code.h new file mode 100644 index 0000000..28d8446 --- /dev/null +++ b/src/code.h @@ -0,0 +1,22 @@ +#ifndef _CODE_H +#define _CODE_H + +/* + Code area is bottom of heap memory +*/ +#define CODESTORE0(M,addr,cmd) M->data[addr]=(unsigned char)cmd +#define CODESTORE1N(M,addr,cmd,x) { CODESTORE0(M,addr,cmd); *((number_t *)&M->data[addr+1])=(number_t)x; } +#define CODESTORE1I(M,addr,cmd,x) { CODESTORE0(M,addr,cmd); *((index_t *)&M->data[addr+1])=x; } +#define CODESTORE1A(M,addr,cmd,x) { CODESTORE0(M,addr,cmd); *((address_t*)&M->data[addr+1])=x; } + + +#define CODEADD0(M,cmd) M->data[M->bottom++]=(unsigned char)cmd +#define CODEADD1N(M,cmd,x) { CODEADD0(M,cmd); *((number_t *)&M->data[M->bottom])=(number_t)x; M->bottom+=number_s; } +#define CODEADD1I(M,cmd,x) { CODEADD0(M,cmd); *((index_t *)&M->data[M->bottom])=x; M->bottom+=index_s;} +#define CODEADD1A(M,cmd,x) { CODEADD0(M,cmd); *((address_t*)&M->data[M->bottom])=x; M->bottom+=address_s;} +#define CODEADDREADVAR(M,R,name) { address_t addr=Allocate(M,R, name, MVAR, 1, NULL); if (addr<0) return error(R,EVAR); CODEADD0(M,READ); *((address_t*)&M->data[M->bottom])=addr; M->bottom+=address_s; } + +index_t CompileExpr(lexer_t *lex, mem_t *M, reg_t *R); +void CompileInstr(lexer_t *lex, mem_t *M, reg_t *R); +int Compile(lexer_t *lex, char *buffer ,context_t *C, int runnable /* pstate */); +#endif