Changeset 12306
- Timestamp:
- 12/25/09 21:52:23 (14 years ago)
- Location:
- trunk/abcl/src/org/armedbear/lisp
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/Autoload.java
r12288 r12306 665 665 autoload(PACKAGE_SYS, "zip", "zip", true); 666 666 667 autoload(PACKAGE_SYS, "proxy-preloaded-function", 668 "AutoloadedFunctionProxy", false); 669 autoload(PACKAGE_SYS, "make-function-preloading-context", 670 "AutoloadedFunctionProxy", false); 671 autoload(PACKAGE_SYS, "function-preload", 672 "AutoloadedFunctionProxy", false); 673 667 674 autoload(Symbol.COPY_LIST, "copy_list"); 668 675 -
trunk/abcl/src/org/armedbear/lisp/CompiledClosure.java
r12288 r12306 220 220 else if (arg instanceof AbstractString) 221 221 namestring = arg.getStringValue(); 222 if (namestring != null) 223 return loadCompiledFunction(namestring); 222 if (namestring != null) { 223 // Debug.trace("autoloading preloaded ... " + namestring); 224 return AutoloadedFunctionProxy.loadPreloadedFunction(namestring); 225 } 224 226 if(arg instanceof JavaObject) { 225 227 try { 226 return loadC ompiledFunction((byte[]) arg.javaInstance(byte[].class));228 return loadClassBytes((byte[]) arg.javaInstance(byte[].class)); 227 229 } catch(Throwable t) { 228 230 Debug.trace(t); -
trunk/abcl/src/org/armedbear/lisp/Lisp.java
r12298 r12306 289 289 throw c; 290 290 } 291 catch (Throwable t) 291 catch (Throwable t) // ControlTransfer handled above 292 292 { 293 293 Debug.trace(t); … … 1205 1205 1206 1206 { 1207 byte[] bytes = readFunctionBytes(namestring); 1208 if (bytes != null) 1209 return loadClassBytes(bytes); 1210 1211 return null; 1212 } 1213 1214 public static final byte[] readFunctionBytes(final String namestring) 1215 { 1207 1216 final LispThread thread = LispThread.currentThread(); 1208 1217 final boolean absolute = Utilities.isFilenameAbsolute(namestring); … … 1277 1286 long size = entry.getSize(); 1278 1287 InputStream in = zipFile.getInputStream(entry); 1279 LispObject obj = loadCompiledFunction(in, (int) size); 1280 return obj != null ? obj : NIL; 1288 return readFunctionBytes(in, (int) size); 1281 1289 } 1282 1290 else … … 1286 1294 = defaultPathname.name.getStringValue() 1287 1295 + "." + "abcl";//defaultPathname.type.getStringValue(); 1288 byte in[] 1289 = Utilities 1290 .getZippedZipEntryAsByteArray(zipFile, 1296 return Utilities 1297 .getZippedZipEntryAsByteArray(zipFile, 1291 1298 entryName, 1292 1299 namestring); 1293 LispObject o = loadCompiledFunction(in);1294 return o != null ? o : NIL;1295 1300 } 1296 1301 } … … 1302 1307 } 1303 1308 } 1309 catch (VerifyError e) 1310 { 1311 error(new LispError("Class verification failed: " + 1312 e.getMessage())); 1313 return null; // not reached 1314 } 1304 1315 catch (IOException e) 1305 1316 { … … 1307 1318 } 1308 1319 } 1309 return error(new LispError("Unable to load " + namestring)); 1320 error(new LispError("Unable to load " + namestring)); 1321 return null; // not reached 1310 1322 } 1311 1323 Pathname pathname = new Pathname(namestring); … … 1314 1326 { 1315 1327 // The .cls file exists. 1316 LispObject obj = null; 1317 try { 1318 obj = loadCompiledFunction(new FileInputStream(file), 1319 (int) file.length()); 1328 try 1329 { 1330 byte[] bytes = readFunctionBytes(new FileInputStream(file), 1331 (int) file.length()); 1332 // FIXME close stream! 1333 if (bytes != null) 1334 return bytes; 1335 } 1336 catch (FileNotFoundException fnf) { 1337 error(new LispError("Unable to load " + pathname.writeToString() 1338 + ": " + fnf.getMessage())); 1339 return null; // not reached 1320 1340 } 1321 catch (FileNotFoundException e) { 1322 return error(new LispError("Unable to load " + 1323 pathname.writeToString() + ": Not found.")); 1341 return null; // not reached 1342 } 1343 try 1344 { 1345 LispObject loadTruename = Symbol.LOAD_TRUENAME.symbolValue(thread); 1346 String zipFileName = ((Pathname)loadTruename).getNamestring(); 1347 ZipFile zipFile = ZipCache.getZip(zipFileName); 1348 try 1349 { 1350 ZipEntry entry = zipFile.getEntry(namestring); 1351 if (entry != null) 1352 { 1353 byte[] bytes = readFunctionBytes(zipFile.getInputStream(entry), 1354 (int) entry.getSize()); 1355 if (bytes != null) 1356 return bytes; 1357 Debug.trace("Unable to load " + namestring); 1358 error(new LispError("Unable to load " + namestring)); 1359 return null; // not reached 1360 } 1361 } 1362 finally 1363 { 1364 ZipCache.removeZip(zipFile.getName()); 1365 } 1366 } 1367 catch (IOException t) 1368 { 1369 Debug.trace(t); 1370 } 1371 error(new FileError("File not found: " + namestring, 1372 new Pathname(namestring))); 1373 return null; // not reached 1374 } 1375 1376 public static final Function makeCompiledFunctionFromClass(Class<?> c) { 1377 try { 1378 if (c != null) { 1379 Function obj = (Function)c.newInstance(); 1380 return obj; 1381 } else { 1382 return null; 1324 1383 } 1325 // FIXME close stream! 1326 if (obj != null) 1327 return obj; 1328 return error(new LispError("Unable to load " + 1329 pathname.writeToString())); 1330 } 1331 LispObject loadTruename = Symbol.LOAD_TRUENAME.symbolValue(thread); 1332 String zipFileName = ((Pathname)loadTruename).getNamestring(); 1333 ZipFile zipFile = null; 1384 } 1385 catch (InstantiationException e) {} // ### FIXME 1386 catch (IllegalAccessException e) {} // ### FIXME 1387 1388 return null; 1389 } 1390 1391 1392 public static final LispObject loadCompiledFunction(InputStream in, int size) 1393 { 1394 byte[] bytes = readFunctionBytes(in, size); 1395 if (bytes != null) 1396 return loadClassBytes(bytes); 1397 else 1398 return error(new FileError("Can't read file off stream.")); 1399 } 1400 1401 1402 1403 private static final byte[] readFunctionBytes(InputStream in, int size) 1404 { 1334 1405 try 1335 1406 { 1336 zipFile = ZipCache.getZip(zipFileName); 1337 ZipEntry entry = zipFile.getEntry(namestring); 1338 if (entry != null) 1339 { 1340 LispObject obj = null; 1341 try { 1342 obj = loadCompiledFunction(zipFile.getInputStream(entry), 1343 (int) entry.getSize()); 1344 } 1345 catch (IOException ignore) { }; 1346 if (obj != null) 1347 return obj; 1348 Debug.trace("Unable to load " + namestring); 1349 return error(new LispError("Unable to load " + namestring)); 1350 } 1351 } 1352 catch (IOException ignore) { 1353 //ignore IOException from ZipCache.getZip() 1354 } 1355 finally 1356 { 1357 try { 1358 ZipCache.removeZip(zipFile.getName()); 1359 } 1360 catch (IOException ignore) { } // ignore 1361 } 1362 return error(new FileError("File not found: " + namestring, 1363 new Pathname(namestring))); 1364 } 1365 1366 public static final LispObject makeCompiledFunctionFromClass(Class<?> c) { 1367 if (c != null) 1368 try { 1369 return (LispObject)c.newInstance(); 1370 } 1371 catch (InstantiationException ignore) { 1372 // ignore 1373 } 1374 catch (IllegalAccessException ignore) { 1375 // ignore 1376 } 1377 return null; 1378 } 1379 1380 private static final LispObject loadCompiledFunction(InputStream in, int size) 1381 { 1382 byte[] bytes = new byte[size]; 1383 int bytesRemaining = size; 1384 int bytesRead = 0; 1385 try { 1407 byte[] bytes = new byte[size]; 1408 int bytesRemaining = size; 1409 int bytesRead = 0; 1386 1410 while (bytesRemaining > 0) 1387 1411 { … … 1393 1417 } 1394 1418 in.close(); 1419 if (bytesRemaining > 0) 1420 Debug.trace("bytesRemaining = " + bytesRemaining); 1421 1422 return bytes; 1423 } 1424 catch (IOException t) 1425 { 1426 Debug.trace(t); // FIXME: call error()? 1427 } 1428 return null; 1429 } 1430 1431 public static final Function loadClassBytes(byte[] bytes) 1432 { 1433 return loadClassBytes(bytes, new JavaClassLoader()); 1395 1434 } 1396 catch (IOException e) { 1397 return null; // fixme: return an error? 1398 } 1399 if (bytesRemaining > 0) 1400 Debug.trace("bytesRemaining = " + bytesRemaining); 1401 1402 return loadCompiledFunction(bytes); 1403 } 1404 1405 public static final LispObject loadCompiledFunction(byte[] bytes) { 1406 return loadCompiledFunction(bytes, new JavaClassLoader()); 1407 } 1408 1409 public static final LispObject loadCompiledFunction(byte[] bytes, JavaClassLoader cl) { 1435 1436 public static final Function loadClassBytes(byte[] bytes, 1437 JavaClassLoader cl) 1438 { 1410 1439 Class<?> c = cl.loadClassFromByteArray(null, bytes, 0, bytes.length); 1411 LispObjectobj = makeCompiledFunctionFromClass(c);1412 if (obj instanceof Function) {1413 ((Function)obj).setClassBytes(bytes);1414 1415 1440 Function obj = makeCompiledFunctionFromClass(c); 1441 if (obj != null) { 1442 obj.setClassBytes(bytes); 1443 } 1444 return obj; 1416 1445 } 1417 1446 … … 2443 2472 exportSpecial("*AUTOLOAD-VERBOSE*", PACKAGE_EXT, NIL); 2444 2473 2474 // ### *preloading-cache* 2475 public static final Symbol AUTOLOADING_CACHE = 2476 internSpecial("*AUTOLOADING-CACHE*", PACKAGE_SYS, NIL); 2477 2445 2478 // ### *compile-file-type* 2446 2479 public static final String COMPILE_FILE_TYPE = "abcl"; -
trunk/abcl/src/org/armedbear/lisp/Load.java
r12298 r12306 45 45 import java.net.URL; 46 46 import java.net.URLDecoder; 47 import java.util.Hashtable; 47 48 import java.util.zip.ZipEntry; 48 49 import java.util.zip.ZipException; … … 607 608 try { 608 609 thread.bindSpecial(_FASL_ANONYMOUS_PACKAGE_, new Package()); 610 thread.bindSpecial(AUTOLOADING_CACHE, 611 AutoloadedFunctionProxy.makePreloadingContext()); 609 612 while (true) { 610 613 LispObject obj = in.faslRead(false, EOF, true, thread); -
trunk/abcl/src/org/armedbear/lisp/Symbol.java
r12298 r12306 3015 3015 public static final Symbol FSET = 3016 3016 PACKAGE_SYS.addInternalSymbol("FSET"); 3017 public static final Symbol FUNCTION_PRELOAD = 3018 PACKAGE_SYS.addInternalSymbol("FUNCTION-PRELOAD"); 3017 3019 public static final Symbol INSTANCE = 3018 3020 PACKAGE_SYS.addInternalSymbol("INSTANCE"); 3019 3021 public static final Symbol MACROEXPAND_MACRO = 3020 3022 PACKAGE_SYS.addInternalSymbol("MACROEXPAND-MACRO"); 3023 public static final Symbol MAKE_FUNCTION_PRELOADING_CONTEXT = 3024 PACKAGE_SYS.addInternalSymbol("MAKE-FUNCTION-PRELOADING-CONTEXT"); 3021 3025 public static final Symbol NAME = 3022 3026 PACKAGE_SYS.addInternalSymbol("NAME"); … … 3027 3031 public static final Symbol OPERATION = 3028 3032 PACKAGE_SYS.addInternalSymbol("OPERATION"); 3033 public static final Symbol PROXY_PRELOADED_FUNCTION = 3034 PACKAGE_SYS.addInternalSymbol("PROXY-PRELOADED-FUNCTION"); 3029 3035 public static final Symbol _SOURCE = 3030 3036 PACKAGE_SYS.addInternalSymbol("%SOURCE"); -
trunk/abcl/src/org/armedbear/lisp/compile-file.lisp
r12229 r12306 161 161 (setf form 162 162 `(fset ',name 163 ( load-compiled-function,(file-namestring classfile))163 (proxy-preloaded-function ',name ,(file-namestring classfile)) 164 164 ,*source-position* 165 165 ',lambda-list … … 485 485 (temp-file (merge-pathnames (make-pathname :type (concatenate 'string type "-tmp")) 486 486 output-file)) 487 (temp-file2 (merge-pathnames (make-pathname :type (concatenate 'string type "-tmp2")) 488 output-file)) 487 489 (warnings-p nil) 488 490 (failure-p nil)) … … 511 513 (jvm::with-saved-compiler-policy 512 514 (jvm::with-file-compilation 513 (write "; -*- Mode: Lisp -*-" :escape nil :stream out)514 (%stream-terpri out)515 (let ((*package* (find-package '#:cl)))516 (write (list 'init-fasl :version *fasl-version*)517 :stream out)518 (%stream-terpri out)519 (write (list 'setq '*source* *compile-file-truename*)520 :stream out)521 (%stream-terpri out))522 515 (handler-bind ((style-warning #'(lambda (c) 523 516 (setf warnings-p t) … … 545 538 (dolist (name *fbound-names*) 546 539 (fmakunbound name))))))) 547 (rename-file temp-file output-file) 540 (with-open-file (in temp-file :direction :input) 541 (with-open-file (out temp-file2 :direction :output 542 :if-does-not-exist :create 543 :if-exists :supersede) 544 ;; write header 545 (write "; -*- Mode: Lisp -*-" :escape nil :stream out) 546 (%stream-terpri out) 547 (let ((*package* (find-package '#:cl)) 548 (count-sym (gensym))) 549 (write (list 'init-fasl :version *fasl-version*) 550 :stream out) 551 (%stream-terpri out) 552 (write (list 'setq '*source* *compile-file-truename*) 553 :stream out) 554 (%stream-terpri out) 555 (dump-form `(dotimes (,count-sym ,*class-number*) 556 (function-preload 557 (%format nil "~A-~D.cls" ,(pathname-name output-file) 558 (1+ ,count-sym)))) out) 559 (%stream-terpri out)) 560 561 562 ;; copy remaining content 563 (loop for line = (read-line in nil :eof) 564 while (not (eq line :eof)) 565 do (write-line line out)))) 566 (delete-file temp-file) 567 (rename-file temp-file2 output-file) 548 568 549 569 (when *compile-file-zip* -
trunk/abcl/src/org/armedbear/lisp/compiler-pass2.lisp
r12272 r12306 2071 2071 (declare-field g +lisp-object+ +field-access-default+) 2072 2072 (emit 'ldc (pool-string (file-namestring pathname))) 2073 (emit-invokestatic +lisp-class+ "loadCompiledFunction"2073 (emit-invokestatic "org/armedbear/lisp/AutoloadedFunctionProxy" "loadPreloadedFunction" 2074 2074 (list +java-string+) +lisp-object+) 2075 2075 (emit 'putstatic *this-class* g +lisp-object+)
Note: See TracChangeset
for help on using the changeset viewer.