summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2023-01-08 09:08:07 -0500
committerDavid Thompson <dthompson2@worcester.edu>2023-06-08 08:14:41 -0400
commit0251a3319532a30b3f7583a8fbde0f4591762c02 (patch)
tree18fc36219f1943894364c0e19ddc33b5d400ac38
parent6f01e1667ca73b94f2f56d7cf53064762f8a44ed (diff)
Add skeleton of Seagull compiler.
-rw-r--r--chickadee/graphics/seagull.scm115
1 files changed, 115 insertions, 0 deletions
diff --git a/chickadee/graphics/seagull.scm b/chickadee/graphics/seagull.scm
new file mode 100644
index 0000000..505c4b4
--- /dev/null
+++ b/chickadee/graphics/seagull.scm
@@ -0,0 +1,115 @@
+;;; Chickadee Game Toolkit
+;;; Copyright © 2023 David Thompson <davet@gnu.org>
+;;;
+;;; Chickadee is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published
+;;; by the Free Software Foundation, either version 3 of the License,
+;;; or (at your option) any later version.
+;;;
+;;; Chickadee is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;; General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see
+;;; <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+;; Seagull is a purely functional, statically typed, Scheme-like
+;; language that can be compiled to GLSL code.
+;;
+;; Notable features and restrictions:
+;; - Vertex and fragment shader output
+;; - Lexical scoping (of course)
+;; - Targets multiple GLSL versions
+;; - Multiple return values
+;; - Type inference
+;; - Nested functions (but no free non-top-level variables)
+;; - Tail recursion allowed, but no other recursion
+;;
+;;; Code:
+(define-module (chickadee graphics seagull)
+ #:use-module (ice-9 format)
+ #:use-module (ice-9 match)
+ #:use-module (srfi srfi-9)
+ #:export (compile-seagull))
+
+;; The Seagull compiler is designed as a series of source-to-source
+;; program transformations in which each transformation pass results
+;; in a program that is one step closer to being directly emitted to
+;; GLSL code.
+
+
+;;;
+;;; Alpha conversion
+;;;
+
+;; Alpha conversion is the process of converting all the user defined
+;; identifiers in a program to uniquely named identifiers. This
+;; process frees the compiler from having to worry about things like
+;; '+' being a user defined variable that shadows the primitive
+;; addition operation.
+
+
+;;;
+;;; Macro expansion
+;;;
+
+;; Macro expansion converts convenient but non-primitive syntax forms
+;; (such as let*) into primitive syntax. Seagull does not currently
+;; support user defined macros, just a set of built-ins.
+
+
+;;;
+;;; Free variable annotation
+;;;
+
+;; All lambda forms are annotated with the variables that appear free
+;; in their body expressions. Unfortunately, GLSL does not allow
+;; nested function definitions, so nested functions in Seagull only
+;; allow free variable references for top-level variables, such as
+;; shader inputs and uniforms.
+
+
+;;;
+;;; Function hoisting
+;;;
+
+;; Move all non-top-level lambda bindings to the top-level. As
+;; mentioned earlier, GLSL does not allow nested functions.
+
+
+;;;
+;;; Explicit tail call marking
+;;;
+
+;; Make note of which function calls are in tail position. GLSL does
+;; not allow for recursive function calls, but Seagull allows them in
+;; tail position only because they can be compiled to a loop in GLSL.
+
+
+;;;
+;;; Type inference
+;;;
+
+;; Transform all program expressions into typed expressions by
+;; applying a variant of the Hindley-Milner type inference algorithm.
+;; GLSL is a statically typed language, but thanks to type inference
+;; Seagull code doesn't need type annotations.
+
+
+;;;
+;;; GLSL emission
+;;;
+
+;; Transform typed expressions into a string of GLSL code.
+
+
+;;;
+;;; Compiler front-end
+;;;
+
+;; Combine all of the compiler passes on a user provided program and
+;; emit GLSL code if the program is valid.