Closed-code-conversion: Transforming Open Code Multi-staged Programs into Closed Ones

다단계 프로그램에서 프로그램 생성 단계의 자유변수 제거

  • 어현준 (포항공과대학교 미래기술사업단) ;
  • 이광근 (서울대학교 컴퓨터공학부)
  • Published : 2009.03.15

Abstract

We present a transformation which converts open-code multi-staged programs into closed ones. Staged computation, which explicitly divides a computation into separate stages, is a unifying framework for existing program generation systems. Because a multi-staged program generates another program, which can also generate a third program and on, the implementation of a multi-staged language is not straightforward. Dynamic binding of (lexically free) variables in code also makes the implementation of a multi-staged language hard. By converting each code into code of function which takes environment for free variables as its argument and giving an actual environment at the code-composition site, we can transform a open-code program into a closed-code one. Combining with Davies and Pfenning's method, our closed-code-conversion enables the implementation of the unstaged language to be useful for executing multi-staged programs. We also prove the correctness of our conversion: the converted program is equivalent to the original program, and the converted program does not have open code.

다단계 프로그래밍이란 매크로 프로그래밍, 부분 계산(partial evaluation), 실행시간 코드 생성(runtime code generation)등을 포섭하는 일반적인 방법론으로, 계산을 여러 단계로 나누어 각 단계에 주어진 부분 입력을 통해 다음 단계를 전문화(specialize)함으로써 효율적인 계산을 수행하게 해 준다. 다단계 프로그램은 일반적인 계산 외에 코드(다음 단계의 프로그램)를 생성, 조림 및 실행시킬 수 있다. 본 논문은 코드에 자유변수를 허용하는 다단계 프로그램을 코드에 자유변수가 없는 다단계 프로그램으로 변환하는 방법을 제안한다. 코드에 존재하는 자유변수는 동적으로 바인딩(binding)되기 때문에 이를 구현하기 어려운 문제가 있다. 자유변수가 있는 코드는 환경을 입력으로 받는 함수의 코드로 변환하고, 필요한 환경은 코드를 조립하는 시점에 넘겨줌으로써 코드에서 자유변수를 제거할 수 있다. 이렇게 자유변수가 제거된 다단계 프로그램은 Davies와 Pfenning이 제안한 방법에 의해 단계가 없는 람다 계산(lambda-calculus)으로 변환된 후 람다 계산법에 의해 실행되어질 수 있다.

Keywords

References

  1. Guy L. Steele. Common Lisp the Language, 2nd edition. Digital Press, 1990
  2. Paul Graham. On Lisp: an advanced technique for Common Lisp. Prentice Hall, 1994
  3. Neil D. Jones, Carsten K. Gomard, and Peter Sestoft. Partial evaluation and automatic generation. Prentice Hall, 1993
  4. Oliver Danvy. Type-directed partial evaluation. In Proceedings of the Symposium on Principles of Programming Languages, pages 242-257, ACM, Jan 1996
  5. M. Leone and Peter Lee. Optimizing ML with run-time code generation. In Proceedings of the Conference on Programming Language Design and Implementation, pages 137-148. ACM, Jun 1996
  6. Massimilian Poletto, Wilson C. Hsieh, Dawson R. Engler, and M. Frans Kasshoek. C and tcc: a language and compiler for dynamic code generation. ACM Transactions on Programming Languages and Systems, 21:324-369, Mar 1999 https://doi.org/10.1145/316686.316697
  7. Rowan Davies and Frank Pfenning. A modal analysis of staged computation. In Proceedings of the Symposium on Principles of Programming Languages, pages 258-270, ACM, Jan 1996
  8. Ik-Soon Kim, Kwangkeun Yi, and Cristiano Calcagno. A polymorphic modal type system for Lisp-like multi-staged languages. In Proceedings of the Symposium on Principles of Programming Languages, pages 257-268, ACM, Jan 2006
  9. Yasuhiko Minamide, Greg Morrisett, and Robert Harper. Typed closure conversion. In Proceedings of the Symposium on Principles of Programming Languages, pages 271-283, ACM, Jan 1996
  10. Paul A. Steckler and Mitchell Wand. Lightweight closure conversion. ACM Transactions on Programming Languages and Systems, 19(1):48-86, Jan 1997 https://doi.org/10.1145/239912.239915