summaryrefslogtreecommitdiff
path: root/src/modules/ast/ir.scm
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-01-18 01:25:47 -0700
committerbd <bdunahu@operationnull.com>2025-01-18 01:25:47 -0700
commitddd448ae86e5730d5cd297f44ec89ee3fa3c0006 (patch)
tree9eaa2c75b9b397fcef0fe9467d10f21cc1e07a0c /src/modules/ast/ir.scm
parent1c216bd45a7d4fb529288192ecff46453309c485 (diff)
use a scheme procedures+eval to manage and transform AST
Removes records for a more-managable scheme-syntax approach. Modules+overriding allows for the IR itself to be represented and evaluated as scheme code during each transformation.
Diffstat (limited to 'src/modules/ast/ir.scm')
-rw-r--r--src/modules/ast/ir.scm50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/modules/ast/ir.scm b/src/modules/ast/ir.scm
new file mode 100644
index 0000000..3b373e5
--- /dev/null
+++ b/src/modules/ast/ir.scm
@@ -0,0 +1,50 @@
+(define-module (modules ast ir)
+ #:export (prog
+ srout
+ neg
+ not
+ mov
+ stack
+ reg
+ imm
+ tmp
+ ret))
+
+;;; Commentary:
+;;;
+;;; Nodes which exist to do nothing when evaluated.
+;;;
+;;; Code:
+
+(define (ir-node type . args)
+ (cons type args))
+
+(define (prog func)
+ (ir-node 'prog func))
+
+(define (srout label instrs)
+ (ir-node 'srout label instrs))
+
+(define (neg dst)
+ (ir-node 'neg dst))
+
+(define (not dst)
+ (ir-node 'not dst))
+
+(define (mov dst src)
+ (ir-node 'mov dst src))
+
+(define (stack val)
+ (ir-node 'stack val))
+
+(define (reg val)
+ (ir-node 'reg val))
+
+(define (imm val)
+ (ir-node 'imm val))
+
+(define (tmp num)
+ (ir-node 'tmp num))
+
+(define (ret)
+ (ir-node 'ret))