Skip to content

Commit caac5a3

Browse files
Merge branch 'master' into tuple_add
2 parents b13b474 + 44e9658 commit caac5a3

23 files changed

+495
-86
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ __pycache__
55
**/*.pytest_cache
66
.*sw*
77
.repl_history.txt
8+
.vscode
89
wasm-pack.log

Cargo.lock

Lines changed: 7 additions & 0 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ clap = "2.31.2"
1313
rustpython_parser = {path = "parser"}
1414
rustpython_vm = {path = "vm"}
1515
rustyline = "2.1.0"
16+
xdg = "2.2.0"
1617

1718
[profile.release]
1819
opt-level = "s"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ If you wish to update the online documentation. Push directly to the `release` b
5656
- `obj`: python builtin types
5757
- `src`: using the other subcrates to bring rustpython to life.
5858
- `docs`: documentation (work in progress)
59-
- `py_code_object`: CPython bytecode to rustpython bytecode convertor (work in progress)
59+
- `py_code_object`: CPython bytecode to rustpython bytecode converter (work in progress)
6060
- `wasm`: Binary crate and resources for WebAssembly build
6161
- `tests`: integration test snippets
6262

@@ -81,8 +81,8 @@ To test rustpython, there is a collection of python snippets located in the
8181

8282
```shell
8383
$ cd tests
84-
$ pipenv shell
85-
$ pytest -v
84+
$ pipenv install
85+
$ pipenv run pytest -v
8686
```
8787

8888
There also are some unittests, you can run those will cargo:

docs/builtins.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Byterun
22

3-
* Builtins are exposted to frame.f_builtins
3+
* Builtins are exposed to frame.f_builtins
44
* f_builtins is assigned during frame creation,
55
self.f_builtins = f_locals['__builtins__']
66
if hasattr(self.f_builtins, '__dict__'):
@@ -21,10 +21,10 @@ TODO:
2121
* Implement a new type NativeFunction
2222
* Wrap a function pointer in NativeFunction
2323
* Refactor the CALL_FUNCTION case so it can call both python function and native function
24-
* During frame creation, force push a nativefunction `print` into the namespace
24+
* During frame creation, force push a native function `print` into the namespace
2525
* Modify LOAD_* so they can search for names in builtins
2626

2727
* Create a module type
2828
* In VM initialization, load the builtins module into locals
29-
* During frame creation, create a field that conatins the builtins dict
29+
* During frame creation, create a field that contains the builtins dict
3030

parser/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub enum Expression {
221221

222222
/*
223223
* In cpython this is called arguments, but we choose parameters to
224-
* distuingish between function parameters and actual call arguments.
224+
* distinguish between function parameters and actual call arguments.
225225
*/
226226
#[derive(Debug, PartialEq, Default)]
227227
pub struct Parameters {

src/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern crate log;
77
extern crate rustpython_parser;
88
extern crate rustpython_vm;
99
extern crate rustyline;
10+
extern crate xdg;
1011

1112
use clap::{App, Arg};
1213
use rustpython_parser::parser;
@@ -154,9 +155,10 @@ fn run_shell(vm: &mut VirtualMachine) -> PyResult {
154155
let mut input = String::new();
155156
let mut rl = Editor::<()>::new();
156157

157-
// TODO: Store the history in a proper XDG directory
158-
let repl_history_path = ".repl_history.txt";
159-
if rl.load_history(repl_history_path).is_err() {
158+
let xdg_dirs = xdg::BaseDirectories::with_prefix("rustpython").unwrap();
159+
let repl_history_path = xdg_dirs.place_cache_file("repl_history.txt").unwrap();
160+
let repl_history_path_str = repl_history_path.to_str().unwrap();
161+
if rl.load_history(repl_history_path_str).is_err() {
160162
println!("No previous history.");
161163
}
162164

@@ -220,7 +222,7 @@ fn run_shell(vm: &mut VirtualMachine) -> PyResult {
220222
}
221223
};
222224
}
223-
rl.save_history(repl_history_path).unwrap();
225+
rl.save_history(repl_history_path_str).unwrap();
224226

225227
Ok(vm.get_none())
226228
}

tests/snippets/basic_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
assert type(a) is complex
4646
assert type(a + a) is complex
4747

48+
a = 1
49+
assert a.conjugate() == a
4850

4951
a = 12345
5052

tests/snippets/bools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ def __bool__(self):
4646
assert False * 7 == 0
4747
assert True > 0
4848
assert int(True) == 1
49+
assert True.conjugate() == 1
50+
assert isinstance(True.conjugate(), int)

tests/snippets/list.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
assert y == [2, 1, 2, 3, 1, 2, 3]
1111

1212
assert x * 0 == [], "list __mul__ by 0 failed"
13+
assert x * -1 == [], "list __mul__ by -1 failed"
1314
assert x * 2 == [1, 2, 3, 1, 2, 3], "list __mul__ by 2 failed"
1415

1516
assert ['a', 'b', 'c'].index('b') == 1
@@ -20,3 +21,20 @@
2021
pass
2122
else:
2223
assert False, "ValueError was not raised"
24+
25+
x = [[1,0,-3], 'a', 1]
26+
y = [[3,2,1], 'z', 2]
27+
assert x < y, "list __lt__ failed"
28+
29+
x = [5, 13, 31]
30+
y = [1, 10, 29]
31+
assert x > y, "list __gt__ failed"
32+
33+
34+
assert [1,2,'a'].pop() == 'a', "list pop failed"
35+
try:
36+
[].pop()
37+
except IndexError:
38+
pass
39+
else:
40+
assert False, "IndexError was not raised"

0 commit comments

Comments
 (0)