Contiki-NG
lvm.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Definitions and declarations for the Propositional Logic Engine.
36  * \author
37  * Nicolas Tsiftes <nvt@sics.se>
38  */
39 
40 #ifndef LVM_H
41 #define LVM_H
42 
43 #include <stdlib.h>
44 
45 #include "db-options.h"
46 
47 enum lvm_status {
48  LVM_FALSE = 0,
49  LVM_TRUE = 1,
50  LVM_INVALID_IDENTIFIER = 2,
51  LVM_SEMANTIC_ERROR = 3,
52  LVM_MATH_ERROR = 4,
53  LVM_STACK_OVERFLOW = 5,
54  LVM_TYPE_ERROR = 6,
55  LVM_VARIABLE_LIMIT_REACHED = 7,
56  LVM_EXECUTION_ERROR = 8,
57  LVM_DERIVATION_ERROR = 9
58 };
59 
60 typedef enum lvm_status lvm_status_t;
61 
62 #define LVM_ERROR(x) (x >= 2)
63 
64 typedef int lvm_ip_t;
65 
66 struct lvm_instance {
67  unsigned char *code;
68  lvm_ip_t size;
69  lvm_ip_t end;
70  lvm_ip_t ip;
71  unsigned error;
72 };
73 typedef struct lvm_instance lvm_instance_t;
74 
75 enum node_type {
76  LVM_ARITH_OP = 0x10,
77  LVM_OPERAND = 0x20,
78  LVM_CMP_OP = 0x40,
79  LVM_CONNECTIVE = 0x80
80 };
81 typedef enum node_type node_type_t;
82 
83 enum operator {
84  LVM_ADD = LVM_ARITH_OP | 1,
85  LVM_SUB = LVM_ARITH_OP | 2,
86  LVM_MUL = LVM_ARITH_OP | 3,
87  LVM_DIV = LVM_ARITH_OP | 4,
88  LVM_EQ = LVM_CMP_OP | 1,
89  LVM_NEQ = LVM_CMP_OP | 2,
90  LVM_GE = LVM_CMP_OP | 3,
91  LVM_GEQ = LVM_CMP_OP | 4,
92  LVM_LE = LVM_CMP_OP | 5,
93  LVM_LEQ = LVM_CMP_OP | 6,
94  LVM_AND = LVM_CONNECTIVE | 1,
95  LVM_OR = LVM_CONNECTIVE | 2,
96  LVM_NOT = LVM_CONNECTIVE | 3
97 };
98 typedef enum operator operator_t;
99 
100 enum operand_type {
101  LVM_VARIABLE,
102  LVM_FLOAT,
103  LVM_LONG
104 };
105 typedef enum operand_type operand_type_t;
106 
107 typedef unsigned char variable_id_t;
108 
109 typedef union {
110  long l;
111 #if LVM_USE_FLOATS
112  float f;
113 #endif
114  variable_id_t id;
115 } operand_value_t;
116 
117 struct operand {
118  operand_type_t type;
119  operand_value_t value;
120 };
121 typedef struct operand operand_t;
122 
123 void lvm_reset(lvm_instance_t *p, unsigned char *code, lvm_ip_t size);
124 void lvm_clone(lvm_instance_t *dst, lvm_instance_t *src);
125 lvm_status_t lvm_derive(lvm_instance_t *p);
126 lvm_status_t lvm_get_derived_range(lvm_instance_t *p, char *name,
127  operand_value_t *min,
128  operand_value_t *max);
129 void lvm_print_derivations(lvm_instance_t *p);
130 lvm_status_t lvm_execute(lvm_instance_t *p);
131 lvm_status_t lvm_register_variable(char *name, operand_type_t type);
132 lvm_status_t lvm_set_variable_value(char *name, operand_value_t value);
133 void lvm_print_code(lvm_instance_t *p);
134 lvm_ip_t lvm_jump_to_operand(lvm_instance_t *p);
135 lvm_ip_t lvm_shift_for_operator(lvm_instance_t *p, lvm_ip_t end);
136 lvm_ip_t lvm_get_end(lvm_instance_t *p);
137 lvm_ip_t lvm_set_end(lvm_instance_t *p, lvm_ip_t end);
138 lvm_status_t lvm_set_op(lvm_instance_t *p, operator_t op);
139 lvm_status_t lvm_set_relation(lvm_instance_t *p, operator_t op);
140 lvm_status_t lvm_set_operand(lvm_instance_t *p, operand_t *op);
141 lvm_status_t lvm_set_long(lvm_instance_t *p, long l);
142 lvm_status_t lvm_set_variable(lvm_instance_t *p, char *name);
143 
144 #endif /* LVM_H */
Database configuration options.