Test program

This commit is contained in:
Dale Weiler 2012-04-11 04:18:40 -04:00
parent 9904bb58c4
commit 387a6ecfa7
2 changed files with 32 additions and 0 deletions

17
code.c
View file

@ -149,6 +149,22 @@ VECTOR_MAKE(char*, code_strings );
/* program header */
prog_header code_header;
void code_write() {
/* Add test program */
code_strings_add(NULL); /* from my understanding str 0 = NULL (always!) */
code_strings_add("test program"); /* whoo a test program :3 */
code_statements_add((prog_section_statement){INSTR_ADD_F, 1, 2, OFS_RETURN});
code_statements_add((prog_section_statement){INSTR_DONE, 0, 0, 0});
code_functions_add ((prog_section_function) {
.entry = 0,
.args = 0,
.locals = 0,
.profile = 0,
.name = 1, /*0 in string table is NULL always */
.nargs = 0, /* CALL0 (no args) */
.argsize = (uint8_t*){0,0,0,0,0,0,0,0}
});
code_header.version = 6;
code_header.crc16 = 0; /* TODO: */
code_header.statements = (prog_section){sizeof(prog_header), code_statements_elements };
@ -166,6 +182,7 @@ void code_write() {
fwrite(code_fields_data, 1, sizeof(prog_section_field) *code_fields_elements, fp);
fwrite(code_functions_data, 1, sizeof(prog_section_function) *code_functions_elements, fp);
fwrite(code_globals_data, 1, sizeof(prog_section_var) *code_globals_elements, fp);
fwrite(
#endif
free(code_statements_data);

15
gmqcc.h
View file

@ -158,6 +158,21 @@ char *util_strdup (const char *);
#define TYPE_FUNCTION 6
#define TYPE_POINTER 7
/*
* Each paramater incerements by 3 since vector types hold
* 3 components (x,y,z).
*/
#define OFS_NULL 0
#define OFS_RETURN 1
#define OFS_PARM0 (OFS_RETURN+3)
#define OFS_PARM1 (OFS_PARM0 +3)
#define OFS_PARM2 (OFS_PARM1 +3)
#define OFS_PARM3 (OFS_PARM2 +3)
#define OFS_PARM4 (OFS_PARM3 +3)
#define OFS_PARM5 (OFS_PARM4 +3)
#define OFS_PARM6 (OFS_PARM5 +3)
#define OFS_PARM7 (OFS_PARM6 +3)
/*
* Instructions
* These are the external instructions supported by the interperter