Numworks Epsilon
1.4.1
Graphing Calculator Operating System
scope.h
Go to the documentation of this file.
1
/*
2
* This file is part of the MicroPython project, http://micropython.org/
3
*
4
* The MIT License (MIT)
5
*
6
* Copyright (c) 2013, 2014 Damien P. George
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
#ifndef MICROPY_INCLUDED_PY_SCOPE_H
27
#define MICROPY_INCLUDED_PY_SCOPE_H
28
29
#include "
py/parse.h
"
30
#include "
py/emitglue.h
"
31
32
enum
{
33
ID_INFO_KIND_GLOBAL_IMPLICIT
,
34
ID_INFO_KIND_GLOBAL_EXPLICIT
,
35
ID_INFO_KIND_LOCAL
,
// in a function f, written and only referenced by f
36
ID_INFO_KIND_CELL
,
// in a function f, read/written by children of f
37
ID_INFO_KIND_FREE
,
// in a function f, belongs to the parent of f
38
};
39
40
enum
{
41
ID_FLAG_IS_PARAM
= 0x01,
42
ID_FLAG_IS_STAR_PARAM
= 0x02,
43
ID_FLAG_IS_DBL_STAR_PARAM
= 0x04,
44
};
45
46
typedef
struct
_id_info_t
{
47
uint8_t
kind
;
48
uint8_t
flags
;
49
// when it's an ID_INFO_KIND_LOCAL this is the unique number of the local
50
// whet it's an ID_INFO_KIND_CELL/FREE this is the unique number of the closed over variable
51
uint16_t
local_num
;
52
qstr
qst
;
53
}
id_info_t
;
54
55
#define SCOPE_IS_FUNC_LIKE(s) ((s) >= SCOPE_LAMBDA)
56
57
// scope is a "block" in Python parlance
58
typedef
enum
{
59
SCOPE_MODULE
,
60
SCOPE_CLASS
,
61
SCOPE_LAMBDA
,
62
SCOPE_LIST_COMP
,
63
SCOPE_DICT_COMP
,
64
SCOPE_SET_COMP
,
65
SCOPE_GEN_EXPR
,
66
SCOPE_FUNCTION
,
67
}
scope_kind_t
;
68
69
typedef
struct
_scope_t
{
70
scope_kind_t
kind
;
71
struct
_scope_t
*
parent
;
72
struct
_scope_t
*
next
;
73
mp_parse_node_t
pn
;
74
uint16_t
source_file
;
// a qstr
75
uint16_t
simple_name
;
// a qstr
76
mp_raw_code_t
*
raw_code
;
77
uint8_t
scope_flags
;
// see runtime0.h
78
uint8_t
emit_options
;
// see compile.h
79
uint16_t
num_pos_args
;
80
uint16_t
num_kwonly_args
;
81
uint16_t
num_def_pos_args
;
82
uint16_t
num_locals
;
83
uint16_t
stack_size
;
// maximum size of the locals stack
84
uint16_t
exc_stack_size
;
// maximum size of the exception stack
85
uint16_t
id_info_alloc
;
86
uint16_t
id_info_len
;
87
id_info_t
*
id_info
;
88
}
scope_t
;
89
90
scope_t
*
scope_new
(
scope_kind_t
kind
,
mp_parse_node_t
pn
,
qstr
source_file
,
mp_uint_t
emit_options
);
91
void
scope_free
(
scope_t
*scope);
92
id_info_t
*
scope_find_or_add_id
(
scope_t
*scope,
qstr
qstr
,
bool
*added);
93
id_info_t
*
scope_find
(
scope_t
*scope,
qstr
qstr
);
94
id_info_t
*
scope_find_global
(
scope_t
*scope,
qstr
qstr
);
95
void
scope_find_local_and_close_over
(
scope_t
*scope,
id_info_t
*
id
,
qstr
qst);
96
97
#endif // MICROPY_INCLUDED_PY_SCOPE_H
_scope_t::num_locals
uint16_t num_locals
Definition:
scope.h:82
_scope_t::pn
mp_parse_node_t pn
Definition:
scope.h:73
mp_uint_t
uintptr_t mp_uint_t
Definition:
mpconfigport.h:74
scope_find_global
id_info_t * scope_find_global(scope_t *scope, qstr qstr)
_scope_t::id_info_len
uint16_t id_info_len
Definition:
scope.h:86
_id_info_t::qst
qstr qst
Definition:
scope.h:52
_scope_t::exc_stack_size
uint16_t exc_stack_size
Definition:
scope.h:84
_scope_t::simple_name
uint16_t simple_name
Definition:
scope.h:75
_scope_t::kind
scope_kind_t kind
Definition:
scope.h:70
ID_INFO_KIND_CELL
Definition:
scope.h:36
SCOPE_MODULE
Definition:
scope.h:59
SCOPE_FUNCTION
Definition:
scope.h:66
parse.h
ID_INFO_KIND_FREE
Definition:
scope.h:37
_scope_t::emit_options
uint8_t emit_options
Definition:
scope.h:78
uint16_t
unsigned short uint16_t
Definition:
stdint.h:5
SCOPE_GEN_EXPR
Definition:
scope.h:65
_scope_t::id_info_alloc
uint16_t id_info_alloc
Definition:
scope.h:85
uint8_t
unsigned char uint8_t
Definition:
stdint.h:4
_scope_t::scope_flags
uint8_t scope_flags
Definition:
scope.h:77
mp_parse_node_t
uintptr_t mp_parse_node_t
Definition:
parse.h:52
_scope_t::num_kwonly_args
uint16_t num_kwonly_args
Definition:
scope.h:80
scope_find
id_info_t * scope_find(scope_t *scope, qstr qstr)
_mp_raw_code_t
Definition:
emitglue.h:42
_scope_t::id_info
id_info_t * id_info
Definition:
scope.h:87
SCOPE_CLASS
Definition:
scope.h:60
SCOPE_LIST_COMP
Definition:
scope.h:62
SCOPE_DICT_COMP
Definition:
scope.h:63
_scope_t::raw_code
mp_raw_code_t * raw_code
Definition:
scope.h:76
qstr
size_t qstr
Definition:
qstr.h:48
ID_INFO_KIND_LOCAL
Definition:
scope.h:35
scope_find_or_add_id
id_info_t * scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added)
scope_free
void scope_free(scope_t *scope)
_scope_t::num_pos_args
uint16_t num_pos_args
Definition:
scope.h:79
ID_INFO_KIND_GLOBAL_EXPLICIT
Definition:
scope.h:34
scope_new
scope_t * scope_new(scope_kind_t kind, mp_parse_node_t pn, qstr source_file, mp_uint_t emit_options)
ID_FLAG_IS_DBL_STAR_PARAM
Definition:
scope.h:43
_id_info_t
Definition:
scope.h:46
scope_kind_t
scope_kind_t
Definition:
scope.h:58
SCOPE_LAMBDA
Definition:
scope.h:61
_scope_t
Definition:
scope.h:69
_scope_t::parent
struct _scope_t * parent
Definition:
scope.h:71
_id_info_t::kind
uint8_t kind
Definition:
scope.h:47
scope_t
struct _scope_t scope_t
scope_find_local_and_close_over
void scope_find_local_and_close_over(scope_t *scope, id_info_t *id, qstr qst)
ID_FLAG_IS_STAR_PARAM
Definition:
scope.h:42
ID_INFO_KIND_GLOBAL_IMPLICIT
Definition:
scope.h:33
emitglue.h
ID_FLAG_IS_PARAM
Definition:
scope.h:41
_id_info_t::flags
uint8_t flags
Definition:
scope.h:48
id_info_t
struct _id_info_t id_info_t
_scope_t::stack_size
uint16_t stack_size
Definition:
scope.h:83
SCOPE_SET_COMP
Definition:
scope.h:64
_id_info_t::local_num
uint16_t local_num
Definition:
scope.h:51
_scope_t::source_file
uint16_t source_file
Definition:
scope.h:74
_scope_t::num_def_pos_args
uint16_t num_def_pos_args
Definition:
scope.h:81
_scope_t::next
struct _scope_t * next
Definition:
scope.h:72
epsilon
python
src
py
scope.h
Generated by
1.8.14