Commit 76948ded authored by Guy Watson's avatar Guy Watson
Browse files

Constrain sub-types more strictly, not allowing for generic base-types

parent fc9d5bad
......@@ -229,17 +229,16 @@
[Func (λ (n c) (+ 1 (att-value 'nesting-level (ast-parent n))))])
;; ints and floats
;; Use these with (fresh-subtype-of ___)
;; For 32 and 64 bit types, use (fresh-type-variable i32 f32)
(define number (base-type 'number))
(define int (base-type 'int number))
(define float (base-type 'float number))
;; All the base types of WebAssembly, with supertypes of int and float
(define i32 (base-type 'i32 int))
(define i64 (base-type 'i64 int))
(define f32 (base-type 'f32 float))
(define f64 (base-type 'f64 float))
;; All the base types of WebAssembly
(define i32 (base-type 'i32))
(define i64 (base-type 'i64))
(define f32 (base-type 'f32))
(define f64 (base-type 'f64))
;; Larger groups
(define (number) (fresh-type-variable i32 i64 f32 f64))
(define (int) (fresh-type-variable i32 i64))
(define (float) (fresh-type-variable f32 f64))
(define (no-child-types)
(λ (n t) (hash)))
......@@ -256,10 +255,10 @@
[Program [i32
(λ (n t)
(hash 'Func i32
'globals (λ (child-node) (fresh-type-variable))))]]
[GlobalDeclaration [(fresh-subtype-of number)
'globals (λ (child-node) (number))))]]
[GlobalDeclaration [(number)
(λ (n t) (hash 'initialvalue t))]]
[Func [(fresh-subtype-of number)
[Func [(number)
(λ (n t)
(hash 'root t))]]
[LiteralIntThirtyTwo [i32
......@@ -270,82 +269,82 @@
(no-child-types)]]
[LiteralFloatSixtyFour [f64
(no-child-types)]]
[Noop [(fresh-subtype-of number) (λ (n t) (hash 'expr t))]] ;;todo This is wierd....
[Noop [(number) (λ (n t) (hash 'expr t))]] ;;todo This is wierd....
[Binop [(fresh-subtype-of number) binop-rhs]]
[Binop [(number) binop-rhs]]
;; Restricted binops:
[Remainder [(fresh-subtype-of int) binop-rhs]]
[And [(fresh-subtype-of int) binop-rhs]]
[Or [(fresh-subtype-of int) binop-rhs]]
[Xor [(fresh-subtype-of int) binop-rhs]]
[ShiftLeft [(fresh-subtype-of int) binop-rhs]]
[ShiftRight [(fresh-subtype-of int) binop-rhs]]
[RotateLeft [(fresh-subtype-of int) binop-rhs]]
[RotateRight [(fresh-subtype-of int) binop-rhs]]
[Min [(fresh-subtype-of float) binop-rhs]]
[Max [(fresh-subtype-of float) binop-rhs]]
[CopySign [(fresh-subtype-of float) binop-rhs]]
[Unop [(fresh-subtype-of number) unop-rhs]]
[Remainder [(int) binop-rhs]]
[And [(int) binop-rhs]]
[Or [(int) binop-rhs]]
[Xor [(int) binop-rhs]]
[ShiftLeft [(int) binop-rhs]]
[ShiftRight [(int) binop-rhs]]
[RotateLeft [(int) binop-rhs]]
[RotateRight [(int) binop-rhs]]
[Min [(float) binop-rhs]]
[Max [(float) binop-rhs]]
[CopySign [(float) binop-rhs]]
[Unop [(number) unop-rhs]]
;; Restricted Unops
[CountLeadingZero [(fresh-subtype-of int) unop-rhs]]
[CountTrailingZero [(fresh-subtype-of int) unop-rhs]]
[NonZeroBits [(fresh-subtype-of int) unop-rhs]]
[AbsoluteValue [(fresh-subtype-of float) unop-rhs]]
[Negate [(fresh-subtype-of float) unop-rhs]]
[SquareRoot [(fresh-subtype-of float) unop-rhs]]
[Ceiling [(fresh-subtype-of float) unop-rhs]]
[Floor [(fresh-subtype-of float) unop-rhs]]
[Truncate [(fresh-subtype-of float) unop-rhs]]
[Nearest [(fresh-subtype-of float) unop-rhs]]
[CountLeadingZero [(int) unop-rhs]]
[CountTrailingZero [(int) unop-rhs]]
[NonZeroBits [(int) unop-rhs]]
[AbsoluteValue [(float) unop-rhs]]
[Negate [(float) unop-rhs]]
[SquareRoot [(float) unop-rhs]]
[Ceiling [(float) unop-rhs]]
[Floor [(float) unop-rhs]]
[Truncate [(float) unop-rhs]]
[Nearest [(float) unop-rhs]]
[Comparison [i32
(λ (n t) ;; The type of the children is unconstrained, they just have to be the same
(define child-type (fresh-subtype-of number))
(define child-type (number))
(hash 'l child-type
'r child-type))]]
[Testop [i32
(λ (n t) ;; The only testop in wasm 1.1 is integer only
(hash 'expr (fresh-subtype-of int)))]]
[IfElse [(fresh-subtype-of number)
(hash 'expr (int)))]]
[IfElse [(number)
(λ (n t)
(hash 'cond i32
'then t
'else t))]]
[If [(fresh-subtype-of number)
[If [(number)
(λ (n t)
(hash 'cond i32
'then t))]]
[Block [(fresh-subtype-of number) (λ (n t) (hash 'expr t))]]
[Loop [(fresh-subtype-of number) (λ (n t) (hash 'expr t))]]
[ForLoop [(fresh-subtype-of number) (λ (n t) (hash 'initial i32
'loopvar i32
'loopbody t))]]
[Branch [(fresh-subtype-of number) (λ (n t) (hash 'val t))]] ;;todo triple check branch interactions here
[BranchIf [(fresh-subtype-of number)
[Block [(number) (λ (n t) (hash 'expr t))]]
[Loop [(number) (λ (n t) (hash 'expr t))]]
[ForLoop [(number) (λ (n t) (hash 'initial i32
'loopvar i32
'loopbody t))]]
[Branch [(number) (λ (n t) (hash 'val t))]] ;;todo triple check branch interactions here
[BranchIf [(number)
(λ (n t) (hash 'cond i32
'val t))]]
[MemStore [(fresh-subtype-of number)
[MemStore [(number)
(λ (n t) (hash 'address i32
'value t
'expr t))]]
[MemLoad [(fresh-type-variable) (λ (n t) (hash 'address i32))]]
[MemLoad [(number) (λ (n t) (hash 'address i32))]]
[LocalGet [i32 (no-child-types)]] ;;todo change to the new reference binding system
[LocalSet [i32 (λ (n t) (hash 'val i32
'expr i32))]]
[LocalTee [i32 (λ (n t) (hash 'val i32))]]
[GlobalGet [(fresh-subtype-of number) (no-child-types)]]
[GlobalSet [(fresh-subtype-of number) (λ (n t) (hash 'val t
'expr t))]]
[GlobalGet [(number) (no-child-types)]]
[GlobalSet [(number) (λ (n t) (hash 'val t
'expr t))]]
;;Type conversions
[TruncateFloat [(fresh-subtype-of int)
[TruncateFloat [(int)
(λ (n t)
(hash 'expr (fresh-subtype-of float)))]]
[ConvertInt [(fresh-subtype-of float)
(hash 'expr (float)))]]
[ConvertInt [(float)
(λ (n t)
(hash 'expr (fresh-subtype-of int)))]]
(hash 'expr (int)))]]
[Wrap [i32 (λ (n t)
(hash 'expr i64))]]
[Extend [i64 (λ (n t)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment