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