Hex Artifact Content
Not logged in

Artifact 97a442948c980634d2fe1d36ebeb9dfc9db09245:


0000: 2f 2a 2a 0d 0a 20 2a 20 41 75 74 68 6f 72 73 3a  /**.. * Authors:
0010: 20 6b 2e 69 6e 61 62 61 0d 0a 20 2a 20 4c 69 63   k.inaba.. * Lic
0020: 65 6e 73 65 3a 20 4e 59 53 4c 20 30 2e 39 39 38  ense: NYSL 0.998
0030: 32 20 28 68 74 74 70 3a 2f 2f 77 77 77 2e 6b 6d  2 (http://www.km
0040: 6f 6e 6f 73 2e 6e 65 74 2f 6e 79 73 6c 2f 29 0d  onos.net/nysl/).
0050: 0a 20 2a 0d 0a 20 2a 20 45 6e 74 72 79 20 70 6f  . *.. * Entry po
0060: 69 6e 74 20 66 6f 72 20 50 6f 6c 65 6d 79 20 69  int for Polemy i
0070: 6e 74 65 72 70 72 65 74 65 72 2e 0d 0a 20 2a 2f  nterpreter... */
0080: 0d 0a 6d 6f 64 75 6c 65 20 6d 61 69 6e 3b 0d 0a  ..module main;..
0090: 69 6d 70 6f 72 74 20 70 6f 6c 65 6d 79 2e 72 65  import polemy.re
00a0: 70 6c 3b 0d 0a 69 6d 70 6f 72 74 20 73 74 64 2e  pl;..import std.
00b0: 73 74 64 69 6f 3b 0d 0a 69 6d 70 6f 72 74 20 73  stdio;..import s
00c0: 74 64 2e 61 6c 67 6f 72 69 74 68 6d 3b 0d 0a 69  td.algorithm;..i
00d0: 6d 70 6f 72 74 20 73 74 64 2e 61 72 72 61 79 3b  mport std.array;
00e0: 0d 0a 0d 0a 2f 2f 2f 20 41 64 76 61 6e 63 65 20  ..../// Advance 
00f0: 61 72 67 73 5b 5d 20 74 6f 20 70 6f 69 6e 74 20  args[] to point 
0100: 74 68 65 20 61 72 67 75 6d 65 6e 74 20 6c 69 73  the argument lis
0110: 74 20 66 65 64 20 74 6f 20 74 68 65 20 73 63 72  t fed to the scr
0120: 69 70 74 2e 0d 0a 2f 2f 2f 20 52 65 74 75 72 6e  ipt.../// Return
0130: 73 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68  s the name of th
0140: 65 20 73 6f 75 72 63 65 20 66 69 6c 65 20 74 6f  e source file to
0150: 20 72 75 6e 2c 20 6f 72 20 72 65 74 75 72 6e 73   run, or returns
0160: 20 22 22 20 69 66 0d 0a 2f 2f 2f 20 6e 6f 20 66   "" if../// no f
0170: 69 6c 65 6e 61 6d 65 20 77 61 73 20 67 69 76 65  ilename was give
0180: 6e 2e 20 41 6c 73 6f 2c 20 72 65 74 75 72 6e 73  n. Also, returns
0190: 20 74 6f 20 6c 69 62 73 5b 5d 20 74 68 65 20 6c   to libs[] the l
01a0: 69 73 74 20 6f 66 0d 0a 2f 2f 2f 20 6c 69 62 72  ist of../// libr
01b0: 61 72 79 20 73 6f 75 72 63 65 20 74 6f 20 6c 6f  ary source to lo
01c0: 61 64 2e 0d 0a 2f 2f 2f 20 54 4f 44 4f 3a 20 75  ad.../// TODO: u
01d0: 73 65 20 73 74 64 2e 67 65 74 6f 70 74 0d 0a 0d  se std.getopt...
01e0: 0a 73 74 72 69 6e 67 20 70 61 72 73 65 41 72 67  .string parseArg
01f0: 76 28 72 65 66 20 73 74 72 69 6e 67 5b 5d 20 61  v(ref string[] a
0200: 72 67 73 2c 20 6f 75 74 20 73 74 72 69 6e 67 5b  rgs, out string[
0210: 5d 20 6c 69 62 73 29 0d 0a 7b 0d 0a 09 61 72 67  ] libs)..{...arg
0220: 73 2e 70 6f 70 46 72 6f 6e 74 28 29 3b 0d 0a 0d  s.popFront();...
0230: 0a 09 77 68 69 6c 65 28 20 21 61 72 67 73 2e 65  ..while( !args.e
0240: 6d 70 74 79 20 26 26 20 61 72 67 73 2e 66 72 6f  mpty && args.fro
0250: 6e 74 3d 3d 22 2d 6c 22 20 29 20 7b 0d 0a 09 09  nt=="-l" ) {....
0260: 61 72 67 73 2e 70 6f 70 46 72 6f 6e 74 28 29 3b  args.popFront();
0270: 0d 0a 09 09 69 66 28 20 21 61 72 67 73 2e 65 6d  ....if( !args.em
0280: 70 74 79 20 29 20 7b 0d 0a 09 09 09 6c 69 62 73  pty ) {.....libs
0290: 20 7e 3d 20 61 72 67 73 2e 66 72 6f 6e 74 28 29   ~= args.front()
02a0: 3b 0d 0a 09 09 09 61 72 67 73 2e 70 6f 70 46 72  ;.....args.popFr
02b0: 6f 6e 74 28 29 3b 0d 0a 09 09 7d 0d 0a 09 7d 0d  ont();....}...}.
02c0: 0a 0d 0a 09 69 66 28 20 61 72 67 73 2e 65 6d 70  ....if( args.emp
02d0: 74 79 20 29 0d 0a 09 09 72 65 74 75 72 6e 20 22  ty )....return "
02e0: 22 3b 0d 0a 09 65 6c 73 65 20 7b 0d 0a 09 09 73  ";...else {....s
02f0: 63 6f 70 65 28 65 78 69 74 29 20 61 72 67 73 2e  cope(exit) args.
0300: 70 6f 70 46 72 6f 6e 74 3b 0d 0a 09 09 72 65 74  popFront;....ret
0310: 75 72 6e 20 61 72 67 73 2e 66 72 6f 6e 74 3b 0d  urn args.front;.
0320: 0a 09 7d 0d 0a 7d 0d 0a 0d 0a 2f 2f 2f 20 45 6e  ..}..}..../// En
0330: 74 72 79 20 70 6f 69 6e 74 2e 0d 0a 0d 0a 76 6f  try point.....vo
0340: 69 64 20 6d 61 69 6e 28 20 73 74 72 69 6e 67 5b  id main( string[
0350: 5d 20 61 72 67 73 20 29 0d 0a 7b 0d 0a 09 73 74  ] args )..{...st
0360: 72 69 6e 67 5b 5d 20 6c 69 62 73 3b 0d 0a 09 73  ring[] libs;...s
0370: 74 72 69 6e 67 20 20 20 73 72 63 20 3d 20 70 61  tring   src = pa
0380: 72 73 65 41 72 67 76 28 61 72 67 73 2c 20 6c 69  rseArgv(args, li
0390: 62 73 29 3b 0d 0a 0d 0a 09 61 75 74 6f 20 72 20  bs);.....auto r 
03a0: 3d 20 6e 65 77 20 52 45 50 4c 28 61 72 67 73 29  = new REPL(args)
03b0: 3b 0d 0a 09 69 66 28 20 73 72 63 2e 65 6d 70 74  ;...if( src.empt
03c0: 79 20 29 0d 0a 09 09 72 2e 67 72 65 65 74 28 29  y )....r.greet()
03d0: 3b 0d 0a 09 66 6f 72 65 61 63 68 28 6c 62 3b 20  ;...foreach(lb; 
03e0: 6c 69 62 73 29 0d 0a 09 09 72 2e 72 75 6e 46 69  libs)....r.runFi
03f0: 6c 65 28 6c 62 29 3b 0d 0a 09 69 66 28 20 73 72  le(lb);...if( sr
0400: 63 2e 65 6d 70 74 79 20 29 0d 0a 09 09 72 2e 72  c.empty )....r.r
0410: 65 70 6c 4c 6f 6f 70 28 29 3b 0d 0a 09 65 6c 73  eplLoop();...els
0420: 65 0d 0a 09 09 72 2e 72 75 6e 46 69 6c 65 28 73  e....r.runFile(s
0430: 72 63 29 3b 0d 0a 7d 0d 0a                       rc);..}..