summaryrefslogtreecommitdiff
path: root/src/types.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'src/types.lisp')
-rw-r--r--src/types.lisp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/types.lisp b/src/types.lisp
new file mode 100644
index 0000000..7bd9775
--- /dev/null
+++ b/src/types.lisp
@@ -0,0 +1,68 @@
+(defpackage #:sarcasm.types
+ (:use #:cl)
+ (:export
+ #:i32 #:i64 #:f32 #:f64
+ #:numtype
+ #:typeidx
+ #:vectype
+ #:funcref
+ #:externref
+ #:reftype
+ #:valtype
+ #:stacksig))
+
+(in-package #:sarcasm.types)
+
+(deftype i32 ()
+ '(integer 0 #.(expt 2 32)))
+
+(deftype i64 ()
+ '(integer 0 #. (expt 2 64)))
+
+(deftype f32 ()
+ 'single-float)
+
+(deftype f64 ()
+ 'double-float)
+
+(deftype numtype ()
+ '(or i32 i64 f32 f64))
+
+(deftype typeidx ()
+ 'i32)
+
+(deftype vectype ()
+ '(bit-vector 128))
+
+(deftype funcref ()
+ 't)
+
+(deftype externref ()
+ 't)
+
+(deftype reftype ()
+ '(or funcref externref))
+
+(deftype valtype ()
+ '(or numtype vectype reftype))
+
+(defun stacksig-p (thing)
+ "A stack effect type is a two element list of lists of keywords.
+
+It describes the types of values consumed off the stack and returned
+to the stack by instructions."
+ (and (listp thing)
+ (= 2 (length thing))
+ (listp (first thing))
+ (listp (second thing))
+ (every #'keywordp (first thing))
+ (every #'keywordp (second thing))))
+
+(deftype stacksig ()
+ "This is not part of the standard grammar, but appears implicitly in
+the WASM table of instructions found
+
+ https://webassembly.github.io/spec/core/appendix/index-instructions.html
+
+In the `Type` column."
+ '(satisfies stack-effect-type-p))