|
1 | | -require "python-semantics-common.k" |
| 1 | +require "python-zsemantics-common.k" |
2 | 2 |
|
3 | 3 | module PYTHON-SEMANTICS-ATTRIBUTE-REF |
4 | 4 | imports PYTHON-SEMANTICS-COMMON |
5 | 5 |
|
6 | 6 | syntax ObjRef ::= "mapLookup" "(" Expression "," Expression ")" [strict] |
| 7 | + | "mapInsert" "(" Expression "," Expression "," Expression ")" [strict] |
7 | 8 | | "basesLookup" "(" Expression "," Expression ")" [strict] |
8 | 9 | | "basesLookup" "(" List "," Expression ")" [strict(2)] |
9 | 10 | | "descriptor" "(" Expression "," Expression "," Expression "," Test ")" [strict] |
10 | 11 | | "checkData" "(" Expression "," Expression ")" [strict] |
| 12 | + | "checkDataSet" "(" Expression "," Expression "," Expression ")" [strict] |
11 | 13 |
|
12 | 14 | rule O . X:Id => try: (getmember(O, "__getattribute__", true, false, true) (Id2String(X))) except ref("AttributeError") : (getmember(O, "__getattr__", true, false, false) (Id2String(X)) -> raise) else: pass |
13 | 15 |
|
@@ -60,4 +62,28 @@ module PYTHON-SEMANTICS-ATTRIBUTE-REF |
60 | 62 | rule <k> descriptor(O:Object, O2:Object, Type:Object, false) => (getmember(O, "__get__", false, false, false) (O, O2, O2, .Arguments)) -> O ...</k> |
61 | 63 | <symbols>... "None" |-> None:Int ...</symbols> when id(O2) ==K None |
62 | 64 |
|
| 65 | + rule setmember(O:Object, Name:Object, Value:Object) => checkDataSet(getmember(O, Name, false, false, false), Name, Value) -> mapInsert(O, Name, Value) -> raiseInternal("AttributeError", "object has no attribute '" +String strvalue(Name) +String "'") |
| 66 | + |
| 67 | + rule checkDataSet(O:Object, Name, Value) => getmember(O, "__set__", false, false, false) (O, Name, Value, .Arguments) -> .Obj |
| 68 | + rule checkDataSet(.Obj, _, _) => .Obj |
| 69 | + |
| 70 | + rule <k> mapInsert(obj(B,_), Name, Value) => ref(Dict) [Name] , .Expressions := Value ...</k> |
| 71 | + <object> |
| 72 | + <id> B </id> |
| 73 | + <oattrs>... "__dict__" |-> Dict ...</oattrs> |
| 74 | + </object> |
| 75 | + |
| 76 | + rule <k> mapInsert(obj(B,_), _, _) => .Obj ...</k> |
| 77 | + <object>... |
| 78 | + <id> B </id> |
| 79 | + <oattrs> Env:Map </oattrs> |
| 80 | + ...</object> when notBool("__dict__" in keys(Env)) |
| 81 | + |
| 82 | + rule <k> mapInsert(obj(B,_), _, _) => raiseInternal("TypeError", "can't set attributes of built-in/extension type") ...</k> |
| 83 | + <object>... |
| 84 | + <id> B </id> |
| 85 | + <oattrs>... "__dict__" |-> _ ...</oattrs> |
| 86 | + <oenv> _ </oenv> |
| 87 | + ...</object> |
| 88 | + |
63 | 89 | endmodule |
0 commit comments