btcs

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

valstack.h (1464B)


      1 
      2 #ifndef BTCS_VALSTACK_H
      3 #define BTCS_VALSTACK_H
      4 
      5 #include "op.h"
      6 #include "val.h"
      7 #include "alloc.h"
      8 
      9 static inline struct val
     10 stack_top_val(struct stack *stack, int ind) {
     11   struct val val;
     12   stack_top_small(struct val, stack, &val, ind);
     13   return val;
     14 }
     15 
     16 static inline struct val
     17 stack_pop_val(struct stack *stack) {
     18   struct val val;
     19   val = stack_top_val(stack, -1);
     20   stack_pop(stack);
     21   return val;
     22 }
     23 
     24 static inline void
     25 stack_set_val(struct stack *stack, int ind, struct val val) {
     26   struct val *pval = (struct val *)(stack->top + ind);
     27   *pval = val;
     28 }
     29 
     30 static inline void
     31 stack_push_val(struct stack *stack, struct val val) {
     32 #if 0
     33   printf("pushing val ");
     34   val_print(val);
     35   printf("\n");
     36 #endif
     37   stack_push_small(struct val, stack, &val);
     38 }
     39 
     40 static inline void
     41 stack_push_raw(struct stack *stack, u8 *data, int len) {
     42   struct val val = { .type = VT_RAW };
     43   u8 *p;
     44   u16 ind;
     45   p = byte_pool_new(len, &ind);
     46   memcpy(p, data, len);
     47   val.ind = ind;
     48   stack_push_val(stack, val);
     49 }
     50 
     51 static inline void
     52 stack_push_op(struct stack *stack, enum opcode opcode) {
     53   struct val val = { .type = VT_OP, .ind = opcode };
     54   stack_push_val(stack, val);
     55 }
     56 
     57 static inline int
     58 stack_any_val(struct stack *stack, struct val val) {
     59   void **p = stack->bottom;
     60   struct val *cval;
     61 
     62   while (p < stack->top) {
     63     cval = (struct val*)p;
     64     if (val.type == cval->type && val.ind == cval->ind)
     65       return 1;
     66     p++;
     67   }
     68 
     69   return 0;
     70 }
     71 
     72 #endif /* BTCS_VALSTACK_H */