1 /* library.h -*- mode:c; coding;utf-8; -*- 2 * 3 * Copyright (c) 2010-2021 Takashi Kato <ktakashi@ymail.com> 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $Id: $ 29 */ 30 #ifndef SAGITTARIUS_PRIVATE_LIBRARY_H_ 31 #define SAGITTARIUS_PRIVATE_LIBRARY_H_ 32 33 #include "sagittariusdefs.h" 34 #include "thread.h" 35 #include "clos.h" 36 37 SG_CLASS_DECL(Sg_LibraryClass); 38 #define SG_CLASS_LIBRARY (&Sg_LibraryClass) 39 40 struct SgLibraryRec 41 { 42 SG_HEADER; 43 SgObject name; /* library name */ 44 SgObject imported; /* imported symbols */ 45 SgObject exported; /* exported symbols */ 46 SgObject version; /* library version (not really used) */ 47 SgObject defined; /* temporary storage to keep what defined 48 in this library. */ 49 SgHashTable *table; /* library inside */ 50 SgInternalMutex lock; 51 SgObject parents; /* imported variables. 52 alist of library and imported variables. 53 this must be like this: 54 ((<lib> . ((<imported> . <name>) ...))) 55 <lib> : parent libarary 56 <imported> : resolved name. cf) prefix etc. 57 <name> : original name. 58 transient. 59 */ 60 readtable_t *readtable; 61 SgObject reader; /* custom reader */ 62 /* library behaviour flags */ 63 int mutableP: 1; /* if this is TRUE then redefinition is 64 always allowed. 65 c.f) user, eval environment and child 66 */ 67 int autoExport: 1; /* automatically exports bindings */ 68 int reserved: 30; 69 70 SgObject holder; /* #f or VM. 71 if this is not #f then the library 72 is child library. 73 */ 74 /* Environment specific generic functions. 75 the structure is 76 generics = (generic ...) 77 generic = (gf max methods ...) 78 NOTE: we add this but defined slot can be used for this 79 so do not access this directly. 80 */ 81 SgObject generics; 82 }; 83 84 #define SG_LIBRARY(obj) ((SgLibrary*)(obj)) 85 #define SG_LIBRARYP(obj) SG_XTYPEP(obj, SG_CLASS_LIBRARY) 86 87 #define SG_LIBRARY_NAME(obj) SG_LIBRARY(obj)->name 88 #define SG_LIBRARY_IMPORTED(obj) SG_LIBRARY(obj)->imported 89 #define SG_LIBRARY_EXPORTED(obj) SG_LIBRARY(obj)->exported 90 #define SG_LIBRARY_DEFINEED(obj) SG_LIBRARY(obj)->defined 91 #define SG_LIBRARY_TABLE(obj) SG_LIBRARY(obj)->table 92 #define SG_LIBRARY_READTABLE(obj) SG_LIBRARY(obj)->readtable 93 #define SG_LIBRARY_READER(obj) SG_LIBRARY(obj)->reader 94 #define SG_LIBRARY_PARENTS(obj) SG_LIBRARY(obj)->parents 95 #define SG_LIBRARY_MUTABLEP(obj) SG_LIBRARY(obj)->mutableP 96 #define SG_LIBRARY_GENERICS(obj) SG_LIBRARY(obj)->generics 97 98 #define SG_CHILD_LIBRARYP(obj) \ 99 (SG_LIBRARYP(obj)&&!SG_FALSEP(SG_LIBRARY(obj)->holder)) 100 101 #define SG_LIBRARY_AUTO_EXPORT(obj) SG_LIBRARY(obj)->autoExport 102 103 SG_CDECL_BEGIN 104 105 SG_EXTERN SgObject Sg_MakeLibrary(SgObject name); 106 SG_EXTERN SgObject Sg_MakeMutableLibrary(SgObject name); 107 SG_EXTERN SgObject Sg_MakeEvalLibrary(); 108 SG_EXTERN SgObject Sg_MakeChildLibrary(SgVM *vm, SgObject name); 109 SG_EXTERN void Sg_RemoveLibrary(SgLibrary *lib); 110 SG_EXTERN SgObject Sg_FindLibrary(SgObject name, int createp); 111 SG_EXTERN void Sg_ImportLibraryFullSpec(SgObject to, SgObject from, 112 SgObject spec); 113 SG_EXTERN void Sg_LibraryExportedSet(SgObject lib, SgObject exportSpec); 114 SG_EXTERN SgObject Sg_SearchLibrary(SgObject lib, int *loadedp); 115 SG_EXTERN SgGloc* Sg_MakeBinding(SgLibrary *lib, SgSymbol *symbol, 116 SgObject value, int flags); 117 118 SG_EXTERN SgObject Sg_SearchLibraryPath(SgObject name); 119 SG_EXTERN SgGloc* Sg_FindBinding(SgObject library, SgObject name, 120 SgObject callback); 121 SG_EXTERN void Sg_InsertBinding(SgLibrary *library, SgObject name, 122 SgObject value); 123 SG_EXTERN void Sg_InsertSandboxBinding(SgObject library, SgObject name, 124 SgObject value); 125 SG_EXTERN SgObject Sg_AddLoadSuffix(SgObject suffix, int appendP); 126 /* make library immutable 127 this operation, for now, is one way. (and not used) 128 */ 129 SG_EXTERN void Sg_LockLibrary(SgLibrary *library); 130 131 SG_EXTERN SgObject Sg_FindDefaultDirectiveByPath(SgObject path); 132 #define Sg_ImportLibrary(t, f) Sg_ImportLibraryFullSpec((t), (f), SG_NIL) 133 134 SG_CDECL_END 135 136 #endif /* SAGITTARIUS_LIBRARY_H_ */ 137 138 /* 139 end of file 140 Local Variables: 141 coding: utf-8-unix 142 End: 143 */ 144