JavaScript as an Embedded DSL
Abstract
Developing 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 challenges, such as moving or sharing pieces of code between the environments. We embed JavaScript as a DSL in Scala, using Lightweight Modular Staging. DSL code can be compiled to JavaScript or executed as part of the server application. We use features of the host language to make client-side programming safer and more convenient. We use gradual typing to interface typed DSL programs with existing JavaScript APIs. We exploit a selective CPS transform already available in the host language to provide a compelling abstraction over asynchronous callback-driven programming in our DSL.
Keywords
JavaScript Scala DSL programming languagesPreview
Unable to display preview. Download preview PDF.
References
- 1.Abadi, M., Cardelli, L., Pierce, B., Plotkin, G.: Dynamic typing in a statically typed language. ACM Trans. Program. Lang. Syst. 13, 237–268 (1991)CrossRefGoogle Scholar
- 2.Ahmed, A., Findler, R.B., Matthews, J., Wadler, P.: Blame for all. In: Proceedings for the 1st Workshop on Script to Program Evolution, STOP 2009, pp. 1–13. ACM, New York (2009)CrossRefGoogle Scholar
- 3.Bierman, G., Meijer, E., Torgersen, M.: Adding Dynamic Types to C\(^\sharp\). In: D’Hondt, T. (ed.) ECOOP 2010. LNCS, vol. 6183, pp. 76–100. Springer, Heidelberg (2010)CrossRefGoogle Scholar
- 4.Brown, K., Sujeeth, A., Lee, H., Rompf, T., Chafi, H., Olukotun, K.: A heterogeneous parallel framework for domain-specific languages. In: 20th International Conference on Parallel Architectures and Compilation Techniques, PACT (2011)Google Scholar
- 5.Carette, J., Kiselyov, O., Shan, C.-C.: Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. J. Funct. Program. 19, 509–543 (2009)MathSciNetzbMATHCrossRefGoogle Scholar
- 6.Chafi, H., DeVito, Z., Moors, A., Rompf, T., Sujeeth, A.K., Hanrahan, P., Odersky, M., Olukotun, K.: Language Virtualization for Heterogeneous Parallel Computing. Onward! (2010)Google Scholar
- 7.Chafi, H., Sujeeth, A.K., Brown, K.J., Lee, H., Atreya, A.R., Olukotun, K.: A domain-specific approach to heterogeneous parallelism. In: Proceedings of the 16th ACM Symposium on Principles and Practice of Parallel Programming, PPoPP (2011)Google Scholar
- 8.
- 9.
- 10.Cooper, E., Lindley, S., Wadler, P., Yallop, J.: Links: Web Programming Without Tiers. In: de Boer, F.S., Bonsangue, M.M., Graf, S., de Roever, W.-P. (eds.) FMCO 2006. LNCS, vol. 4709, pp. 266–296. Springer, Heidelberg (2007)CrossRefGoogle Scholar
- 11.Cooper, E., Lindley, S., Wadler, P., Yallop, J.: The Essence of Form Abstraction. In: Ramalingam, G. (ed.) APLAS 2008. LNCS, vol. 5356, pp. 205–220. Springer, Heidelberg (2008)CrossRefGoogle Scholar
- 12.Danvy, O., Filinski, A.: Abstracting control. In: Proceedings of the 1990 ACM Conference on LISP and Functional Programming, LFP 1990, pp. 151–160. ACM, New York (1990)CrossRefGoogle Scholar
- 13.Danvy, O., Filinski, A.: Representing control: A study of the cps transformation. Mathematical Structures in Computer Science 2(4), 361–391 (1992)MathSciNetzbMATHCrossRefGoogle Scholar
- 14.
- 15.Flanagan, D.: (2011), https://github.com/davidflanagan/javascript6_examples/blob/master/examples/21.06.koch.js
- 16.Flanagan, D.: JavaScript: The Definitive Guide, 6th edn. O’Reilly Media, Inc. (2011)Google Scholar
- 17.
- 18.Hofer, C., Ostermann, K., Rendel, T., Moors, A.: Polymorphic embedding of dsls. In: Proceedings of the 7th International Conference on Generative Programming and Component Engineering, GPCE 2008, pp. 137–148. ACM, New York (2008)CrossRefGoogle Scholar
- 19.Kats, L.C.L., Visser, E.: The Spoofax language workbench. Rules for declarative specification of languages and IDEs. In: Rinard, M. (ed.) Proceedings of the 25th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2010, Reno, NV, USA, October 17-21, pp. 444–463 (2010)Google Scholar
- 20.Khoo, Y.P., Hicks, M., Foster, J.S., Sazawal, V.: Directing javascript with arrows. SIGPLAN Not. 44, 49–58 (2009)Google Scholar
- 21.Lee, H., Brown, K., Sujeeth, A., Chafi, H., Rompf, T., Odersky, M., Olukotun, K.: Implementing domain-specific languages for heterogeneous parallel computing. IEEE Micro. 31, 42–53 (2011)CrossRefGoogle Scholar
- 22.Meyerovich, L.A., Guha, A., Baskin, J., Cooper, G.H., Greenberg, M., Bromfield, A., Krishnamurthi, S.: Flapjax: a programming language for ajax applications. In: Proceedings of the 24th ACM SIGPLAN Conference on Object Oriented Programming Systems Languages and Applications, OOPSLA 2009, pp. 1–20. ACM, New York (2009)CrossRefGoogle Scholar
- 23.Moors, A., Piessens, F., Odersky, M.: Generics of a Higher Kind. ACM SIGPLAN Notices 43, 423–438 (2008)CrossRefGoogle Scholar
- 24.Moors, A., Rompf, T., Haller, P., Odersky, M.: Scala-virtualized. In: PEPM 2012 (2012)Google Scholar
- 25.Odersky, M., Zenger, M.: Scalable Component Abstractions. In: Proceedings of OOPSLA 2005 (2005)Google Scholar
- 26.Petříček, T., Syme, D.: F# web tools: Rich client/server web applications in f#Google Scholar
- 27.Rompf, T., Maier, I., Odersky, M.: Implementing First-Class Polymorphic Delimited Continuations by a Type-Directed Selective CPS-Transform. In: Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming. ACM, New York (2009)Google Scholar
- 28.Rompf, T., Odersky, M.: Lightweight Modular Staging: A Pragmatic Approach to Runtime Code Generation and Compiled DSLs. In: GPCE (2010)Google Scholar
- 29.Rompf, T., Sujeeth, A.K., Lee, H., Brown, K.J., Chafi, H., Oderksy, M., Olukotun, K.: Building-blocks for performance oriented DSLs. In: Electronic Proceedings in Theoretical Computer Science (2011)Google Scholar
- 30.
- 31.Siek, J.G., Taha, W.: Gradual typing for functional languages. In: Scheme and Functional Programming Workshop (September 2006)Google Scholar
- 32.Siek, J.G., Taha, W.: Gradual Typing for Objects. In: Bateni, M. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 2–27. Springer, Heidelberg (2007)CrossRefGoogle Scholar
- 33.Sujeeth, A.K., Lee, H., Brown, K.J., Rompf, T., Wu, M., Atreya, A.R., Odersky, M., Olukotun, K.: OptiML: an implicitly parallel domain-specific language for machine learning. In: Proceedings of the 28th International Conference on Machine Learning, ICML (2011)Google Scholar
- 34.Taha, W., Sheard, T.: Metaml and multi-stage programming with explicit annotations. Theor. Comput. Sci. 248, 211–242 (2000)zbMATHCrossRefGoogle Scholar
- 35.Ureche, V., Rompf, T., Sujeeth, A., Chafi, H., Odersky, M.: Stagedsac: A case study in performance-oriented dsl development. In: PEPM (2012)Google Scholar
- 36.Visser, E.: WebDSL: A Case Study in Domain-Specific Language Engineering. In: Lämmel, R., Visser, J., Saraiva, J. (eds.) GTTSE 2007. LNCS, vol. 5235, pp. 291–373. Springer, Heidelberg (2008)Google Scholar
- 37.Vogt, J.C.: Type Safe Integration of Query Languages into Scala. Diplomarbeit, RWTH Aachen, Germany (2011)Google Scholar
- 38.Wadler, P., Findler, R.B.: Well-Typed Programs Can’t Be Blamed. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 1–16. Springer, Heidelberg (2009)CrossRefGoogle Scholar