[SOLVED]what is MP_QSTR__lt_stdin_gt_

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
jickster
Posts: 106
Joined: Thu Sep 07, 2017 8:57 pm

[SOLVED]what is MP_QSTR__lt_stdin_gt_

Post by jickster » Wed Dec 13, 2017 4:43 pm

Code: Select all

#if MICROPY_ENABLE_COMPILER
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
    nlr_buf_t nlr;
    if (nlr_push(&nlr) == 0) {
        mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 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);
    }
}
#endif
I know it's a qstring

Code: Select all

QDEF(MP_QSTR__lt_stdin_gt_, (const byte*)"\xe3\x07" "<stdin>")
but is a "special" value? i.e. when you pass it in to

Code: Select all

mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, size_t len, size_t free_len) {
    mp_reader_t reader;
    mp_reader_new_mem(&reader, (const byte*)str, len, free_len);
    return mp_lexer_new(src_name, reader);
}

mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader) {
    mp_lexer_t *lex = m_new_obj(mp_lexer_t);

    lex->source_name = src_name;
    ...

does it have some special side effects?
Last edited by jickster on Wed Dec 13, 2017 8:25 pm, edited 1 time in total.

User avatar
dhylands
Posts: 2569
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: what is MP_QSTR__lt_stdin_gt_

Post by dhylands » Wed Dec 13, 2017 6:39 pm

The reason that it's "special" is that the less-than and greater than signs make it non-parseable as a regular symbol. There is a script which will look for usages of MP_QSTR_foo and create a qstr for "foo". But since you can't have MP_QSTR_<stdin> as a valid symbol in C, we needed to allow another mechanism to map it.

The use of <stdin> is just to differentiate it from a real filename, since <stdin> isn't considered a valid filename. It's also what python 3 uses. For example:

Code: Select all

Python 3.5.3 (default, Sep 24 2017, 15:18:48) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> prnt(xxx)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'prnt' is not defined
>>> 

jickster
Posts: 106
Joined: Thu Sep 07, 2017 8:57 pm

Re: what is MP_QSTR__lt_stdin_gt_

Post by jickster » Wed Dec 13, 2017 8:25 pm

dhylands wrote:
Wed Dec 13, 2017 6:39 pm
The reason that it's "special" is that the less-than and greater than signs make it non-parseable as a regular symbol. There is a script which will look for usages of MP_QSTR_foo and create a qstr for "foo". But since you can't have MP_QSTR_<stdin> as a valid symbol in C, we needed to allow another mechanism to map it.

The use of <stdin> is just to differentiate it from a real filename, since <stdin> isn't considered a valid filename. It's also what python 3 uses. For example:

Code: Select all

Python 3.5.3 (default, Sep 24 2017, 15:18:48) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> prnt(xxx)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'prnt' is not defined
>>> 
Thanks! Your replies are greatly appreciated :)

Post Reply