Skip to content

Commit c8026f9

Browse files
authored
Merge pull request RustPython#718 from RustPython/master
Update the demo page, since we have a new shiny console added!
2 parents 1929bc0 + 8f6d8a7 commit c8026f9

File tree

138 files changed

+10152
-6873
lines changed

Some content is hidden

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

138 files changed

+10152
-6873
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target
2+
/*/target
23
**/*.rs.bk
34
**/*.bytecode
45
__pycache__

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ matrix:
115115
- TRAVIS_RUST_VERSION=nightly
116116
- REGULAR_TEST=false
117117
- CODE_COVERAGE=true
118+
- name: test WASM
119+
language: python
120+
python: 3.6
121+
cache:
122+
pip: true
123+
# Because we're using the Python Travis environment, we can't use
124+
# the built-in cargo cacher
125+
directories:
126+
- /home/travis/.cargo
127+
- target
128+
addons:
129+
firefox: latest
130+
install:
131+
- nvm install node
132+
- pip install pipenv
133+
script:
134+
- wasm/tests/.travis-runner.sh
135+
env:
136+
- REGULAR_TEST=true
137+
- TRAVIS_RUST_VERSION=stable
118138
allow_failures:
119139
- rust: nightly
120140
env: REGULAR_TEST=true

Cargo.lock

Lines changed: 86 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Windel Bouwman", "Shing Lyu <[email protected]>"]
55
edition = "2018"
66

77
[workspace]
8-
members = [".", "vm", "wasm/lib", "parser"]
8+
members = [".", "derive", "vm", "wasm/lib", "parser"]
99

1010
[dependencies]
1111
log="0.4.1"
@@ -15,6 +15,3 @@ rustpython_parser = {path = "parser"}
1515
rustpython_vm = {path = "vm"}
1616
rustyline = "2.1.0"
1717
xdg = "2.2.0"
18-
19-
[profile.release]
20-
opt-level = "s"

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ $ pipenv install
9797
$ pipenv run pytest -v
9898
```
9999

100-
There also are some unit tests, you can run those will cargo:
100+
There also are some unit tests, you can run those with cargo:
101101

102102
```shell
103103
$ cargo test --all
@@ -201,6 +201,10 @@ The code style used is the default rustfmt codestyle. Please format your code ac
201201

202202
Chat with us on [gitter][gitter].
203203

204+
# Code of conduct
205+
206+
Our code of conduct [can be found here](code-of-conduct.md).
207+
204208
# Credit
205209

206210
The initial work was based on [windelbouwman/rspython](https://github.com/windelbouwman/rspython) and [shinglyu/RustPython](https://github.com/shinglyu/RustPython)

code-of-conduct.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq
77+

derive/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "rustpython_derive"
3+
version = "0.1.0"
4+
authors = ["Joey <[email protected]>"]
5+
edition = "2018"
6+
7+
[lib]
8+
proc-macro = true
9+
10+
[dependencies]
11+
syn = "0.15.29"
12+
quote = "0.6.11"
13+
proc-macro2 = "0.4.27"

derive/src/lib.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
extern crate proc_macro;
2+
3+
use proc_macro::TokenStream;
4+
use proc_macro2::TokenStream as TokenStream2;
5+
use quote::quote;
6+
use syn::{Data, DeriveInput, Fields};
7+
8+
#[proc_macro_derive(FromArgs)]
9+
pub fn derive_from_args(input: TokenStream) -> TokenStream {
10+
let ast: DeriveInput = syn::parse(input).unwrap();
11+
12+
let gen = impl_from_args(&ast);
13+
gen.to_string().parse().unwrap()
14+
}
15+
16+
fn impl_from_args(input: &DeriveInput) -> TokenStream2 {
17+
// FIXME: This references types using `crate` instead of `rustpython_vm`
18+
// so that it can be used in the latter. How can we support both?
19+
let fields = match input.data {
20+
Data::Struct(ref data) => {
21+
match data.fields {
22+
Fields::Named(ref fields) => fields.named.iter().map(|field| {
23+
let name = &field.ident;
24+
quote! {
25+
#name: crate::pyobject::TryFromObject::try_from_object(
26+
vm,
27+
args.take_keyword(stringify!(#name)).unwrap_or_else(|| vm.ctx.none())
28+
)?,
29+
}
30+
}),
31+
Fields::Unnamed(_) | Fields::Unit => unimplemented!(), // TODO: better error message
32+
}
33+
}
34+
Data::Enum(_) | Data::Union(_) => unimplemented!(), // TODO: better error message
35+
};
36+
37+
let name = &input.ident;
38+
quote! {
39+
impl crate::function::FromArgs for #name {
40+
fn from_args(
41+
vm: &crate::vm::VirtualMachine,
42+
args: &mut crate::function::PyFuncArgs
43+
) -> Result<Self, crate::function::ArgumentError> {
44+
Ok(#name { #(#fields)* })
45+
}
46+
}
47+
}
48+
}

parser/src/ast.rs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ pub enum Statement {
122122
// docstring: String,
123123
body: Vec<LocatedStatement>,
124124
decorator_list: Vec<Expression>,
125+
returns: Option<Expression>,
125126
},
126127
}
127128

@@ -217,6 +218,7 @@ pub enum Expression {
217218
True,
218219
False,
219220
None,
221+
Ellipsis,
220222
}
221223

222224
impl Expression {
@@ -259,6 +261,7 @@ impl Expression {
259261
Lambda { .. } => "lambda",
260262
IfExpression { .. } => "conditional expression",
261263
True | False | None => "keyword",
264+
Ellipsis => "ellipsis",
262265
}
263266
}
264267
}
@@ -269,14 +272,20 @@ impl Expression {
269272
*/
270273
#[derive(Debug, PartialEq, Default)]
271274
pub struct Parameters {
272-
pub args: Vec<String>,
273-
pub kwonlyargs: Vec<String>,
274-
pub vararg: Option<Option<String>>, // Optionally we handle optionally named '*args' or '*'
275-
pub kwarg: Option<Option<String>>,
275+
pub args: Vec<Parameter>,
276+
pub kwonlyargs: Vec<Parameter>,
277+
pub vararg: Varargs, // Optionally we handle optionally named '*args' or '*'
278+
pub kwarg: Varargs,
276279
pub defaults: Vec<Expression>,
277280
pub kw_defaults: Vec<Option<Expression>>,
278281
}
279282

