Skip to content
This repository was archived by the owner on May 5, 2023. It is now read-only.

Commit 9b4bc88

Browse files
author
Shing Lyu
committed
Merge branch 'master' of github.com:shinglyu/RustPython
2 parents 75567f5 + c913206 commit 9b4bc88

File tree

7 files changed

+328
-116
lines changed

7 files changed

+328
-116
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ A Python interpreter written in Rust
66
# Installation
77

88
```
9-
virtualenv venv --python=python3
10-
source venv/bin/activate
11-
pip install bytecode
9+
bash init_env.sh
1210
```
1311

1412
# Run
1513

1614
```
1715
./test.sh <path/to/file.py> # compile and run
18-
./test.sh --bytecode <path/to/file.py> # print the bytecode
19-
./test.sh --dis <path/to/file.py> # Run python -m dis
16+
./test.sh <path/to/file.py> --bytecode # print the bytecode in JSON
17+
./test.sh <path/to/file.py> --dis # Run python -m dis
2018
```
2119

2220
## Manual
@@ -32,9 +30,11 @@ cargo run ../test.bytecode
3230
# Testing & debugging
3331

3432
```
35-
./test_all.sh
33+
./test_all.sh # Run all tests under tests/
3634
```
3735

36+
* If a test is expected to fail or raise exception, add `xfail_*` prefix to the filename.
37+
3838
## Logging
3939

4040
```
@@ -57,8 +57,8 @@ RUST_LOG=debug ./tests_all.sh
5757
* Runs the [pybenchmark](https://pybenchmarks.org/) benchmark test
5858
* Run famous/popular python modules (which?)
5959

60-
* Compatible with CPython 2.7
60+
* Compatible with CPython 3.6
6161

6262
# Rust version
63-
rustc 1.16.0-nightly (bf6d7b665 2017-01-15)
63+
rustc 1.20.0-nightly
6464

RustPython/src/builtins.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
use NativeType;
2+
use std::rc::Rc;
3+
use std::ops::Deref;
24

3-
pub fn print(args: Vec<NativeType>) -> NativeType {
5+
pub fn print(args: Vec<Rc<NativeType>>) -> NativeType {
46
for elem in args {
57
// TODO: figure out how python's print vectors
6-
match elem {
7-
NativeType::NoneType => println!("None"),
8-
NativeType::Boolean(b)=> {
9-
if b {
8+
match elem.deref() {
9+
&NativeType::NoneType => println!("None"),
10+
&NativeType::Boolean(ref b)=> {
11+
if *b {
1012
println!("True");
1113
} else {
1214
println!("False");
1315
}
1416
},
15-
NativeType::Int(x) => println!("{}", x),
16-
NativeType::Float(x) => println!("{}", x),
17-
NativeType::Str(x) => println!("{}", x),
18-
NativeType::Unicode(x) => println!("{}", x),
17+
&NativeType::Int(ref x) => println!("{}", x),
18+
&NativeType::Float(ref x) => println!("{}", x),
19+
&NativeType::Str(ref x) => println!("{}", x),
20+
&NativeType::Unicode(ref x) => println!("{}", x),
1921
_ => panic!("Print for {:?} not implemented yet", elem),
2022
/*
2123
List(Vec<NativeType>),
@@ -31,11 +33,11 @@ pub fn print(args: Vec<NativeType>) -> NativeType {
3133
NativeType::NoneType
3234
}
3335

34-
pub fn len(args: Vec<NativeType>) -> NativeType {
36+
pub fn len(args: Vec<Rc<NativeType>>) -> NativeType {
3537
if args.len() != 1 {
3638
panic!("len(s) expects exactly one parameter");
3739
}
38-
let len = match &args[0] {
40+
let len = match args[0].deref() {
3941
&NativeType::List(ref l) => l.len(),
4042
&NativeType::Tuple(ref t) => t.len(),
4143
&NativeType::Str(ref s) => s.len(),

0 commit comments

Comments
 (0)