40
40
*/
41
41
package com .oracle .graal .python .nodes .generator ;
42
42
43
+ import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
44
+
43
45
import com .oracle .graal .python .builtins .objects .common .HashingStorage ;
44
46
import com .oracle .graal .python .builtins .objects .common .HashingStorageLibrary ;
45
47
import com .oracle .graal .python .builtins .objects .dict .PDict ;
48
+ import com .oracle .graal .python .nodes .ErrorMessages ;
49
+ import com .oracle .graal .python .nodes .PRaiseNode ;
46
50
import com .oracle .graal .python .nodes .expression .ExpressionNode ;
47
51
import com .oracle .truffle .api .CompilerDirectives ;
48
52
import com .oracle .truffle .api .dsl .Cached ;
@@ -56,6 +60,8 @@ public abstract class DictConcatNode extends ExpressionNode {
56
60
57
61
@ Children final ExpressionNode [] mappables ;
58
62
63
+ @ Child private PRaiseNode raiseNode ;
64
+
59
65
protected DictConcatNode (ExpressionNode ... mappablesNodes ) {
60
66
this .mappables = mappablesNodes ;
61
67
}
@@ -66,6 +72,7 @@ public Object concat(VirtualFrame frame,
66
72
@ Cached ConditionProfile hasFrame ,
67
73
@ CachedLibrary (limit = "2" ) HashingStorageLibrary firstlib ,
68
74
@ CachedLibrary (limit = "1" ) HashingStorageLibrary otherlib ) {
75
+ // TODO support mappings in general
69
76
PDict first = null ;
70
77
PDict other ;
71
78
for (ExpressionNode n : mappables ) {
@@ -90,12 +97,22 @@ private static void addAllToDict(VirtualFrame frame, PDict dict, PDict other, Co
90
97
dict .setDictStorage (dictStorage );
91
98
}
92
99
93
- private static PDict expectDict (Object first ) {
100
+ private PDict expectDict (Object first ) {
94
101
if (!(first instanceof PDict )) {
95
- CompilerDirectives .transferToInterpreter ();
96
- throw new RuntimeException ("non-dictionary in dictionary appending" );
102
+ throw getRaiseNode ().raise (TypeError , ErrorMessages .OBJ_ISNT_MAPPING , first );
97
103
}
98
104
return (PDict ) first ;
99
105
}
100
106
107
+ protected final PRaiseNode getRaiseNode () {
108
+ if (raiseNode == null ) {
109
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
110
+ if (isAdoptable ()) {
111
+ raiseNode = insert (PRaiseNode .create ());
112
+ } else {
113
+ raiseNode = PRaiseNode .getUncached ();
114
+ }
115
+ }
116
+ return raiseNode ;
117
+ }
101
118
}
0 commit comments