comparison truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/LanguageRegistrationTest.java @ 22066:78c3d3d8d86e

Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 06 Aug 2015 08:31:49 +0200
parents e7c2d36daf72
children dc83cc1f94f2 3aad794eec0e
comparison
equal deleted inserted replaced
22065:503529c65456 22066:78c3d3d8d86e
46 @ExpectError("Registered language class must subclass TruffleLanguage") 46 @ExpectError("Registered language class must subclass TruffleLanguage")
47 @TruffleLanguage.Registration(name = "myLang", version = "0", mimeType = "text/x-my") 47 @TruffleLanguage.Registration(name = "myLang", version = "0", mimeType = "text/x-my")
48 public static final class MyLangNoSubclass { 48 public static final class MyLangNoSubclass {
49 } 49 }
50 50
51 @ExpectError("Language must have a public constructor accepting TruffleLanguage.Env as parameter") 51 @ExpectError("Language class must have public static final singleton field called INSTANCE")
52 @TruffleLanguage.Registration(name = "myLangNoCnstr", version = "0", mimeType = "text/x-my") 52 @TruffleLanguage.Registration(name = "myLangNoCnstr", version = "0", mimeType = "text/x-my")
53 public static final class MyLangWrongConstr extends TruffleLanguage { 53 public static final class MyLangWrongConstr extends TruffleLanguage<Object> {
54 private MyLangWrongConstr() { 54 private MyLangWrongConstr() {
55 super(null); 55 super();
56 } 56 }
57 57
58 @Override 58 @Override
59 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException { 59 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException {
60 throw new IOException(); 60 throw new IOException();
61 } 61 }
62 62
63 @Override 63 @Override
64 protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { 64 protected Object findExportedSymbol(Object context, String globalName, boolean onlyExplicit) {
65 return null; 65 return null;
66 } 66 }
67 67
68 @Override 68 @Override
69 protected Object getLanguageGlobal() { 69 protected Object getLanguageGlobal(Object context) {
70 return null; 70 return null;
71 } 71 }
72 72
73 @Override 73 @Override
74 protected boolean isObjectOfLanguage(Object object) { 74 protected boolean isObjectOfLanguage(Object object) {
83 @Override 83 @Override
84 protected DebugSupportProvider getDebugSupport() { 84 protected DebugSupportProvider getDebugSupport() {
85 return null; 85 return null;
86 } 86 }
87 87
88 @Override
89 protected Object createContext(Env env) {
90 throw new UnsupportedOperationException();
91 }
92
88 } 93 }
89 94
90 @ExpectError("Language must have a public constructor accepting TruffleLanguage.Env as parameter") 95 @ExpectError("Language class must have public static final singleton field called INSTANCE")
91 @TruffleLanguage.Registration(name = "myLangNoCnstr", version = "0", mimeType = "text/x-my") 96 @TruffleLanguage.Registration(name = "myLangNoField", version = "0", mimeType = "text/x-my")
92 public static final class MyLangNoConstr extends TruffleLanguage { 97 public static final class MyLangNoField extends TruffleLanguage<Object> {
93 public MyLangNoConstr() { 98 public MyLangNoField() {
94 super(null); 99 super();
95 } 100 }
96 101
97 @Override 102 @Override
98 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException { 103 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException {
99 throw new IOException(); 104 throw new IOException();
100 } 105 }
101 106
102 @Override 107 @Override
103 protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { 108 protected Object findExportedSymbol(Object context, String globalName, boolean onlyExplicit) {
104 return null; 109 return null;
105 } 110 }
106 111
107 @Override 112 @Override
108 protected Object getLanguageGlobal() { 113 protected Object getLanguageGlobal(Object context) {
109 return null; 114 return null;
110 } 115 }
111 116
112 @Override 117 @Override
113 protected boolean isObjectOfLanguage(Object object) { 118 protected boolean isObjectOfLanguage(Object object) {
122 @Override 127 @Override
123 protected DebugSupportProvider getDebugSupport() { 128 protected DebugSupportProvider getDebugSupport() {
124 return null; 129 return null;
125 } 130 }
126 131
132 @Override
133 protected Object createContext(Env env) {
134 throw new UnsupportedOperationException();
135 }
136
127 } 137 }
128 138
129 @TruffleLanguage.Registration(name = "myLangGood", version = "0", mimeType = "text/x-my") 139 @TruffleLanguage.Registration(name = "myLangGood", version = "0", mimeType = "text/x-my")
130 public static final class MyLangGood extends TruffleLanguage { 140 public static final class MyLangGood extends TruffleLanguage<Object> {
131 public MyLangGood(TruffleLanguage.Env env) { 141 private MyLangGood() {
132 super(env); 142 super();
133 } 143 }
134 144
145 public static final MyLangGood INSTANCE = new MyLangGood();
146
135 @Override 147 @Override
136 protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { 148 protected Object findExportedSymbol(Object context, String globalName, boolean onlyExplicit) {
137 return null; 149 return null;
138 } 150 }
139 151
140 @Override 152 @Override
141 protected Object getLanguageGlobal() { 153 protected Object getLanguageGlobal(Object context) {
142 return null; 154 return null;
143 } 155 }
144 156
145 @Override 157 @Override
146 protected boolean isObjectOfLanguage(Object object) { 158 protected boolean isObjectOfLanguage(Object object) {
160 @Override 172 @Override
161 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException { 173 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException {
162 throw new IOException(); 174 throw new IOException();
163 } 175 }
164 176
177 @Override
178 protected Object createContext(Env env) {
179 return env;
180 }
181
165 } 182 }
166 } 183 }