Changeset 173 for trunk/mdcl.d
- Timestamp:
- 05/27/07 16:59:34 (2 years ago)
- Files:
-
- trunk/mdcl.d (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/mdcl.d
r170 r173 45 45 writefln(); 46 46 writefln("Flags:"); 47 writefln("\t-i Enter interactive mode, after executing any script file."); 48 writefln("\t-v Print the version of the CLI."); 49 writefln("\t-h Print this message and end."); 47 writefln("\t-i Enter interactive mode, after executing any script file."); 48 writefln("\t-v Print the version of the CLI."); 49 writefln("\t-h Print this message and end."); 50 writefln("\t-I path Specifies an import path to search when importing modules."); 50 51 writefln(); 51 52 writefln("If mdcl is called without any arguments, it will be as if you passed it"); 52 53 writefln("the -v and -i arguments (it will print the version and enter interactive"); 53 54 writefln("mode)."); 55 writefln(); 56 writefln("If the filename has no extension, it will be treated as a MiniD import-"); 57 writefln("style module name. So \"a.b\" will look for a module named b in the a"); 58 writefln("directory. The -I flag also affects the search paths used for this."); 54 59 writefln(); 55 60 writefln("When passing a filename followed by args, all the args will be available"); … … 81 86 char[] inputFile; 82 87 char[][] scriptArgs; 88 char[][] importPaths; 83 89 84 90 if(args.length == 1) … … 107 113 printUsage(); 108 114 return; 115 116 case "-I": 117 i++; 118 119 if(i >= args.length) 120 { 121 writefln("-I must be followed by a path"); 122 printUsage(); 123 return; 124 } 125 126 importPaths ~= args[i]; 127 break; 109 128 110 129 default: … … 123 142 124 143 MDState state = MDInitialize(); 144 145 foreach(path; importPaths) 146 MDGlobalState().addImportPath(path); 125 147 126 148 if(inputFile.length > 0) … … 132 154 else if(inputFile.length >= 4 && inputFile[$ - 4 .. $] == ".mdm") 133 155 def = MDModuleDef.loadFromFile(inputFile); 156 157 MDValue[] params = new MDValue[scriptArgs.length]; 158 159 foreach(i, arg; scriptArgs) 160 params[i] = arg; 161 162 if(def is null) 163 { 164 try 165 { 166 if(MDGlobalState().loadModuleFromFile(state, utf.toUTF32(inputFile), params) is null) 167 writefln("Error: could not find module '%s'", inputFile); 168 } 169 catch(MDException e) 170 { 171 writefln("Error: ", e); 172 writefln(MDState.getTracebackString()); 173 } 174 } 134 175 else 135 176 { 136 char[] sourceName = inputFile ~ ".md"; 137 char[] moduleName = inputFile ~ ".mdm"; 138 139 if(file.exists(sourceName)) 140 { 141 if(file.exists(moduleName)) 142 { 143 long sourceTime; 144 long moduleTime; 145 long dummy; 146 147 file.getTimes(sourceName, dummy, dummy, sourceTime); 148 file.getTimes(moduleName, dummy, dummy, moduleTime); 149 150 if(sourceTime > moduleTime) 151 def = compileModule(sourceName); 152 else 153 def = MDModuleDef.loadFromFile(moduleName); 154 } 155 else 156 def = compileModule(sourceName); 157 } 158 else 159 def = MDModuleDef.loadFromFile(moduleName); 160 } 161 162 MDNamespace ns = MDGlobalState().registerModule(def, state); 163 164 MDValue[] params = new MDValue[scriptArgs.length]; 165 166 foreach(i, v; scriptArgs) 167 params[i] = v; 168 169 try 170 MDGlobalState().staticInitModule(def, ns, state, params); 171 catch(MDException e) 172 { 173 writefln("Error: ", e); 174 writefln(MDState.getTracebackString()); 177 try 178 MDGlobalState().initializeModule(state, def, params); 179 catch(MDException e) 180 { 181 writefln("Error: ", e); 182 writefln(MDState.getTracebackString()); 183 } 175 184 } 176 185 } … … 181 190 bool run = true; 182 191 183 MDGlobalState(). setGlobal("exit"d,MDGlobalState().newClosure192 MDGlobalState().globals["exit"d] = MDGlobalState().newClosure 184 193 ( 185 194 (MDState s, uint numParams) … … 188 197 return 0; 189 198 }, "exit" 190 ) );199 ); 191 200 192 201 version(Windows) … … 233 242 { 234 243 scope closure = MDGlobalState().newClosure(def); 235 state.easyCall(closure, 0, MDValue(MDGlobalState().globals ));244 state.easyCall(closure, 0, MDValue(MDGlobalState().globals.ns)); 236 245 } 237 246 catch(MDException e)
