Abstract
Compiling MATLAB---a dynamic, array-based language---to JavaScript is an attractive proposal: the output code can be deployed on a platform used by billions and can leverage the countless hours that have gone into making JavaScript JIT engines fast. But before that can happen, the original MATLAB code must be properly translated, making sure to bridge the semantic gaps of the two languages.
An important area where MATLAB and JavaScript differ is in their handling of arrays: for example, in MATLAB, arrays are one-indexed and writing at an index beyond the end of an array extends it; in JavaScript, typed arrays are zero-indexed and writing out of bounds is a no-op. A MATLAB-to-JavaScript compiler must address these mismatches. Another salient and pervasive difference between the two languages is the assignment of arrays to variables: in MATLAB, this operation has value semantics, while in JavaScript is has reference semantics.
In this paper, we present MatJuice --- a source-to-source, ahead-of-time compiler back-end for MATLAB --- and how it deals efficiently with this last issue. We present an intra-procedural data-flow analysis to track where each array variable may point to and which variables are possibly aliased. We also present the associated copy insertion transformation that uses the points-to information to insert explicit copies when necessary. The resulting JavaScript program respects the MATLAB value semantics and we show that it performs fewer run-time copies than some alternative approaches.
- A. Casey et al. McLab: an extensible compiler toolkit for MATLAB and related languages. In Proceedings of the Third C* Conference on Computer Science and Software Engineering, C3S2E ’10, pages 114–117, New York, NY, USA, 2010. ACM. Google Scholar
Digital Library
- J. Doherty. McSaf: An Extensible Static Analysis Framework For The MATLAB Language. Master’s thesis, August 2011.Google Scholar
- A. W. Dubrau and L. J. Hendren. Taming MATLAB. In Proceedings of the ACM international conference on Object oriented programming systems languages and applications, OOPSLA ’12, pages 503–522, New York, NY, USA, 2012. ACM. ISBN 978-1-4503-1561-6. doi: 10. 1145/2384616.2384653. Google Scholar
Digital Library
- Faiz Khan et al. Using JavaScript and WebCL for Numerical Computations: A Comparative Study of Native and Web Technologies.Google Scholar
- GNU. Octave: Miscellaneous Techniques. https://www. gnu.org/software/octave/doc/interpreter/ Miscellaneous-Techniques.html.Google Scholar
- T. K. Group. Typed Array Specification v1.0. https: //www.khronos.org/registry/typedarray/ specs/1.0.Google Scholar
- V. Kumar. Mix10: Compiling matlab to x10 for high performance. Master’s thesis, April 2014.Google Scholar
- N. Lameed and L. Hendren. Staged Static Techniques to Efficiently Implement Array Copy Semantics in a MATLAB JIT Compiler. In Proceedings of the 20th International Conference on Compiler Construction. Springer Berlin / Heidelberg, 2011. Google Scholar
Digital Library
- N. Lameed and L. Hendren. Staged Static Techniques to Efficiently Implement Array Copy Semantics in a MATLAB JIT Compiler. In ETAPS 2011. Springer Berlin / Heidelberg, Mar 2011. Google Scholar
Digital Library
- J. Lecoq. Matlabtips: Copy on Write. http://www. matlabtips.com/copy-on-write/.Google Scholar
- X. Li. Mc2for: A tool for automatically translating matlab to fortran 95. pages 234–243. IEEE, 2014.Google Scholar
- R Core Team. R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria,.Google Scholar
- R Core Team. R Internals: Rest of header. https://cran.r-project.org/doc/manuals/rpatched/R-ints.html#Rest-of-header,.Google Scholar
- L. Shure. MATLAB: Memory Management for Functions and Variables. http://blogs.mathworks.com/ loren/2006/05/10/memory-management-forfunctions-and-variables/.Google Scholar
Index Terms
Efficiently implementing the copy semantics of MATLAB's arrays in JavaScript
Recommendations
Efficiently implementing the copy semantics of MATLAB's arrays in JavaScript
DLS 2016: Proceedings of the 12th Symposium on Dynamic LanguagesCompiling MATLAB---a dynamic, array-based language---to JavaScript is an attractive proposal: the output code can be deployed on a platform used by billions and can leverage the countless hours that have gone into making JavaScript JIT engines fast. ...
Staged static techniques to efficiently implement array copy semantics in a MATLAB JIT compiler
CC'11/ETAPS'11: Proceedings of the 20th international conference on Compiler construction: part of the joint European conferences on theory and practice of softwareMatlab has gained widespread acceptance among scientists. Several dynamic aspects of the language contribute to its appeal, but also provide many challenges. One such problem is caused by the copy semantics of Matlab. Existing Matlab systems rely on ...
JavaScript as an embedded DSL
ECOOP'12: Proceedings of the 26th European conference on Object-Oriented ProgrammingDeveloping rich web applications requires mastering different environments on the client and server sides. While there is considerable choice on the server-side, the client-side is tied to JavaScript, which poses substantial software engineering ...







Comments