<commit_before>#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "py/nlr.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/repl.h"
#include "py/gc.h"
#include "lib/utils/pyexec.h"
#include "readline.h"
#include "wiring.h"


void do_str(const char *src, mp_parse_input_kind_t input_kind) {
    mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
    if (lex == NULL) {
        printf("MemoryError: lexer could not allocate memory\n");
        return;
    }

    nlr_buf_t nlr;
    if (nlr_push(&nlr) == 0) {
        qstr source_name = lex->source_name;
        mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
        mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true);
        mp_call_function_0(module_fun);
        nlr_pop();
    } else {
        // uncaught exception
        mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
    }
}

static char *stack_top;
static char heap[16*1024];

void mp_setup() {
    int stack_dummy;
    stack_top = (char*)&stack_dummy;

#if MICROPY_ENABLE_GC
    gc_init(heap, heap + sizeof(heap));
#endif

    mp_init();
    readline_init0(); 

#if MICROPY_REPL_EVENT_DRIVEN
    pyexec_event_repl_init();
#endif

    usbserial_begin(9600);
}

static bool pyexec_exit = false;

void mp_loop() {
    if(!pyexec_exit) {
#if MICROPY_REPL_EVENT_DRIVEN
        for (;;) {
            int c = mp_hal_stdin_rx_chr();
            if (pyexec_event_repl_process_char(c)) {
                break;
            }
        }
#else
        pyexec_friendly_repl();
#endif

        mp_deinit();
        // pyexec_exit = true;
    }
}<commit_msg>duo/wiring.c: fix ExtInt initialization issue, if micropython performs a soft reset.<commit_after>#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "py/nlr.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/repl.h"
#include "py/gc.h"
#include "lib/utils/pyexec.h"
#include "readline.h"
#include "wiring.h"


void do_str(const char *src, mp_parse_input_kind_t input_kind) {
    mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
    if (lex == NULL) {
        printf("MemoryError: lexer could not allocate memory\n");
        return;
    }

    nlr_buf_t nlr;
    if (nlr_push(&nlr) == 0) {
        qstr source_name = lex->source_name;
        mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
        mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true);
        mp_call_function_0(module_fun);
        nlr_pop();
    } else {
        // uncaught exception
        mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
    }
}

static char *stack_top;
static char heap[16*1024];

void mp_setup() {
    int stack_dummy;
    stack_top = (char*)&stack_dummy;

#if MICROPY_ENABLE_GC
    gc_init(heap, heap + sizeof(heap));
#endif

    mp_init();
    readline_init0(); 
    extint_init0();

#if MICROPY_REPL_EVENT_DRIVEN
    pyexec_event_repl_init();
#endif

    usbserial_begin(9600);
}

static bool pyexec_exit = false;

void mp_loop() {
    if(!pyexec_exit) {
#if MICROPY_REPL_EVENT_DRIVEN
        for (;;) {
            int c = mp_hal_stdin_rx_chr();
            if (pyexec_event_repl_process_char(c)) {
                break;
            }
        }
#else
        pyexec_friendly_repl();
#endif

        mp_deinit();
        // pyexec_exit = true;
    }
}
{'fraction_non_alphanumeric': 0.12409394027254277, 'fraction_numerical': 0.008408234270803132, 'mean_word_length': 3.073199527744982, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7337574', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1336, 'n_words': 243}