#ifndef VM_COMPILE_H #define VM_COMPILE_H #include "../common/fio.h" #include "../common/llist.h" #include "../common/data.h" #include // FILE /*** GLOBAL DATA ***/ extern char* vm_datatypes[]; extern char* vm_expressions[]; extern char* vm_assignments[]; extern char* vm_operations[]; extern const char *vm_pc_binary_operators[]; extern const char *vm_pc_assignment_operators[]; extern const char *vm_pc_operators[][6]; struct vm_pc_Scope vm_pc_global_scope; struct Table *vm_pc_group_scopes; struct Table *vm_pc_local_scopes; /*** STRUCTURES ***/ struct vm_pc_Variable { char *type; // data type as string, malloc'd and memcpy'd char *data; // data as string, malloc'd and memcpy'd }; struct vm_pc_Operation { int operation; char *var_1; char *var_2; char *var_3; char *var_4; }; struct vm_pc_Function { struct vm_pc_Variable *ret; // return variable struct Table *parameters; // input params struct Table *variables; // function local variables struct Table *operations; // operations! :) }; struct vm_pc_Scope { struct Table *variables; struct Table *functions; }; struct vm_pc_ENode { char type; // +, -, /, variable, value, function, etc. void *data; // variable name, function, etc. struct vm_pc_ENode *left; struct vm_pc_ENode *right; }; struct vm_pc_ENodeFunction { char *name; // name of function struct vm_pc_ENode *params; // array of parameters in Expression form }; /*** PARSING ***/ int vm_precompileFile(const char *file_name); //int vm_precompileSection(FILE *file, int *lpos_, int *cpos_, struct vm_pc_Scope *global, struct vm_pc_Scope *group, struct vm_pc_Scope *local); int vm_precompileSection(char *file_buffer, int *file_pos_, int *lpos_, int *cpos_, struct vm_pc_Scope *global, struct vm_pc_Scope *group, struct vm_pc_Scope *local); //int vm_precompileFunction(FILE *file, int *lpos_, int *cpos_, struct vm_pc_Scope *global, struct vm_pc_Scope *group, struct vm_pc_Scope *local, struct vm_pc_Function *func); int vm_precompileFunction(char *file_buffer, int *file_pos_, int *lpos_, int *cpos_, struct vm_pc_Scope *global, struct vm_pc_Scope *group, struct vm_pc_Scope *local, struct vm_pc_Function *func); /*** POPULATING ***/ int vm_pc_addVariableToScope(struct vm_pc_Scope *scope, const char *data_type, const char *data_name); int vm_pc_addFunctionToScope(struct vm_pc_Scope *scope, struct vm_pc_Function *func, const char *func_name); int vm_pc_setVariable(struct vm_pc_Variable *variable, const char *value); /*** ALLOC ***/ struct vm_pc_ENode *vm_pc_newENode(char type, void *data); struct vm_pc_Variable *vm_pc_newVariable(const char *type, const char *value); struct vm_pc_Function *vm_pc_newFunction(); /*** FREE ***/ int vm_pc_freeVariable(struct vm_pc_Variable *variable); int vm_pc_freeVariables(struct Table *variables); int vm_pc_freeFunction(struct vm_pc_Function *function); int vm_pc_freeFunctions(struct Table *functions); int vm_pc_freeScope(struct vm_pc_Scope *scope); /*** ETC ***/ int vm_pc_dumpScope(struct vm_pc_Scope *scope); int vm_isReserved(char *word); #endif