|
| 1 | +#include <stdint.h> |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | + |
| 5 | +#include "mpconfig.h" |
| 6 | +#include "nlr.h" |
| 7 | +#include "misc.h" |
| 8 | +#include "qstr.h" |
| 9 | +#include "lexer.h" |
| 10 | +#include "parse.h" |
| 11 | +#include "obj.h" |
| 12 | +#include "parsehelper.h" |
| 13 | +#include "compile.h" |
| 14 | +#include "runtime0.h" |
| 15 | +#include "runtime.h" |
| 16 | +#include "repl.h" |
| 17 | + |
| 18 | +#include "tinytest.h" |
| 19 | +#include "tinytest_macros.h" |
| 20 | + |
| 21 | +inline void do_str(const char *src) { |
| 22 | + mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); |
| 23 | + if (lex == NULL) { |
| 24 | + tt_abort_msg("Lexer initialization error"); |
| 25 | + } |
| 26 | + |
| 27 | + mp_parse_error_kind_t parse_error_kind; |
| 28 | + mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT, &parse_error_kind); |
| 29 | + |
| 30 | + if (pn == MP_PARSE_NODE_NULL) { |
| 31 | + mp_parse_show_exception(lex, parse_error_kind); |
| 32 | + mp_lexer_free(lex); |
| 33 | + tt_abort_msg("Parser error"); |
| 34 | + } |
| 35 | + |
| 36 | + // parse okay |
| 37 | + qstr source_name = mp_lexer_source_name(lex); |
| 38 | + mp_lexer_free(lex); |
| 39 | + mp_obj_t module_fun = mp_compile(pn, source_name, MP_EMIT_OPT_NONE, true); |
| 40 | + mp_parse_node_free(pn); |
| 41 | + |
| 42 | + if (module_fun == mp_const_none) { |
| 43 | + tt_abort_msg("Computer error"); |
| 44 | + } |
| 45 | + |
| 46 | + nlr_buf_t nlr; |
| 47 | + if (nlr_push(&nlr) == 0) { |
| 48 | + mp_call_function_0(module_fun); |
| 49 | + nlr_pop(); |
| 50 | + } else { |
| 51 | + mp_obj_print_exception((mp_obj_t)nlr.ret_val); |
| 52 | + tt_abort_msg("Uncaught exception"); |
| 53 | + } |
| 54 | +end: |
| 55 | + ; |
| 56 | +} |
| 57 | + |
| 58 | +#include "genhdr/tests.h" |
| 59 | + |
| 60 | +int main() { |
| 61 | + const char a[] = {"sim"}; |
| 62 | + qstr_init(); |
| 63 | + mp_init(); |
| 64 | + int r = tinytest_main(1, (const char **) a, groups); |
| 65 | + mp_deinit(); |
| 66 | + printf( "status: %i\n", r); |
| 67 | + return r; |
| 68 | +} |
| 69 | + |
| 70 | +void gc_collect(void) { |
| 71 | +} |
| 72 | + |
| 73 | +mp_lexer_t *mp_lexer_new_from_file(const char *filename) { |
| 74 | + return NULL; |
| 75 | +} |
| 76 | + |
| 77 | +mp_import_stat_t mp_import_stat(const char *path) { |
| 78 | + return MP_IMPORT_STAT_NO_EXIST; |
| 79 | +} |
| 80 | + |
| 81 | +mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args) { |
| 82 | + return mp_const_none; |
| 83 | +} |
| 84 | +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_open_obj, 1, 2, mp_builtin_open); |
| 85 | + |
| 86 | +void nlr_jump_fail(void *val) { |
| 87 | +} |
0 commit comments