btcs

bitcoin script parser/evaluator/compiler/decompiler
git clone git://jb55.com/btcs
Log | Files | Refs | README | LICENSE

val.h (962B)


      1 
      2 #ifndef BTCS_VAL_H
      3 #define BTCS_VAL_H
      4 
      5 #include "misc.h"
      6 #include "stack.h"
      7 
      8 enum valtype {
      9   VT_SCRIPTNUM=0,
     10   VT_SMALLINT,
     11   VT_OP,
     12   VT_RAW,
     13   VT_DATA,
     14   VT_N
     15 };
     16 // UPDATE VAL_TYPE_BITS if you need more valtypes
     17 
     18 
     19 #define VAL_TYPE_BITS 3
     20 /* static const int COMPACT_VAL_BITS = (32-VAL_TYPE_BITS-1); */
     21 #define VAL_COMPACT_BITS 29
     22 
     23 struct val {
     24   u8 type : VAL_TYPE_BITS;
     25   int ind : VAL_COMPACT_BITS;
     26 };
     27 
     28 #define smallintval(n) ((struct val){ .type = VT_SMALLINT, .ind = n })
     29 #define falseval smallintval(0)
     30 #define trueval  smallintval(1)
     31 
     32 // we want val to fit into the size of a 32-bit pointer
     33 STATIC_ASSERT(sizeof(struct val) <= 4, val_doesnt_fit_in_stack);
     34 
     35 struct val val_copy(struct val a);
     36 u32 val_size(struct val val);
     37 
     38 int
     39 val_eq(struct val a, struct val b);
     40 
     41 void val_serialize(struct val val, u32 *len, u8 *buf, int bufsize);
     42 void val_bytes(struct val val, u32 *len, u8 *buf, int bufsize);
     43 
     44 struct val val_from_int(s64);
     45 
     46 #endif /* BTCS_VAL_H */