From: Michael Wallner Date: Mon, 20 Feb 2017 13:10:33 +0000 (+0100) Subject: calc: generate calculators X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=52ed5940ed0ab3cafd36fbded2e83c92563e7b2b;p=m6w6%2Fext-psi calc: generate calculators --- diff --git a/Makefile.frag b/Makefile.frag index 91e5012..9e33c50 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -36,9 +36,21 @@ $(PHP_PSI_SRCDIR)/src/parser.c: $(PHP_PSI_SRCDIR)/src/parser.re # trickery needed for relative #line directives cd $(PHP_PSI_SRCDIR) && $(RE2C) -o $@ $(patsubst $(PHP_PSI_SRCDIR)/%,%,$<) -$(PHP_PSI_SRCDIR)/src/token.h: $(PHP_PSI_SRCDIR)/src/token_oper_cmp.h -$(PHP_PSI_SRCDIR)/src/token_oper_cmp.h: $(PHP_PSI_SRCDIR)/scripts/gen_oper.php +$(PHP_PSI_SRCDIR)/src/calc/basic.h: $(PHP_PSI_SRCDIR)/scripts/gen_calc_basic.php $(PHP_EXECUTABLE) $< >$@ +$(PHP_PSI_SRCDIR)/src/calc/bin.h: $(PHP_PSI_SRCDIR)/scripts/gen_calc_bin.php + $(PHP_EXECUTABLE) $< >$@ +$(PHP_PSI_SRCDIR)/src/calc/bool.h: $(PHP_PSI_SRCDIR)/scripts/gen_calc_bool.php + $(PHP_EXECUTABLE) $< >$@ +$(PHP_PSI_SRCDIR)/src/calc/cast.h: $(PHP_PSI_SRCDIR)/scripts/gen_calc_cast.php + $(PHP_EXECUTABLE) $< >$@ +$(PHP_PSI_SRCDIR)/src/calc/cmp.h: $(PHP_PSI_SRCDIR)/scripts/gen_calc_cmp.php + $(PHP_EXECUTABLE) $< >$@ +$(PHP_PSI_SRCDIR)/src/calc/oper.h: $(PHP_PSI_SRCDIR)/scripts/gen_calc_oper.php + $(PHP_EXECUTABLE) $< >$@ + +.PHONY: psi-generated +psi-generated: $(PHP_PSI_GENERATED) PHP_PSI_DEPEND = $(patsubst $(PHP_PSI_SRCDIR)/%,$(PHP_PSI_BUILDDIR)/%,$(PHP_PSI_SOURCES:.c=.dep)) @@ -47,7 +59,6 @@ $(PHP_PSI_BUILDDIR)/%.dep: $(PHP_PSI_SRCDIR)/%.c $(CPPFLAGS) $(DEFS) $(INCLUDES) $< \ || touch $@ -token_oper_cmp.h: $(PHP_PSI_SRCDIR)/src/token_oper_cmp.h php_psi_stdinc.h: php_psi_posix.h: diff --git a/config.m4 b/config.m4 index 3ced949..828c937 100644 --- a/config.m4 +++ b/config.m4 @@ -151,18 +151,29 @@ if test "$PHP_PSI" != no; then PHP_ADD_INCLUDE($PHP_PSI_SRCDIR) PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src) + PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src/calc) PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src/types) PHP_ADD_INCLUDE($PHP_PSI_BUILDDIR) PHP_ADD_BUILD_DIR($PHP_PSI_BUILDDIR/src) PHP_ADD_BUILD_DIR($PHP_PSI_BUILDDIR/src/types) - PHP_PSI_HEADERS=`(cd $PHP_PSI_SRCDIR/src && ls *.h types/*.h)` + PHP_PSI_HEADERS=" \ + src/calc/basic.h src/calc/bin.h src/calc/bool.h src/calc/cast.h \ + src/calc/cmp.h src/calc/oper.h \ + `(cd $PHP_PSI_SRCDIR/src && ls *.h types/*.h)` \ + " # parser* should come first PHP_PSI_SOURCES=" \ - src/parser_proc.c src/parser.c - `(cd $PHP_PSI_SRCDIR && ls src/*.c src/types/*.c | $EGREP -v '^src/parser')` \ + src/parser_proc.c src/parser.c \ + `(cd $PHP_PSI_SRCDIR && ls src/*.c src/types/*.c \ + | $EGREP -v '^src/parser' \ + )` \ + " + PHP_PSI_GENERATED=" \ + src/parser_proc.y src/parser_proc.c src/parser.c \ + src/calc/basic.h src/calc/bin.h src/calc/bool.h src/calc/cast.h \ + src/calc/cmp.h src/calc/oper.h \ " - PHP_PSI_GENERATED="src/parser_proc.y src/parser_proc.c src/parser.c" PHP_NEW_EXTENSION(psi, $PHP_PSI_SOURCES, $ext_shared) PHP_INSTALL_HEADERS(ext/psi, php_psi.h $PHP_PSI_HEADERS) diff --git a/scripts/_include.php b/scripts/_include.php new file mode 100644 index 0000000..acd539b --- /dev/null +++ b/scripts/_include.php @@ -0,0 +1,68 @@ + "i8", + "UINT8" => "u8", + "INT16" => "i16", + "UINT16" => "u16", + "INT32" => "i32", + "UINT32" => "u32", + "INT64" => "i64", + "UINT64" => "u64", + "FLOAT" => "fval", + "DOUBLE" => "dval", + "LONG_DOUBLE" => "ldval", +]; + +function t_is_int($t) { + switch ($t{0}) { + case "U": + case "I": + return true; + default: + return false; + } +} + +function t_is_special($t) { + switch ($t) { + case "LONG_DOUBLE": + return true; + default: + return false; + } +} + +?> +/******************************************************************************* + Copyright (c) 2016, Michael Wallner . + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ + +#include "php_psi_stdinc.h" +#include + +#include "token.h" \ No newline at end of file diff --git a/scripts/gen_calc_basic.php b/scripts/gen_calc_basic.php new file mode 100644 index 0000000..0af83a8 --- /dev/null +++ b/scripts/gen_calc_basic.php @@ -0,0 +1,143 @@ + "+", + "sub" => "-", + "mul" => "*", + "div" => "/", +]; + +function t_for_res($t1, $t2) { + global $types; + + $p = array_flip(array_keys($types)); + + if ($p[$t2] >= 8 || $p[$t1] >= 8) { + if ($p[$t2] > $p[$t1]) { + return $t2; + } + return $t1; + } + + $u1 = $t1{0} === "U"; + $s1 = substr($t1, $u1 ? 4 : 3); + $u2 = $t2{0} === "U"; + $s2 = substr($t2, $u2 ? 4 : 3); + + if ($u1 && $u2) { + return "UINT".min(64,max($s1*2,$s2*2)); + } else { + return "INT".min(64,max($s1*2,$s2*2)); + } + +} + +function v_for_res($t1, $t2) { + global $types; + + return $types[t_for_res($t1, $t2)]; +} + +?> + + + $op) : ?> +static inline token_t psi_calc_(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + + switch (t1) { + $v1) : ?> + + +#if HAVE_ + + + case PSI_T_: + switch (t2) { + $v2) : ?> + + +# if HAVE_ + + + case PSI_T_: + res-> = v1-> v2->; + return PSI_T_; + + +# endif + + + + default: + assert(0); + break; + } + break; + + +#endif + + + + default: + assert(0); + break; + } + + return 0; +} + + + +static inline token_t psi_calc_mod(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + impl_val i1, i2; + + switch (t1) { + $v1) : ?> + + +#if HAVE_ + + + case PSI_T_: + i1.i64 = v1->; + break; + + +#endif + + + + default: + assert(0); + break; + } + + switch (t2) { + $v2) : ?> + + +#if HAVE_ + + + case PSI_T_: + i2.i64 = v2->; + break; + + + +#endif + + + default: + assert(0); + break; + } + + res->i64 = i1.i64 % i2.i64; + return PSI_T_INT64; +} diff --git a/scripts/gen_calc_bin.php b/scripts/gen_calc_bin.php new file mode 100644 index 0000000..c7dbf01 --- /dev/null +++ b/scripts/gen_calc_bin.php @@ -0,0 +1,98 @@ + "<<", + "rshift" => ">>", + "and" => "&", + "xor" => "^", + "or" => "|", +]; + +?> + + $op) : ?> + +static inline token_t psi_calc_bin_(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + impl_val i1, i2; + + switch (t1) { + $v1) : ?> + + +#if HAVE_ + + + case PSI_T_: + i1.u64 = v1->; + break; + + +#endif + + + + default: + assert(0); + break; + } + + switch (t2) { + $v2) : ?> + + +#if HAVE_ + + + case PSI_T_: + i2.u64 = v2->; + break; + + + +#endif + + + default: + assert(0); + break; + } + + res->u64 = i1.u64 i2.u64; + return PSI_T_UINT64; +} + + +static inline token_t psi_calc_bin_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + impl_val i1; + + (void) t2; + (void) v2; + + switch (t1) { + $v1) : ?> + + +#if HAVE_ + + + case PSI_T_: + i1.u64 = v1->; + break; + + +#endif + + + + default: + assert(0); + break; + } + + res->u64 = ~i1.u64; + return PSI_T_UINT64; +} \ No newline at end of file diff --git a/scripts/gen_calc_bool.php b/scripts/gen_calc_bool.php new file mode 100644 index 0000000..1aaad08 --- /dev/null +++ b/scripts/gen_calc_bool.php @@ -0,0 +1,140 @@ + + + +static inline token_t psi_calc_bool_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + (void) t2; + (void) v2; + + switch (t1) { + $v1) : ?> + + +#if HAVE_ + + + case PSI_T_: + res->u8 = !v1->; + break; + + +#endif + + + + default: + assert(0); + break; + } + return PSI_T_UINT8; +} + +static inline token_t psi_calc_bool_or(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + switch (t1) { + $v1) : ?> + + +#if HAVE_ + + + case PSI_T_: + if (v1->) + goto return_true; + break; + + +#endif + + + + default: + assert(0); + break; + } + + switch (t2) { + $v2) : ?> + + +#if HAVE_ + + + case PSI_T_: + if (v2->) + goto return_true; + break; + + +#endif + + + + default: + assert(0); + break; + } + + res->u8 = 0; + return PSI_T_UINT8; + +return_true: + res->u8 = 1; + return PSI_T_UINT8; +} + +static inline token_t psi_calc_bool_and(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + switch (t1) { + $v1) : ?> + + +#if HAVE_ + + + case PSI_T_: + if (!v1->) + goto return_false; + break; + + +#endif + + + + default: + assert(0); + break; + } + + switch (t2) { + $v2) : ?> + + +#if HAVE_ + + + case PSI_T_: + if (!v2->) + goto return_false; + break; + + +#endif + + + + default: + assert(0); + break; + } + + res->u8 = 1; + return PSI_T_UINT8; + +return_false: + res->u8 = 0; + return PSI_T_UINT8; +} diff --git a/scripts/gen_calc_cast.php b/scripts/gen_calc_cast.php new file mode 100644 index 0000000..9015008 --- /dev/null +++ b/scripts/gen_calc_cast.php @@ -0,0 +1,48 @@ + + + +static inline void psi_calc_cast(token_t in_type, impl_val *in_val, token_t out_type, impl_val *out_val) +{ + switch (out_type) { + $v) : ?> + + +#if HAVE_ + + + case PSI_T_: + switch (in_type) { + $v_in) : ?> + + +# if HAVE_ + + + case PSI_T_: + out_val-> = in_val->; + break; + + +# endif + + + + default: + assert(0); + break; + } + break; + + +#endif + + + + default: + assert(0); + break; + } +} + diff --git a/scripts/gen_calc_cmp.php b/scripts/gen_calc_cmp.php new file mode 100644 index 0000000..8f82bfb --- /dev/null +++ b/scripts/gen_calc_cmp.php @@ -0,0 +1,61 @@ + "==", + "ne" => "!=", + "lt" => "<", + "gt" => ">", + "le" => "<=", + "ge" => ">=" +]; + +?> + + $op) : ?> + +static inline token_t psi_calc_cmp_(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + switch (t1) { + $v1) : ?> + + +#if HAVE_ + + + case PSI_T_: + switch (t2) { + $v2) : ?> + + +# if HAVE_ + + + case PSI_T_: + res->u8 = v1-> v2->; + break; + + +# endif + + + + default: + assert(0); + break; + } + break; + + +#endif + + + + default: + assert(0); + break; + } + return PSI_T_UINT8; +} + diff --git a/scripts/gen_calc_oper.php b/scripts/gen_calc_oper.php new file mode 100644 index 0000000..126e9ac --- /dev/null +++ b/scripts/gen_calc_oper.php @@ -0,0 +1,63 @@ + + + +static inline int psi_calc_oper(token_t op1, token_t op2) +{ + if (PSI_T_LPAREN == op2) { + return -1; + } else if (PSI_T_LPAREN == op1) { + return 1; + } else if (op1 == op2) { + return 0; + } else if (!op1) { + return 1; + } else if (!op2) { + return -1; + } + + switch (op1) { + $ops1) : ?> + + + case PSI_T_: + switch (op2) { + $ops2) : ?> + + + case PSI_T_: + return $prec2?1:-1)?>; + + + + default: + assert(0); + break; + } + break; + + + + default: + assert(0); + break; + } + return 0; +} diff --git a/scripts/gen_cmp.php b/scripts/gen_cmp.php deleted file mode 100644 index 89524ee..0000000 --- a/scripts/gen_cmp.php +++ /dev/null @@ -1,27 +0,0 @@ - "fval", - "DOUBLE" => "dval", - "LONG_DOUBLE" => "ldval", - "INT8" => "i8", - "UINT8" => "u8", - "INT16" => "i16", - "UINT16" => "u16", - "INT32" => "i32", - "UINT32" => "u32", - "INT64" => "i64", - "UINT64" => "u64", -]; - -printf("\tswitch (t1) { \\\n"); -foreach ($types as $t1 => $f1) { - printf("\tcase PSI_T_%s: \\\n", $t1); - printf("\t\tswitch (t2) { \\\n"); - foreach ($types as $t2 => $f2) { - printf("\t\tcase PSI_T_%s:\tPSI_CALC_OP2(u8, %s, %s);\tbreak; \\\n", - $t2, $f1, $f2); - } - printf("\t\tEMPTY_SWITCH_DEFAULT_CASE(); \\\n\t\t} \\\n\t\tbreak; \\\n"); -} -printf("\tEMPTY_SWITCH_DEFAULT_CASE(); \\\n\t} \\\n"); \ No newline at end of file diff --git a/scripts/gen_int.php b/scripts/gen_int.php deleted file mode 100644 index 2df05ed..0000000 --- a/scripts/gen_int.php +++ /dev/null @@ -1,35 +0,0 @@ - "i8", - "UINT8" => "u8", - "INT16" => "i16", - "UINT16" => "u16", - "INT32" => "i32", - "UINT32" => "u32", - "INT64" => "i64", - "UINT64" => "u64", -]; - -printf("\tswitch (t1) { \\\n"); -foreach ($types as $t1 => $f1) { - $s1 = substr($f1, 1); - $u1 = $f1{0} == "u"; - printf("\tcase PSI_T_%s: \\\n", $t1); - printf("\t\tswitch (t2) { \\\n"); - foreach ($types as $t2 => $f2) { - $s2 = substr($f2, 1); - $u2 = $f2{0} == "u"; - - if ($u1 && $u2) { - $fr = "u".min(64,max($s1*2,$s2*2)); - } else { - $fr = "i".min(64,max($s1*2,$s2*2)); - } - - printf("\t\tcase PSI_T_%s:\tPSI_CALC_OP2(%s, %s, %s);\treturn PSI_T_%s; \\\n", - $t2, $fr, $f1, $f2, str_replace(["u","i"], ["UINT","INT"], $fr)); - } - printf("\t\tEMPTY_SWITCH_DEFAULT_CASE(); \\\n\t\t} \\\n\t\tbreak; \\\n"); -} -printf("\tEMPTY_SWITCH_DEFAULT_CASE(); \\\n\t} \\\n"); \ No newline at end of file diff --git a/scripts/gen_oper.php b/scripts/gen_oper.php deleted file mode 100644 index e35bc4b..0000000 --- a/scripts/gen_oper.php +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - Copyright (c) 2016, Michael Wallner . - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*******************************************************************************/ - -static inline int psi_token_oper_cmp(token_t op1, token_t op2) { - switch (op1) { - $ops1) { - foreach ($ops1 as $op1) { - printf("\tcase PSI_T_%s:\n", $op1); - printf("\t\tswitch (op2) {\n"); - foreach ($oper as $prec2 => $ops2) { - foreach ($ops2 as $op2) { - printf("\t\t\tcase PSI_T_%s: %sreturn %2d;\n", $op2, - str_repeat(" ", 10 - strlen($op2)), - $prec1==$prec2?0:($prec1>$prec2?1:-1)); - } - } - printf("\t\t}\n\t\tassert(0);\n\t\tbreak;\n"); - } -} -?> - } - assert(0); - return 0; -} diff --git a/src/calc.c b/src/calc.c deleted file mode 100644 index 2dc85f4..0000000 --- a/src/calc.c +++ /dev/null @@ -1,638 +0,0 @@ -/******************************************************************************* - Copyright (c) 2016, Michael Wallner . - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*******************************************************************************/ - -#include "php_psi_stdinc.h" -#include - -#include "token.h" -#include "calc.h" - -#define PSI_CALC_CAST_SET(in_type, in_val, op, out_val, out_var) \ -switch (in_type) { \ -case PSI_T_INT8: (out_val)->out_var op (in_val)->i8; break; \ -case PSI_T_UINT8: (out_val)->out_var op (in_val)->u8; break; \ -case PSI_T_INT16: (out_val)->out_var op (in_val)->i16; break; \ -case PSI_T_UINT16: (out_val)->out_var op (in_val)->u16; break; \ -case PSI_T_INT32: (out_val)->out_var op (in_val)->i32; break; \ -case PSI_T_UINT32: (out_val)->out_var op (in_val)->u32; break; \ -case PSI_T_INT64: (out_val)->out_var op (in_val)->i64; break; \ -case PSI_T_UINT64: (out_val)->out_var op (in_val)->u64; break; \ -case PSI_T_FLOAT: (out_val)->out_var op (in_val)->fval; break; \ -case PSI_T_DOUBLE: (out_val)->out_var op (in_val)->dval; break; \ -case PSI_T_LONG_DOUBLE: (out_val)->out_var op (in_val)->ldval; break; \ -default: \ - assert(0); \ -} - -#define PSI_CALC_CAST(in_type, in_val, op, out_type, out_val) \ -switch (out_type) { \ -case PSI_T_INT8: PSI_CALC_CAST_SET(in_type, in_val, op, out_val, i8) break; \ -case PSI_T_UINT8: PSI_CALC_CAST_SET(in_type, in_val, op, out_val, u8) break; \ -case PSI_T_INT16: PSI_CALC_CAST_SET(in_type, in_val, op, out_val, i16) break; \ -case PSI_T_UINT16: PSI_CALC_CAST_SET(in_type, in_val, op, out_val, u16) break; \ -case PSI_T_INT32: PSI_CALC_CAST_SET(in_type, in_val, op, out_val, i32) break; \ -case PSI_T_UINT32: PSI_CALC_CAST_SET(in_type, in_val, op, out_val, u32) break; \ -case PSI_T_INT64: PSI_CALC_CAST_SET(in_type, in_val, op, out_val, i64) break; \ -case PSI_T_UINT64: PSI_CALC_CAST_SET(in_type, in_val, op, out_val, u64) break; \ -case PSI_T_FLOAT: PSI_CALC_CAST_SET(in_type, in_val, op, out_val, fval) break; \ -case PSI_T_DOUBLE: PSI_CALC_CAST_SET(in_type, in_val, op, out_val, dval) break; \ -case PSI_T_LONG_DOUBLE: PSI_CALC_CAST_SET(in_type, in_val, op, out_val, ldval) break; \ -default: \ - assert(0); \ -} - -#define PSI_CALC_CAST_SET_INT(in_type, in_val, op, out_val, out_var) \ -switch (in_type) { \ -case PSI_T_INT8: (out_val)->out_var op (in_val)->i8; break; \ -case PSI_T_UINT8: (out_val)->out_var op (in_val)->u8; break; \ -case PSI_T_INT16: (out_val)->out_var op (in_val)->i16; break; \ -case PSI_T_UINT16: (out_val)->out_var op (in_val)->u16; break; \ -case PSI_T_INT32: (out_val)->out_var op (in_val)->i32; break; \ -case PSI_T_UINT32: (out_val)->out_var op (in_val)->u32; break; \ -case PSI_T_INT64: (out_val)->out_var op (in_val)->i64; break; \ -case PSI_T_UINT64: (out_val)->out_var op (in_val)->u64; break; \ -default: \ - assert(0); \ -} -#define PSI_CALC_CAST_INT(in_type, in_val, op, out_type, out_val) \ -switch (out_type) { \ -case PSI_T_INT8: PSI_CALC_CAST_SET_INT(in_type, in_val, op, out_val, i8) break; \ -case PSI_T_UINT8: PSI_CALC_CAST_SET_INT(in_type, in_val, op, out_val, u8) break; \ -case PSI_T_INT16: PSI_CALC_CAST_SET_INT(in_type, in_val, op, out_val, i16) break; \ -case PSI_T_UINT16: PSI_CALC_CAST_SET_INT(in_type, in_val, op, out_val, u16) break; \ -case PSI_T_INT32: PSI_CALC_CAST_SET_INT(in_type, in_val, op, out_val, i32) break; \ -case PSI_T_UINT32: PSI_CALC_CAST_SET_INT(in_type, in_val, op, out_val, u32) break; \ -case PSI_T_INT64: PSI_CALC_CAST_SET_INT(in_type, in_val, op, out_val, i64) break; \ -case PSI_T_UINT64: PSI_CALC_CAST_SET_INT(in_type, in_val, op, out_val, u64) break; \ -default: \ - assert(0); \ -} - -void psi_calc_cast(token_t in_type, impl_val *in_val, token_t out_type, impl_val *out_val) -{ - PSI_CALC_CAST(in_type, in_val, =, out_type, out_val) -} - -#if 0 -#define PSI_CALC_OP(var) do { \ - const char *fmt = "calc %" PRI##var ", %" PRI##var ": %" PRI##var "\n"; \ - res->var = PSI_CALC(v1->var, v2->var); \ - if (!res->var && (v1->var || v2->var)) fprintf(stderr, fmt, v1->var, v2->var, res->var); \ -} while (0) -#define PSI_CALC_OP2(vres, var1, var2) do { \ - const char *fmt = "calc %" PRI##var1 ", %" PRI##var2 ": %" PRI##vres "\n"; \ - res->vres = PSI_CALC(v1->var1, v2->var2); \ - if (!res->vres && (v1->var1 || v2->var2)) fprintf(stderr, fmt, v1->var1, v2->var2, res->vres); \ -} while(0) -#else -#define PSI_CALC_OP(var) res->var = PSI_CALC(v1->var, v2->var) -#define PSI_CALC_OP2(vres, var1, var2) res->vres = PSI_CALC(v1->var1, v2->var2) -#endif - -#ifdef HAVE_LONG_DOUBLE -# define PSI_CALC_NO_LD -# define PSI_CALC_OP_LD PSI_CALC_OP(ldval) -# define PSI_CALC_OP2_LD2(var1) PSI_CALC_OP2(ldval, var1, ldval) -# define PSI_CALC_OP2_LD1(var2) PSI_CALC_OP2(ldval, ldval, var2) -#else -# define PSI_CALC_NO_LD abort() -# define PSI_CALC_OP_LD PSI_CALC_NO_LD -# define PSI_CALC_OP2_LD2(var) PSI_CALC_NO_LD -# define PSI_CALC_OP2_LD1(var) PSI_CALC_NO_LD -#endif - -#define PSI_CALC_FN(op) token_t psi_calc_##op(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) \ -{ \ - if (t1 == t2) { \ - switch (t1) { \ - case PSI_T_FLOAT: PSI_CALC_OP(fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP(dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP_LD; break; \ - case PSI_T_INT8: PSI_CALC_OP(i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP(u8); break; \ - case PSI_T_INT16: PSI_CALC_OP(i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP(u16); break; \ - case PSI_T_INT32: PSI_CALC_OP(i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP(u32); break; \ - case PSI_T_INT64: PSI_CALC_OP(i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP(u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - return t1; \ - } else if (t1 == PSI_T_DOUBLE) { \ - switch (t2) { \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2_LD2(dval); return t2; \ - case PSI_T_FLOAT: PSI_CALC_OP2(dval, dval, fval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(dval, dval, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(dval, dval, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(dval, dval, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(dval, dval, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(dval, dval, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(dval, dval, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(dval, dval, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(dval, dval, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - return t1; \ - } else if (t2 == PSI_T_DOUBLE) { \ - switch (t1) { \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2_LD1(dval); return t1; \ - case PSI_T_FLOAT: PSI_CALC_OP2(dval, fval, dval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(dval, i8, dval); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(dval, u8, dval); break; \ - case PSI_T_INT16: PSI_CALC_OP2(dval, i16, dval); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(dval, u16, dval); break; \ - case PSI_T_INT32: PSI_CALC_OP2(dval, i32, dval); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(dval, u32, dval); break; \ - case PSI_T_INT64: PSI_CALC_OP2(dval, i64, dval); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(dval, u64, dval); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - return t2; \ - } else if (t1 == PSI_T_LONG_DOUBLE) { \ - PSI_CALC_NO_LD; \ - switch (t2) { \ - case PSI_T_DOUBLE: PSI_CALC_OP2_LD1(dval); break; \ - case PSI_T_FLOAT: PSI_CALC_OP2_LD1(fval); break; \ - case PSI_T_INT8: PSI_CALC_OP2_LD1(i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2_LD1(u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2_LD1(i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2_LD1(u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2_LD1(i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2_LD1(u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2_LD1(i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2_LD1(u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - return t1; \ - } else if (t2 == PSI_T_LONG_DOUBLE) { \ - PSI_CALC_NO_LD; \ - switch (t1) { \ - case PSI_T_DOUBLE: PSI_CALC_OP2_LD2(dval); break; \ - case PSI_T_FLOAT: PSI_CALC_OP2_LD2(fval); break; \ - case PSI_T_INT8: PSI_CALC_OP2_LD2(i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2_LD2(u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2_LD2(i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2_LD2(u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2_LD2(i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2_LD2(u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2_LD2(i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2_LD2(u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - return t2; \ - } else if (t1 == PSI_T_FLOAT) { \ - switch (t2) { \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2_LD2(fval); return t2; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(dval, fval, dval); return t2; \ - case PSI_T_INT8: PSI_CALC_OP2(fval, fval, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(fval, fval, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(fval, fval, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(fval, fval, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(fval, fval, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(fval, fval, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(fval, fval, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(fval, fval, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - return t1; \ - } else if (t2 == PSI_T_FLOAT) { \ - switch (t1) { \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2_LD1(fval); return t1; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(dval, dval, fval); return t1; \ - case PSI_T_INT8: PSI_CALC_OP2(fval, i8, fval); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(fval, u8, fval); break; \ - case PSI_T_INT16: PSI_CALC_OP2(fval, i16, fval); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(fval, u16, fval); break; \ - case PSI_T_INT32: PSI_CALC_OP2(fval, i32, fval); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(fval, u32, fval); break; \ - case PSI_T_INT64: PSI_CALC_OP2(fval, i64, fval); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(fval, u64, fval); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - return t2; \ - } else { \ - switch (t1) { \ - case PSI_T_INT8: \ - switch (t2) { \ - case PSI_T_INT8: PSI_CALC_OP2(i16, i8, i8); return PSI_T_INT16; \ - case PSI_T_UINT8: PSI_CALC_OP2(i16, i8, u8); return PSI_T_INT16; \ - case PSI_T_INT16: PSI_CALC_OP2(i32, i8, i16); return PSI_T_INT32; \ - case PSI_T_UINT16: PSI_CALC_OP2(i32, i8, u16); return PSI_T_INT32; \ - case PSI_T_INT32: PSI_CALC_OP2(i64, i8, i32); return PSI_T_INT64; \ - case PSI_T_UINT32: PSI_CALC_OP2(i64, i8, u32); return PSI_T_INT64; \ - case PSI_T_INT64: PSI_CALC_OP2(i64, i8, i64); return PSI_T_INT64; \ - case PSI_T_UINT64: PSI_CALC_OP2(i64, i8, u64); return PSI_T_INT64; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_UINT8: \ - switch (t2) { \ - case PSI_T_INT8: PSI_CALC_OP2(i16, u8, i8); return PSI_T_INT16; \ - case PSI_T_UINT8: PSI_CALC_OP2(u16, u8, u8); return PSI_T_UINT16; \ - case PSI_T_INT16: PSI_CALC_OP2(i32, u8, i16); return PSI_T_INT32; \ - case PSI_T_UINT16: PSI_CALC_OP2(u32, u8, u16); return PSI_T_UINT32; \ - case PSI_T_INT32: PSI_CALC_OP2(i64, u8, i32); return PSI_T_INT64; \ - case PSI_T_UINT32: PSI_CALC_OP2(u64, u8, u32); return PSI_T_UINT64; \ - case PSI_T_INT64: PSI_CALC_OP2(i64, u8, i64); return PSI_T_INT64; \ - case PSI_T_UINT64: PSI_CALC_OP2(u64, u8, u64); return PSI_T_UINT64; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_INT16: \ - switch (t2) { \ - case PSI_T_INT8: PSI_CALC_OP2(i32, i16, i8); return PSI_T_INT32; \ - case PSI_T_UINT8: PSI_CALC_OP2(i32, i16, u8); return PSI_T_INT32; \ - case PSI_T_INT16: PSI_CALC_OP2(i32, i16, i16); return PSI_T_INT32; \ - case PSI_T_UINT16: PSI_CALC_OP2(i32, i16, u16); return PSI_T_INT32; \ - case PSI_T_INT32: PSI_CALC_OP2(i64, i16, i32); return PSI_T_INT64; \ - case PSI_T_UINT32: PSI_CALC_OP2(i64, i16, u32); return PSI_T_INT64; \ - case PSI_T_INT64: PSI_CALC_OP2(i64, i16, i64); return PSI_T_INT64; \ - case PSI_T_UINT64: PSI_CALC_OP2(i64, i16, u64); return PSI_T_INT64; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_UINT16: \ - switch (t2) { \ - case PSI_T_INT8: PSI_CALC_OP2(i32, u16, i8); return PSI_T_INT32; \ - case PSI_T_UINT8: PSI_CALC_OP2(u32, u16, u8); return PSI_T_UINT32; \ - case PSI_T_INT16: PSI_CALC_OP2(i32, u16, i16); return PSI_T_INT32; \ - case PSI_T_UINT16: PSI_CALC_OP2(u32, u16, u16); return PSI_T_UINT32; \ - case PSI_T_INT32: PSI_CALC_OP2(i64, u16, i32); return PSI_T_INT64; \ - case PSI_T_UINT32: PSI_CALC_OP2(u64, u16, u32); return PSI_T_UINT64; \ - case PSI_T_INT64: PSI_CALC_OP2(i64, u16, i64); return PSI_T_INT64; \ - case PSI_T_UINT64: PSI_CALC_OP2(u64, u16, u64); return PSI_T_UINT64; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_INT32: \ - switch (t2) { \ - case PSI_T_INT8: PSI_CALC_OP2(i64, i32, i8); return PSI_T_INT64; \ - case PSI_T_UINT8: PSI_CALC_OP2(i64, i32, u8); return PSI_T_INT64; \ - case PSI_T_INT16: PSI_CALC_OP2(i64, i32, i16); return PSI_T_INT64; \ - case PSI_T_UINT16: PSI_CALC_OP2(i64, i32, u16); return PSI_T_INT64; \ - case PSI_T_INT32: PSI_CALC_OP2(i64, i32, i32); return PSI_T_INT64; \ - case PSI_T_UINT32: PSI_CALC_OP2(i64, i32, u32); return PSI_T_INT64; \ - case PSI_T_INT64: PSI_CALC_OP2(i64, i32, i64); return PSI_T_INT64; \ - case PSI_T_UINT64: PSI_CALC_OP2(i64, i32, u64); return PSI_T_INT64; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_UINT32: \ - switch (t2) { \ - case PSI_T_INT8: PSI_CALC_OP2(i64, u32, i8); return PSI_T_INT64; \ - case PSI_T_UINT8: PSI_CALC_OP2(u64, u32, u8); return PSI_T_UINT64; \ - case PSI_T_INT16: PSI_CALC_OP2(i64, u32, i16); return PSI_T_INT64; \ - case PSI_T_UINT16: PSI_CALC_OP2(u64, u32, u16); return PSI_T_UINT64; \ - case PSI_T_INT32: PSI_CALC_OP2(i64, u32, i32); return PSI_T_INT64; \ - case PSI_T_UINT32: PSI_CALC_OP2(u64, u32, u32); return PSI_T_UINT64; \ - case PSI_T_INT64: PSI_CALC_OP2(i64, u32, i64); return PSI_T_INT64; \ - case PSI_T_UINT64: PSI_CALC_OP2(u64, u32, u64); return PSI_T_UINT64; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_INT64: \ - switch (t2) { \ - case PSI_T_INT8: PSI_CALC_OP2(i64, i64, i8); return PSI_T_INT64; \ - case PSI_T_UINT8: PSI_CALC_OP2(i64, i64, u8); return PSI_T_INT64; \ - case PSI_T_INT16: PSI_CALC_OP2(i64, i64, i16); return PSI_T_INT64; \ - case PSI_T_UINT16: PSI_CALC_OP2(i64, i64, u16); return PSI_T_INT64; \ - case PSI_T_INT32: PSI_CALC_OP2(i64, i64, i32); return PSI_T_INT64; \ - case PSI_T_UINT32: PSI_CALC_OP2(i64, i64, u32); return PSI_T_INT64; \ - case PSI_T_INT64: PSI_CALC_OP2(i64, i64, i64); return PSI_T_INT64; \ - case PSI_T_UINT64: PSI_CALC_OP2(i64, i64, u64); return PSI_T_INT64; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_UINT64: \ - switch (t2) { \ - case PSI_T_INT8: PSI_CALC_OP2(i64, u64, i8); return PSI_T_INT64; \ - case PSI_T_UINT8: PSI_CALC_OP2(u64, u64, u8); return PSI_T_UINT64; \ - case PSI_T_INT16: PSI_CALC_OP2(i64, u64, i16); return PSI_T_INT64; \ - case PSI_T_UINT16: PSI_CALC_OP2(u64, u64, u16); return PSI_T_UINT64; \ - case PSI_T_INT32: PSI_CALC_OP2(i64, u64, i32); return PSI_T_INT64; \ - case PSI_T_UINT32: PSI_CALC_OP2(u64, u64, u32); return PSI_T_UINT64; \ - case PSI_T_INT64: PSI_CALC_OP2(i64, u64, i64); return PSI_T_INT64; \ - case PSI_T_UINT64: PSI_CALC_OP2(u64, u64, u64); return PSI_T_UINT64; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - } \ - assert(0); \ - return 0; \ -} - -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) + (var2) -PSI_CALC_FN(add) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) * (var2) -PSI_CALC_FN(mul) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) - (var2) -PSI_CALC_FN(sub) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) / (var2) -PSI_CALC_FN(div) -#undef PSI_CALC - -token_t psi_calc_mod(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) -{ - impl_val i1, i2; - - PSI_CALC_CAST(t1, v1, =, PSI_T_INT64, &i1); - PSI_CALC_CAST(t2, v2, =, PSI_T_INT64, &i2); - - res->i64 = i1.i64 % i2.i64; - - return PSI_T_INT64; -} - -#define PSI_CALC_BIT_FN(op) token_t psi_calc_##op(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) \ -{ \ - impl_val i1, i2; \ - PSI_CALC_CAST(t1, v1, =, PSI_T_UINT64, &i1); \ - PSI_CALC_CAST(t2, v2, =, PSI_T_UINT64, &i2); \ - res->u64 = PSI_CALC(i1.u64, i2.u64); \ - return PSI_T_UINT64; \ -} - -#define PSI_CALC(var1, var2) (var1) << (var2) -PSI_CALC_BIT_FN(bin_lshift) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) >> (var2) -PSI_CALC_BIT_FN(bin_rshift) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) & (var2) -PSI_CALC_BIT_FN(bin_and) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) ^ (var2) -PSI_CALC_BIT_FN(bin_xor) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) | (var2) -PSI_CALC_BIT_FN(bin_or) -#undef PSI_CALC - -#define PSI_CALC_CMP_FN(op) token_t psi_calc_##op(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) \ -{ \ - switch (t1) { \ - case PSI_T_FLOAT: \ - switch (t2) { \ - case PSI_T_FLOAT: PSI_CALC_OP2(u8, fval, fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(u8, fval, dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2(u8, fval, ldval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(u8, fval, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(u8, fval, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(u8, fval, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(u8, fval, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(u8, fval, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(u8, fval, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(u8, fval, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(u8, fval, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_DOUBLE: \ - switch (t2) { \ - case PSI_T_FLOAT: PSI_CALC_OP2(u8, dval, fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(u8, dval, dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2(u8, dval, ldval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(u8, dval, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(u8, dval, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(u8, dval, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(u8, dval, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(u8, dval, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(u8, dval, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(u8, dval, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(u8, dval, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_LONG_DOUBLE: \ - switch (t2) { \ - case PSI_T_FLOAT: PSI_CALC_OP2(u8, ldval, fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(u8, ldval, dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2(u8, ldval, ldval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(u8, ldval, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(u8, ldval, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(u8, ldval, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(u8, ldval, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(u8, ldval, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(u8, ldval, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(u8, ldval, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(u8, ldval, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_INT8: \ - switch (t2) { \ - case PSI_T_FLOAT: PSI_CALC_OP2(u8, i8, fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(u8, i8, dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2(u8, i8, ldval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(u8, i8, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(u8, i8, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(u8, i8, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(u8, i8, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(u8, i8, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(u8, i8, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(u8, i8, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(u8, i8, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_UINT8: \ - switch (t2) { \ - case PSI_T_FLOAT: PSI_CALC_OP2(u8, u8, fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(u8, u8, dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2(u8, u8, ldval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(u8, u8, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(u8, u8, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(u8, u8, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(u8, u8, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(u8, u8, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(u8, u8, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(u8, u8, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(u8, u8, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_INT16: \ - switch (t2) { \ - case PSI_T_FLOAT: PSI_CALC_OP2(u8, i16, fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(u8, i16, dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2(u8, i16, ldval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(u8, i16, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(u8, i16, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(u8, i16, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(u8, i16, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(u8, i16, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(u8, i16, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(u8, i16, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(u8, i16, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_UINT16: \ - switch (t2) { \ - case PSI_T_FLOAT: PSI_CALC_OP2(u8, u16, fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(u8, u16, dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2(u8, u16, ldval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(u8, u16, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(u8, u16, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(u8, u16, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(u8, u16, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(u8, u16, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(u8, u16, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(u8, u16, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(u8, u16, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_INT32: \ - switch (t2) { \ - case PSI_T_FLOAT: PSI_CALC_OP2(u8, i32, fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(u8, i32, dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2(u8, i32, ldval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(u8, i32, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(u8, i32, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(u8, i32, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(u8, i32, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(u8, i32, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(u8, i32, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(u8, i32, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(u8, i32, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_UINT32: \ - switch (t2) { \ - case PSI_T_FLOAT: PSI_CALC_OP2(u8, u32, fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(u8, u32, dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2(u8, u32, ldval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(u8, u32, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(u8, u32, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(u8, u32, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(u8, u32, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(u8, u32, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(u8, u32, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(u8, u32, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(u8, u32, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_INT64: \ - switch (t2) { \ - case PSI_T_FLOAT: PSI_CALC_OP2(u8, i64, fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(u8, i64, dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2(u8, i64, ldval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(u8, i64, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(u8, i64, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(u8, i64, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(u8, i64, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(u8, i64, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(u8, i64, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(u8, i64, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(u8, i64, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - case PSI_T_UINT64: \ - switch (t2) { \ - case PSI_T_FLOAT: PSI_CALC_OP2(u8, u64, fval); break; \ - case PSI_T_DOUBLE: PSI_CALC_OP2(u8, u64, dval); break; \ - case PSI_T_LONG_DOUBLE: PSI_CALC_OP2(u8, u64, ldval); break; \ - case PSI_T_INT8: PSI_CALC_OP2(u8, u64, i8); break; \ - case PSI_T_UINT8: PSI_CALC_OP2(u8, u64, u8); break; \ - case PSI_T_INT16: PSI_CALC_OP2(u8, u64, i16); break; \ - case PSI_T_UINT16: PSI_CALC_OP2(u8, u64, u16); break; \ - case PSI_T_INT32: PSI_CALC_OP2(u8, u64, i32); break; \ - case PSI_T_UINT32: PSI_CALC_OP2(u8, u64, u32); break; \ - case PSI_T_INT64: PSI_CALC_OP2(u8, u64, i64); break; \ - case PSI_T_UINT64: PSI_CALC_OP2(u8, u64, u64); break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - break; \ - EMPTY_SWITCH_DEFAULT_CASE(); \ - } \ - return PSI_T_UINT8; \ -} - -#define PSI_CALC(var1, var2) (var1) == (var2) -PSI_CALC_CMP_FN(cmp_eq) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) != (var2) -PSI_CALC_CMP_FN(cmp_ne) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) <= (var2) -PSI_CALC_CMP_FN(cmp_le) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) >= (var2) -PSI_CALC_CMP_FN(cmp_ge) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) < (var2) -PSI_CALC_CMP_FN(cmp_lt) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) > (var2) -PSI_CALC_CMP_FN(cmp_gt) -#undef PSI_CALC - -#define PSI_CALC_BOOL_FN(op) token_t psi_calc_##op(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) \ -{ \ - impl_val i1, i2; \ - PSI_CALC_CAST(t1, v1, =!!, PSI_T_UINT8, &i1); \ - PSI_CALC_CAST(t2, v2, =!!, PSI_T_UINT8, &i2); \ - res->u8 = PSI_CALC(i1.u8, i2.u8); \ - return PSI_T_UINT8; \ -} - -#define PSI_CALC(var1, var2) (var1) && (var2) -PSI_CALC_BOOL_FN(and) -#undef PSI_CALC -#define PSI_CALC(var1, var2) (var1) || (var2) -PSI_CALC_BOOL_FN(or) -#undef PSI_CALC - -token_t psi_calc_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) -{ - (void) t2; - (void) v2; - - PSI_CALC_CAST(t1, v1, =!, t1, res); - return t1; -} - -token_t psi_calc_bin_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) -{ - impl_val i1; - - (void) t2; - (void) v2; - - PSI_CALC_CAST(t1, v1, =, PSI_T_UINT64, &i1); - PSI_CALC_CAST_INT(t1, &i1, =~, t1, res); - return t1; -} diff --git a/src/calc.h b/src/calc.h index dbbb116..49114ef 100644 --- a/src/calc.h +++ b/src/calc.h @@ -35,31 +35,11 @@ typedef token_t (*psi_calc)(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_add(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_sub(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_mul(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_div(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_mod(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); - -token_t psi_calc_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_bin_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); - -token_t psi_calc_bin_lshift(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_bin_rshift(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_bin_and(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_bin_xor(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_bin_or(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); - -token_t psi_calc_and(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_or(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); - -token_t psi_calc_cmp_eq(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_cmp_ne(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_cmp_le(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_cmp_ge(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_cmp_lt(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); -token_t psi_calc_cmp_gt(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); - -void psi_calc_cast(token_t in_type, impl_val *in_val, token_t out_type, impl_val *out_val); +#include "calc/basic.h" +#include "calc/bin.h" +#include "calc/bool.h" +#include "calc/cast.h" +#include "calc/cmp.h" +#include "calc/oper.h" #endif diff --git a/src/calc/basic.h b/src/calc/basic.h new file mode 100644 index 0000000..ac021e0 --- /dev/null +++ b/src/calc/basic.h @@ -0,0 +1,2082 @@ +/******************************************************************************* + Copyright (c) 2016, Michael Wallner . + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ + +#include "php_psi_stdinc.h" +#include + +#include "token.h" + +static inline token_t psi_calc_add(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + + switch (t1) { + case PSI_T_INT8: + switch (t2) { + case PSI_T_INT8: + res->i16 = v1->i8 + v2->i8; + return PSI_T_INT16; + case PSI_T_UINT8: + res->i16 = v1->i8 + v2->u8; + return PSI_T_INT16; + case PSI_T_INT16: + res->i32 = v1->i8 + v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->i32 = v1->i8 + v2->u16; + return PSI_T_INT32; + case PSI_T_INT32: + res->i64 = v1->i8 + v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i8 + v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i8 + v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i8 + v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i8 + v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i8 + v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i8 + v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT8: + switch (t2) { + case PSI_T_INT8: + res->i16 = v1->u8 + v2->i8; + return PSI_T_INT16; + case PSI_T_UINT8: + res->u16 = v1->u8 + v2->u8; + return PSI_T_UINT16; + case PSI_T_INT16: + res->i32 = v1->u8 + v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->u32 = v1->u8 + v2->u16; + return PSI_T_UINT32; + case PSI_T_INT32: + res->i64 = v1->u8 + v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u8 + v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u8 + v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u8 + v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u8 + v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u8 + v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u8 + v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT16: + switch (t2) { + case PSI_T_INT8: + res->i32 = v1->i16 + v2->i8; + return PSI_T_INT32; + case PSI_T_UINT8: + res->i32 = v1->i16 + v2->u8; + return PSI_T_INT32; + case PSI_T_INT16: + res->i32 = v1->i16 + v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->i32 = v1->i16 + v2->u16; + return PSI_T_INT32; + case PSI_T_INT32: + res->i64 = v1->i16 + v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i16 + v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i16 + v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i16 + v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i16 + v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i16 + v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i16 + v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT16: + switch (t2) { + case PSI_T_INT8: + res->i32 = v1->u16 + v2->i8; + return PSI_T_INT32; + case PSI_T_UINT8: + res->u32 = v1->u16 + v2->u8; + return PSI_T_UINT32; + case PSI_T_INT16: + res->i32 = v1->u16 + v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->u32 = v1->u16 + v2->u16; + return PSI_T_UINT32; + case PSI_T_INT32: + res->i64 = v1->u16 + v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u16 + v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u16 + v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u16 + v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u16 + v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u16 + v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u16 + v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT32: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->i32 + v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->i64 = v1->i32 + v2->u8; + return PSI_T_INT64; + case PSI_T_INT16: + res->i64 = v1->i32 + v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->i64 = v1->i32 + v2->u16; + return PSI_T_INT64; + case PSI_T_INT32: + res->i64 = v1->i32 + v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i32 + v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i32 + v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i32 + v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i32 + v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i32 + v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i32 + v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT32: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->u32 + v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->u64 = v1->u32 + v2->u8; + return PSI_T_UINT64; + case PSI_T_INT16: + res->i64 = v1->u32 + v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->u64 = v1->u32 + v2->u16; + return PSI_T_UINT64; + case PSI_T_INT32: + res->i64 = v1->u32 + v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u32 + v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u32 + v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u32 + v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u32 + v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u32 + v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u32 + v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT64: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->i64 + v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->i64 = v1->i64 + v2->u8; + return PSI_T_INT64; + case PSI_T_INT16: + res->i64 = v1->i64 + v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->i64 = v1->i64 + v2->u16; + return PSI_T_INT64; + case PSI_T_INT32: + res->i64 = v1->i64 + v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i64 + v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i64 + v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i64 + v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i64 + v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i64 + v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i64 + v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT64: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->u64 + v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->u64 = v1->u64 + v2->u8; + return PSI_T_UINT64; + case PSI_T_INT16: + res->i64 = v1->u64 + v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->u64 = v1->u64 + v2->u16; + return PSI_T_UINT64; + case PSI_T_INT32: + res->i64 = v1->u64 + v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u64 + v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u64 + v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u64 + v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u64 + v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u64 + v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u64 + v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_FLOAT: + switch (t2) { + case PSI_T_INT8: + res->fval = v1->fval + v2->i8; + return PSI_T_FLOAT; + case PSI_T_UINT8: + res->fval = v1->fval + v2->u8; + return PSI_T_FLOAT; + case PSI_T_INT16: + res->fval = v1->fval + v2->i16; + return PSI_T_FLOAT; + case PSI_T_UINT16: + res->fval = v1->fval + v2->u16; + return PSI_T_FLOAT; + case PSI_T_INT32: + res->fval = v1->fval + v2->i32; + return PSI_T_FLOAT; + case PSI_T_UINT32: + res->fval = v1->fval + v2->u32; + return PSI_T_FLOAT; + case PSI_T_INT64: + res->fval = v1->fval + v2->i64; + return PSI_T_FLOAT; + case PSI_T_UINT64: + res->fval = v1->fval + v2->u64; + return PSI_T_FLOAT; + case PSI_T_FLOAT: + res->fval = v1->fval + v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->fval + v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->fval + v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->dval = v1->dval + v2->i8; + return PSI_T_DOUBLE; + case PSI_T_UINT8: + res->dval = v1->dval + v2->u8; + return PSI_T_DOUBLE; + case PSI_T_INT16: + res->dval = v1->dval + v2->i16; + return PSI_T_DOUBLE; + case PSI_T_UINT16: + res->dval = v1->dval + v2->u16; + return PSI_T_DOUBLE; + case PSI_T_INT32: + res->dval = v1->dval + v2->i32; + return PSI_T_DOUBLE; + case PSI_T_UINT32: + res->dval = v1->dval + v2->u32; + return PSI_T_DOUBLE; + case PSI_T_INT64: + res->dval = v1->dval + v2->i64; + return PSI_T_DOUBLE; + case PSI_T_UINT64: + res->dval = v1->dval + v2->u64; + return PSI_T_DOUBLE; + case PSI_T_FLOAT: + res->dval = v1->dval + v2->fval; + return PSI_T_DOUBLE; + case PSI_T_DOUBLE: + res->dval = v1->dval + v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->dval + v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->ldval = v1->ldval + v2->i8; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT8: + res->ldval = v1->ldval + v2->u8; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT16: + res->ldval = v1->ldval + v2->i16; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT16: + res->ldval = v1->ldval + v2->u16; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT32: + res->ldval = v1->ldval + v2->i32; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT32: + res->ldval = v1->ldval + v2->u32; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT64: + res->ldval = v1->ldval + v2->i64; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT64: + res->ldval = v1->ldval + v2->u64; + return PSI_T_LONG_DOUBLE; + case PSI_T_FLOAT: + res->ldval = v1->ldval + v2->fval; + return PSI_T_LONG_DOUBLE; + case PSI_T_DOUBLE: + res->ldval = v1->ldval + v2->dval; + return PSI_T_LONG_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->ldval + v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; +#endif + + default: + assert(0); + break; + } + + return 0; +} +static inline token_t psi_calc_sub(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + + switch (t1) { + case PSI_T_INT8: + switch (t2) { + case PSI_T_INT8: + res->i16 = v1->i8 - v2->i8; + return PSI_T_INT16; + case PSI_T_UINT8: + res->i16 = v1->i8 - v2->u8; + return PSI_T_INT16; + case PSI_T_INT16: + res->i32 = v1->i8 - v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->i32 = v1->i8 - v2->u16; + return PSI_T_INT32; + case PSI_T_INT32: + res->i64 = v1->i8 - v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i8 - v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i8 - v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i8 - v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i8 - v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i8 - v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i8 - v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT8: + switch (t2) { + case PSI_T_INT8: + res->i16 = v1->u8 - v2->i8; + return PSI_T_INT16; + case PSI_T_UINT8: + res->u16 = v1->u8 - v2->u8; + return PSI_T_UINT16; + case PSI_T_INT16: + res->i32 = v1->u8 - v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->u32 = v1->u8 - v2->u16; + return PSI_T_UINT32; + case PSI_T_INT32: + res->i64 = v1->u8 - v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u8 - v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u8 - v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u8 - v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u8 - v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u8 - v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u8 - v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT16: + switch (t2) { + case PSI_T_INT8: + res->i32 = v1->i16 - v2->i8; + return PSI_T_INT32; + case PSI_T_UINT8: + res->i32 = v1->i16 - v2->u8; + return PSI_T_INT32; + case PSI_T_INT16: + res->i32 = v1->i16 - v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->i32 = v1->i16 - v2->u16; + return PSI_T_INT32; + case PSI_T_INT32: + res->i64 = v1->i16 - v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i16 - v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i16 - v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i16 - v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i16 - v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i16 - v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i16 - v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT16: + switch (t2) { + case PSI_T_INT8: + res->i32 = v1->u16 - v2->i8; + return PSI_T_INT32; + case PSI_T_UINT8: + res->u32 = v1->u16 - v2->u8; + return PSI_T_UINT32; + case PSI_T_INT16: + res->i32 = v1->u16 - v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->u32 = v1->u16 - v2->u16; + return PSI_T_UINT32; + case PSI_T_INT32: + res->i64 = v1->u16 - v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u16 - v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u16 - v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u16 - v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u16 - v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u16 - v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u16 - v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT32: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->i32 - v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->i64 = v1->i32 - v2->u8; + return PSI_T_INT64; + case PSI_T_INT16: + res->i64 = v1->i32 - v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->i64 = v1->i32 - v2->u16; + return PSI_T_INT64; + case PSI_T_INT32: + res->i64 = v1->i32 - v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i32 - v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i32 - v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i32 - v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i32 - v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i32 - v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i32 - v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT32: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->u32 - v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->u64 = v1->u32 - v2->u8; + return PSI_T_UINT64; + case PSI_T_INT16: + res->i64 = v1->u32 - v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->u64 = v1->u32 - v2->u16; + return PSI_T_UINT64; + case PSI_T_INT32: + res->i64 = v1->u32 - v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u32 - v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u32 - v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u32 - v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u32 - v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u32 - v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u32 - v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT64: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->i64 - v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->i64 = v1->i64 - v2->u8; + return PSI_T_INT64; + case PSI_T_INT16: + res->i64 = v1->i64 - v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->i64 = v1->i64 - v2->u16; + return PSI_T_INT64; + case PSI_T_INT32: + res->i64 = v1->i64 - v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i64 - v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i64 - v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i64 - v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i64 - v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i64 - v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i64 - v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT64: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->u64 - v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->u64 = v1->u64 - v2->u8; + return PSI_T_UINT64; + case PSI_T_INT16: + res->i64 = v1->u64 - v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->u64 = v1->u64 - v2->u16; + return PSI_T_UINT64; + case PSI_T_INT32: + res->i64 = v1->u64 - v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u64 - v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u64 - v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u64 - v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u64 - v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u64 - v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u64 - v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_FLOAT: + switch (t2) { + case PSI_T_INT8: + res->fval = v1->fval - v2->i8; + return PSI_T_FLOAT; + case PSI_T_UINT8: + res->fval = v1->fval - v2->u8; + return PSI_T_FLOAT; + case PSI_T_INT16: + res->fval = v1->fval - v2->i16; + return PSI_T_FLOAT; + case PSI_T_UINT16: + res->fval = v1->fval - v2->u16; + return PSI_T_FLOAT; + case PSI_T_INT32: + res->fval = v1->fval - v2->i32; + return PSI_T_FLOAT; + case PSI_T_UINT32: + res->fval = v1->fval - v2->u32; + return PSI_T_FLOAT; + case PSI_T_INT64: + res->fval = v1->fval - v2->i64; + return PSI_T_FLOAT; + case PSI_T_UINT64: + res->fval = v1->fval - v2->u64; + return PSI_T_FLOAT; + case PSI_T_FLOAT: + res->fval = v1->fval - v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->fval - v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->fval - v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->dval = v1->dval - v2->i8; + return PSI_T_DOUBLE; + case PSI_T_UINT8: + res->dval = v1->dval - v2->u8; + return PSI_T_DOUBLE; + case PSI_T_INT16: + res->dval = v1->dval - v2->i16; + return PSI_T_DOUBLE; + case PSI_T_UINT16: + res->dval = v1->dval - v2->u16; + return PSI_T_DOUBLE; + case PSI_T_INT32: + res->dval = v1->dval - v2->i32; + return PSI_T_DOUBLE; + case PSI_T_UINT32: + res->dval = v1->dval - v2->u32; + return PSI_T_DOUBLE; + case PSI_T_INT64: + res->dval = v1->dval - v2->i64; + return PSI_T_DOUBLE; + case PSI_T_UINT64: + res->dval = v1->dval - v2->u64; + return PSI_T_DOUBLE; + case PSI_T_FLOAT: + res->dval = v1->dval - v2->fval; + return PSI_T_DOUBLE; + case PSI_T_DOUBLE: + res->dval = v1->dval - v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->dval - v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->ldval = v1->ldval - v2->i8; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT8: + res->ldval = v1->ldval - v2->u8; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT16: + res->ldval = v1->ldval - v2->i16; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT16: + res->ldval = v1->ldval - v2->u16; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT32: + res->ldval = v1->ldval - v2->i32; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT32: + res->ldval = v1->ldval - v2->u32; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT64: + res->ldval = v1->ldval - v2->i64; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT64: + res->ldval = v1->ldval - v2->u64; + return PSI_T_LONG_DOUBLE; + case PSI_T_FLOAT: + res->ldval = v1->ldval - v2->fval; + return PSI_T_LONG_DOUBLE; + case PSI_T_DOUBLE: + res->ldval = v1->ldval - v2->dval; + return PSI_T_LONG_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->ldval - v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; +#endif + + default: + assert(0); + break; + } + + return 0; +} +static inline token_t psi_calc_mul(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + + switch (t1) { + case PSI_T_INT8: + switch (t2) { + case PSI_T_INT8: + res->i16 = v1->i8 * v2->i8; + return PSI_T_INT16; + case PSI_T_UINT8: + res->i16 = v1->i8 * v2->u8; + return PSI_T_INT16; + case PSI_T_INT16: + res->i32 = v1->i8 * v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->i32 = v1->i8 * v2->u16; + return PSI_T_INT32; + case PSI_T_INT32: + res->i64 = v1->i8 * v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i8 * v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i8 * v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i8 * v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i8 * v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i8 * v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i8 * v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT8: + switch (t2) { + case PSI_T_INT8: + res->i16 = v1->u8 * v2->i8; + return PSI_T_INT16; + case PSI_T_UINT8: + res->u16 = v1->u8 * v2->u8; + return PSI_T_UINT16; + case PSI_T_INT16: + res->i32 = v1->u8 * v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->u32 = v1->u8 * v2->u16; + return PSI_T_UINT32; + case PSI_T_INT32: + res->i64 = v1->u8 * v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u8 * v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u8 * v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u8 * v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u8 * v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u8 * v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u8 * v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT16: + switch (t2) { + case PSI_T_INT8: + res->i32 = v1->i16 * v2->i8; + return PSI_T_INT32; + case PSI_T_UINT8: + res->i32 = v1->i16 * v2->u8; + return PSI_T_INT32; + case PSI_T_INT16: + res->i32 = v1->i16 * v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->i32 = v1->i16 * v2->u16; + return PSI_T_INT32; + case PSI_T_INT32: + res->i64 = v1->i16 * v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i16 * v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i16 * v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i16 * v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i16 * v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i16 * v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i16 * v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT16: + switch (t2) { + case PSI_T_INT8: + res->i32 = v1->u16 * v2->i8; + return PSI_T_INT32; + case PSI_T_UINT8: + res->u32 = v1->u16 * v2->u8; + return PSI_T_UINT32; + case PSI_T_INT16: + res->i32 = v1->u16 * v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->u32 = v1->u16 * v2->u16; + return PSI_T_UINT32; + case PSI_T_INT32: + res->i64 = v1->u16 * v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u16 * v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u16 * v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u16 * v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u16 * v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u16 * v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u16 * v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT32: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->i32 * v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->i64 = v1->i32 * v2->u8; + return PSI_T_INT64; + case PSI_T_INT16: + res->i64 = v1->i32 * v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->i64 = v1->i32 * v2->u16; + return PSI_T_INT64; + case PSI_T_INT32: + res->i64 = v1->i32 * v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i32 * v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i32 * v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i32 * v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i32 * v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i32 * v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i32 * v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT32: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->u32 * v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->u64 = v1->u32 * v2->u8; + return PSI_T_UINT64; + case PSI_T_INT16: + res->i64 = v1->u32 * v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->u64 = v1->u32 * v2->u16; + return PSI_T_UINT64; + case PSI_T_INT32: + res->i64 = v1->u32 * v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u32 * v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u32 * v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u32 * v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u32 * v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u32 * v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u32 * v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT64: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->i64 * v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->i64 = v1->i64 * v2->u8; + return PSI_T_INT64; + case PSI_T_INT16: + res->i64 = v1->i64 * v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->i64 = v1->i64 * v2->u16; + return PSI_T_INT64; + case PSI_T_INT32: + res->i64 = v1->i64 * v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i64 * v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i64 * v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i64 * v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i64 * v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i64 * v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i64 * v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT64: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->u64 * v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->u64 = v1->u64 * v2->u8; + return PSI_T_UINT64; + case PSI_T_INT16: + res->i64 = v1->u64 * v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->u64 = v1->u64 * v2->u16; + return PSI_T_UINT64; + case PSI_T_INT32: + res->i64 = v1->u64 * v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u64 * v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u64 * v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u64 * v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u64 * v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u64 * v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u64 * v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_FLOAT: + switch (t2) { + case PSI_T_INT8: + res->fval = v1->fval * v2->i8; + return PSI_T_FLOAT; + case PSI_T_UINT8: + res->fval = v1->fval * v2->u8; + return PSI_T_FLOAT; + case PSI_T_INT16: + res->fval = v1->fval * v2->i16; + return PSI_T_FLOAT; + case PSI_T_UINT16: + res->fval = v1->fval * v2->u16; + return PSI_T_FLOAT; + case PSI_T_INT32: + res->fval = v1->fval * v2->i32; + return PSI_T_FLOAT; + case PSI_T_UINT32: + res->fval = v1->fval * v2->u32; + return PSI_T_FLOAT; + case PSI_T_INT64: + res->fval = v1->fval * v2->i64; + return PSI_T_FLOAT; + case PSI_T_UINT64: + res->fval = v1->fval * v2->u64; + return PSI_T_FLOAT; + case PSI_T_FLOAT: + res->fval = v1->fval * v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->fval * v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->fval * v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->dval = v1->dval * v2->i8; + return PSI_T_DOUBLE; + case PSI_T_UINT8: + res->dval = v1->dval * v2->u8; + return PSI_T_DOUBLE; + case PSI_T_INT16: + res->dval = v1->dval * v2->i16; + return PSI_T_DOUBLE; + case PSI_T_UINT16: + res->dval = v1->dval * v2->u16; + return PSI_T_DOUBLE; + case PSI_T_INT32: + res->dval = v1->dval * v2->i32; + return PSI_T_DOUBLE; + case PSI_T_UINT32: + res->dval = v1->dval * v2->u32; + return PSI_T_DOUBLE; + case PSI_T_INT64: + res->dval = v1->dval * v2->i64; + return PSI_T_DOUBLE; + case PSI_T_UINT64: + res->dval = v1->dval * v2->u64; + return PSI_T_DOUBLE; + case PSI_T_FLOAT: + res->dval = v1->dval * v2->fval; + return PSI_T_DOUBLE; + case PSI_T_DOUBLE: + res->dval = v1->dval * v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->dval * v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->ldval = v1->ldval * v2->i8; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT8: + res->ldval = v1->ldval * v2->u8; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT16: + res->ldval = v1->ldval * v2->i16; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT16: + res->ldval = v1->ldval * v2->u16; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT32: + res->ldval = v1->ldval * v2->i32; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT32: + res->ldval = v1->ldval * v2->u32; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT64: + res->ldval = v1->ldval * v2->i64; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT64: + res->ldval = v1->ldval * v2->u64; + return PSI_T_LONG_DOUBLE; + case PSI_T_FLOAT: + res->ldval = v1->ldval * v2->fval; + return PSI_T_LONG_DOUBLE; + case PSI_T_DOUBLE: + res->ldval = v1->ldval * v2->dval; + return PSI_T_LONG_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->ldval * v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; +#endif + + default: + assert(0); + break; + } + + return 0; +} +static inline token_t psi_calc_div(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + + switch (t1) { + case PSI_T_INT8: + switch (t2) { + case PSI_T_INT8: + res->i16 = v1->i8 / v2->i8; + return PSI_T_INT16; + case PSI_T_UINT8: + res->i16 = v1->i8 / v2->u8; + return PSI_T_INT16; + case PSI_T_INT16: + res->i32 = v1->i8 / v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->i32 = v1->i8 / v2->u16; + return PSI_T_INT32; + case PSI_T_INT32: + res->i64 = v1->i8 / v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i8 / v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i8 / v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i8 / v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i8 / v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i8 / v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i8 / v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT8: + switch (t2) { + case PSI_T_INT8: + res->i16 = v1->u8 / v2->i8; + return PSI_T_INT16; + case PSI_T_UINT8: + res->u16 = v1->u8 / v2->u8; + return PSI_T_UINT16; + case PSI_T_INT16: + res->i32 = v1->u8 / v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->u32 = v1->u8 / v2->u16; + return PSI_T_UINT32; + case PSI_T_INT32: + res->i64 = v1->u8 / v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u8 / v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u8 / v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u8 / v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u8 / v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u8 / v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u8 / v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT16: + switch (t2) { + case PSI_T_INT8: + res->i32 = v1->i16 / v2->i8; + return PSI_T_INT32; + case PSI_T_UINT8: + res->i32 = v1->i16 / v2->u8; + return PSI_T_INT32; + case PSI_T_INT16: + res->i32 = v1->i16 / v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->i32 = v1->i16 / v2->u16; + return PSI_T_INT32; + case PSI_T_INT32: + res->i64 = v1->i16 / v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i16 / v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i16 / v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i16 / v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i16 / v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i16 / v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i16 / v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT16: + switch (t2) { + case PSI_T_INT8: + res->i32 = v1->u16 / v2->i8; + return PSI_T_INT32; + case PSI_T_UINT8: + res->u32 = v1->u16 / v2->u8; + return PSI_T_UINT32; + case PSI_T_INT16: + res->i32 = v1->u16 / v2->i16; + return PSI_T_INT32; + case PSI_T_UINT16: + res->u32 = v1->u16 / v2->u16; + return PSI_T_UINT32; + case PSI_T_INT32: + res->i64 = v1->u16 / v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u16 / v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u16 / v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u16 / v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u16 / v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u16 / v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u16 / v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT32: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->i32 / v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->i64 = v1->i32 / v2->u8; + return PSI_T_INT64; + case PSI_T_INT16: + res->i64 = v1->i32 / v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->i64 = v1->i32 / v2->u16; + return PSI_T_INT64; + case PSI_T_INT32: + res->i64 = v1->i32 / v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i32 / v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i32 / v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i32 / v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i32 / v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i32 / v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i32 / v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT32: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->u32 / v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->u64 = v1->u32 / v2->u8; + return PSI_T_UINT64; + case PSI_T_INT16: + res->i64 = v1->u32 / v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->u64 = v1->u32 / v2->u16; + return PSI_T_UINT64; + case PSI_T_INT32: + res->i64 = v1->u32 / v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u32 / v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u32 / v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u32 / v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u32 / v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u32 / v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u32 / v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT64: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->i64 / v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->i64 = v1->i64 / v2->u8; + return PSI_T_INT64; + case PSI_T_INT16: + res->i64 = v1->i64 / v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->i64 = v1->i64 / v2->u16; + return PSI_T_INT64; + case PSI_T_INT32: + res->i64 = v1->i64 / v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->i64 = v1->i64 / v2->u32; + return PSI_T_INT64; + case PSI_T_INT64: + res->i64 = v1->i64 / v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->i64 = v1->i64 / v2->u64; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->fval = v1->i64 / v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->i64 / v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->i64 / v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT64: + switch (t2) { + case PSI_T_INT8: + res->i64 = v1->u64 / v2->i8; + return PSI_T_INT64; + case PSI_T_UINT8: + res->u64 = v1->u64 / v2->u8; + return PSI_T_UINT64; + case PSI_T_INT16: + res->i64 = v1->u64 / v2->i16; + return PSI_T_INT64; + case PSI_T_UINT16: + res->u64 = v1->u64 / v2->u16; + return PSI_T_UINT64; + case PSI_T_INT32: + res->i64 = v1->u64 / v2->i32; + return PSI_T_INT64; + case PSI_T_UINT32: + res->u64 = v1->u64 / v2->u32; + return PSI_T_UINT64; + case PSI_T_INT64: + res->i64 = v1->u64 / v2->i64; + return PSI_T_INT64; + case PSI_T_UINT64: + res->u64 = v1->u64 / v2->u64; + return PSI_T_UINT64; + case PSI_T_FLOAT: + res->fval = v1->u64 / v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->u64 / v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->u64 / v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_FLOAT: + switch (t2) { + case PSI_T_INT8: + res->fval = v1->fval / v2->i8; + return PSI_T_FLOAT; + case PSI_T_UINT8: + res->fval = v1->fval / v2->u8; + return PSI_T_FLOAT; + case PSI_T_INT16: + res->fval = v1->fval / v2->i16; + return PSI_T_FLOAT; + case PSI_T_UINT16: + res->fval = v1->fval / v2->u16; + return PSI_T_FLOAT; + case PSI_T_INT32: + res->fval = v1->fval / v2->i32; + return PSI_T_FLOAT; + case PSI_T_UINT32: + res->fval = v1->fval / v2->u32; + return PSI_T_FLOAT; + case PSI_T_INT64: + res->fval = v1->fval / v2->i64; + return PSI_T_FLOAT; + case PSI_T_UINT64: + res->fval = v1->fval / v2->u64; + return PSI_T_FLOAT; + case PSI_T_FLOAT: + res->fval = v1->fval / v2->fval; + return PSI_T_FLOAT; + case PSI_T_DOUBLE: + res->dval = v1->fval / v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->fval / v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->dval = v1->dval / v2->i8; + return PSI_T_DOUBLE; + case PSI_T_UINT8: + res->dval = v1->dval / v2->u8; + return PSI_T_DOUBLE; + case PSI_T_INT16: + res->dval = v1->dval / v2->i16; + return PSI_T_DOUBLE; + case PSI_T_UINT16: + res->dval = v1->dval / v2->u16; + return PSI_T_DOUBLE; + case PSI_T_INT32: + res->dval = v1->dval / v2->i32; + return PSI_T_DOUBLE; + case PSI_T_UINT32: + res->dval = v1->dval / v2->u32; + return PSI_T_DOUBLE; + case PSI_T_INT64: + res->dval = v1->dval / v2->i64; + return PSI_T_DOUBLE; + case PSI_T_UINT64: + res->dval = v1->dval / v2->u64; + return PSI_T_DOUBLE; + case PSI_T_FLOAT: + res->dval = v1->dval / v2->fval; + return PSI_T_DOUBLE; + case PSI_T_DOUBLE: + res->dval = v1->dval / v2->dval; + return PSI_T_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->dval / v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->ldval = v1->ldval / v2->i8; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT8: + res->ldval = v1->ldval / v2->u8; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT16: + res->ldval = v1->ldval / v2->i16; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT16: + res->ldval = v1->ldval / v2->u16; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT32: + res->ldval = v1->ldval / v2->i32; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT32: + res->ldval = v1->ldval / v2->u32; + return PSI_T_LONG_DOUBLE; + case PSI_T_INT64: + res->ldval = v1->ldval / v2->i64; + return PSI_T_LONG_DOUBLE; + case PSI_T_UINT64: + res->ldval = v1->ldval / v2->u64; + return PSI_T_LONG_DOUBLE; + case PSI_T_FLOAT: + res->ldval = v1->ldval / v2->fval; + return PSI_T_LONG_DOUBLE; + case PSI_T_DOUBLE: + res->ldval = v1->ldval / v2->dval; + return PSI_T_LONG_DOUBLE; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->ldval = v1->ldval / v2->ldval; + return PSI_T_LONG_DOUBLE; +# endif + + default: + assert(0); + break; + } + break; +#endif + + default: + assert(0); + break; + } + + return 0; +} + + +static inline token_t psi_calc_mod(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + impl_val i1, i2; + + switch (t1) { + case PSI_T_INT8: + i1.i64 = v1->i8; + break; + + case PSI_T_UINT8: + i1.i64 = v1->u8; + break; + + case PSI_T_INT16: + i1.i64 = v1->i16; + break; + + case PSI_T_UINT16: + i1.i64 = v1->u16; + break; + + case PSI_T_INT32: + i1.i64 = v1->i32; + break; + + case PSI_T_UINT32: + i1.i64 = v1->u32; + break; + + case PSI_T_INT64: + i1.i64 = v1->i64; + break; + + case PSI_T_UINT64: + i1.i64 = v1->u64; + break; + + case PSI_T_FLOAT: + i1.i64 = v1->fval; + break; + + case PSI_T_DOUBLE: + i1.i64 = v1->dval; + break; + +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i1.i64 = v1->ldval; + break; + +#endif + + default: + assert(0); + break; + } + + switch (t2) { + case PSI_T_INT8: + i2.i64 = v2->i8; + break; + case PSI_T_UINT8: + i2.i64 = v2->u8; + break; + case PSI_T_INT16: + i2.i64 = v2->i16; + break; + case PSI_T_UINT16: + i2.i64 = v2->u16; + break; + case PSI_T_INT32: + i2.i64 = v2->i32; + break; + case PSI_T_UINT32: + i2.i64 = v2->u32; + break; + case PSI_T_INT64: + i2.i64 = v2->i64; + break; + case PSI_T_UINT64: + i2.i64 = v2->u64; + break; + case PSI_T_FLOAT: + i2.i64 = v2->fval; + break; + case PSI_T_DOUBLE: + i2.i64 = v2->dval; + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i2.i64 = v2->ldval; + break; +#endif + + default: + assert(0); + break; + } + + res->i64 = i1.i64 % i2.i64; + return PSI_T_INT64; +} diff --git a/src/calc/bin.h b/src/calc/bin.h new file mode 100644 index 0000000..3e9e4a0 --- /dev/null +++ b/src/calc/bin.h @@ -0,0 +1,608 @@ +/******************************************************************************* + Copyright (c) 2016, Michael Wallner . + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ + +#include "php_psi_stdinc.h" +#include + +#include "token.h" + +static inline token_t psi_calc_bin_lshift(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + impl_val i1, i2; + + switch (t1) { + case PSI_T_INT8: + i1.u64 = v1->i8; + break; + + case PSI_T_UINT8: + i1.u64 = v1->u8; + break; + + case PSI_T_INT16: + i1.u64 = v1->i16; + break; + + case PSI_T_UINT16: + i1.u64 = v1->u16; + break; + + case PSI_T_INT32: + i1.u64 = v1->i32; + break; + + case PSI_T_UINT32: + i1.u64 = v1->u32; + break; + + case PSI_T_INT64: + i1.u64 = v1->i64; + break; + + case PSI_T_UINT64: + i1.u64 = v1->u64; + break; + + case PSI_T_FLOAT: + i1.u64 = v1->fval; + break; + + case PSI_T_DOUBLE: + i1.u64 = v1->dval; + break; + +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i1.u64 = v1->ldval; + break; + +#endif + + default: + assert(0); + break; + } + + switch (t2) { + case PSI_T_INT8: + i2.u64 = v2->i8; + break; + case PSI_T_UINT8: + i2.u64 = v2->u8; + break; + case PSI_T_INT16: + i2.u64 = v2->i16; + break; + case PSI_T_UINT16: + i2.u64 = v2->u16; + break; + case PSI_T_INT32: + i2.u64 = v2->i32; + break; + case PSI_T_UINT32: + i2.u64 = v2->u32; + break; + case PSI_T_INT64: + i2.u64 = v2->i64; + break; + case PSI_T_UINT64: + i2.u64 = v2->u64; + break; + case PSI_T_FLOAT: + i2.u64 = v2->fval; + break; + case PSI_T_DOUBLE: + i2.u64 = v2->dval; + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i2.u64 = v2->ldval; + break; +#endif + + default: + assert(0); + break; + } + + res->u64 = i1.u64 << i2.u64; + return PSI_T_UINT64; +} + +static inline token_t psi_calc_bin_rshift(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + impl_val i1, i2; + + switch (t1) { + case PSI_T_INT8: + i1.u64 = v1->i8; + break; + + case PSI_T_UINT8: + i1.u64 = v1->u8; + break; + + case PSI_T_INT16: + i1.u64 = v1->i16; + break; + + case PSI_T_UINT16: + i1.u64 = v1->u16; + break; + + case PSI_T_INT32: + i1.u64 = v1->i32; + break; + + case PSI_T_UINT32: + i1.u64 = v1->u32; + break; + + case PSI_T_INT64: + i1.u64 = v1->i64; + break; + + case PSI_T_UINT64: + i1.u64 = v1->u64; + break; + + case PSI_T_FLOAT: + i1.u64 = v1->fval; + break; + + case PSI_T_DOUBLE: + i1.u64 = v1->dval; + break; + +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i1.u64 = v1->ldval; + break; + +#endif + + default: + assert(0); + break; + } + + switch (t2) { + case PSI_T_INT8: + i2.u64 = v2->i8; + break; + case PSI_T_UINT8: + i2.u64 = v2->u8; + break; + case PSI_T_INT16: + i2.u64 = v2->i16; + break; + case PSI_T_UINT16: + i2.u64 = v2->u16; + break; + case PSI_T_INT32: + i2.u64 = v2->i32; + break; + case PSI_T_UINT32: + i2.u64 = v2->u32; + break; + case PSI_T_INT64: + i2.u64 = v2->i64; + break; + case PSI_T_UINT64: + i2.u64 = v2->u64; + break; + case PSI_T_FLOAT: + i2.u64 = v2->fval; + break; + case PSI_T_DOUBLE: + i2.u64 = v2->dval; + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i2.u64 = v2->ldval; + break; +#endif + + default: + assert(0); + break; + } + + res->u64 = i1.u64 >> i2.u64; + return PSI_T_UINT64; +} + +static inline token_t psi_calc_bin_and(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + impl_val i1, i2; + + switch (t1) { + case PSI_T_INT8: + i1.u64 = v1->i8; + break; + + case PSI_T_UINT8: + i1.u64 = v1->u8; + break; + + case PSI_T_INT16: + i1.u64 = v1->i16; + break; + + case PSI_T_UINT16: + i1.u64 = v1->u16; + break; + + case PSI_T_INT32: + i1.u64 = v1->i32; + break; + + case PSI_T_UINT32: + i1.u64 = v1->u32; + break; + + case PSI_T_INT64: + i1.u64 = v1->i64; + break; + + case PSI_T_UINT64: + i1.u64 = v1->u64; + break; + + case PSI_T_FLOAT: + i1.u64 = v1->fval; + break; + + case PSI_T_DOUBLE: + i1.u64 = v1->dval; + break; + +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i1.u64 = v1->ldval; + break; + +#endif + + default: + assert(0); + break; + } + + switch (t2) { + case PSI_T_INT8: + i2.u64 = v2->i8; + break; + case PSI_T_UINT8: + i2.u64 = v2->u8; + break; + case PSI_T_INT16: + i2.u64 = v2->i16; + break; + case PSI_T_UINT16: + i2.u64 = v2->u16; + break; + case PSI_T_INT32: + i2.u64 = v2->i32; + break; + case PSI_T_UINT32: + i2.u64 = v2->u32; + break; + case PSI_T_INT64: + i2.u64 = v2->i64; + break; + case PSI_T_UINT64: + i2.u64 = v2->u64; + break; + case PSI_T_FLOAT: + i2.u64 = v2->fval; + break; + case PSI_T_DOUBLE: + i2.u64 = v2->dval; + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i2.u64 = v2->ldval; + break; +#endif + + default: + assert(0); + break; + } + + res->u64 = i1.u64 & i2.u64; + return PSI_T_UINT64; +} + +static inline token_t psi_calc_bin_xor(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + impl_val i1, i2; + + switch (t1) { + case PSI_T_INT8: + i1.u64 = v1->i8; + break; + + case PSI_T_UINT8: + i1.u64 = v1->u8; + break; + + case PSI_T_INT16: + i1.u64 = v1->i16; + break; + + case PSI_T_UINT16: + i1.u64 = v1->u16; + break; + + case PSI_T_INT32: + i1.u64 = v1->i32; + break; + + case PSI_T_UINT32: + i1.u64 = v1->u32; + break; + + case PSI_T_INT64: + i1.u64 = v1->i64; + break; + + case PSI_T_UINT64: + i1.u64 = v1->u64; + break; + + case PSI_T_FLOAT: + i1.u64 = v1->fval; + break; + + case PSI_T_DOUBLE: + i1.u64 = v1->dval; + break; + +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i1.u64 = v1->ldval; + break; + +#endif + + default: + assert(0); + break; + } + + switch (t2) { + case PSI_T_INT8: + i2.u64 = v2->i8; + break; + case PSI_T_UINT8: + i2.u64 = v2->u8; + break; + case PSI_T_INT16: + i2.u64 = v2->i16; + break; + case PSI_T_UINT16: + i2.u64 = v2->u16; + break; + case PSI_T_INT32: + i2.u64 = v2->i32; + break; + case PSI_T_UINT32: + i2.u64 = v2->u32; + break; + case PSI_T_INT64: + i2.u64 = v2->i64; + break; + case PSI_T_UINT64: + i2.u64 = v2->u64; + break; + case PSI_T_FLOAT: + i2.u64 = v2->fval; + break; + case PSI_T_DOUBLE: + i2.u64 = v2->dval; + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i2.u64 = v2->ldval; + break; +#endif + + default: + assert(0); + break; + } + + res->u64 = i1.u64 ^ i2.u64; + return PSI_T_UINT64; +} + +static inline token_t psi_calc_bin_or(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + impl_val i1, i2; + + switch (t1) { + case PSI_T_INT8: + i1.u64 = v1->i8; + break; + + case PSI_T_UINT8: + i1.u64 = v1->u8; + break; + + case PSI_T_INT16: + i1.u64 = v1->i16; + break; + + case PSI_T_UINT16: + i1.u64 = v1->u16; + break; + + case PSI_T_INT32: + i1.u64 = v1->i32; + break; + + case PSI_T_UINT32: + i1.u64 = v1->u32; + break; + + case PSI_T_INT64: + i1.u64 = v1->i64; + break; + + case PSI_T_UINT64: + i1.u64 = v1->u64; + break; + + case PSI_T_FLOAT: + i1.u64 = v1->fval; + break; + + case PSI_T_DOUBLE: + i1.u64 = v1->dval; + break; + +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i1.u64 = v1->ldval; + break; + +#endif + + default: + assert(0); + break; + } + + switch (t2) { + case PSI_T_INT8: + i2.u64 = v2->i8; + break; + case PSI_T_UINT8: + i2.u64 = v2->u8; + break; + case PSI_T_INT16: + i2.u64 = v2->i16; + break; + case PSI_T_UINT16: + i2.u64 = v2->u16; + break; + case PSI_T_INT32: + i2.u64 = v2->i32; + break; + case PSI_T_UINT32: + i2.u64 = v2->u32; + break; + case PSI_T_INT64: + i2.u64 = v2->i64; + break; + case PSI_T_UINT64: + i2.u64 = v2->u64; + break; + case PSI_T_FLOAT: + i2.u64 = v2->fval; + break; + case PSI_T_DOUBLE: + i2.u64 = v2->dval; + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i2.u64 = v2->ldval; + break; +#endif + + default: + assert(0); + break; + } + + res->u64 = i1.u64 | i2.u64; + return PSI_T_UINT64; +} + +static inline token_t psi_calc_bin_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + impl_val i1; + + (void) t2; + (void) v2; + + switch (t1) { + case PSI_T_INT8: + i1.u64 = v1->i8; + break; + + case PSI_T_UINT8: + i1.u64 = v1->u8; + break; + + case PSI_T_INT16: + i1.u64 = v1->i16; + break; + + case PSI_T_UINT16: + i1.u64 = v1->u16; + break; + + case PSI_T_INT32: + i1.u64 = v1->i32; + break; + + case PSI_T_UINT32: + i1.u64 = v1->u32; + break; + + case PSI_T_INT64: + i1.u64 = v1->i64; + break; + + case PSI_T_UINT64: + i1.u64 = v1->u64; + break; + + case PSI_T_FLOAT: + i1.u64 = v1->fval; + break; + + case PSI_T_DOUBLE: + i1.u64 = v1->dval; + break; + +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + i1.u64 = v1->ldval; + break; + +#endif + + default: + assert(0); + break; + } + + res->u64 = ~i1.u64; + return PSI_T_UINT64; +} \ No newline at end of file diff --git a/src/calc/bool.h b/src/calc/bool.h new file mode 100644 index 0000000..99f5f0a --- /dev/null +++ b/src/calc/bool.h @@ -0,0 +1,310 @@ +/******************************************************************************* + Copyright (c) 2016, Michael Wallner . + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ + +#include "php_psi_stdinc.h" +#include + +#include "token.h" + +static inline token_t psi_calc_bool_not(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + (void) t2; + (void) v2; + + switch (t1) { + case PSI_T_INT8: + res->u8 = !v1->i8; + break; + case PSI_T_UINT8: + res->u8 = !v1->u8; + break; + case PSI_T_INT16: + res->u8 = !v1->i16; + break; + case PSI_T_UINT16: + res->u8 = !v1->u16; + break; + case PSI_T_INT32: + res->u8 = !v1->i32; + break; + case PSI_T_UINT32: + res->u8 = !v1->u32; + break; + case PSI_T_INT64: + res->u8 = !v1->i64; + break; + case PSI_T_UINT64: + res->u8 = !v1->u64; + break; + case PSI_T_FLOAT: + res->u8 = !v1->fval; + break; + case PSI_T_DOUBLE: + res->u8 = !v1->dval; + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = !v1->ldval; + break; +#endif + + default: + assert(0); + break; + } + return PSI_T_UINT8; +} + +static inline token_t psi_calc_bool_or(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + switch (t1) { + case PSI_T_INT8: + if (v1->i8) + goto return_true; + break; + case PSI_T_UINT8: + if (v1->u8) + goto return_true; + break; + case PSI_T_INT16: + if (v1->i16) + goto return_true; + break; + case PSI_T_UINT16: + if (v1->u16) + goto return_true; + break; + case PSI_T_INT32: + if (v1->i32) + goto return_true; + break; + case PSI_T_UINT32: + if (v1->u32) + goto return_true; + break; + case PSI_T_INT64: + if (v1->i64) + goto return_true; + break; + case PSI_T_UINT64: + if (v1->u64) + goto return_true; + break; + case PSI_T_FLOAT: + if (v1->fval) + goto return_true; + break; + case PSI_T_DOUBLE: + if (v1->dval) + goto return_true; + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + if (v1->ldval) + goto return_true; + break; +#endif + + default: + assert(0); + break; + } + + switch (t2) { + case PSI_T_INT8: + if (v2->i8) + goto return_true; + break; + case PSI_T_UINT8: + if (v2->u8) + goto return_true; + break; + case PSI_T_INT16: + if (v2->i16) + goto return_true; + break; + case PSI_T_UINT16: + if (v2->u16) + goto return_true; + break; + case PSI_T_INT32: + if (v2->i32) + goto return_true; + break; + case PSI_T_UINT32: + if (v2->u32) + goto return_true; + break; + case PSI_T_INT64: + if (v2->i64) + goto return_true; + break; + case PSI_T_UINT64: + if (v2->u64) + goto return_true; + break; + case PSI_T_FLOAT: + if (v2->fval) + goto return_true; + break; + case PSI_T_DOUBLE: + if (v2->dval) + goto return_true; + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + if (v2->ldval) + goto return_true; + break; +#endif + + default: + assert(0); + break; + } + + res->u8 = 0; + return PSI_T_UINT8; + +return_true: + res->u8 = 1; + return PSI_T_UINT8; +} + +static inline token_t psi_calc_bool_and(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + switch (t1) { + case PSI_T_INT8: + if (!v1->i8) + goto return_false; + break; + case PSI_T_UINT8: + if (!v1->u8) + goto return_false; + break; + case PSI_T_INT16: + if (!v1->i16) + goto return_false; + break; + case PSI_T_UINT16: + if (!v1->u16) + goto return_false; + break; + case PSI_T_INT32: + if (!v1->i32) + goto return_false; + break; + case PSI_T_UINT32: + if (!v1->u32) + goto return_false; + break; + case PSI_T_INT64: + if (!v1->i64) + goto return_false; + break; + case PSI_T_UINT64: + if (!v1->u64) + goto return_false; + break; + case PSI_T_FLOAT: + if (!v1->fval) + goto return_false; + break; + case PSI_T_DOUBLE: + if (!v1->dval) + goto return_false; + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + if (!v1->ldval) + goto return_false; + break; +#endif + + default: + assert(0); + break; + } + + switch (t2) { + case PSI_T_INT8: + if (!v2->i8) + goto return_false; + break; + case PSI_T_UINT8: + if (!v2->u8) + goto return_false; + break; + case PSI_T_INT16: + if (!v2->i16) + goto return_false; + break; + case PSI_T_UINT16: + if (!v2->u16) + goto return_false; + break; + case PSI_T_INT32: + if (!v2->i32) + goto return_false; + break; + case PSI_T_UINT32: + if (!v2->u32) + goto return_false; + break; + case PSI_T_INT64: + if (!v2->i64) + goto return_false; + break; + case PSI_T_UINT64: + if (!v2->u64) + goto return_false; + break; + case PSI_T_FLOAT: + if (!v2->fval) + goto return_false; + break; + case PSI_T_DOUBLE: + if (!v2->dval) + goto return_false; + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + if (!v2->ldval) + goto return_false; + break; +#endif + + default: + assert(0); + break; + } + + res->u8 = 1; + return PSI_T_UINT8; + +return_false: + res->u8 = 0; + return PSI_T_UINT8; +} diff --git a/src/calc/cast.h b/src/calc/cast.h new file mode 100644 index 0000000..c6f14aa --- /dev/null +++ b/src/calc/cast.h @@ -0,0 +1,515 @@ +/******************************************************************************* + Copyright (c) 2016, Michael Wallner . + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ + +#include "php_psi_stdinc.h" +#include + +#include "token.h" + +static inline void psi_calc_cast(token_t in_type, impl_val *in_val, token_t out_type, impl_val *out_val) +{ + switch (out_type) { + case PSI_T_INT8: + switch (in_type) { + case PSI_T_INT8: + out_val->i8 = in_val->i8; + break; + case PSI_T_UINT8: + out_val->i8 = in_val->u8; + break; + case PSI_T_INT16: + out_val->i8 = in_val->i16; + break; + case PSI_T_UINT16: + out_val->i8 = in_val->u16; + break; + case PSI_T_INT32: + out_val->i8 = in_val->i32; + break; + case PSI_T_UINT32: + out_val->i8 = in_val->u32; + break; + case PSI_T_INT64: + out_val->i8 = in_val->i64; + break; + case PSI_T_UINT64: + out_val->i8 = in_val->u64; + break; + case PSI_T_FLOAT: + out_val->i8 = in_val->fval; + break; + case PSI_T_DOUBLE: + out_val->i8 = in_val->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + out_val->i8 = in_val->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT8: + switch (in_type) { + case PSI_T_INT8: + out_val->u8 = in_val->i8; + break; + case PSI_T_UINT8: + out_val->u8 = in_val->u8; + break; + case PSI_T_INT16: + out_val->u8 = in_val->i16; + break; + case PSI_T_UINT16: + out_val->u8 = in_val->u16; + break; + case PSI_T_INT32: + out_val->u8 = in_val->i32; + break; + case PSI_T_UINT32: + out_val->u8 = in_val->u32; + break; + case PSI_T_INT64: + out_val->u8 = in_val->i64; + break; + case PSI_T_UINT64: + out_val->u8 = in_val->u64; + break; + case PSI_T_FLOAT: + out_val->u8 = in_val->fval; + break; + case PSI_T_DOUBLE: + out_val->u8 = in_val->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + out_val->u8 = in_val->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT16: + switch (in_type) { + case PSI_T_INT8: + out_val->i16 = in_val->i8; + break; + case PSI_T_UINT8: + out_val->i16 = in_val->u8; + break; + case PSI_T_INT16: + out_val->i16 = in_val->i16; + break; + case PSI_T_UINT16: + out_val->i16 = in_val->u16; + break; + case PSI_T_INT32: + out_val->i16 = in_val->i32; + break; + case PSI_T_UINT32: + out_val->i16 = in_val->u32; + break; + case PSI_T_INT64: + out_val->i16 = in_val->i64; + break; + case PSI_T_UINT64: + out_val->i16 = in_val->u64; + break; + case PSI_T_FLOAT: + out_val->i16 = in_val->fval; + break; + case PSI_T_DOUBLE: + out_val->i16 = in_val->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + out_val->i16 = in_val->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT16: + switch (in_type) { + case PSI_T_INT8: + out_val->u16 = in_val->i8; + break; + case PSI_T_UINT8: + out_val->u16 = in_val->u8; + break; + case PSI_T_INT16: + out_val->u16 = in_val->i16; + break; + case PSI_T_UINT16: + out_val->u16 = in_val->u16; + break; + case PSI_T_INT32: + out_val->u16 = in_val->i32; + break; + case PSI_T_UINT32: + out_val->u16 = in_val->u32; + break; + case PSI_T_INT64: + out_val->u16 = in_val->i64; + break; + case PSI_T_UINT64: + out_val->u16 = in_val->u64; + break; + case PSI_T_FLOAT: + out_val->u16 = in_val->fval; + break; + case PSI_T_DOUBLE: + out_val->u16 = in_val->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + out_val->u16 = in_val->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT32: + switch (in_type) { + case PSI_T_INT8: + out_val->i32 = in_val->i8; + break; + case PSI_T_UINT8: + out_val->i32 = in_val->u8; + break; + case PSI_T_INT16: + out_val->i32 = in_val->i16; + break; + case PSI_T_UINT16: + out_val->i32 = in_val->u16; + break; + case PSI_T_INT32: + out_val->i32 = in_val->i32; + break; + case PSI_T_UINT32: + out_val->i32 = in_val->u32; + break; + case PSI_T_INT64: + out_val->i32 = in_val->i64; + break; + case PSI_T_UINT64: + out_val->i32 = in_val->u64; + break; + case PSI_T_FLOAT: + out_val->i32 = in_val->fval; + break; + case PSI_T_DOUBLE: + out_val->i32 = in_val->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + out_val->i32 = in_val->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT32: + switch (in_type) { + case PSI_T_INT8: + out_val->u32 = in_val->i8; + break; + case PSI_T_UINT8: + out_val->u32 = in_val->u8; + break; + case PSI_T_INT16: + out_val->u32 = in_val->i16; + break; + case PSI_T_UINT16: + out_val->u32 = in_val->u16; + break; + case PSI_T_INT32: + out_val->u32 = in_val->i32; + break; + case PSI_T_UINT32: + out_val->u32 = in_val->u32; + break; + case PSI_T_INT64: + out_val->u32 = in_val->i64; + break; + case PSI_T_UINT64: + out_val->u32 = in_val->u64; + break; + case PSI_T_FLOAT: + out_val->u32 = in_val->fval; + break; + case PSI_T_DOUBLE: + out_val->u32 = in_val->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + out_val->u32 = in_val->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT64: + switch (in_type) { + case PSI_T_INT8: + out_val->i64 = in_val->i8; + break; + case PSI_T_UINT8: + out_val->i64 = in_val->u8; + break; + case PSI_T_INT16: + out_val->i64 = in_val->i16; + break; + case PSI_T_UINT16: + out_val->i64 = in_val->u16; + break; + case PSI_T_INT32: + out_val->i64 = in_val->i32; + break; + case PSI_T_UINT32: + out_val->i64 = in_val->u32; + break; + case PSI_T_INT64: + out_val->i64 = in_val->i64; + break; + case PSI_T_UINT64: + out_val->i64 = in_val->u64; + break; + case PSI_T_FLOAT: + out_val->i64 = in_val->fval; + break; + case PSI_T_DOUBLE: + out_val->i64 = in_val->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + out_val->i64 = in_val->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT64: + switch (in_type) { + case PSI_T_INT8: + out_val->u64 = in_val->i8; + break; + case PSI_T_UINT8: + out_val->u64 = in_val->u8; + break; + case PSI_T_INT16: + out_val->u64 = in_val->i16; + break; + case PSI_T_UINT16: + out_val->u64 = in_val->u16; + break; + case PSI_T_INT32: + out_val->u64 = in_val->i32; + break; + case PSI_T_UINT32: + out_val->u64 = in_val->u32; + break; + case PSI_T_INT64: + out_val->u64 = in_val->i64; + break; + case PSI_T_UINT64: + out_val->u64 = in_val->u64; + break; + case PSI_T_FLOAT: + out_val->u64 = in_val->fval; + break; + case PSI_T_DOUBLE: + out_val->u64 = in_val->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + out_val->u64 = in_val->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_FLOAT: + switch (in_type) { + case PSI_T_INT8: + out_val->fval = in_val->i8; + break; + case PSI_T_UINT8: + out_val->fval = in_val->u8; + break; + case PSI_T_INT16: + out_val->fval = in_val->i16; + break; + case PSI_T_UINT16: + out_val->fval = in_val->u16; + break; + case PSI_T_INT32: + out_val->fval = in_val->i32; + break; + case PSI_T_UINT32: + out_val->fval = in_val->u32; + break; + case PSI_T_INT64: + out_val->fval = in_val->i64; + break; + case PSI_T_UINT64: + out_val->fval = in_val->u64; + break; + case PSI_T_FLOAT: + out_val->fval = in_val->fval; + break; + case PSI_T_DOUBLE: + out_val->fval = in_val->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + out_val->fval = in_val->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_DOUBLE: + switch (in_type) { + case PSI_T_INT8: + out_val->dval = in_val->i8; + break; + case PSI_T_UINT8: + out_val->dval = in_val->u8; + break; + case PSI_T_INT16: + out_val->dval = in_val->i16; + break; + case PSI_T_UINT16: + out_val->dval = in_val->u16; + break; + case PSI_T_INT32: + out_val->dval = in_val->i32; + break; + case PSI_T_UINT32: + out_val->dval = in_val->u32; + break; + case PSI_T_INT64: + out_val->dval = in_val->i64; + break; + case PSI_T_UINT64: + out_val->dval = in_val->u64; + break; + case PSI_T_FLOAT: + out_val->dval = in_val->fval; + break; + case PSI_T_DOUBLE: + out_val->dval = in_val->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + out_val->dval = in_val->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + switch (in_type) { + case PSI_T_INT8: + out_val->ldval = in_val->i8; + break; + case PSI_T_UINT8: + out_val->ldval = in_val->u8; + break; + case PSI_T_INT16: + out_val->ldval = in_val->i16; + break; + case PSI_T_UINT16: + out_val->ldval = in_val->u16; + break; + case PSI_T_INT32: + out_val->ldval = in_val->i32; + break; + case PSI_T_UINT32: + out_val->ldval = in_val->u32; + break; + case PSI_T_INT64: + out_val->ldval = in_val->i64; + break; + case PSI_T_UINT64: + out_val->ldval = in_val->u64; + break; + case PSI_T_FLOAT: + out_val->ldval = in_val->fval; + break; + case PSI_T_DOUBLE: + out_val->ldval = in_val->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + out_val->ldval = in_val->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#endif + + default: + assert(0); + break; + } +} + diff --git a/src/calc/cmp.h b/src/calc/cmp.h new file mode 100644 index 0000000..8fac2f3 --- /dev/null +++ b/src/calc/cmp.h @@ -0,0 +1,2945 @@ +/******************************************************************************* + Copyright (c) 2016, Michael Wallner . + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ + +#include "php_psi_stdinc.h" +#include + +#include "token.h" + +static inline token_t psi_calc_cmp_eq(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + switch (t1) { + case PSI_T_INT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i8 == v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i8 == v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i8 == v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i8 == v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i8 == v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i8 == v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i8 == v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i8 == v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i8 == v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i8 == v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i8 == v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u8 == v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u8 == v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u8 == v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u8 == v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u8 == v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u8 == v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u8 == v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u8 == v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u8 == v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u8 == v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u8 == v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i16 == v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i16 == v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i16 == v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i16 == v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i16 == v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i16 == v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i16 == v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i16 == v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i16 == v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i16 == v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i16 == v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u16 == v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u16 == v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u16 == v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u16 == v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u16 == v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u16 == v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u16 == v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u16 == v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u16 == v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u16 == v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u16 == v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i32 == v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i32 == v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i32 == v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i32 == v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i32 == v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i32 == v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i32 == v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i32 == v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i32 == v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i32 == v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i32 == v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u32 == v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u32 == v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u32 == v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u32 == v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u32 == v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u32 == v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u32 == v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u32 == v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u32 == v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u32 == v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u32 == v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i64 == v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i64 == v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i64 == v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i64 == v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i64 == v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i64 == v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i64 == v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i64 == v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i64 == v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i64 == v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i64 == v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u64 == v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u64 == v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u64 == v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u64 == v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u64 == v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u64 == v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u64 == v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u64 == v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u64 == v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u64 == v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u64 == v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_FLOAT: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->fval == v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->fval == v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->fval == v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->fval == v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->fval == v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->fval == v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->fval == v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->fval == v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->fval == v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->fval == v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->fval == v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->dval == v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->dval == v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->dval == v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->dval == v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->dval == v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->dval == v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->dval == v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->dval == v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->dval == v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->dval == v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->dval == v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->ldval == v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->ldval == v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->ldval == v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->ldval == v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->ldval == v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->ldval == v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->ldval == v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->ldval == v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->ldval == v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->ldval == v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->ldval == v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#endif + + default: + assert(0); + break; + } + return PSI_T_UINT8; +} + +static inline token_t psi_calc_cmp_ne(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + switch (t1) { + case PSI_T_INT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i8 != v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i8 != v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i8 != v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i8 != v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i8 != v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i8 != v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i8 != v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i8 != v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i8 != v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i8 != v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i8 != v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u8 != v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u8 != v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u8 != v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u8 != v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u8 != v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u8 != v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u8 != v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u8 != v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u8 != v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u8 != v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u8 != v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i16 != v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i16 != v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i16 != v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i16 != v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i16 != v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i16 != v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i16 != v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i16 != v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i16 != v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i16 != v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i16 != v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u16 != v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u16 != v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u16 != v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u16 != v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u16 != v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u16 != v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u16 != v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u16 != v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u16 != v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u16 != v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u16 != v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i32 != v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i32 != v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i32 != v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i32 != v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i32 != v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i32 != v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i32 != v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i32 != v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i32 != v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i32 != v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i32 != v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u32 != v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u32 != v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u32 != v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u32 != v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u32 != v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u32 != v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u32 != v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u32 != v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u32 != v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u32 != v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u32 != v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i64 != v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i64 != v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i64 != v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i64 != v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i64 != v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i64 != v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i64 != v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i64 != v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i64 != v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i64 != v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i64 != v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u64 != v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u64 != v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u64 != v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u64 != v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u64 != v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u64 != v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u64 != v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u64 != v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u64 != v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u64 != v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u64 != v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_FLOAT: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->fval != v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->fval != v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->fval != v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->fval != v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->fval != v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->fval != v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->fval != v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->fval != v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->fval != v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->fval != v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->fval != v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->dval != v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->dval != v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->dval != v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->dval != v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->dval != v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->dval != v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->dval != v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->dval != v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->dval != v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->dval != v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->dval != v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->ldval != v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->ldval != v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->ldval != v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->ldval != v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->ldval != v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->ldval != v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->ldval != v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->ldval != v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->ldval != v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->ldval != v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->ldval != v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#endif + + default: + assert(0); + break; + } + return PSI_T_UINT8; +} + +static inline token_t psi_calc_cmp_lt(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + switch (t1) { + case PSI_T_INT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i8 < v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i8 < v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i8 < v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i8 < v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i8 < v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i8 < v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i8 < v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i8 < v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i8 < v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i8 < v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i8 < v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u8 < v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u8 < v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u8 < v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u8 < v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u8 < v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u8 < v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u8 < v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u8 < v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u8 < v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u8 < v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u8 < v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i16 < v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i16 < v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i16 < v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i16 < v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i16 < v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i16 < v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i16 < v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i16 < v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i16 < v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i16 < v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i16 < v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u16 < v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u16 < v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u16 < v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u16 < v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u16 < v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u16 < v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u16 < v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u16 < v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u16 < v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u16 < v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u16 < v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i32 < v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i32 < v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i32 < v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i32 < v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i32 < v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i32 < v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i32 < v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i32 < v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i32 < v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i32 < v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i32 < v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u32 < v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u32 < v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u32 < v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u32 < v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u32 < v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u32 < v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u32 < v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u32 < v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u32 < v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u32 < v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u32 < v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i64 < v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i64 < v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i64 < v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i64 < v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i64 < v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i64 < v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i64 < v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i64 < v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i64 < v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i64 < v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i64 < v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u64 < v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u64 < v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u64 < v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u64 < v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u64 < v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u64 < v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u64 < v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u64 < v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u64 < v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u64 < v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u64 < v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_FLOAT: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->fval < v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->fval < v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->fval < v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->fval < v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->fval < v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->fval < v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->fval < v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->fval < v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->fval < v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->fval < v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->fval < v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->dval < v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->dval < v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->dval < v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->dval < v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->dval < v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->dval < v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->dval < v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->dval < v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->dval < v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->dval < v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->dval < v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->ldval < v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->ldval < v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->ldval < v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->ldval < v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->ldval < v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->ldval < v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->ldval < v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->ldval < v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->ldval < v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->ldval < v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->ldval < v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#endif + + default: + assert(0); + break; + } + return PSI_T_UINT8; +} + +static inline token_t psi_calc_cmp_gt(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + switch (t1) { + case PSI_T_INT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i8 > v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i8 > v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i8 > v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i8 > v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i8 > v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i8 > v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i8 > v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i8 > v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i8 > v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i8 > v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i8 > v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u8 > v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u8 > v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u8 > v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u8 > v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u8 > v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u8 > v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u8 > v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u8 > v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u8 > v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u8 > v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u8 > v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i16 > v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i16 > v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i16 > v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i16 > v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i16 > v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i16 > v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i16 > v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i16 > v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i16 > v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i16 > v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i16 > v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u16 > v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u16 > v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u16 > v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u16 > v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u16 > v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u16 > v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u16 > v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u16 > v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u16 > v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u16 > v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u16 > v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i32 > v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i32 > v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i32 > v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i32 > v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i32 > v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i32 > v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i32 > v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i32 > v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i32 > v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i32 > v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i32 > v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u32 > v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u32 > v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u32 > v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u32 > v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u32 > v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u32 > v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u32 > v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u32 > v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u32 > v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u32 > v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u32 > v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i64 > v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i64 > v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i64 > v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i64 > v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i64 > v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i64 > v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i64 > v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i64 > v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i64 > v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i64 > v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i64 > v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u64 > v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u64 > v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u64 > v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u64 > v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u64 > v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u64 > v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u64 > v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u64 > v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u64 > v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u64 > v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u64 > v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_FLOAT: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->fval > v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->fval > v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->fval > v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->fval > v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->fval > v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->fval > v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->fval > v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->fval > v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->fval > v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->fval > v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->fval > v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->dval > v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->dval > v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->dval > v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->dval > v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->dval > v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->dval > v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->dval > v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->dval > v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->dval > v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->dval > v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->dval > v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->ldval > v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->ldval > v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->ldval > v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->ldval > v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->ldval > v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->ldval > v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->ldval > v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->ldval > v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->ldval > v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->ldval > v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->ldval > v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#endif + + default: + assert(0); + break; + } + return PSI_T_UINT8; +} + +static inline token_t psi_calc_cmp_le(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + switch (t1) { + case PSI_T_INT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i8 <= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i8 <= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i8 <= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i8 <= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i8 <= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i8 <= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i8 <= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i8 <= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i8 <= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i8 <= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i8 <= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u8 <= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u8 <= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u8 <= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u8 <= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u8 <= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u8 <= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u8 <= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u8 <= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u8 <= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u8 <= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u8 <= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i16 <= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i16 <= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i16 <= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i16 <= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i16 <= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i16 <= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i16 <= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i16 <= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i16 <= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i16 <= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i16 <= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u16 <= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u16 <= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u16 <= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u16 <= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u16 <= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u16 <= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u16 <= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u16 <= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u16 <= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u16 <= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u16 <= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i32 <= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i32 <= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i32 <= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i32 <= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i32 <= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i32 <= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i32 <= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i32 <= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i32 <= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i32 <= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i32 <= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u32 <= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u32 <= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u32 <= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u32 <= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u32 <= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u32 <= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u32 <= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u32 <= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u32 <= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u32 <= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u32 <= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i64 <= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i64 <= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i64 <= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i64 <= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i64 <= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i64 <= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i64 <= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i64 <= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i64 <= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i64 <= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i64 <= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u64 <= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u64 <= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u64 <= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u64 <= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u64 <= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u64 <= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u64 <= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u64 <= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u64 <= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u64 <= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u64 <= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_FLOAT: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->fval <= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->fval <= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->fval <= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->fval <= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->fval <= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->fval <= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->fval <= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->fval <= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->fval <= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->fval <= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->fval <= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->dval <= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->dval <= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->dval <= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->dval <= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->dval <= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->dval <= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->dval <= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->dval <= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->dval <= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->dval <= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->dval <= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->ldval <= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->ldval <= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->ldval <= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->ldval <= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->ldval <= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->ldval <= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->ldval <= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->ldval <= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->ldval <= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->ldval <= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->ldval <= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#endif + + default: + assert(0); + break; + } + return PSI_T_UINT8; +} + +static inline token_t psi_calc_cmp_ge(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res) +{ + switch (t1) { + case PSI_T_INT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i8 >= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i8 >= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i8 >= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i8 >= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i8 >= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i8 >= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i8 >= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i8 >= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i8 >= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i8 >= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i8 >= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT8: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u8 >= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u8 >= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u8 >= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u8 >= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u8 >= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u8 >= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u8 >= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u8 >= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u8 >= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u8 >= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u8 >= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i16 >= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i16 >= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i16 >= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i16 >= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i16 >= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i16 >= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i16 >= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i16 >= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i16 >= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i16 >= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i16 >= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT16: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u16 >= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u16 >= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u16 >= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u16 >= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u16 >= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u16 >= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u16 >= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u16 >= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u16 >= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u16 >= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u16 >= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i32 >= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i32 >= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i32 >= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i32 >= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i32 >= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i32 >= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i32 >= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i32 >= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i32 >= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i32 >= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i32 >= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT32: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u32 >= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u32 >= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u32 >= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u32 >= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u32 >= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u32 >= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u32 >= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u32 >= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u32 >= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u32 >= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u32 >= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_INT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->i64 >= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->i64 >= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->i64 >= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->i64 >= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->i64 >= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->i64 >= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->i64 >= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->i64 >= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->i64 >= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->i64 >= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->i64 >= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_UINT64: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->u64 >= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->u64 >= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->u64 >= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->u64 >= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->u64 >= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->u64 >= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->u64 >= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->u64 >= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->u64 >= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->u64 >= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->u64 >= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_FLOAT: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->fval >= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->fval >= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->fval >= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->fval >= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->fval >= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->fval >= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->fval >= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->fval >= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->fval >= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->fval >= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->fval >= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; + case PSI_T_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->dval >= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->dval >= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->dval >= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->dval >= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->dval >= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->dval >= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->dval >= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->dval >= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->dval >= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->dval >= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->dval >= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + switch (t2) { + case PSI_T_INT8: + res->u8 = v1->ldval >= v2->i8; + break; + case PSI_T_UINT8: + res->u8 = v1->ldval >= v2->u8; + break; + case PSI_T_INT16: + res->u8 = v1->ldval >= v2->i16; + break; + case PSI_T_UINT16: + res->u8 = v1->ldval >= v2->u16; + break; + case PSI_T_INT32: + res->u8 = v1->ldval >= v2->i32; + break; + case PSI_T_UINT32: + res->u8 = v1->ldval >= v2->u32; + break; + case PSI_T_INT64: + res->u8 = v1->ldval >= v2->i64; + break; + case PSI_T_UINT64: + res->u8 = v1->ldval >= v2->u64; + break; + case PSI_T_FLOAT: + res->u8 = v1->ldval >= v2->fval; + break; + case PSI_T_DOUBLE: + res->u8 = v1->ldval >= v2->dval; + break; +# if HAVE_LONG_DOUBLE + case PSI_T_LONG_DOUBLE: + res->u8 = v1->ldval >= v2->ldval; + break; +# endif + + default: + assert(0); + break; + } + break; +#endif + + default: + assert(0); + break; + } + return PSI_T_UINT8; +} diff --git a/src/calc/oper.h b/src/calc/oper.h new file mode 100644 index 0000000..cf86b18 --- /dev/null +++ b/src/calc/oper.h @@ -0,0 +1,1011 @@ +/******************************************************************************* + Copyright (c) 2016, Michael Wallner . + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ + +#include "php_psi_stdinc.h" +#include + +#include "token.h" + +static inline int psi_calc_oper(token_t op1, token_t op2) +{ + if (PSI_T_LPAREN == op2) { + return -1; + } else if (PSI_T_LPAREN == op1) { + return 1; + } else if (op1 == op2) { + return 0; + } else if (!op1) { + return 1; + } else if (!op2) { + return -1; + } + + switch (op1) { + case PSI_T_NOT: + switch (op2) { + case PSI_T_NOT: + return 0; + case PSI_T_TILDE: + return 0; + case PSI_T_ASTERISK: + return -1; + case PSI_T_SLASH: + return -1; + case PSI_T_MODULO: + return -1; + case PSI_T_PLUS: + return -1; + case PSI_T_MINUS: + return -1; + case PSI_T_LSHIFT: + return -1; + case PSI_T_RSHIFT: + return -1; + case PSI_T_LCHEVR: + return -1; + case PSI_T_CMP_LE: + return -1; + case PSI_T_RCHEVR: + return -1; + case PSI_T_CMP_GE: + return -1; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_TILDE: + switch (op2) { + case PSI_T_NOT: + return 0; + case PSI_T_TILDE: + return 0; + case PSI_T_ASTERISK: + return -1; + case PSI_T_SLASH: + return -1; + case PSI_T_MODULO: + return -1; + case PSI_T_PLUS: + return -1; + case PSI_T_MINUS: + return -1; + case PSI_T_LSHIFT: + return -1; + case PSI_T_RSHIFT: + return -1; + case PSI_T_LCHEVR: + return -1; + case PSI_T_CMP_LE: + return -1; + case PSI_T_RCHEVR: + return -1; + case PSI_T_CMP_GE: + return -1; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_ASTERISK: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 0; + case PSI_T_SLASH: + return 0; + case PSI_T_MODULO: + return 0; + case PSI_T_PLUS: + return -1; + case PSI_T_MINUS: + return -1; + case PSI_T_LSHIFT: + return -1; + case PSI_T_RSHIFT: + return -1; + case PSI_T_LCHEVR: + return -1; + case PSI_T_CMP_LE: + return -1; + case PSI_T_RCHEVR: + return -1; + case PSI_T_CMP_GE: + return -1; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_SLASH: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 0; + case PSI_T_SLASH: + return 0; + case PSI_T_MODULO: + return 0; + case PSI_T_PLUS: + return -1; + case PSI_T_MINUS: + return -1; + case PSI_T_LSHIFT: + return -1; + case PSI_T_RSHIFT: + return -1; + case PSI_T_LCHEVR: + return -1; + case PSI_T_CMP_LE: + return -1; + case PSI_T_RCHEVR: + return -1; + case PSI_T_CMP_GE: + return -1; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_MODULO: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 0; + case PSI_T_SLASH: + return 0; + case PSI_T_MODULO: + return 0; + case PSI_T_PLUS: + return -1; + case PSI_T_MINUS: + return -1; + case PSI_T_LSHIFT: + return -1; + case PSI_T_RSHIFT: + return -1; + case PSI_T_LCHEVR: + return -1; + case PSI_T_CMP_LE: + return -1; + case PSI_T_RCHEVR: + return -1; + case PSI_T_CMP_GE: + return -1; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_PLUS: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 0; + case PSI_T_MINUS: + return 0; + case PSI_T_LSHIFT: + return -1; + case PSI_T_RSHIFT: + return -1; + case PSI_T_LCHEVR: + return -1; + case PSI_T_CMP_LE: + return -1; + case PSI_T_RCHEVR: + return -1; + case PSI_T_CMP_GE: + return -1; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_MINUS: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 0; + case PSI_T_MINUS: + return 0; + case PSI_T_LSHIFT: + return -1; + case PSI_T_RSHIFT: + return -1; + case PSI_T_LCHEVR: + return -1; + case PSI_T_CMP_LE: + return -1; + case PSI_T_RCHEVR: + return -1; + case PSI_T_CMP_GE: + return -1; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_LSHIFT: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 0; + case PSI_T_RSHIFT: + return 0; + case PSI_T_LCHEVR: + return -1; + case PSI_T_CMP_LE: + return -1; + case PSI_T_RCHEVR: + return -1; + case PSI_T_CMP_GE: + return -1; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_RSHIFT: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 0; + case PSI_T_RSHIFT: + return 0; + case PSI_T_LCHEVR: + return -1; + case PSI_T_CMP_LE: + return -1; + case PSI_T_RCHEVR: + return -1; + case PSI_T_CMP_GE: + return -1; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_LCHEVR: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 1; + case PSI_T_RSHIFT: + return 1; + case PSI_T_LCHEVR: + return 0; + case PSI_T_CMP_LE: + return 0; + case PSI_T_RCHEVR: + return 0; + case PSI_T_CMP_GE: + return 0; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_CMP_LE: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 1; + case PSI_T_RSHIFT: + return 1; + case PSI_T_LCHEVR: + return 0; + case PSI_T_CMP_LE: + return 0; + case PSI_T_RCHEVR: + return 0; + case PSI_T_CMP_GE: + return 0; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_RCHEVR: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 1; + case PSI_T_RSHIFT: + return 1; + case PSI_T_LCHEVR: + return 0; + case PSI_T_CMP_LE: + return 0; + case PSI_T_RCHEVR: + return 0; + case PSI_T_CMP_GE: + return 0; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_CMP_GE: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 1; + case PSI_T_RSHIFT: + return 1; + case PSI_T_LCHEVR: + return 0; + case PSI_T_CMP_LE: + return 0; + case PSI_T_RCHEVR: + return 0; + case PSI_T_CMP_GE: + return 0; + case PSI_T_AMPERSAND: + return -1; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_AMPERSAND: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 1; + case PSI_T_RSHIFT: + return 1; + case PSI_T_LCHEVR: + return 1; + case PSI_T_CMP_LE: + return 1; + case PSI_T_RCHEVR: + return 1; + case PSI_T_CMP_GE: + return 1; + case PSI_T_AMPERSAND: + return 0; + case PSI_T_CMP_EQ: + return -1; + case PSI_T_CMP_NE: + return -1; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_CMP_EQ: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 1; + case PSI_T_RSHIFT: + return 1; + case PSI_T_LCHEVR: + return 1; + case PSI_T_CMP_LE: + return 1; + case PSI_T_RCHEVR: + return 1; + case PSI_T_CMP_GE: + return 1; + case PSI_T_AMPERSAND: + return 1; + case PSI_T_CMP_EQ: + return 0; + case PSI_T_CMP_NE: + return 0; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_CMP_NE: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 1; + case PSI_T_RSHIFT: + return 1; + case PSI_T_LCHEVR: + return 1; + case PSI_T_CMP_LE: + return 1; + case PSI_T_RCHEVR: + return 1; + case PSI_T_CMP_GE: + return 1; + case PSI_T_AMPERSAND: + return 1; + case PSI_T_CMP_EQ: + return 0; + case PSI_T_CMP_NE: + return 0; + case PSI_T_CARET: + return -1; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_CARET: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 1; + case PSI_T_RSHIFT: + return 1; + case PSI_T_LCHEVR: + return 1; + case PSI_T_CMP_LE: + return 1; + case PSI_T_RCHEVR: + return 1; + case PSI_T_CMP_GE: + return 1; + case PSI_T_AMPERSAND: + return 1; + case PSI_T_CMP_EQ: + return 1; + case PSI_T_CMP_NE: + return 1; + case PSI_T_CARET: + return 0; + case PSI_T_PIPE: + return -1; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_PIPE: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 1; + case PSI_T_RSHIFT: + return 1; + case PSI_T_LCHEVR: + return 1; + case PSI_T_CMP_LE: + return 1; + case PSI_T_RCHEVR: + return 1; + case PSI_T_CMP_GE: + return 1; + case PSI_T_AMPERSAND: + return 1; + case PSI_T_CMP_EQ: + return 1; + case PSI_T_CMP_NE: + return 1; + case PSI_T_CARET: + return 1; + case PSI_T_PIPE: + return 0; + case PSI_T_AND: + return -1; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_AND: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 1; + case PSI_T_RSHIFT: + return 1; + case PSI_T_LCHEVR: + return 1; + case PSI_T_CMP_LE: + return 1; + case PSI_T_RCHEVR: + return 1; + case PSI_T_CMP_GE: + return 1; + case PSI_T_AMPERSAND: + return 1; + case PSI_T_CMP_EQ: + return 1; + case PSI_T_CMP_NE: + return 1; + case PSI_T_CARET: + return 1; + case PSI_T_PIPE: + return 1; + case PSI_T_AND: + return 0; + case PSI_T_OR: + return -1; + default: + assert(0); + break; + } + break; + + case PSI_T_OR: + switch (op2) { + case PSI_T_NOT: + return 1; + case PSI_T_TILDE: + return 1; + case PSI_T_ASTERISK: + return 1; + case PSI_T_SLASH: + return 1; + case PSI_T_MODULO: + return 1; + case PSI_T_PLUS: + return 1; + case PSI_T_MINUS: + return 1; + case PSI_T_LSHIFT: + return 1; + case PSI_T_RSHIFT: + return 1; + case PSI_T_LCHEVR: + return 1; + case PSI_T_CMP_LE: + return 1; + case PSI_T_RCHEVR: + return 1; + case PSI_T_CMP_GE: + return 1; + case PSI_T_AMPERSAND: + return 1; + case PSI_T_CMP_EQ: + return 1; + case PSI_T_CMP_NE: + return 1; + case PSI_T_CARET: + return 1; + case PSI_T_PIPE: + return 1; + case PSI_T_AND: + return 1; + case PSI_T_OR: + return 0; + default: + assert(0); + break; + } + break; + + default: + assert(0); + break; + } + return 0; +} diff --git a/src/token.h b/src/token.h index 75f76fb..5062bc5 100644 --- a/src/token.h +++ b/src/token.h @@ -51,8 +51,6 @@ static inline size_t psi_offset_padding(size_t diff, size_t alignment) { typedef int token_t; -#include "token_oper_cmp.h" - static inline size_t psi_t_alignment(token_t t) { #define PSI_ALIGNOF(T) case PSI_T_## T: return ALIGNOF_## T ##_T; diff --git a/src/token_oper_cmp.h b/src/token_oper_cmp.h deleted file mode 100644 index 04f6be2..0000000 --- a/src/token_oper_cmp.h +++ /dev/null @@ -1,531 +0,0 @@ -/******************************************************************************* - Copyright (c) 2016, Michael Wallner . - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*******************************************************************************/ - -static inline int psi_token_oper_cmp(token_t op1, token_t op2) { - switch (op1) { - case PSI_T_NOT: - switch (op2) { - case PSI_T_NOT: return 0; - case PSI_T_TILDE: return 0; - case PSI_T_ASTERISK: return -1; - case PSI_T_SLASH: return -1; - case PSI_T_MODULO: return -1; - case PSI_T_PLUS: return -1; - case PSI_T_MINUS: return -1; - case PSI_T_LSHIFT: return -1; - case PSI_T_RSHIFT: return -1; - case PSI_T_LCHEVR: return -1; - case PSI_T_CMP_LE: return -1; - case PSI_T_RCHEVR: return -1; - case PSI_T_CMP_GE: return -1; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_TILDE: - switch (op2) { - case PSI_T_NOT: return 0; - case PSI_T_TILDE: return 0; - case PSI_T_ASTERISK: return -1; - case PSI_T_SLASH: return -1; - case PSI_T_MODULO: return -1; - case PSI_T_PLUS: return -1; - case PSI_T_MINUS: return -1; - case PSI_T_LSHIFT: return -1; - case PSI_T_RSHIFT: return -1; - case PSI_T_LCHEVR: return -1; - case PSI_T_CMP_LE: return -1; - case PSI_T_RCHEVR: return -1; - case PSI_T_CMP_GE: return -1; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_ASTERISK: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 0; - case PSI_T_SLASH: return 0; - case PSI_T_MODULO: return 0; - case PSI_T_PLUS: return -1; - case PSI_T_MINUS: return -1; - case PSI_T_LSHIFT: return -1; - case PSI_T_RSHIFT: return -1; - case PSI_T_LCHEVR: return -1; - case PSI_T_CMP_LE: return -1; - case PSI_T_RCHEVR: return -1; - case PSI_T_CMP_GE: return -1; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_SLASH: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 0; - case PSI_T_SLASH: return 0; - case PSI_T_MODULO: return 0; - case PSI_T_PLUS: return -1; - case PSI_T_MINUS: return -1; - case PSI_T_LSHIFT: return -1; - case PSI_T_RSHIFT: return -1; - case PSI_T_LCHEVR: return -1; - case PSI_T_CMP_LE: return -1; - case PSI_T_RCHEVR: return -1; - case PSI_T_CMP_GE: return -1; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_MODULO: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 0; - case PSI_T_SLASH: return 0; - case PSI_T_MODULO: return 0; - case PSI_T_PLUS: return -1; - case PSI_T_MINUS: return -1; - case PSI_T_LSHIFT: return -1; - case PSI_T_RSHIFT: return -1; - case PSI_T_LCHEVR: return -1; - case PSI_T_CMP_LE: return -1; - case PSI_T_RCHEVR: return -1; - case PSI_T_CMP_GE: return -1; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_PLUS: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 0; - case PSI_T_MINUS: return 0; - case PSI_T_LSHIFT: return -1; - case PSI_T_RSHIFT: return -1; - case PSI_T_LCHEVR: return -1; - case PSI_T_CMP_LE: return -1; - case PSI_T_RCHEVR: return -1; - case PSI_T_CMP_GE: return -1; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_MINUS: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 0; - case PSI_T_MINUS: return 0; - case PSI_T_LSHIFT: return -1; - case PSI_T_RSHIFT: return -1; - case PSI_T_LCHEVR: return -1; - case PSI_T_CMP_LE: return -1; - case PSI_T_RCHEVR: return -1; - case PSI_T_CMP_GE: return -1; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_LSHIFT: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 0; - case PSI_T_RSHIFT: return 0; - case PSI_T_LCHEVR: return -1; - case PSI_T_CMP_LE: return -1; - case PSI_T_RCHEVR: return -1; - case PSI_T_CMP_GE: return -1; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_RSHIFT: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 0; - case PSI_T_RSHIFT: return 0; - case PSI_T_LCHEVR: return -1; - case PSI_T_CMP_LE: return -1; - case PSI_T_RCHEVR: return -1; - case PSI_T_CMP_GE: return -1; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_LCHEVR: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 1; - case PSI_T_RSHIFT: return 1; - case PSI_T_LCHEVR: return 0; - case PSI_T_CMP_LE: return 0; - case PSI_T_RCHEVR: return 0; - case PSI_T_CMP_GE: return 0; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_CMP_LE: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 1; - case PSI_T_RSHIFT: return 1; - case PSI_T_LCHEVR: return 0; - case PSI_T_CMP_LE: return 0; - case PSI_T_RCHEVR: return 0; - case PSI_T_CMP_GE: return 0; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_RCHEVR: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 1; - case PSI_T_RSHIFT: return 1; - case PSI_T_LCHEVR: return 0; - case PSI_T_CMP_LE: return 0; - case PSI_T_RCHEVR: return 0; - case PSI_T_CMP_GE: return 0; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_CMP_GE: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 1; - case PSI_T_RSHIFT: return 1; - case PSI_T_LCHEVR: return 0; - case PSI_T_CMP_LE: return 0; - case PSI_T_RCHEVR: return 0; - case PSI_T_CMP_GE: return 0; - case PSI_T_AMPERSAND: return -1; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_AMPERSAND: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 1; - case PSI_T_RSHIFT: return 1; - case PSI_T_LCHEVR: return 1; - case PSI_T_CMP_LE: return 1; - case PSI_T_RCHEVR: return 1; - case PSI_T_CMP_GE: return 1; - case PSI_T_AMPERSAND: return 0; - case PSI_T_CMP_EQ: return -1; - case PSI_T_CMP_NE: return -1; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_CMP_EQ: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 1; - case PSI_T_RSHIFT: return 1; - case PSI_T_LCHEVR: return 1; - case PSI_T_CMP_LE: return 1; - case PSI_T_RCHEVR: return 1; - case PSI_T_CMP_GE: return 1; - case PSI_T_AMPERSAND: return 1; - case PSI_T_CMP_EQ: return 0; - case PSI_T_CMP_NE: return 0; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_CMP_NE: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 1; - case PSI_T_RSHIFT: return 1; - case PSI_T_LCHEVR: return 1; - case PSI_T_CMP_LE: return 1; - case PSI_T_RCHEVR: return 1; - case PSI_T_CMP_GE: return 1; - case PSI_T_AMPERSAND: return 1; - case PSI_T_CMP_EQ: return 0; - case PSI_T_CMP_NE: return 0; - case PSI_T_CARET: return -1; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_CARET: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 1; - case PSI_T_RSHIFT: return 1; - case PSI_T_LCHEVR: return 1; - case PSI_T_CMP_LE: return 1; - case PSI_T_RCHEVR: return 1; - case PSI_T_CMP_GE: return 1; - case PSI_T_AMPERSAND: return 1; - case PSI_T_CMP_EQ: return 1; - case PSI_T_CMP_NE: return 1; - case PSI_T_CARET: return 0; - case PSI_T_PIPE: return -1; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_PIPE: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 1; - case PSI_T_RSHIFT: return 1; - case PSI_T_LCHEVR: return 1; - case PSI_T_CMP_LE: return 1; - case PSI_T_RCHEVR: return 1; - case PSI_T_CMP_GE: return 1; - case PSI_T_AMPERSAND: return 1; - case PSI_T_CMP_EQ: return 1; - case PSI_T_CMP_NE: return 1; - case PSI_T_CARET: return 1; - case PSI_T_PIPE: return 0; - case PSI_T_AND: return -1; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_AND: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 1; - case PSI_T_RSHIFT: return 1; - case PSI_T_LCHEVR: return 1; - case PSI_T_CMP_LE: return 1; - case PSI_T_RCHEVR: return 1; - case PSI_T_CMP_GE: return 1; - case PSI_T_AMPERSAND: return 1; - case PSI_T_CMP_EQ: return 1; - case PSI_T_CMP_NE: return 1; - case PSI_T_CARET: return 1; - case PSI_T_PIPE: return 1; - case PSI_T_AND: return 0; - case PSI_T_OR: return -1; - } - assert(0); - break; - case PSI_T_OR: - switch (op2) { - case PSI_T_NOT: return 1; - case PSI_T_TILDE: return 1; - case PSI_T_ASTERISK: return 1; - case PSI_T_SLASH: return 1; - case PSI_T_MODULO: return 1; - case PSI_T_PLUS: return 1; - case PSI_T_MINUS: return 1; - case PSI_T_LSHIFT: return 1; - case PSI_T_RSHIFT: return 1; - case PSI_T_LCHEVR: return 1; - case PSI_T_CMP_LE: return 1; - case PSI_T_RCHEVR: return 1; - case PSI_T_CMP_GE: return 1; - case PSI_T_AMPERSAND: return 1; - case PSI_T_CMP_EQ: return 1; - case PSI_T_CMP_NE: return 1; - case PSI_T_CARET: return 1; - case PSI_T_PIPE: return 1; - case PSI_T_AND: return 1; - case PSI_T_OR: return 0; - } - assert(0); - break; - } - assert(0); - return 0; -} diff --git a/src/types/num_exp.c b/src/types/num_exp.c index c211f45..20a09c6 100644 --- a/src/types/num_exp.c +++ b/src/types/num_exp.c @@ -290,17 +290,17 @@ bool psi_num_exp_validate(struct psi_data *data, struct psi_num_exp *exp, if (exp->op) { switch (exp->op) { case PSI_T_NOT: - exp->calc = psi_calc_not; + exp->calc = psi_calc_bool_not; break; case PSI_T_TILDE: exp->calc = psi_calc_bin_not; break; case PSI_T_OR: - exp->calc = psi_calc_or; + exp->calc = psi_calc_bool_or; break; case PSI_T_AND: - exp->calc = psi_calc_and; + exp->calc = psi_calc_bool_and; break; case PSI_T_CMP_EQ: exp->calc = psi_calc_cmp_eq; @@ -438,23 +438,6 @@ static inline void psi_num_exp_verify_result(token_t t, impl_val *res, struct ps if (frame) PSI_DEBUG_PRINT(frame->context, "%s", "\n"); } -static inline int psi_num_exp_op_cmp(token_t op1, token_t op2) -{ - if (PSI_T_LPAREN == op2) { - return -1; - } else if (PSI_T_LPAREN == op1) { - return 1; - } else if (op1 == op2) { - return 0; - } else if (!op1) { - return 1; - } else if (!op2) { - return -1; - } - - return psi_token_oper_cmp(op1, op2); -} - static void psi_num_exp_reduce(struct psi_num_exp *exp, struct psi_plist **output_ptr, struct psi_plist **input_ptr, struct psi_call_frame *frame) { @@ -490,7 +473,7 @@ static void psi_num_exp_reduce(struct psi_num_exp *exp, struct psi_plist **outpu case PSI_T_TILDE: while (psi_plist_top(input, &entry)) { /* bail out if exp->op >= entry.type */ - if (psi_num_exp_op_cmp(exp->op, entry.type) != 1) { + if (psi_calc_oper(exp->op, entry.type) != 1) { break; } psi_plist_pop(input, NULL); @@ -507,7 +490,7 @@ static void psi_num_exp_reduce(struct psi_num_exp *exp, struct psi_plist **outpu psi_num_exp_reduce(exp->data.b.lhs, &output, &input, frame); while (psi_plist_top(input, &entry)) { /* bail out if exp->op > entry.type */ - if (psi_num_exp_op_cmp(exp->op, entry.type) == -1) { + if (psi_calc_oper(exp->op, entry.type) == -1) { break; } psi_plist_pop(input, NULL);