blob: 0eedd095ef8452b9d98e9f86f955218fd5645fea [file] [log] [blame]
Paul Sokolovskye79c6b62015-09-11 17:57:47 +03001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2015 Paul Sokolovsky
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
27#include <assert.h>
28#include <string.h>
29#include <errno.h>
30#include <dlfcn.h>
31
32#include "py/nlr.h"
33#include "py/runtime.h"
34#include "py/binary.h"
35
36#include <jni.h>
37
38#define JJ(call, ...) (*env)->call(env, __VA_ARGS__)
Paul Sokolovsky7a4b10c2015-09-14 00:12:27 +030039#define JJ1(call) (*env)->call(env)
Paul Sokolovskye79c6b62015-09-11 17:57:47 +030040
41static JavaVM *jvm;
42static JNIEnv *env;
Paul Sokolovsky1cb5de22015-09-17 13:31:16 +030043static jclass Class_class;
Paul Sokolovskye79c6b62015-09-11 17:57:47 +030044static jclass String_class;
45static jmethodID Class_getField_mid;
46static jmethodID Class_getMethods_mid;
47static jmethodID Class_getConstructors_mid;
48static jmethodID Method_getName_mid;
49static jmethodID Method_toString_mid;
50
Paul Sokolovskyb2d880d2015-09-21 12:02:22 -070051static jclass List_class;
52static jmethodID List_get_mid;
53static jmethodID List_set_mid;
54
Paul Sokolovskye79c6b62015-09-11 17:57:47 +030055STATIC const mp_obj_type_t jobject_type;
56STATIC const mp_obj_type_t jmethod_type;
57
Paul Sokolovsky7a4b10c2015-09-14 00:12:27 +030058STATIC mp_obj_t new_jobject(jobject jo);
Paul Sokolovsky1cb5de22015-09-17 13:31:16 +030059STATIC mp_obj_t new_jclass(jclass jc);
Paul Sokolovskye79c6b62015-09-11 17:57:47 +030060STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, mp_uint_t n_args, const mp_obj_t *args);
61
62typedef struct _mp_obj_jclass_t {
63 mp_obj_base_t base;
64 jclass cls;
65} mp_obj_jclass_t;
66
67typedef struct _mp_obj_jobject_t {
68 mp_obj_base_t base;
69 jobject obj;
70} mp_obj_jobject_t;
71
72typedef struct _mp_obj_jmethod_t {
73 mp_obj_base_t base;
74 jobject obj;
75 jmethodID meth;
76 qstr name;
Paul Sokolovsky7a4b10c2015-09-14 00:12:27 +030077 bool is_static;
Paul Sokolovskye79c6b62015-09-11 17:57:47 +030078} mp_obj_jmethod_t;
79
Paul Sokolovskye632b1f2015-09-23 07:10:55 -070080// Utility functions
81
82STATIC bool is_object_type(const char *jtypesig) {
83 while (*jtypesig != ' ' && *jtypesig) {
84 if (*jtypesig == '.') {
85 return true;
86 }
87 jtypesig++;
88 }
89 return false;
90}
91
Paul Sokolovskye79c6b62015-09-11 17:57:47 +030092// jclass
93
94STATIC void jclass_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
95 (void)kind;
96 mp_obj_jclass_t *self = self_in;
97 // Variable value printed as cast to int
98 mp_printf(print, "<jclass @%p>", self->cls);
99}
100
101STATIC void jclass_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) {
102 if (dest[0] == MP_OBJ_NULL) {
103 // load attribute
104 mp_obj_jclass_t *self = self_in;
105 const char *attr = qstr_str(attr_in);
106
107 jstring field_name = JJ(NewStringUTF, attr);
108 jobject field = JJ(CallObjectMethod, self->cls, Class_getField_mid, field_name);
Paul Sokolovsky7a4b10c2015-09-14 00:12:27 +0300109 if (!JJ1(ExceptionCheck)) {
110 jfieldID field_id = JJ(FromReflectedField, field);
111 jobject obj = JJ(GetStaticObjectField, self->cls, field_id);
112 dest[0] = new_jobject(obj);
113 return;
114 }
115 //JJ1(ExceptionDescribe);
116 JJ1(ExceptionClear);
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300117
Paul Sokolovsky7a4b10c2015-09-14 00:12:27 +0300118 mp_obj_jmethod_t *o = m_new_obj(mp_obj_jmethod_t);
119 o->base.type = &jmethod_type;
120 o->name = attr_in;
121 o->meth = NULL;
122 o->obj = self->cls;
123 o->is_static = true;
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300124 dest[0] = o;
125 }
126}
127
128STATIC mp_obj_t jclass_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
129 if (n_kw != 0) {
130 nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "kwargs not supported"));
131 }
132 mp_obj_jclass_t *self = self_in;
133
134 jarray methods = JJ(CallObjectMethod, self->cls, Class_getConstructors_mid);
135
136 return call_method(self->cls, NULL, methods, true, n_args, args);
137}
138
139STATIC const mp_map_elem_t jclass_locals_dict_table[] = {
140// { MP_OBJ_NEW_QSTR(MP_QSTR_get), (mp_obj_t)&ffivar_get_obj },
141// { MP_OBJ_NEW_QSTR(MP_QSTR_set), (mp_obj_t)&ffivar_set_obj },
142};
143
144STATIC MP_DEFINE_CONST_DICT(jclass_locals_dict, jclass_locals_dict_table);
145
146STATIC const mp_obj_type_t jclass_type = {
147 { &mp_type_type },
148 .name = MP_QSTR_jclass,
149 .print = jclass_print,
150 .attr = jclass_attr,
151 .call = jclass_call,
152 .locals_dict = (mp_obj_t)&jclass_locals_dict,
153};
154
Paul Sokolovsky1cb5de22015-09-17 13:31:16 +0300155STATIC mp_obj_t new_jclass(jclass jc) {
156 mp_obj_jclass_t *o = m_new_obj(mp_obj_jclass_t);
157 o->base.type = &jclass_type;
158 o->cls = jc;
159 return o;
160}
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300161
162// jobject
163
164STATIC void jobject_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
165 (void)kind;
166 mp_obj_jobject_t *self = self_in;
167 // Variable value printed as cast to int
168 mp_printf(print, "<jobject @%p>", self->obj);
169}
170
171STATIC void jobject_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) {
172 if (dest[0] == MP_OBJ_NULL) {
173 // load attribute
174 mp_obj_jobject_t *self = self_in;
175
176 mp_obj_jmethod_t *o = m_new_obj(mp_obj_jmethod_t);
177 o->base.type = &jmethod_type;
178 o->name = attr_in;
179 o->meth = NULL;
180 o->obj = self->obj;
Paul Sokolovsky7a4b10c2015-09-14 00:12:27 +0300181 o->is_static = false;
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300182 dest[0] = o;
183 }
184}
185
Paul Sokolovskyb2d880d2015-09-21 12:02:22 -0700186STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
187 mp_obj_jobject_t *self = self_in;
188 if (!JJ(IsInstanceOf, self->obj, List_class)) {
189 return MP_OBJ_NULL;
190 }
191
192 mp_uint_t idx = mp_obj_get_int(index);
193
194 if (value == MP_OBJ_NULL) {
195 // delete
196 assert(0);
197 } else if (value == MP_OBJ_SENTINEL) {
198 // load
199 jobject el = JJ(CallObjectMethod, self->obj, List_get_mid, idx);
200 return new_jobject(el);
201 } else {
202 // store
203 assert(0);
204 }
205
206
207return MP_OBJ_NULL;
208}
209
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300210STATIC const mp_obj_type_t jobject_type = {
211 { &mp_type_type },
212 .name = MP_QSTR_jobject,
213 .print = jobject_print,
214 .attr = jobject_attr,
Paul Sokolovskyb2d880d2015-09-21 12:02:22 -0700215 .subscr = jobject_subscr,
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300216// .locals_dict = (mp_obj_t)&jobject_locals_dict,
217};
218
Paul Sokolovsky26a9b4d2015-09-13 01:25:04 +0300219STATIC mp_obj_t new_jobject(jobject jo) {
Paul Sokolovsky7e18d3b2015-09-24 15:29:22 -0700220 if (jo == NULL) {
221 return mp_const_none;
222 } else if (JJ(IsInstanceOf, jo, String_class)) {
Paul Sokolovskyed22e9b2015-09-22 17:01:01 -0700223 const char *s = JJ(GetStringUTFChars, jo, NULL);
224 mp_obj_t ret = mp_obj_new_str(s, strlen(s), false);
225 JJ(ReleaseStringUTFChars, jo, s);
226 return ret;
227 } else if (JJ(IsInstanceOf, jo, Class_class)) {
228 return new_jclass(jo);
229 } else {
230 mp_obj_jobject_t *o = m_new_obj(mp_obj_jobject_t);
231 o->base.type = &jobject_type;
232 o->obj = jo;
233 return o;
234 }
235
Paul Sokolovsky26a9b4d2015-09-13 01:25:04 +0300236}
237
238
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300239// jmethod
240
241STATIC void jmethod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
242 (void)kind;
243 mp_obj_jmethod_t *self = self_in;
244 // Variable value printed as cast to int
245 mp_printf(print, "<jmethod '%s'>", qstr_str(self->name));
246}
247
Paul Sokolovsky4e7bde82015-09-12 00:19:18 +0300248#define IMATCH(s, static) ((!strncmp(s, static, sizeof(static) - 1)) && (s += sizeof(static) - 1))
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300249
250#define CHECK_TYPE(java_type_name) \
Paul Sokolovsky4e7bde82015-09-12 00:19:18 +0300251 if (strncmp(arg_type, java_type_name, sizeof(java_type_name) - 1) != 0) { \
252 return false; \
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300253 } \
Paul Sokolovsky4e7bde82015-09-12 00:19:18 +0300254 arg_type += sizeof(java_type_name) - 1;
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300255
256STATIC const char *strprev(const char *s, char c) {
257 while (*s != c) {
258 s--;
259 }
260 return s;
261}
262
Paul Sokolovsky4e7bde82015-09-12 00:19:18 +0300263STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) {
264 const char *arg_type = *jtypesig;
265 mp_obj_type_t *type = mp_obj_get_type(arg);
266
267 if (type == &mp_type_str) {
268 if (IMATCH(arg_type, "java.lang.String") || IMATCH(arg_type, "java.lang.Object")) {
269 out->l = JJ(NewStringUTF, mp_obj_str_get_str(arg));
270 } else {
271 return false;
272 }
273 } else if (type == &mp_type_int) {
Paul Sokolovsky011c7f52015-09-18 13:19:50 +0300274 if (IMATCH(arg_type, "int") || IMATCH(arg_type, "long")) {
275 // TODO: Java long is 64-bit actually
276 out->j = mp_obj_get_int(arg);
277 } else {
278 return false;
279 }
Paul Sokolovsky1e9d8e12015-09-19 01:04:41 +0300280 } else if (type == &jobject_type) {
281 printf("TODO: Check java arg type!!\n");
282 mp_obj_jobject_t *jo = arg;
283 out->l = jo->obj;
Paul Sokolovsky4e7bde82015-09-12 00:19:18 +0300284 } else {
285 nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "arg type not supported"));
286 }
287
288 *jtypesig = arg_type;
289 return true;
290}
291
Paul Sokolovsky26a9b4d2015-09-13 01:25:04 +0300292// jvalue is known to be union of jobject and friends. And yet from C's
293// perspective, it's aggregate object which may require passing via stack
294// instead of registers. Work that around by passing jobject and typecasting
295// it.
296#define MATCH(s, static) (!strncmp(s, static, sizeof(static) - 1))
297STATIC mp_obj_t jvalue2py(const char *jtypesig, jobject arg) {
Paul Sokolovsky51673322015-09-14 00:15:08 +0300298 if (arg == NULL || MATCH(jtypesig, "void")) {
Paul Sokolovsky26a9b4d2015-09-13 01:25:04 +0300299 return mp_const_none;
Paul Sokolovsky6196aa42015-09-20 00:36:26 +0300300 } else if (MATCH(jtypesig, "boolean")) {
301 return mp_obj_new_bool((bool)arg);
Paul Sokolovsky26a9b4d2015-09-13 01:25:04 +0300302 } else if (MATCH(jtypesig, "int")) {
303 return mp_obj_new_int((mp_int_t)arg);
Paul Sokolovskye632b1f2015-09-23 07:10:55 -0700304 } else if (is_object_type(jtypesig)) {
305 // Non-primitive, object type
306 return new_jobject(arg);
Paul Sokolovsky26a9b4d2015-09-13 01:25:04 +0300307 }
308
Paul Sokolovskye632b1f2015-09-23 07:10:55 -0700309 printf("Unknown return type: %s\n", jtypesig);
Paul Sokolovskyb230a862015-09-15 14:07:12 +0300310
Paul Sokolovsky26a9b4d2015-09-13 01:25:04 +0300311 return MP_OBJ_NULL;
312}
313
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300314STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, mp_uint_t n_args, const mp_obj_t *args) {
315 jvalue jargs[n_args];
316// printf("methods=%p\n", methods);
317 jsize num_methods = JJ(GetArrayLength, methods);
318 for (int i = 0; i < num_methods; i++) {
319 jobject meth = JJ(GetObjectArrayElement, methods, i);
320 jobject name_o = JJ(CallObjectMethod, meth, Method_toString_mid);
321 const char *decl = JJ(GetStringUTFChars, name_o, NULL);
322 const char *arg_types = strchr(decl, '(') + 1;
323 //const char *arg_types_end = strchr(arg_types, ')');
324// printf("method[%d]=%p %s\n", i, meth, decl);
325
326 const char *meth_name = NULL;
327 const char *ret_type = NULL;
328 if (!is_constr) {
329 meth_name = strprev(arg_types, '.') + 1;
330 ret_type = strprev(meth_name, ' ') - 1;
331 ret_type = strprev(ret_type, ' ') + 1;
332
333 int name_len = strlen(name);
334 if (strncmp(name, meth_name, name_len/*arg_types - meth_name - 1*/) || meth_name[name_len] != '('/*(*/) {
335 continue;
336 }
337 }
338// printf("method[%d]=%p %s\n", i, meth, decl);
339// printf("!!!%s\n", arg_types);
340// printf("name=%p meth_name=%s\n", name, meth_name);
341
342 bool found = true;
343 for (int i = 0; i < n_args; i++) {
Paul Sokolovsky4e7bde82015-09-12 00:19:18 +0300344 if (!py2jvalue(&arg_types, args[i], &jargs[i])) {
345 goto next_method;
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300346 }
347
348 if (*arg_types == ',') {
349 arg_types++;
350 }
351 }
352
353 if (found) {
354// printf("found!\n");
355 jmethodID method_id = JJ(FromReflectedMethod, meth);
356 jobject res;
357 if (is_constr) {
358 res = JJ(NewObjectA, obj, method_id, jargs);
Paul Sokolovsky26a9b4d2015-09-13 01:25:04 +0300359 JJ(ReleaseStringUTFChars, name_o, decl);
360 return new_jobject(res);
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300361 } else {
362 res = JJ(CallObjectMethodA, obj, method_id, jargs);
Paul Sokolovsky26a9b4d2015-09-13 01:25:04 +0300363 mp_obj_t ret = jvalue2py(ret_type, res);
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300364 JJ(ReleaseStringUTFChars, name_o, decl);
365 if (ret != MP_OBJ_NULL) {
366 return ret;
367 }
368 nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "cannot handle return type"));
369 }
370 }
371
Paul Sokolovsky4e7bde82015-09-12 00:19:18 +0300372next_method:
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300373 JJ(ReleaseStringUTFChars, name_o, decl);
374 }
375
376 nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "method not found"));
377}
378
379
380STATIC mp_obj_t jmethod_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
381 if (n_kw != 0) {
382 nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "kwargs not supported"));
383 }
384 mp_obj_jmethod_t *self = self_in;
385
386 const char *name = qstr_str(self->name);
387// jstring meth_name = JJ(NewStringUTF, name);
388
Paul Sokolovsky7a4b10c2015-09-14 00:12:27 +0300389 jclass obj_class = self->obj;
390 if (!self->is_static) {
391 obj_class = JJ(GetObjectClass, self->obj);
392 }
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300393 jarray methods = JJ(CallObjectMethod, obj_class, Class_getMethods_mid);
394
395 return call_method(self->obj, name, methods, false, n_args, args);
396}
397
398STATIC const mp_obj_type_t jmethod_type = {
399 { &mp_type_type },
400 .name = MP_QSTR_jmethod,
401 .print = jmethod_print,
402 .call = jmethod_call,
403// .attr = jobject_attr,
404// .locals_dict = (mp_obj_t)&jobject_locals_dict,
405};
406
407#ifdef __ANDROID__
408#define LIBJVM_SO "libdvm.so"
409#else
410#define LIBJVM_SO "libjvm.so"
411#endif
412
413STATIC void create_jvm() {
414 JavaVMInitArgs args;
415 JavaVMOption options;
416 options.optionString = "-Djava.class.path=.";
417 args.version = JNI_VERSION_1_6;
418 args.nOptions = 1;
419 args.options = &options;
420 args.ignoreUnrecognized = 0;
421
422 if (env) {
423 return;
424 }
425
426 void *libjvm = dlopen(LIBJVM_SO, RTLD_NOW | RTLD_GLOBAL);
427 if (!libjvm) {
428 nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "unable to load libjvm.so, use LD_LIBRARY_PATH"));
429 }
430 int (*_JNI_CreateJavaVM)(void*, void**, void*) = dlsym(libjvm, "JNI_CreateJavaVM");
431
432 int st = _JNI_CreateJavaVM(&jvm, (void**)&env, &args);
433 if (st < 0 || !env) {
434 nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "unable to create JVM"));
435 }
436
Paul Sokolovsky1cb5de22015-09-17 13:31:16 +0300437 Class_class = JJ(FindClass, "java/lang/Class");
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300438 jclass method_class = JJ(FindClass, "java/lang/reflect/Method");
439 String_class = JJ(FindClass, "java/lang/String");
440
Paul Sokolovsky1cb5de22015-09-17 13:31:16 +0300441 Class_getField_mid = (*env)->GetMethodID(env, Class_class, "getField",
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300442 "(Ljava/lang/String;)Ljava/lang/reflect/Field;");
Paul Sokolovsky1cb5de22015-09-17 13:31:16 +0300443 Class_getMethods_mid = (*env)->GetMethodID(env, Class_class, "getMethods",
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300444 "()[Ljava/lang/reflect/Method;");
Paul Sokolovsky1cb5de22015-09-17 13:31:16 +0300445 Class_getConstructors_mid = (*env)->GetMethodID(env, Class_class, "getConstructors",
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300446 "()[Ljava/lang/reflect/Constructor;");
447 Method_getName_mid = (*env)->GetMethodID(env, method_class, "getName",
448 "()Ljava/lang/String;");
449 Method_toString_mid = (*env)->GetMethodID(env, method_class, "toString",
450 "()Ljava/lang/String;");
Paul Sokolovskyb2d880d2015-09-21 12:02:22 -0700451
452 List_class = JJ(FindClass, "java/util/List");
453 List_get_mid = JJ(GetMethodID, List_class, "get",
454 "(I)Ljava/lang/Object;");
455 List_set_mid = JJ(GetMethodID, List_class, "set",
456 "(ILjava/lang/Object;)Ljava/lang/Object;");
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300457}
458
459STATIC mp_obj_t mod_jni_cls(mp_obj_t cls_name_in) {
460 const char *cls_name = mp_obj_str_get_str(cls_name_in);
461 if (!env) {
462 create_jvm();
463 }
464 jclass cls = JJ(FindClass, cls_name);
465
466 mp_obj_jclass_t *o = m_new_obj(mp_obj_jclass_t);
467 o->base.type = &jclass_type;
468 o->cls = cls;
469 return o;
470}
471MP_DEFINE_CONST_FUN_OBJ_1(mod_jni_cls_obj, mod_jni_cls);
472
Paul Sokolovskycb6cf5e2015-09-16 01:09:39 +0300473STATIC mp_obj_t mod_jni_env() {
474 return mp_obj_new_int((mp_int_t)env);
475}
476MP_DEFINE_CONST_FUN_OBJ_0(mod_jni_env_obj, mod_jni_env);
477
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300478STATIC const mp_map_elem_t mp_module_jni_globals_table[] = {
479 { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_jni) },
480 { MP_OBJ_NEW_QSTR(MP_QSTR_cls), (mp_obj_t)&mod_jni_cls_obj },
Paul Sokolovskycb6cf5e2015-09-16 01:09:39 +0300481 { MP_OBJ_NEW_QSTR(MP_QSTR_env), (mp_obj_t)&mod_jni_env_obj },
Paul Sokolovskye79c6b62015-09-11 17:57:47 +0300482};
483
484STATIC MP_DEFINE_CONST_DICT(mp_module_jni_globals, mp_module_jni_globals_table);
485
486const mp_obj_module_t mp_module_jni = {
487 .base = { &mp_type_module },
488 .name = MP_QSTR_jni,
489 .globals = (mp_obj_dict_t*)&mp_module_jni_globals,
490};