forked from runtimeverification/python-semantics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-semantics-ops.k
More file actions
21 lines (14 loc) · 1.38 KB
/
Copy pathpython-semantics-ops.k
File metadata and controls
21 lines (14 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require "python-semantics-common.k"
module PYTHON-SEMANTICS-OPS
imports PYTHON-SEMANTICS-COMMON
syntax ObjRef ::= "coerceBinaryBase" "(" Expression "," Expression "," Expression "," Expression ")" [strict(1, 2)]
| "coerceBinary" "(" Expression "," Expression "," Expression "," Expression "," String ")" [strict(1, 2)]
| "coerceUnary" "(" Expression "," Expression "," String ")" [strict(1)]
| "coercion" "(" Expression ")" [strict]
rule <k> coerceBinary(O:Object, O2:Object, X, RX, S:String) => coerceBinaryBase(O, O2, X, RX) -> (raiseInternal("TypeError", "unsupported operand type(s) for " +String S)) ...</k>
rule <k> coerceBinaryBase(O, O2, X, RX) => test(hasbase(getbases(gettype(O2)), gettype(O)), coercion(getmember(O2, RX, true, false, false) (O, .Arguments)), .Obj) -> coercion(getmember(O, X, true, false, false) (O2, .Arguments)) -> coercion(getmember(O2, RX, true, false, false) (O, .Arguments)) ...</k>
rule <k> coerceUnary(O, X, S) => coercion(getmember(O, X, true, false, false) (.Arguments)) -> (raiseInternal("TypeError", "bad operand type for " +String S)) ...</k>
rule <k> coercion(obj(N,ObjState:Bag)) => test(or((N ==Int NoneId), (N ==Int NotImplementedId)), .Obj, obj(N,ObjState)) ...</k>
<symbols>... "None" |-> NoneId "NotImplemented" |-> NotImplementedId ...</symbols>
rule coercion(.Obj) => .Obj
endmodule