Re: bigloo-lib / jigloo modifications
Damien MATTEI <[email protected]>
| Newsgroups | gmane.lisp.scheme.bigloo |
|---|---|
| Message-ID | <[email protected]> |
Hi , sorry for my late answer but i have to code and test before answering... i agree with you, if i had no time for testing i will not made this project conversion from ASP / MS ACCESS / I2S / Windows to MySQL / Linux / Apache Tomcat / Java / Bigloo / Kawa ... and i'm already using the JDBC driver in java in a DataBAse.java class with functions called from bigloo and it's not always easy, i'm changing the code to use less or more java depanding of what bigloo can do (or can not) or what i know how to do with bigloo... as you said when dealing with java from scheme there is a lot of interface to import in scheme to be able to use the java objects. It's relatively easy to use string, int and a array of them in bigloo scheme as they are fundamental types that have scheme equivalent but when importing complex types it could be very heavy, the problem with java is that when you import a single object as all is object oriented with tons of heritage you rapidly got all the java definitions to import... response continue in the body message: Le Wednesday 27 January 2016 14:32:29 Vladimir Tsichevski, vous avez écrit : > Hi Damien, > On 20.01.2016 14:09, Damien MATTEI wrote: > > Hi Vladimir, > > > > thank you for your answer your help is precious, > > i didn't noticed there was an earlier version on github, > The googlecode has archived all projects and recommended to move to github. So did I recently. > > i just try it last evening, if something is possible it will be easiest from this version. > > Note that i have no use of gtk* in my application, i'm just trying to use the mysql feature of the bigloo-lib3 because the project i'm developing is porting a web project (originally under I2S from microsoft and access under windows) with > > connection to relational database hosted on an apache tomcat8 web engine (for security reasons) under linux and MySQL (MariaDB now) . The language used with apache tomcat is Java, > > i should say java byte-code as the tomcat engine do not care if you created the *.class or .jar or .war files from java source or any other language that produce java byte-code for jvm > > such as Scheme. So the project is using little java source, some Bigloo Scheme source files, and Kawa Scheme source files too. > Great company :-) :-) yes and there is also ABCL (Armed Bear Common Lisp) that seems great for Java i will test it if i have time... > > As there is no support for MySQL database connection in Kawa Scheme and Bigloo Scheme i have those choices: > > -the easy way but not really pretty:made a simple class in java source code that handle the SQL request generated by Scheme source code classes > > -find a library for Bigloo or Kawa that handle database connection with MySQL > > I'm workin on the two solutions because i only use the java front-end version of bigloo, > > and i do not know if the bigloo-lib3 is compatible with the java front-end of bigloo (option -jvm for bigloo) > > is your library only for bigloo compiling to C language or is it compatible too with the Java compilation option of bigloo ? > Never tried using Bigloo with Java. I doubt Bigloo can translate C library calls to Java native interface. > > I would recommend using JDBC. It works great for MySQL. I wrote rdbms interface for Bigloo since it was the only option to > access relation DBs uniformly from bigloo interpreter and/or compiler. There is no such problems in Java. > > > > anyway i find interesting info in your code , from lib-bigloo2 to lib-bigloo3 the use of $string->bstring which is undocumented but help porting code, still work in latest bigloo (4.2c) > I will take a look at code as soon as I have some spare time. > > Regards, > Vladimir > > PS: from my experience, if you have to deal with Java, you shall write your projects mostly in Java, and probably use other > languages compiled to Java bytecode just for exploring and testing. Otherwise soon you'll find yourself writing interfaces to > dozens of Java libraries with no usual help from Java IDE. yes dozens and dozens ,it could not be done by hand, bigloo have a tools called jigloo ,quoting the documentation: "28.4.1 Automatic Java clauses generation Java clauses can be automatically generated using the Jigloo program which is distributed in the same package as Bigloo. Using Jigloo may be a good way to understand how Java classes, methods, and variables have to be declared in Bigloo. Jigloo reads Java class files and generate the Bigloo java clauses for that classes." it is a good tool for importing java definitions in scheme but when you import a class in java ,its definition use also others classes and so on... you rapidly have to import recursively a lot of definitions, so i added a few options to jigloo to do it automatically and it worked fine for my project, i have put the modified version of jigloo in attachment as it could be useful for someone else too. Here are the option for this version of jigloo: [mattei@moita bin]$ java jigloo -help usage: jigloo [options] [src_name]* -o <name> -- Name the output file <name>. -no-directives -- Do not emit directives header. -no-transient -- Do not emit 'transient' keyword. -no-volatile -- Do not emit 'volatile' keyword. -r -- Recursively generate Java clauses. -skip-nested-classes -- Skip nested classes (only compatible with -r option). -v[23] -- Be verbose. -r Recursively generate Java clauses. when doing this you have the problem of nested classes that could generetae redefiniton errors at compilation so i added a -skip-nested-classes options to Skip nested classes, first i added two options -no-transient and -no-volatile for not emiting 'transient' and 'volatile' keywords that have no scheme equivalment and genereted errors at compilation. i use this jigloo for importing definitions for java.sql.ResultSet and java.langString this way: java jigloo -r -skip-nested-classes -no-transient -no-volatile -o ../jigloo-generated-ResultSet.scm java.sql.ResultSet fileList = [java.sql.ResultSet, java.sql.Date, java.lang.String, java.util.Calendar, java.math.BigDecimal, java.sql.Time, java.sql.Timestamp, java.io.InputStream, java.sql.SQLWarning, java.sql.ResultSetMetaData, java.io.Reader, java.lang.Object, java.sql.SQLType, java.sql.Statement, java.sql.Blob, java.sql.Clob, java.sql.Ref, java.sql.Array, java.sql.RowId, java.sql.NClob, java.sql.SQLXML, java.util.Map, java.lang.Class, java.net.URL, java.time.Instant, java.time.LocalDate, java.util.Date, java.nio.charset.Charset, java.lang.StringBuilder, java.lang.StringBuffer, java.util.Comparator, java.lang.CharSequence, java.lang.Iterable, java.util.Locale, java.util.stream.IntStream, java.util.TimeZone, java.util.Set, java.math.MathContext, java.math.BigInteger, java.math.RoundingMode, java.time.LocalTime, java.time.LocalDateTime, java.lang.Throwable, java.sql.SQLException, java.util.Iterator, java.io.PrintWriter, java.io.PrintStream, java.lang.StackTraceElement, java.util.Spliterator, java.util.function.Consumer, java.nio.CharBuffer , java.lang.Integer, java.sql.Connection, java.io.OutputStream, java.io.Writer, javax.xml.transform.Source, javax.xml.transform.Result, java.util.Collection, java.util.function.BiFunction, java.util.function.BiConsumer, java.util.function.Function, java.lang.ClassLoader, java.security.ProtectionDomain, java.lang.reflect.TypeVariable, java.lang.reflect.Type, java.lang.Package, java.lang.reflect.Method, java.lang.reflect.Constructor, java.lang.reflect.Field, java.lang.annotation.Annotation, java.lang.reflect.AnnotatedType, java.net.URLStreamHandler, java.net.URI, java.net.URLConnection, java.net.Proxy, java.net.URLStreamHandlerFactory, java.time.temporal.Temporal, java.time.temporal.TemporalAmount, java.time.temporal.TemporalUnit, java.time.temporal.TemporalField, java.time.temporal.TemporalAdjuster, java.time.OffsetDateTime, java.time.ZoneOffset, java.time.ZonedDateTime, java.time.ZoneId, java.time.temporal.TemporalAccessor, java.time.Clock, java.time.temporal.TemporalQuery, java.time.temporal.ValueRange, java.time.Month, java.time.DayOfWeek, java.time.chrono.Era, java.time.chrono.ChronoLocalDate, java.time.Period, java.time.chrono.ChronoPeriod, java.time.chrono.IsoChronology, java.time.chrono.Chronology, java.time.OffsetTime, java.time.chrono.ChronoLocalDateTime, java.time.format.DateTimeFormatter, java.nio.ByteBuffer, java.util.SortedMap, java.nio.charset.CharsetDecoder, java.nio.charset.CharsetEncoder, java.lang.AbstractStringBuilder, java.lang.Appendable, java.util.function.ToIntFunction, java.util.function.ToLongFunction, java.util.function.ToDoubleFunction, java.util.List, java.lang.Enum, java.util.function.IntConsumer, java.util.stream.Stream, java.util.function.IntFunction, java.util.stream.LongStream, java.util.function.IntToLongFunction, java.util.stream.DoubleStream, java.util.function.IntToDoubleFunction, java.util.OptionalDouble, java.util.IntSummaryStatistics, java.util.function.IntPredicate, java.util.OptionalInt, java.util.stream.BaseStream, java.util.function.IntSupplier, java.util.function.IntBinaryOperator, java.util.PrimitiveIterator, java.util.function.Supplier, java.util.function.ObjIntConsumer, java.util.function.IntUnaryOperator, java.lang.Runnable, java.util.function.Predicate, java.util.Random, java.time.chrono.ChronoZonedDateTime, java.io.File, java.util.function.DoubleConsumer, java.util.function.LongConsumer, java.nio.ByteOrder, java.nio.Buffer, java.sql.DatabaseMetaData, java.sql.PreparedStatement, java.sql.CallableStatement, java.sql.Savepoint, java.util.Properties, java.sql.Struct, java.util.concurrent.Executor, java.util.Enumeration, java.security.CodeSource, java.security.PermissionCollection, java.security.Principal, java.security.Permission, java.lang.reflect.GenericDeclaration, java.lang.reflect.Parameter, java.lang.reflect.AccessibleObject, java.net.FileNameMap, java.net.ContentHandlerFactory, java.net.SocketAddress, java.time.Duration, java.time.format.ResolverStyle, java.time.zone.ZoneRules, java.time.format.TextStyle, java.time.chrono.IsoEra, java.time.temporal.ChronoField, java.time.format.FormatStyle, java.time.format.DecimalStyle, java.text.ParsePosition, java.text.Format, java.nio.ShortBuffer, java.nio.IntBuffer, java.nio.LongBuffer, java.nio.FloatBuffer, java.nio.DoubleBuffer, java.nio.charset.CoderResult, java.nio.charset.CodingErrorAction, java.util.function.UnaryOperator, java.util.ListIterator, java.util.Optional, java.util.function.BinaryOperator, java.util.stream.Collector, java.util.function.LongToIntFunction, java.util.function.LongFunction, java.util.function.LongToDoubleFunction, java.util.LongSummaryStatistics, java.util.function.LongPredicate, java.util.OptionalLong, java.util.function.LongSupplier, java.util.function.LongBinaryOperator, java.util.function.ObjLongConsumer, java.util.function.LongUnaryOperator, java.util.function.DoubleToIntFunction, java.util.function.DoubleFunction, java.util.function.DoubleToLongFunction, java.util.DoubleSummaryStatistics, java.util.function.DoublePredicate, java.util.function.DoubleSupplier, java.util.function.DoubleBinaryOperator, java.util.function.ObjDoubleConsumer, java.util.function.DoubleUnaryOperator, java.lang.Double, java.lang.Long, java.io.FilenameFilter, java.io.FileFilter, java.nio.file.Path, java.sql.RowIdLifetime, java.sql.ParameterMetaData, java.security.cert.Certificate, java.security.CodeSigner, javax.security.auth.Subject, java.lang.reflect.Executable, java.net.ContentHandler, java.time.zone.ZoneOffsetTransition, java.text.AttributedCharacterIterator, java.text.FieldPosition, java.nio.file.WatchKey, java.nio.file.WatchService, java.nio.file.WatchEvent, java.nio.file.FileSystem, java.nio.file.LinkOption, java.security.PublicKey, java.security.Provider, java.security.cert.CertPath, java.security.Timestamp, java.security.AccessControlContext, java.security.PrivilegedExceptionAction, java.security.PrivilegedAction, java.nio.file.Watchable, java.util.concurrent.TimeUnit, java.nio.file.PathMatcher, java.nio.file.attribute.UserPrincipalLookupService, java.nio.file.spi.FileSystemProvider, java.security.DomainCombiner, java.lang.Thread, java.nio.file.attribute.UserPrincipal, java.nio.file.attribute.GroupPrincipal, java.nio.file.OpenOption, java.nio.channels.FileChannel, java.nio.file.attribute.FileAttribute, java.nio.channels.AsynchronousFileChannel, java.util.concurrent.ExecutorService, java.nio.channels.SeekableByteChannel, java.nio.file.CopyOption, java.nio.file.FileStore, java.nio.file.attribute.FileAttributeView, java.nio.file.attribute.BasicFileAttributes, java.nio.file.DirectoryStream, java.nio.file.AccessMode, java.lang.ThreadGroup, java.nio.channels.WritableByteChannel, java.nio.channels.ReadableByteChannel, java.nio.channels.FileLock, java.nio.MappedByteBuffer, java.util.concurrent.Future, java.nio.channels.CompletionHandler, java.util.concurrent.Callable, java.nio.file.attribute.FileStoreAttributeView, java.nio.file.attribute.FileTime, java.nio.channels.Channel] yes it's huge... ;-) and that's only the java class names (see the attached files for an idea of the output file jigloo-generated-ResultSet.scm perheaps for this reason i hava a warning of bigloo at compilation: *** WARNING:bigloo:apply Method too large. This may cause some troubles to Jvm jits (current size: 8673, limit size: 8000). You should consider splitting this function in small pieces. *** WARNING:bigloo:clinit Method too large. This may cause some troubles to Jvm jits (current size: 12706, limit size: 8000). You should consider splitting this function in small pieces. the JIT compiler, probably it will not be able to load and compile faster something but i do not care of that ... i'm not saying it's the best and simple way to do ,but it worked ,even at run time in an apache tomcat web container. regards, damien -- [email protected], [email protected], UNS / OCA / CNRS
jigloo.java
(text/x-java, 11.5 KB)
/*=====================================================================*/
/* serrano/prgm/project/bigloo/jigloo/jigloo.java */
/* ------------------------------------------------------------- */
/* Author : Manuel Serrano */
/* Creation : Mon Jan 1 17:24:51 2001 */
/* Last change : Sam 30 jan 2016 00:00:55 CET (mattei) */
/* Copyright : 2001-06 Manuel Serrano */
/* ------------------------------------------------------------- */
/* Automatic Bigloo Java module clause generation (by */
/* instrospection of JVM class files). */
/*=====================================================================*/
import java.lang.*;
import java.io.*;
import java.util.*;
import java.lang.reflect.*;
/*---------------------------------------------------------------------*/
/* jigloo ... */
/*---------------------------------------------------------------------*/
public abstract class jigloo {
static PrintStream out = System.out;
static int verbose = 0;
static boolean directives = true;
static Hashtable arrays = new Hashtable();
static boolean isInterface = false;
static ArrayList<String> fileList;
static boolean recurse = false;
static boolean no_transient = false;
static boolean no_volatile = false;
static boolean skip_nested_classes = false;
static void verbose( int level, String s ) {
if( verbose >= level ) {
System.err.println( s );
}
}
static void emit( String s ) {
out.print( s );
}
static String type_name( Class type ) {
if( type.isArray() ) {
if( type.getComponentType() == byte.class )
return "bstring";
else
return type_name( type.getComponentType() ) + "*";
}
// if ( type == Object.class )
// return "obj";
if ( type == boolean.class )
return "bool";
if ( type == byte.class )
return "char";
if ( type == char.class )
return "ucs2";
if ( type == long.class )
return "elong";
if ( type.getName().equals("bigloo.pair") )
return "pair";
if ( type.getName().equals("bigloo.procedure") )
return "procedure";
String tn = type.getName();
// if (tn.contains("$")) {
// System.err.println(tn);
// System.err.println(type.getSimpleName());
// System.err.println(type.getCanonicalName());
// }
String[] parts = tn.split("\\$");
String java_class_name = parts[0];
if (!skip_nested_classes)
java_class_name = tn;
if (recurse)
if (java_class_name.startsWith("org.") || java_class_name.startsWith("java"))
if (!(fileList.contains(java_class_name))) {
fileList.add(java_class_name);
//System.err.println(java_class_name);
}
return tn;
}
static void jigloo_type( Class type ) {
if( type.isArray() ) jigloo_array( type );
String tn = type_name( type );
emit( "::" + tn );
//System.err.println(tn);
}
static void jigloo_args( Class[] args ) {
emit( "(" );
for( int i = 0; i < args.length; i++ ) {
jigloo_type( args[ i ] );
emit( " " );
}
emit( ") " );
}
static void jigloo_args( Class first, Class[] args ) {
emit( "(" );
jigloo_type( first );
emit( " " );
for( int i = 0; i < args.length; i++ ) {
jigloo_type( args[ i ] );
emit( " " );
}
emit( ") " );
}
static void jigloo_modifiers( int mod ) {
// only emit abstract, if the current class is really an interface.
if( isInterface && Modifier.isAbstract( mod ) ) emit( "abstract " );
if( Modifier.isFinal( mod ) ) emit( "final " );
if( Modifier.isInterface( mod ) ) emit( "interface " );
if( Modifier.isNative( mod ) ) emit( "native " );
if( Modifier.isPrivate( mod ) ) emit( "private " );
if( Modifier.isProtected( mod ) ) emit( "protected " );
if( Modifier.isPublic( mod ) ) emit( "public " );
if( Modifier.isStatic( mod ) ) emit( "static " );
if( Modifier.isStrict( mod ) ) emit( "strict " );
if( Modifier.isSynchronized( mod ) ) emit( "synchronized " );
if (( Modifier.isTransient( mod ) ) && (!no_transient)) emit( "transient " );
if (( Modifier.isVolatile( mod ) ) && (!no_volatile)) emit( "volatile " );
emit( " " );
}
static void jigloo_constructor( Constructor constr, int override_index ) {
emit( " (constructor " );
jigloo_modifiers( constr.getModifiers() );
emit( constr.getName() );
if( override_index != 0 )
emit( Integer.toString( override_index ) );
emit( " " );
jigloo_args( constr.getParameterTypes() );
emit( ")\n" );
}
static void jigloo_field( Field field ) {
emit( " (field " );
jigloo_modifiers( field.getModifiers() );
emit( field.getName() );
jigloo_type( field.getType() );
emit( " \"" + field.getName() + "\")\n" );
}
static void jigloo_method( Class owner, Method method, Hashtable overrides ) {
int mod = method.getModifiers();
if( ! Modifier.isNative( mod ) ) {
Integer override_index= (Integer)overrides.get( method.getName() );
emit( " (method " );
jigloo_modifiers( mod );
emit( method.getName() );
if( override_index.intValue() != 0 ) {
emit( override_index.toString() );
overrides.put( method.getName(),
new Integer( override_index.intValue() + 1 ) );
}
jigloo_type( method.getReturnType() );
emit( " " );
if( Modifier.isStatic( mod ) )
jigloo_args( method.getParameterTypes() );
else
jigloo_args( owner, method.getParameterTypes() );
emit( " \"" + method.getName() + "\")\n" );
}
}
static void jigloo_array( Class an_array ) {
Class component = an_array.getComponentType();
arrays.put( type_name( an_array ), an_array );
if( component.isArray() ) {
jigloo_array( component );
}
}
static int jigloo_array_depth( Class an_array ) {
int res = 0;
Class item = an_array.getComponentType();
while( item.isArray() ) {
res++;
item = item.getComponentType();
}
return res;
}
static void jigloo_emit_array( Class an_array ) {
String tname = type_name( an_array );
if( !tname.equals( "bstring" ) ) {
emit( " (array " + tname + " " );
jigloo_type( an_array.getComponentType() );
emit( ")\n" );
}
}
static void jigloo_emit_arrays() {
Object[] tab = arrays.values().toArray();
int i = 0;
int depth = 0;
boolean empty = tab.length == 0;
while( !empty ) {
empty = true;
for( i = 0; i < tab.length; i++ ) {
Object an_obj = tab[ i ];
if( an_obj != null ) {
Class a_class = (Class)an_obj;
if( jigloo_array_depth( a_class ) == depth ) {
jigloo_emit_array( a_class );
tab[ i ] = null;
} else {
empty = false;
}
}
}
depth++;
}
}
static void jigloo_class( Class a_class ) {
if( a_class.isArray() ) {
jigloo_array( a_class );
} else {
Class the_super = a_class.getSuperclass();
String name = a_class.getName();
Class[] all_classes = a_class.getClasses();
Constructor[] all_constructors = a_class.getConstructors();
Field[] all_fields = a_class.getFields();
Method[] all_methods = a_class.getMethods();
Hashtable overrides = new Hashtable();
// handling overrides
for( int i = 0; i < all_methods.length; i++ ) {
Integer override_count = (Integer)overrides.get( all_methods[i].getName() );
overrides.put( all_methods[i].getName(),
new Integer( (override_count == null) ? 0 : 1 ) );
}
for( int i = 0; i < all_classes.length; i++ ) {
jigloo_class( all_classes[ i ] );
}
int mod = a_class.getModifiers();
isInterface = (Modifier.isInterface(mod));
// start the class emission
if( isInterface ) {
// must not do this for abstract classes!
// (otherwise java.lang.IncompatibleClassChangeError)
emit( " (abstract-class " + name + "\n" );
} else {
emit( " (class " + name + "\n" );
}
for( int i = 0; i < all_constructors.length; i++ ) {
jigloo_constructor( all_constructors[ i ],
((all_constructors.length == 0) ? 0 : (i+1)) );
}
for( int i = 0; i < all_fields.length; i++ ) {
jigloo_field( all_fields[ i ] );
}
for( int i = 0; i < all_methods.length; i++ ) {
jigloo_method( a_class, all_methods[ i ], overrides );
}
// stop with this class
emit( " \"" + name + "\")\n" );
}
}
static void jigloo_file( String filename ) {
verbose( 1, " [" + filename + "]" );
try {
jigloo_class( Class.forName( new String( filename ) ) );
} catch( Throwable e ) {
System.err.println( "*** ERROR:jigloo:Can't open class -- " + filename );
}
}
static String[] parse_args( String argv[] ) {
String[] file = new String[ argv.length ];
String[] res;
int w = 0;
for( int i = 0; i < argv.length; i++ ) {
if( argv[ i ].equals( "-help" ) ) {
System.err.println( "usage: jigloo [options] [src_name]*" );
System.err.println();
System.err.println( " -o <name> -- Name the output file <name>." );
System.err.println( " -no-directives -- Do not emit directives header." );
System.err.println( " -no-transient -- Do not emit 'transient' keyword." );
System.err.println( " -no-volatile -- Do not emit 'volatile' keyword." );
System.err.println( " -r -- Recursively generate Java clauses." );
System.err.println( " -skip-nested-classes -- Skip nested classes (only compatible with -r option)." );
System.err.println( " -v[23] -- Be verbose." );
System.exit( 0 );
} else {
if ( argv[ i ].equals( "-skip-nested-classes" ) )
skip_nested_classes = true;
else {
if ( argv[ i ].equals( "-no-transient" ) )
no_transient = true;
else {
if ( argv[ i ].equals( "-no-volatile" ) )
no_volatile = true;
else {
if ( argv[ i ].equals( "-r" ) )
recurse = true;
else {
if( argv[ i ].equals( "-no-directives" ) )
directives = false;
else {
if( argv[ i ].equals( "-o" ) ) {
try {
out = new PrintStream( new FileOutputStream( argv[ i + 1 ] ) );
i++;
} catch( java.io.FileNotFoundException e ) {
System.err.println( "*** ERROR:jigloo:Can't open file for output -- " + argv[ i + 1 ] );
}
} else {
if( argv[ i ].equals( "-v" ) )
verbose = 1;
else {
if( argv[ i ].equals( "-v2" ) )
verbose = 2;
else {
if( argv[ i ].equals( "-v3" ) )
verbose = 3;
else {
file[ w ] = argv[ i ];
w++;
}
}
}
}
}
}
}
}
}
}
}
if ((skip_nested_classes) && (!recurse)) {
System.err.println( "with -skip-nested-classes option you must use -r option");
System.exit( 1 );
}
res = new String[ w ];
System.arraycopy( file, 0, res, 0, w );
return res;
}
public static void main( String argv[] ) {
fileList = new ArrayList<String>(Arrays.asList(parse_args( argv )));
if( directives ) emit( "(directives\n (java\n" );
for( int i = 0; i < fileList.size(); i++ )
jigloo_file( fileList.get(i) );
jigloo_emit_arrays();
if( directives ) emit( "))\n" );
System.err.println( "fileList = "+fileList );
}
}
jigloo-generated-ResultSet.scm
(text/x-java, 660.9 KB) - not displayed