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)으로 변환된 후 람다 계산법에 의해 실행되어질 수 있다.