language

some fools attempt at an interpreted language
Log | Files | Refs | README

bc.h (1762B)


      1 /* `bc` handles bytecode objects.
      2  */
      3 
      4 #ifndef BC_H
      5 #define BC_H
      6 
      7 #include <stdlib.h>
      8 #include <stdio.h>
      9 
     10 #include "fh.h"
     11 #include "var.h"
     12 #include "helper.h"
     13 
     14 typedef unsigned int bc_addr;
     15 
     16 /* 'Bytecode Container'
     17  */
     18 typedef struct bc_cont {
     19 	bc_addr   real_addr; // Real address of instruction
     20 	byte_t    op;        // Opcode of instruction
     21 	byte_t    mdata;     // Opcode metadata
     22 	byte_t    adata;     // Opcode arguement metadata
     23 	byte_t*   args[3];   // Raw arguements
     24 	int       sarg[3];   // Size of arguements
     25 	var_cont* varg[3];   // Typed arguements
     26 } bc_cont;
     27 
     28 typedef struct bc_t {
     29 	bc_addr   size;                     // Size of program
     30 	bc_cont*  heap;   // Heap of instructions
     31 } bc_t;
     32 
     33 #include "is.h"
     34 
     35 /* Handles allocation for new `bc_cont` instances
     36  */
     37 void bc_cont_new(bc_cont*);
     38 
     39 /* Deallocates all the things, assuming the arguement is the root.
     40  *  bc_cont* - bytecode container, root node (hopefully)
     41  */
     42 void bc_cont_del(bc_cont*);
     43 
     44 /* Given a file object, and an instance of `bc_cont` with proper metadata, this
     45  * function will read arguements into bc_cont.
     46  */
     47 void get_opcode_adata(FILE*, bc_cont*);
     48 byte_t* get_byte_arg (FILE*, int*);
     49 byte_t* get_name_arg (FILE*, int*);
     50 byte_t* get_addr_arg (FILE*, int*);
     51 byte_t* get_dync_arg (FILE*, int*);
     52 
     53 /* Process arguements into typed & readable data
     54  *  bc_cont* - bytecode container
     55  */
     56 void process_args(bc_cont*);
     57 
     58 /* Reads program into bc_cont instances
     59  *  FILE*    - File descriptor
     60  *  bc_addr* - pointer to size variable
     61  */
     62 bc_cont* bc_read(FILE* f, bc_addr*);
     63 
     64 /* Reads program into bc_t instance
     65  *  char* - filename
     66  */
     67 bc_t* bc_init(char*);
     68 
     69 /* Deletes instance of bc_t*
     70  */
     71 void bc_del(bc_t*);
     72 
     73 /* Thing for pretty printing
     74  */
     75 void bc_print_op(bc_cont*);
     76 
     77 #endif // BC_H