283+
#[derive(Debug, PartialEq, Default)]
284+
pub struct Parameter {
285+
pub arg: String,
286+
pub annotation: Option<Box<Expression>>,
287+
}
288+
280289
#[derive(Debug, PartialEq)]
281290
pub enum ComprehensionKind {
282291
GeneratorExpression { element: Expression },
@@ -357,16 +366,53 @@ pub enum Number {
357366
Complex { real: f64, imag: f64 },
358367
}
359368

369+
/// Transforms a value prior to formatting it.
370+
#[derive(Copy, Clone, Debug, PartialEq)]
371+
pub enum ConversionFlag {
372+
/// Converts by calling `str(<value>)`.
373+
Str,
374+
/// Converts by calling `ascii(<value>)`.
375+
Ascii,
376+
/// Converts by calling `repr(<value>)`.
377+
Repr,
378+
}
379+
360380
#[derive(Debug, PartialEq)]
361381
pub enum StringGroup {
362382
Constant {
363383
value: String,
364384
},
365385
FormattedValue {
366386
value: Box<Expression>,
387+
conversion: Option<ConversionFlag>,
367388
spec: String,
368389
},
369390
Joined {
370391
values: Vec<StringGroup>,
371392
},
372393
}
394+
395+
#[derive(Debug, PartialEq)]
396+
pub enum Varargs {
397+
None,
398+
Unnamed,
399+
Named(Parameter),
400+
}
401+
402+
impl Default for Varargs {
403+
fn default() -> Varargs {
404+
Varargs::None
405+
}
406+
}
407+
408+
impl From<Option<Option<Parameter>>> for Varargs {
409+
fn from(opt: Option<Option<Parameter>>) -> Varargs {
410+
match opt {
411+
Some(inner_opt) => match inner_opt {
412+
Some(param) => Varargs::Named(param),
413+
None => Varargs::Unnamed,
414+
},
415+
None => Varargs::None,
416+
}
417+
}
418+
}

0 commit comments

Comments
 (0)