// // MyLisp.java : miolisp トップレベルインターフェイスクラス // // This is a part of miolisp sourcefile // Copyright (C) 1998 Nishiyama, Naoki / Mio software lab. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // import java.lang.* ; import java.util.* ; import java.io.* ; public class MyLisp { static String INITLSP ; // 立上げ時に読む LISP ファイル GetOpt opt ; Sreader sr ; Environment env ; static public void main(String s[]) throws Exception { MyLisp m = new MyLisp(s) ; m.run() ; } MyLisp(String s[]) { opt = new GetOpt("-",s) ; sr = new Sreader(System.in) ; env = new Environment() ; } public void run() throws Exception { init() ; // command line option -exec '(expr .....)' String s = opt.getarg("exec") ; if (s != null) { Evalutil.Evalstring(s,env) ; } if (!opt.isDefine("notoplevel")) toplevel() ; } public void init() throws Exception { INITLSP = opt.getarg("init") ; if (INITLSP == null) INITLSP = "init.lsp" ; // Bind import function GetNative.bindimport() ; // Loading startup lisp file (e.g.: init.lsp) try { Sloader.load(env,INITLSP) ; } catch (FileNotFoundException e) { System.out.println(INITLSP+" Not Found.") ; } } public void toplevel() throws Exception { Object o ; System.out.println() ; System.out.println("Mio Lisp Toplevel Interface (Rel. Alpha 1.2)") ; System.out.println("Copyright (C) 1998 / Nishiyama, Naoki / Mio software lab.") ; System.out.println() ; System.out.println("This is free software with ABSOLUTELY NO WARRANTY.") ; System.out.println("See the file COPYING for details.") ; System.out.println() ; do { try { System.out.print("miolisp>") ; // GUI 処理に時間を配分するためのおまじない while (!sr.ready()) { Thread.sleep(10) ; } o = sr.read() ; } catch(SreaderException e) { e.printStackTrace() ; break ; } try { long ls = System.currentTimeMillis() ; o = Eval.eval(o,env) ; long le = System.currentTimeMillis() ; System.out.println(Sexpr.toStr(o)) ; System.out.println("---> "+(le-ls)+" (ms).") ; } catch(Exception e) { e.printStackTrace() ; } } while(true) ; } }