Path: news.daimi.aau.dk!news.uni-c.dk!newsfeed.sunet.se!news00.sunet.se!sunic!news.sprintlink.net!news.frontiernet.net!news.his.com!news2.cais.net!news.cais.net!news.jsums.edu!gatech!news.mathworks.com!fu-berlin.de!zrz.TU-Berlin.DE!marie!wpp From: wpp@marie.physik.TU-Berlin.DE (Kai Petzke) Newsgroups: comp.lang.beta Subject: Re: How to immediately compile/load patterns Date: 6 Mar 96 13:06:33 GMT Organization: Technical University Berlin, Germany Lines: 76 Message-ID: References: <4hf6pjINNbul@hood.sps.mot.com> NNTP-Posting-Host: marie.physik.tu-berlin.de moss@risc.sps.mot.com (Matthew Moss) writes: >I am experimenting with an environment where I need to compile a pattern >located in some text file and immediately be able to access that pattern >in the running program. Something like this: Well, as was already pointed out, there is no "straightforward" solution for this. However, using "hacker" methods, your plan should actually do doable. The following is derived from the (tested) scheme to dynamically load code into C programs: step 1: write your BETA code to a file. step 2: call the BETA compiler for that code: system("beta -c file.bet"); step 3: load that object into a dynamic shared object: system("ld -r -shared -o file.so file.o"); step 4: Use the C function "dlopen" to load that shared library: void *handle = dlopen("file.so", RTLD_NOW); step 5: With `dlsym(void *handle, char *symname)' you can find out, which symbol of the shared object has been loaded to which address. It is probably a bad idea to try to directly call a DO part. But what might work, is to find the pointer to the pattern data structure in the loaded object, and transfer that pointer to a pattern variable. This should be doable without using assembler hacks, but you will have to study the assembler output of the Mjolner system, so that you actually know, how it stores pattern variables. Note, that each pattern variable holds two fields - a pointer to the pattern data structure, and a pointer to the enclosing object. You will want to write a C function, that performs all the steps mentioned above. Call that C function from BETA as follows: (# p: ##object; DynLoader: external (# a: [1] @char; r: @integer enter (a,r) #); do (* Dummy is a pattern, that is defined in the same ATTRIBUTES * section as the pattern, that will be dynamically loaded *) dummy##->p##; ("file.bet", @@p)->DynLoader; (* Now p is ready for use *) #); >My first guess would be to read the COFF information out of the .o file >produced from the compile. But since I plan on adding the pattern to >a persistent store, maybe there is an easier way via a temporary PS. >has anyone done this before? Thanx... Making these "temporary" patterns compatible with persistent stores is another tough thing. In particular, temporary stores need a list of all possible types, if they load objects from a store. I don't know, how this list can be generated in case of dynamically generated objects ... Kai -- Kai Petzke, Technical University of Berlin, Germany http://www.physik.tu-berlin.de/~wpp/ to learn about Linux, Postgres and BETA. wpp@marie.physik.tu-berlin.de for regular e-mail How fast can computers get? -- Warp 9, of course, on Star Trek.