Commit cdc55727 authored by Guy Watson's avatar Guy Watson
Browse files

Add Comparison and Testop node types

These node types are necessary for the type system, since they always result in an i32 regardless of the type of the operands
parent 71c5fd9b
......@@ -51,35 +51,45 @@
[Expr #f ()
#:prop may-be-generated #f]
[Literal Expr ()
#:prop choice-weight 3
#:prop choice-weight 3 ;; default is 10
#:prop may-be-generated #f]
[LiteralIntThirtyTwo Literal ([v = (random -1000 1000)]) ;;todo add command line feature for the whole range
#:prop choice-weight 3]
#:prop choice-weight 3]
[LiteralIntSixtyFour Literal ([v = (random -1000 1000)])
#:prop choice-weight 3]
#:prop choice-weight 3]
[LiteralFloatThirtyTwo Literal ([v = (+ (random -1000 1000) (random))])
#:prop choice-weight 3]
#:prop choice-weight 3]
[LiteralFloatSixtyFour Literal ([v = (+ (random -1000 1000) (random))])
#:prop choice-weight 3]
#:prop choice-weight 3]
[Noop Expr ([expr : Expr])]
[Binop Expr ([l : Expr] [r : Expr]) ;; use l and r here
#:prop choice-weight 30 ;; default is 10
#:prop may-be-generated #f]
[Equal Binop ()]
[NotEqual Binop ()]
[Binop Expr ([l : Expr] [r : Expr]) ;;Binops take a left and a right and produce the same type
#:prop choice-weight 30 ;; as the result
#:prop may-be-generated #f]
[Comparison Expr ([l : Expr] [r : Expr]) ;;Comparisons take a left and a right of the same type
#:prop choice-weight 20 ;; but return a boolean, which is always an i32
#:prop may-be-generated #f] ;; Section 2.4.1 in the spec has more detail
[Unop Expr ([expr : Expr]) ;;Unops take one operand and return a value of that type
#:prop choice-weight 20
#:prop may-be-generated #f]
[Testop Expr ([expr : Expr]) ;;Testops take one operand but return a boolean (i32)
#:prop choice-weight 10
#:prop may-be-generated #f]
[Equal Comparison ()]
[NotEqual Comparison ()]
[Addition Binop ()]
[Subtraction Binop ()]
[Multiplication Binop ()]
[DivisionSigned Binop ()]
[DivisionSigned Binop ()] ;;todo Maybe add the signedness as a field instead of a whole other instruction
;;todo After looking at the float instructions.... yup. This needs to be done
[DivisionUnsigned Binop ()]
[LessThanSigned Binop ()]
[LessThanUnsigned Binop ()]
[GreaterThanSigned Binop ()]
[GreaterThanUnsigned Binop ()]
[LessThanOrEqualSigned Binop ()]
[LessThanOrEqualUnsigned Binop ()]
[GreaterThanOrEqualSigned Binop ()]
[GreaterThanOrEqualUnsigned Binop ()]
[LessThanSigned Comparison ()]
[LessThanUnsigned Comparison ()]
[GreaterThanSigned Comparison ()]
[GreaterThanUnsigned Comparison ()]
[LessThanOrEqualSigned Comparison ()]
[LessThanOrEqualUnsigned Comparison ()]
[GreaterThanOrEqualSigned Comparison ()]
[GreaterThanOrEqualUnsigned Comparison ()]
[RemainderSigned Binop ()]
[RemainderUnsigned Binop ()]
[And Binop ()]
......@@ -90,11 +100,8 @@
[ShiftRightUnsigned Binop ()]
[RotateLeft Binop ()]
[RotateRight Binop ()]
[Unop Expr ([expr : Expr])
#:prop choice-weight 20
#:prop may-be-generated #f]
[EqualZero Unop ()]
[CountLeadingZero Unop ()]
[EqualZero Testop ()]
[CountLeadingZero Unop ()] ;; According to the spec, these are unops, not testops
[CountTrailingZero Unop ()]
[NonZeroBits Unop ()]
[IfElse Expr ([cond : Expr]
......@@ -251,6 +258,14 @@
[Unop [(fresh-subtype-of number)
(λ (n t)
(hash 'expr t))]]
[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))
(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)
(λ (n t)
(hash 'cond i32
......@@ -274,7 +289,7 @@
'value t
'expr t))]]
[MemLoad [(fresh-type-variable) (λ (n t) (hash 'address i32))]]
[LocalGet [i32 (no-child-types)]]
[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))]]
......@@ -437,6 +452,13 @@
[Unop (λ (n) (append
($xsmith_render-node (ast-child 'expr n))
(list (att-value 'math-op n))))]
[Comparison (λ (n) (append
($xsmith_render-node (ast-child 'l n))
($xsmith_render-node (ast-child 'r n))
(list (att-value 'math-op n))))]
[Testop (λ (n) (append
($xsmith_render-node (ast-child 'expr n))
(list (att-value 'math-op n))))]
[IfElse (λ (n)
(append
($xsmith_render-node (ast-child 'cond n))
......
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