00001 00002 #include <basix/int.hpp> 00003 #include <basix/vector.hpp> 00004 #include <basix/port.hpp> 00005 #include <basix/literal.hpp> 00006 #include <basix/compound.hpp> 00007 #include <basix/mmx_syntax.hpp> 00008 #include <basix/lisp_syntax.hpp> 00009 #include <basix/cpp_syntax.hpp> 00010 #include <basix/syntactic.hpp> 00011 #include <basix/tuple.hpp> 00012 #include <basix/glue.hpp> 00013 00014 #define int_literal(x) as_int (as_string (x)) 00015 #define is_generic_literal is<literal> 00016 #define gen_literal_apply(f,v) gen (as<generic> (f), v) 00017 #define gen_literal_access(f,v) access (as<generic> (f), v) 00018 #define is_generic_compound is<compound> 00019 #define compound_arguments(x) cdr (as_vector (x)) 00020 #define gen_compound_apply(f,v) gen (as<generic> (f), v) 00021 00022 namespace mmx { 00023 static syntactic 00024 GLUE_1 (const generic &arg_1) { 00025 return as_syntactic (arg_1); 00026 } 00027 00028 static syntactic 00029 GLUE_2 (const int &arg_1) { 00030 return syntactic (arg_1); 00031 } 00032 00033 static generic 00034 GLUE_3 (const syntactic &arg_1) { 00035 return as_generic (arg_1); 00036 } 00037 00038 static string 00039 GLUE_4 (const syntactic &arg_1) { 00040 return as_string (arg_1); 00041 } 00042 00043 static syntactic 00044 GLUE_5 (const generic &arg_1) { 00045 return flatten (arg_1); 00046 } 00047 00048 static syntactic 00049 GLUE_6 (const syntactic &arg_1) { 00050 return syntactic_apply (arg_1); 00051 } 00052 00053 static syntactic 00054 GLUE_7 (const syntactic &arg_1, const syntactic &arg_2) { 00055 return syntactic_apply (arg_1, arg_2); 00056 } 00057 00058 static syntactic 00059 GLUE_8 (const syntactic &arg_1, const syntactic &arg_2, const syntactic &arg_3) { 00060 return syntactic_apply (arg_1, arg_2, arg_3); 00061 } 00062 00063 static syntactic 00064 GLUE_9 (const syntactic &arg_1) { 00065 return -arg_1; 00066 } 00067 00068 static syntactic 00069 GLUE_10 (const syntactic &arg_1) { 00070 return square (arg_1); 00071 } 00072 00073 static syntactic 00074 GLUE_11 (const syntactic &arg_1, const syntactic &arg_2) { 00075 return arg_1 + arg_2; 00076 } 00077 00078 static syntactic 00079 GLUE_12 (const syntactic &arg_1, const syntactic &arg_2) { 00080 return arg_1 - arg_2; 00081 } 00082 00083 static syntactic 00084 GLUE_13 (const syntactic &arg_1, const syntactic &arg_2) { 00085 return arg_1 * arg_2; 00086 } 00087 00088 static syntactic 00089 GLUE_14 (const syntactic &arg_1, const syntactic &arg_2) { 00090 return arg_1 / arg_2; 00091 } 00092 00093 static syntactic 00094 GLUE_15 (const syntactic &arg_1, const syntactic &arg_2) { 00095 return pow (arg_1, arg_2); 00096 } 00097 00098 static bool 00099 GLUE_16 (const bool &arg_1) { 00100 return set_frac_flag (arg_1); 00101 } 00102 00103 static syntactic 00104 GLUE_17 (const tuple<syntactic> &arg_1) { 00105 return ordered_sum (as_vector (arg_1)); 00106 } 00107 00108 static syntactic 00109 GLUE_18 (const tuple<syntactic> &arg_1) { 00110 return ordered_product (as_vector (arg_1)); 00111 } 00112 00113 static bool 00114 GLUE_19 (const syntactic &arg_1, const syntactic &arg_2) { 00115 return arg_1 < arg_2; 00116 } 00117 00118 static bool 00119 GLUE_20 (const syntactic &arg_1, const syntactic &arg_2) { 00120 return arg_1 <= arg_2; 00121 } 00122 00123 static bool 00124 GLUE_21 (const syntactic &arg_1, const syntactic &arg_2) { 00125 return arg_1 > arg_2; 00126 } 00127 00128 static bool 00129 GLUE_22 (const syntactic &arg_1, const syntactic &arg_2) { 00130 return arg_1 >= arg_2; 00131 } 00132 00133 void 00134 glue_syntactic () { 00135 static bool done = false; 00136 if (done) return; 00137 done = true; 00138 call_glue (string ("glue_expression")); 00139 define_type<syntactic > (lit ("Syntactic")); 00140 define ("syntactic", GLUE_1); 00141 define_converter (":>", GLUE_2, PENALTY_INCLUSION); 00142 define ("as_generic", GLUE_3); 00143 define ("as_string", GLUE_4); 00144 define ("flatten", GLUE_5); 00145 define ("apply", GLUE_6); 00146 define ("apply", GLUE_7); 00147 define ("apply", GLUE_8); 00148 define ("-", GLUE_9); 00149 define ("square", GLUE_10); 00150 define ("+", GLUE_11); 00151 define ("-", GLUE_12); 00152 define ("*", GLUE_13); 00153 define ("/", GLUE_14); 00154 define ("^", GLUE_15); 00155 define ("set_frac_flag", GLUE_16); 00156 define ("ordered_sum", GLUE_17); 00157 define ("ordered_product", GLUE_18); 00158 define ("<", GLUE_19); 00159 define ("<=", GLUE_20); 00160 define (">", GLUE_21); 00161 define (">=", GLUE_22); 00162 } 00163 }