-
Notifications
You must be signed in to change notification settings - Fork 1.3k
GSoC 2009 Scilab
by Baozeng Ding
This project adds the support for the Scilab language into SWIG. We will add a "-scilab" option to SWIG's current backend, which indicates SWIG to generate wrapper for Scilab. As the C++ language has not been fully supported by Scilab,we would implement the module with the C features. The project would make the function of SWIG more complete and the scilab language better flexibility. We will build the Scilab module based on the octave module which SWIG has supported already.
Scilab is a famous open source software for scientific computing. It has been recognized as the best substitute for commercial software like Matlab, Xmath and Matrix. Its scientific computing is very powerful. To make it more efficient, Scilab has provided the C API for high performance. In order to simplify the task of interfacing Scilab languages to C, we would like to use the tool SWIG. It is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. It also supports languages including non-scripting languages such as C#, Common Lisp , Java, Lua, Modula-3, OCAML, Octave and R. By supporting Scilab, we could make the function of SWIG more perfect and the Scilab language better flexibility,which will benefit both SWIG and Scilab communities.
The motivation I chose this project is that I am very interested in compiler technology. I have used the lex and yacc tool to implement a simple paint program. When I browsed the projects provided by the GSOC, I was attracted by this project at first sight of eye. Although I have not used SWIG before, I was surprised by its function of supporting so many languages. I wondered how it could implement such great function and therefore I have downloaded the source code of SWIG and its document. I spent some days on learning how it wrapper the C/C++ language into different target languages. It would be not difficult for me to support another language like Scilab into SWIG.
During the project, I can improve my understanding of SWIG and Scilab, and improve my experience of compiler technology and C/C++. What's more, it can also give me a chance to interact with an open source community. I would like to engage with the SWIG community after the projects and maintain the development of SWIG for supporting Scilab.
This project includes 2 phases. The second phase contains 8 smaller phases.
Although I have never touched SWIG and Scilab before, owing to my great interest in it, I have learned the basic knowledge about them during the ten days when it is the time for the application. However,before coding, there are some still prepare work that I have to do.There are two major things to prepare: One is to learn the core files of SWIG for generating the module. As SWIG has supported so many languages already, it would be easy to learn the principle of the SWIG by one language it has supported already. If I want to learn one existing language module well, I must know the classes that SWIG defined for itself. The files locates in the /swig-1.3.39/source/swig. The other one is to learn the core of the Scilab language which is very useful for writing the wrapper file. For instance in the "Appendix II",the wrapper file contains a header file "stack-c.h" which all of the wrapper files of the Scilab language must contain. It defines a stack for storing the Scilab objects in which file we could know how to get a Scilab object from the stack and how to check its type and so on.
Estimated time: From April 15 to May 15.
About coding:
The coding task is to build the Scilab Module for SWIG. As Scilab has not supported the C++ language completely(this is being doing currently ). In other words, there is no suitable API for calling C++ language(this may be solved later). So in this project we just let the Scilab module to support the C features. When Scilab supports C++, we could extend our module to add the C++ features as the C++ features layer is a higher layer than the C features. Another important thing is the typemap issue for the module. Although the function of Scilab is similar to the octave language, it has some difference from it. For example, Scilab has special constants,like "%pi" which represents Pi. Another way is that its implement mechanism is unique(It uses the stack to store the Scilab objects).So we have to define new typemaps in addition to the usual typemaps used by all the other modules. The two main files of source code is as following: "scilab.cxx": It is the file we should write in the source/modules directory of SWIG. The basic frame of the Scilab.cxx is in the "Appendix I ". (This file is based on the octave module as they are similar and I have compiled it in my machine and proved it is right). The content of Scilab.cxx contains how to parsing of command line options, some initial configuration of the SWIG library and preprocessor, the top() method, the wrapper function and how to generate the Scilab wrapper file. We will gradually complete the file by adding the support of C features one by one. For example, fist we make the file support the global variant. Then we let the file to support the constants and so on. "scilab.swg": Before proceeding, we need create a directory "scilab" for the module in the \Lib directory. In this directory we would write the file "scilab.swg".This file is used to define the special typemap that the module need. There are also some standard library files we need write in the \Lib directory,such as typemape.i, std_string.i, std_vector.i, stl.i and so on. These files could be copied from other modules and be modified suitable for Scilab module. This is the coding period which I plan utill now. With the study in depth, I can make it better.
About tests:
Each of the language modules provides many examples and a test-suite. These examples are used to demonstrate different features of the language module for SWIG end-users. So in this project, we will write a sub directory named scilab in the \Examples directory. In the sub directory we will provide different examples. These examples contains the following: global variables,constants, functor,enum,pointer,and so on.These examples could be implemented during the coding period as they are useful for development of the Scilab Module. Besides we need create a comprehensive test-suite int the /examples/test-suite directory. We use the test-suit to test if our module could support the features we are expected to.
Aout the documentation:
We need to provide a chapter in the html documentation on the basics of using Scilab Module.
The coding,tests and documentation would be going on hand by hand. After we add one feature, we will test and documentation about the feature. We would add eight features for the Scilab module.The time design as following :
1.global variables
Estimated time: From May 23 to June 3
2.functions
Estimated time: From June 3 to June 15
3.constants
Estimated time: From June 15 to June 25
4.enumerations
Estimated time: From June 25 to July 5
5.structures and unions
Estimated time: From July 5 to July 15
6.pointers
Estimated time: From July 15 to July 25
7.references
Estimated time: From July 25 to August 5
8.arrays
Estimated time: From August 5 to August 15
I am a student majoring in Software and Theory in Institute of Software,Chinese Academy of Science,China. I am familiar with C/C++, Java. I am interested in compiler technology and source code. I have experience in the source code of peersim(Peer-to-Peer Simulator) and security module of Linux kernel.
Although I had no experience of SWIG and Scilab before the gsoc begins, I try my best to learn as much as possible for this project during these ten days. SWIG is not a simplistic C++ lexing tool like several apparently similar wrapper generation tool. It implements the full C++ type system and it is able to understand C++ semantics. In my opinion, the most important mechanism is the parse trees for the front-end and typemap for the back-end. I have read some source code for exiting modules in the /source/modules directory. As the time is limited, I have not read the core code for SWIG-1.3 in /source/swig directory yet. But I have read the chapter "Extending SWIG to support new languages" int SWIG-1.3 documentation and "Extending SWIG" in SWIG-1.1 documentation. In the latter chapter, it refers to the SWIG datatypes such as the datatype class, the Function Parameters, the String Class, the Hash Tables Class, the Wrapperfunction class. All of these is very important for me to understand how to support a new language module and give me a basic frame that to write the Scilab module code. In addition, I have used Matlab in one of my college course "information concealment", which has to deal with a lot of data. Until now, I have a quick read about the Scilab documentation and have known the basic knowledge about it,such as its data type,its operation,its function and so on. its date type grammar.The most related chapter is "Interfacing C or Fortran programs with Scilab", in which it provides the API "ilib_build" for call C function.
There are only three courses this semester. I would learn them from 7 to 11'o clock in the evening.So it would not take much of my time in the day. The examination will be held at the beginning of June and be easy to pass. Before the exam, I have about 30 hours a week to do the preparing work for the project. And from June 7th, I would have about 40 hours a week for the project, including the summer holiday. My IRC name is sploving on #swig-gsoc and my email is :[email protected]