aboutsummaryrefslogtreecommitdiffstats
path: root/atk16_schasm/core.scm
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-03-07 00:08:25 +0200
committerJan Tuomi <jan@jantuomi.fi>2025-03-07 00:13:20 +0200
commitb541261d70e625398cb61d52141a7a975be9bcf4 (patch)
treeab591066d90b968e252146061285c97c466895fe /atk16_schasm/core.scm
parent4d2179e1d373614e87240096e10d68a5d900e919 (diff)
Develop procedure macros
Diffstat (limited to 'atk16_schasm/core.scm')
-rw-r--r--atk16_schasm/core.scm22
1 files changed, 21 insertions, 1 deletions
diff --git a/atk16_schasm/core.scm b/atk16_schasm/core.scm
index 08a0bd5..7c292f1 100644
--- a/atk16_schasm/core.scm
+++ b/atk16_schasm/core.scm
@@ -1,7 +1,8 @@
(import (chicken base)
(chicken bitwise)
(chicken format)
- (chicken io))
+ (chicken io)
+ (only srfi-1 iota))
;; Utils
@@ -15,6 +16,12 @@
((_ fn-body expr ...)
(lambda (x) (fn-body expr ... x)))))
+(define (zip alist blist)
+ (if (null? alist)
+ '()
+ ;; else, cons and recurse
+ (cons (cons (car alist) (car blist)) (zip (cdr alist) (cdr blist)))))
+
(define (type-of pair)
(if (pair? pair) (car pair) (error "not a pair" pair)))
(define (val-of pair)
@@ -27,6 +34,19 @@
(let ((v (assoc k alist)))
(and v (cdr v))))
+(define-syntax inc!
+ (syntax-rules ()
+ ((_ n)
+ (set! n (+ n 1)))
+ ((_ n m)
+ (set! n (+ n m)))))
+(define-syntax sub!
+ (syntax-rules ()
+ ((_ n)
+ (set! n (- n 1)))
+ ((_ n m)
+ (set! n (- n m)))))
+
(define (string->ascii-list s)
(let* ((len (string-length s))
(dummy (cons #f '()))