Sergey, This looks great! I'll have a look tonight or tomorrow night, currently on lunch at work. I think Java and Python bindings would be a very popular addition - python is used a lot in scientific computing. I believe there's already a wrapper for gmp? Gmpy?
Antony On 4/23/10, Sergey Bochkanov <[email protected]> wrote: > > Hello, MPIR-developers! > > I want to inform you about new MPIR-related project called X-MPIR. The > idea is to develop a whole set of bindings for a wide set of > programming languages using automatic translation. > > MPIR/GMP have overwhelming API - hundreds of functions with lots of > parameters. It is hard to manually write wrapper even for one > programming language. However, API is quite regular and code > generation will easily solve this problem - it doesn't matter 20 or > 200 functions to generate, once you have described them in regular > form. Almost all popular languages can have their MPIR interface with > just a tiny bit of programming. > > I've created small proof-of-concept interface generator for C# (under > Win32/Win64). All significant MPIR functions are implemented, 220 in > total. > >>>> STRUCTURE > > From the end user's point of view wrapper consists of one C# unit - > xmpir.cs, and two DLL's - xmpir32.dll and xmpir64.dll. If you want to > use MPIR from C# you just have to include xmpir.cs into you project > and to place DLL's into binaries folder. Interface is very similar to > the original one. > > Deep in the project internals we have: > * mpir.x - formal description of MPIR interface > * xgen_core.php and xgen_wrapper.php - interface generator. It is > written in PHP because this language is very similar to C and have a > lot of text-processing functions. > * computer-generated file: xmpir.c, which must be linked against > static MPIR library. xmpir32.dll and xmpir64.dll are just xmpir.c > compiled with 32 or 64-bit compilers. > * computer-generated file: xmpir.cs, C# wrapper itself. > >>>> FEATURES AND FUTURE > > Essential features of the new interface are: > * automatic switching between 32-bit and 64-bit dynamic libraries. C# > is designed to be platform-agnostic, i.e. carefully written C# > program should be able to be executed without recompilation > under any OS - 32-bit or 64-bit. However, this goal is hard to > achieve when you use external libraries written using native code. > New interface solves this problem. > * solution of some 32/64-bit issues. X-MPIR ABI isn't changed when you > migrate from 32-bit OS to 64-bit one. For example, X-MPIR always > accepts 64-bit bitcounts (but raises an exception when you try to > specify values which don't fit into the current machine word) > * similarity to the original interface > * easy to use. This interface is intended to be shipped in the > precompiled form - to ease installation for those who is unfamiliar > with C. > > Future development: > * c# interface under Linux/Mono in the same "no recompilation of C# > program needed" way. > * interfaces for another programming languages. Java, Python, > FreePascal... Something else? > * some way of errors handling - current version of interface doesn't > handle divisions by zero and memory allocation errors > * automatic switching to either 32 or 64-bit libraries may be extended > to the automatic selection of the optimized library. We can choose > between libraries optimized for P4, Core, Core 2, AMD - all in the > runtime, without recompilation of application. > >>>> LIMITATIONS > > Limitations and drawbacks: > * printf-like input/output functions were not included in the new > interface. It is hard to interface such functions in the > interoperable way > * new interface have constant performance penalty which is about 300 > CPU cycles per function call ('constant' = it is approximately same > for all functions) > >>>> DOWNLOAD > > New interface (C# file, precompiled "Generic C" DLLs, code generator) > can be downloaded from http://www.alglib.net/x/xmpir/xmpir-0.1.zip > >>>> LICENSE > > License is LGPL 3, both for the core part (DLLs) and for the client > part (xmpir.cs). That is because I want to keep things simple for the > first time and to synchronize overall license with MPIR's one. > > However I think that the client part of the wrapper may be licensed > under terms which are different from LGPL 3 (but are compatible with > LGPL 3). LGPL requirements may be satisfied even with non-LGPL license > for xmpir.cs (I am talking about permission to use shared library > mechanism to distribute the rest of the application under non-LGPL > license). > > >>>> EXAMPLE > > Here is example of a simple C# program which uses new interface: > >> using System; >> using System.Runtime.InteropServices; >> using System.Diagnostics; >> class MyClass >> { >> [STAThread] >> static void Main(string[] args) >> { >> mpir.mpz_t f = mpir.mpz_init_set_ui(1); >> int i; >> for(i=2; i<=30; i++) >> mpir.mpz_mul_si(f, f, i); >> System.Console.Write("30! = "); >> System.Console.WriteLine(mpir.mpz_get_string(10,f)); >> mpir.mpz_clear(f); >> } >> } > > > Anybody interested to participate? There are several difficulties > which slow down development. For example, manual takes too much time > because English isn't my native language (I haven't started working > on manual yet). Maybe someone wants to help? > > > -- > With best regards, > Sergey mailto:[email protected] > > -- > You received this message because you are subscribed to the Google Groups > "mpir-devel" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/mpir-devel?hl=en. > > -- Antony Vennard [email protected] -- You received this message because you are subscribed to the Google Groups "mpir-devel" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/mpir-devel?hl=en.
