C-lisp and Flexible Macro Programming with S-expressions

Vedanth Padmaraman,Sasank Chilamkurthy
2024-10-23
Abstract:Llama$.$lisp is a compiler framework intended to target offload processor backends such as GPUs, using intermediate representation languages (IRs) that are device-agnostic. The Llama$.$lisp IRs are formulated as S-expressions. This makes them easy to generate using higher level programming languages, which is one of the primary goals for Llama$.$lisp. The highest IR layer currently implemented in Llama$.$lisp is C-Lisp. In this paper, we describe the macro system developed for the Llama$.$lisp compiler framework. We show how we implemented FFI bindings as an example of this system.
Programming Languages
What problem does this paper attempt to address?
The main problem that this paper attempts to solve is to simplify and unify the complexity of writing high - performance code on different hardware architectures (especially GPUs). Specifically, the author designed a compiler framework named Llama.lisp, aiming to solve the problem of fragmentation in the existing GPU compiler ecosystem by using device - independent intermediate representation languages (IRs), thereby achieving performance portability across different hardware architectures. ### Main Problems 1. **Complexity of GPU Programming**: It is very difficult to write code that can run efficiently on GPUs (i.e., kernel programming). 2. **Fragmentation of the Compiler Ecosystem**: The existing GPU compiler ecosystem is very fragmented, making it difficult to port code between different hardware architectures. 3. **Performance Portability**: Existing solutions usually cannot guarantee the performance consistency of code on different hardware architectures. ### Solutions To solve the above problems, the author proposes the following: - **Llama.lisp Compiler Framework**: This is a Lisp - inspired compiler framework that adopts a multi - layer structure to simplify the complexity of the compiler. Each layer uses S - expressions as the syntactic basis, allowing high - level programming languages to easily generate these intermediate representations. - **C - Lisp Layer**: This is the highest - level IR layer in Llama.lisp, providing a structured LLVM IR interface, semantically imitating the C language but using S - expression syntax. - **Macro System (Prelisp)**: To enhance the functionality of C - Lisp, the author developed a powerful macro system that allows the functionality of C - Lisp to be extended by modern general - purpose programming languages such as Python, reducing the dependence on language features. - **FFI Binding Generation**: Through the Prelisp macro system, the ability to automatically generate C - Lisp bindings from C header files is achieved, further simplifying the use of external libraries. ### Markdown - format Display of Formulas The paper does not involve specific mathematical, physical or chemical formulas, and mainly discusses programming languages and compiler technologies. Therefore, there is no need to display complex formulas here. However, if it is necessary to display some programming - related expressions, the following Markdown format can be used: ```markdown ```lisp (fadd <op1> <op2>) ``` ```json ["fadd", <op1>, <op2>] ``` ``` In short, this paper aims to simplify the writing of high - performance code and cross - platform porting, especially in the field of GPU programming, by designing a flexible and efficient compiler framework.