-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUtilities.rkt
43 lines (36 loc) · 1.2 KB
/
Utilities.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#lang racket
(require redex/reduction-semantics
"Syntax.rkt")
(provide (all-defined-out))
(define-syntax where/not
(syntax-rules ()
[(where/not x y) (match (term y)
[x #f]
[_ #t])]))
;; NOTE: Useful for the very popular myriad index-based lookups
(define-metafunction WASM
index : (any ...) j -> any
[(index (any ...) j)
,(list-ref (term (any ...)) (term j))])
;; NOTE: Useful for the very popular myriad index-based lookups
(define-metafunction WASM
with-index : (any ...) j any -> (any ...)
[(with-index (any_1 ...) j any_2)
,(append (take (term (any_1 ...)) (term j))
(term (any_2))
(drop (term (any_1 ...)) (add1 (term j))))])
; Returns the number of bits required to represent values of a given type
; Equivalent to |t|
(define-metafunction WASM
bit-width : t -> natural
[(bit-width i32) 32]
[(bit-width i64) 64]
[(bit-width f32) 32]
[(bit-width f64) 64])
; Returns the number of bits required to represent values of a given packed type
; Equivalent to |tp|
(define-metafunction WASM
packed-bit-width : tp -> natural
[(packed-bit-width i8) 8]
[(packed-bit-width i16) 16]
[(packed-bit-width i32) 32])