Skip to content

Commit 53c48bf

Browse files
committed
reorganize compiler crates
1 parent ffacac0 commit 53c48bf

66 files changed

Lines changed: 12079 additions & 152 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.toml‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
[package]
2-
name = "rustpython-compiler-core"
2+
name = "rustpython-compiler"
33
version = "0.1.2"
4-
description = "Compiler for python code into bytecode for the rustpython VM."
4+
description = "A usability wrapper around rustpython-parser and rustpython-compiler-core"
55
authors = ["RustPython Team"]
6-
repository = "https://github.com/RustPython/RustPython"
7-
license = "MIT"
86
edition = "2021"
97

108
[dependencies]
11-
indexmap = "1.8.1"
12-
itertools = "0.10.3"
13-
rustpython-bytecode = { path = "../bytecode", version = "0.1.1" }
14-
rustpython-ast = { path = "../ast", features = ["unparse"] }
15-
num-complex = { version = "0.4.0", features = ["serde"] }
16-
num-traits = "0.2.14"
17-
log = "0.4.16"
18-
ahash = "0.7.6"
19-
20-
[dev-dependencies]
21-
rustpython-parser = { path = "../parser" }
22-
insta = "1.14.0"
9+
thiserror = "1.0"
10+
rustpython-codegen = { path = "codegen" }
11+
rustpython-parser = { path = "parser" }
12+
rustpython-bytecode = { path = "bytecode" }

‎ast/Cargo.toml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "rustpython-ast"
3+
version = "0.1.0"
4+
authors = ["RustPython Team"]
5+
edition = "2021"
6+
7+
[features]
8+
default = ["constant-optimization", "fold"]
9+
constant-optimization = ["fold"]
10+
fold = []
11+
unparse = ["rustpython-common"]
12+
13+
[dependencies]
14+
num-bigint = "0.4.3"
15+
rustpython-common = { path = "../../common", optional = true }
16+
rustpython-bytecode = { path = "../bytecode"}

‎ast/Python.asdl‎

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
-- ASDL's 4 builtin types are:
2+
-- identifier, int, string, constant
3+
4+
module Python
5+
{
6+
mod = Module(stmt* body, type_ignore* type_ignores)
7+
| Interactive(stmt* body)
8+
| Expression(expr body)
9+
| FunctionType(expr* argtypes, expr returns)
10+
11+
stmt = FunctionDef(identifier name, arguments args,
12+
stmt* body, expr* decorator_list, expr? returns,
13+
string? type_comment)
14+
| AsyncFunctionDef(identifier name, arguments args,
15+
stmt* body, expr* decorator_list, expr? returns,
16+
string? type_comment)
17+
18+
| ClassDef(identifier name,
19+
expr* bases,
20+
keyword* keywords,
21+
stmt* body,
22+
expr* decorator_list)
23+
| Return(expr? value)
24+
25+
| Delete(expr* targets)
26+
| Assign(expr* targets, expr value, string? type_comment)
27+
| AugAssign(expr target, operator op, expr value)
28+
-- 'simple' indicates that we annotate simple name without parens
29+
| AnnAssign(expr target, expr annotation, expr? value, int simple)
30+
31+
-- use 'orelse' because else is a keyword in target languages
32+
| For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
33+
| AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
34+
| While(expr test, stmt* body, stmt* orelse)
35+
| If(expr test, stmt* body, stmt* orelse)
36+
| With(withitem* items, stmt* body, string? type_comment)
37+
| AsyncWith(withitem* items, stmt* body, string? type_comment)
38+
39+
| Match(expr subject, match_case* cases)
40+
41+
| Raise(expr? exc, expr? cause)
42+
| Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
43+
| Assert(expr test, expr? msg)
44+
45+
| Import(alias* names)
46+
| ImportFrom(identifier? module, alias* names, int? level)
47+
48+
| Global(identifier* names)
49+
| Nonlocal(identifier* names)
50+
| Expr(expr value)
51+
| Pass | Break | Continue
52+
53+
-- col_offset is the byte offset in the utf8 string the parser uses
54+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
55+
56+
-- BoolOp() can use left & right?
57+
expr = BoolOp(boolop op, expr* values)
58+
| NamedExpr(expr target, expr value)
59+
| BinOp(expr left, operator op, expr right)
60+
| UnaryOp(unaryop op, expr operand)
61+
| Lambda(arguments args, expr body)
62+
| IfExp(expr test, expr body, expr orelse)
63+
| Dict(expr* keys, expr* values)
64+
| Set(expr* elts)
65+
| ListComp(expr elt, comprehension* generators)
66+
| SetComp(expr elt, comprehension* generators)
67+
| DictComp(expr key, expr value, comprehension* generators)
68+
| GeneratorExp(expr elt, comprehension* generators)
69+
-- the grammar constrains where yield expressions can occur
70+
| Await(expr value)
71+
| Yield(expr? value)
72+
| YieldFrom(expr value)
73+
-- need sequences for compare to distinguish between
74+
-- x < 4 < 3 and (x < 4) < 3
75+
| Compare(expr left, cmpop* ops, expr* comparators)
76+
| Call(expr func, expr* args, keyword* keywords)
77+
| FormattedValue(expr value, int conversion, expr? format_spec)
78+
| JoinedStr(expr* values)
79+
| Constant(constant value, string? kind)
80+
81+
-- the following expression can appear in assignment context
82+
| Attribute(expr value, identifier attr, expr_context ctx)
83+
| Subscript(expr value, expr slice, expr_context ctx)
84+
| Starred(expr value, expr_context ctx)
85+
| Name(identifier id, expr_context ctx)
86+
| List(expr* elts, expr_context ctx)
87+
| Tuple(expr* elts, expr_context ctx)
88+
89+
-- can appear only in Subscript
90+
| Slice(expr? lower, expr? upper, expr? step)
91+
92+
-- col_offset is the byte offset in the utf8 string the parser uses
93+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
94+
95+
expr_context = Load | Store | Del
96+
97+
boolop = And | Or
98+
99+
operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
100+
| RShift | BitOr | BitXor | BitAnd | FloorDiv
101+
102+
unaryop = Invert | Not | UAdd | USub
103+
104+
cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
105+
106+
comprehension = (expr target, expr iter, expr* ifs, int is_async)
107+
108+
excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
109+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
110+
111+
arguments = (arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs,
112+
expr* kw_defaults, arg? kwarg, expr* defaults)
113+
114+
arg = (identifier arg, expr? annotation, string? type_comment)
115+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
116+
117+
-- keyword arguments supplied to call (NULL identifier for **kwargs)
118+
keyword = (identifier? arg, expr value)
119+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
120+
121+
-- import name with optional 'as' alias.
122+
alias = (identifier name, identifier? asname)
123+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
124+
125+
withitem = (expr context_expr, expr? optional_vars)
126+
127+
match_case = (pattern pattern, expr? guard, stmt* body)
128+
129+
pattern = MatchValue(expr value)
130+
| MatchSingleton(constant value)
131+
| MatchSequence(pattern* patterns)
132+
| MatchMapping(expr* keys, pattern* patterns, identifier? rest)
133+
| MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)
134+
135+
| MatchStar(identifier? name)
136+
-- The optional "rest" MatchMapping parameter handles capturing extra mapping keys
137+
138+
| MatchAs(pattern? pattern, identifier? name)
139+
| MatchOr(pattern* patterns)
140+
141+
attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
142+
143+
type_ignore = TypeIgnore(int lineno, string tag)
144+
}

0 commit comments

Comments
 (0)