language

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

ns.h (2582B)


      1 /* `ns` Namespace implementation
      2  */
      3 
      4 #ifndef NS_H
      5 #define NS_H
      6 
      7 #include <stdlib.h>
      8 
      9 #include "var.h"
     10 #include "helper.h"
     11 
     12 typedef unsigned int ns_addr;
     13 
     14 typedef struct ns_cont {
     15 	long level;
     16 	ns_addr    size;
     17 	var_cont** names;
     18 	struct ns_cont* next;
     19 } ns_cont;
     20 
     21 typedef struct ns_t {
     22 	long id;
     23 	ns_cont* root;
     24 	ns_cont* last;
     25 } ns_t;
     26 
     27 #define NS_CTX_DEPTH 32
     28 typedef struct ns_ctx {
     29 	int ptr;
     30 	ns_t* spaces[NS_CTX_DEPTH];
     31 } ns_ctx;
     32 
     33 /* Initializes namespace context
     34  */
     35 ns_ctx* ns_ctx_init(void);
     36 void ns_ctx_del(ns_ctx*);
     37 
     38 /* Push namespace to context
     39  */
     40 void ns_ctx_push(ns_ctx*, ns_t*);
     41 
     42 /* Pop namespace out of context
     43  */
     44 ns_t* ns_ctx_pop(ns_ctx*);
     45 
     46 /* Initializes namespace of size
     47  *  ns_addr - name limit
     48  */
     49 ns_t* ns_init(ns_addr);
     50 
     51 /* Initialize namespace container of size
     52  *  ns_addr - name limit
     53  *  int     - level
     54  */
     55 ns_cont* ns_cont_init(ns_addr, int);
     56 
     57 /* Cleans up memory
     58  */
     59 void ns_del(ns_t*);
     60 var_cont* ns_cont_del(ns_cont*, ns_addr);
     61 
     62 /* Pushes namespace of size
     63  * ns_t*   - namespace instance
     64  * ns_addr - name limit
     65  */
     66 void ns_push(ns_t*, ns_addr);
     67 
     68 /* Pops last namespace level
     69  */
     70 var_cont* ns_pop(ns_t*);
     71 
     72 /* Declares a variable, at root or last namespace
     73  *  ns_t*     - Namespace instance
     74  *  b_type    - Type of variable
     75  *  int       - Mux value         [0]
     76  *  ns_addr   - Variable name
     77  *
     78  * @param[0] = namespace level
     79  *  0 -> current namespace
     80  *  1 -> global namespace
     81  */
     82 void ns_dec(ns_t*, b_type, int, ns_addr);
     83 
     84 /* Declares a variable, at namespace
     85  *  ns_t*     - Namespace instance
     86  *  b_type    - Type of variable
     87  *  ns_addr   - Variable name
     88  */
     89 void ns_cont_dec(ns_cont*, b_type, ns_addr);
     90 
     91 /* Sets variable to value, at root or last namespace
     92  *  ns_t*     - namespace instance
     93  *  int       - mux value         [0]
     94  *  ns_addr   - Variable name
     95  *  var_cont* - Variable
     96  *
     97  * @param[0] = namespace level
     98  * * 0 -> current namespace
     99  * * 1 -> global namespace
    100  */
    101 void ns_set(ns_t*, int, ns_addr, var_cont*);
    102 
    103 /* Sets variable to value, at root or last namespace
    104  *  ns_cont*  - Namespace instance
    105  *  var_cont* - Variable
    106  *  ns_addr   - Variable name
    107  */
    108 void ns_cont_set(ns_cont*, var_cont*, ns_addr);
    109 
    110 /* Gets variable from address
    111  *  ns_t*     - namespace instance
    112  *  int       - mux value         [0]
    113  *  ns_addr   - Variable name
    114  *
    115  * @param[0] = namespace level
    116  *  0 -> current namespace
    117  *  1 -> global namespace
    118  */
    119 var_cont* ns_get(ns_t*, int, ns_addr);
    120 
    121 /* Gets variable from address
    122  *  ns_t*     - namespace instance
    123  *  ns_addr   - Variable name
    124  */
    125 var_cont* ns_cont_get(ns_cont*, ns_addr);
    126 
    127 #endif // NS_H