1 module exec; 2 3 import std.stdio; 4 import std.conv; 5 import std.string; 6 import std.algorithm; 7 8 // contains the stuff for like the language.. 9 10 import kobj; 11 import cv; 12 import xp; 13 import st; 14 import kt; 15 import kc; 16 import so; 17 import cp; 18 import ku; 19 import ps; 20 import vl; 21 import ct; 22 import xps; 23 import va; 24 25 void kyle_execute(kyle_state s) 26 { 27 state st = state.idle; 28 kyle_context ctx = kyle_context.none; 29 30 string blc; 31 string fname; 32 kyle_arguments arg = new kyle_arguments(); 33 foreach (char l; s.supplied_code) 34 { 35 if (s.err) 36 break; 37 if (l == '#' && st == state.idle) 38 { 39 st = state.collecting; 40 blc = ""; 41 } 42 else if (l == '@' && st == state.idle) 43 { 44 st = state.collectetc; 45 ctx = kyle_context.ifstatement; 46 47 blc = ""; 48 } 49 else if (l == '{' && ctx == kyle_context.ifstatement) 50 { 51 kyle_expr_type t = kyle_each_side(blc)[1]; 52 53 string[] sides = kyle_each_side(blc)[0]; 54 55 string side1 = ""; 56 string side2 = ""; 57 58 if (t == kyle_expr_type.compareTo) 59 { 60 side1 = sides[0]; 61 if (kyle_has_value(s, sides[0])) 62 { 63 side1 = kyle_getvalue(s, sides[0]); 64 } 65 66 side2 = sides[1]; 67 if (kyle_has_value(s, sides[1])) 68 { 69 side2 = kyle_getvalue(s, sides[1]); 70 } 71 if (side1 == side2) 72 { 73 ctx = kyle_context.gathering; 74 } 75 } 76 else if (t == kyle_expr_type.review) 77 { 78 if (kyle_has_value(s, sides[0])) 79 { 80 string val = kyle_getvalue(s, sides[0]); 81 82 if (to!bool(val)) 83 { 84 ctx = kyle_context.gathering; 85 } 86 } else { 87 if (kyle_parsebool(sides[0])) ctx = kyle_context.gathering; 88 } 89 } 90 91 st = state.rely; 92 93 blc = ""; 94 } 95 else if (l == '}' && ctx == kyle_context.gathering) 96 { 97 // COPY ALL DELEGATES OVER TO SCOPE 2 98 99 auto if_block = kyle_new(); 100 101 kyle_transfer_delegates(s, if_block); 102 103 kyle_set_code(if_block, strip(blc)); 104 105 kyle_execute(if_block); // execute the if block 106 107 st = state.idle; 108 blc = ""; 109 ctx = kyle_context.none; 110 } 111 else if (l == ' ' && st == state.collecting) 112 { 113 st = state.blocking; 114 ctx = kyle_context.running; 115 fname = strip(blc); 116 blc = ""; 117 } 118 else if (l == ' ' && st == state.blocking && ctx == kyle_context.running) 119 { 120 if (blc.length > 0) 121 { 122 arg.outType = arg.outType ~ blc; 123 blc = ""; 124 } 125 } 126 127 else if (l == '"' && st == state.blocking) 128 { 129 st = state.stoned; 130 } 131 else if (l == '"' && st == state.stoned) 132 { 133 st = state.blocking; 134 } 135 136 else if (l == s.line_ending && st == state.blocking) 137 { 138 if (blc.length > 0) 139 arg.outType = arg.outType ~ blc; 140 141 st = state.idle; 142 ctx = kyle_context.none; 143 if (fname == "mod") 144 { 145 if (s.use_mod) 146 s.toplevel_header = kyle_vararg!(string).kyle_convert_argument(0, arg); 147 } 148 else if (fname in s.deles) 149 { 150 s.deles[fname](arg, s); 151 } 152 153 blc = ""; 154 arg = new kyle_arguments(); 155 } 156 else if (l == s.comment_op && st != state.blocking) 157 { 158 st = state.ignorant; 159 } 160 else if (l == s.comment_break && st == state.ignorant) 161 { 162 blc = ""; 163 st = state.idle; 164 continue; 165 } 166 else if (l == '\n' && st == state.idle) 167 continue; 168 169 else if (l == s.line_ending && st == state.blocking) 170 { 171 s.err = true; 172 s.errmsg = ("unexpected token '#' where `blocking' was expected, maybe `;' was needed?"); 173 } 174 else 175 { 176 blc = blc ~ l; 177 } 178 } 179 }