Skip to content

Commit 13b211f

Browse files
committed
compile flags (no idea what I'm doing)
1 parent 87eee4b commit 13b211f

7 files changed

Lines changed: 71 additions & 41 deletions

File tree

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#cargo-features = ["profile-rustflags"]
2+
13
[package]
24
name = "RustyPython"
35
version = "0.1.0"
@@ -11,6 +13,13 @@ mopa = "0.2.2"
1113
ahash = "0.8.11"
1214

1315
[profile.release]
16+
lto = "fat"
17+
#opt-level = 3
18+
#rustflags = ["-C", "target-cpu=native"]
19+
overflow-checks = false
20+
codegen-units = 1
21+
22+
[profile.bench]
1423
debug = true
1524

1625
[features]

README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,42 @@ Once the `assert` and method definition is added, more sophisticated tests will
3030

3131
| Test Name | Status | Notes |
3232
|--------------------|--------|------------------------------------|
33-
| test_object | ✔️ | |
34-
| test_simple | ✔️ | should include more int operations |
35-
| test_addition | ✔️ | optimized 😎 |
36-
| test_deep_for_loop | ✔️ | optimized 😎 |
37-
| test_while_add | ✔️ | optimized 😎 |
38-
| test_simple_if_for | ✔️ | optimized 😎 |
39-
| test_primatives | 🚧 | need to add all the primatives |
40-
| test_control_flow || need to add if, strings & indexing |
41-
| test_tuple || need tuples and tuple unpacking |
33+
| test_object | ✔️ | |
34+
| test_simple | ✔️ | should include more int operations |
35+
| test_addition | ✔️ | optimized 😎 |
36+
| test_deep_for_loop | ✔️ | optimized 😎 |
37+
| test_while_add | ✔️ | optimized 😎 |
38+
| test_simple_if_for | ✔️ | optimized 😎 |
39+
| test_primatives | 🚧 | need to add all the primatives |
40+
| test_control_flow | | need to add if, strings & indexing |
41+
| test_tuple | | need tuples and tuple unpacking |
4242

4343

4444
## Supported Features
4545

4646
| Feature | Supported | Notes |
47-
|------------------------|------|--------------------------------------------------------------|
48-
| User-defined Variables | ✔️ | |
49-
| Print Function | ✔️ | |
50-
| Operator overloading | ✔️ | |
51-
| For Loops | ✔️ | Doesn't support tuple unpacking (yet) |
52-
| Comments | ✔️ | |
53-
| If/if-else Statements | ✔️ | |
54-
| While Loops | ✔️ | Close to CPython speeds! |
55-
| Basic Math Operations | 🚧 | still needs % and // |
56-
| Math Assign Operations | 🚧 | still needs //=, @=, **=, no support for in-pace methods yet |
57-
| Primatives | 🚧 | int, float, bool, None (limited implementation) |
58-
| Built in types | 🚧 | range only | |
59-
| Keyword: assert | 🚧 | parsing but not implemented
60-
| Match Statements || |
61-
| User-defined Functions || |
62-
| User-define classes || |
63-
| User-define modules || |
64-
| Error Handling || |
65-
| Generators || |
66-
| Importing modules || |
67-
| Typeing || |
68-
| Keyword: with || |
69-
| Keyword: global || |
70-
| Keyword: del || |
71-
| Async || |
47+
|------------------------|-----------|--------------------------------------------------------------|
48+
| User-defined Variables | ✔️ | |
49+
| Print Function | ✔️ | |
50+
| Operator overloading | ✔️ | |
51+
| For Loops | ✔️ | Doesn't support tuple unpacking (yet) |
52+
| Comments | ✔️ | |
53+
| If/if-else Statements | ✔️ | |
54+
| While Loops | ✔️ | Close to CPython speeds! |
55+
| Basic Math Operations | 🚧 | still needs % and // |
56+
| Math Assign Operations | 🚧 | still needs //=, @=, **=, no support for in-pace methods yet |
57+
| Primatives | 🚧 | int, float, bool, None (limited implementation) |
58+
| Built in types | 🚧 | range only | |
59+
| Keyword: assert | 🚧 | parsing but not implemented |
60+
| Match Statements | | |
61+
| User-defined Functions | | |
62+
| User-define classes | | |
63+
| User-define modules | | |
64+
| Error Handling | | |
65+
| Generators | | |
66+
| Importing modules | | |
67+
| Typeing | | |
68+
| Keyword: with | | |
69+
| Keyword: global | | |
70+
| Keyword: del | | |
71+
| Async | | |

benchmarker.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def benchmark_rs(test):
6868
"""
6969

7070
if __name__ == '__main__':
71-
test_file = "test_simple_if_for.py"
71+
test_file = "test_addition.py"
7272

7373
rusty_time = benchmark_rusty(test_file)
7474
rs_time = benchmark_rs(test_file)
@@ -77,5 +77,10 @@ def benchmark_rs(test):
7777
print(f"RustyPython: {rusty_time}s")
7878
print(f"RustPython: {rs_time}s" )
7979
print(f"CPython: {py_time}s")
80-
print(f"{rusty_time/py_time :.2f}x slower than CPython")
80+
81+
if rusty_time > py_time:
82+
print(f"{rusty_time/py_time :.2f}x slower than CPython")
83+
else:
84+
print(f"{py_time/rusty_time :.2f}x faster than CPython")
85+
8186
print(f"{rs_time/rusty_time :.2f}x faster than RustPython")

flamegraph.svg

Lines changed: 2 additions & 2 deletions
Loading

src/builtins/types/pyfloat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn convert_mutable_to_float(pyobj: &PyObject, mutable_obj: &PyMutableObject,
3838

3939
let float_result = expect_float(&func_result, arena);
4040

41-
return float_result.map_err(|error| {
41+
return float_result.map_err(|_error| {
4242
let message = format!("{}.__float__ returned non-float (type {{<other type>}})", pyobj.clone_class(arena).get_name());
4343
arena.exceptions.type_error.instantiate(message)
4444
});

src/evaluator.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::builtins::function_utils::{call_function, eval_internal_func, eval_obj_init};
1+
use crate::builtins::function_utils::{call_function, call_function_1_arg_min, eval_internal_func, eval_obj_init};
22
use crate::builtins::functions::compare::compare_op;
33
use crate::builtins::functions::math_op::math_op;
44
use crate::builtins::structure::magic_methods::PyMagicMethod;
@@ -127,6 +127,22 @@ fn eval_op_equals(var_name: &String, expr: &Expr, op: PyMagicMethod, arena: &mut
127127
Ok(())
128128
}
129129

130+
// fn eval_assert(expr1: &Expr, expr2: &Option<Expr>, arena: &mut PyArena) -> EmptyFuncReturnType {
131+
// let result1 = eval_expr(expr1, arena)?;
132+
//
133+
// if let Some(expr2) = expr2 {
134+
// let result2 = eval_expr(expr2, arena)?;
135+
//
136+
// let is_equal = compare_op(&result1, &result2, &Comparitor::Equal, arena)?;
137+
//
138+
// if !convert_pyobj_to_bool(&is_equal, arena)? {
139+
// let repr_method = result2.get_magic_method(&PyMagicMethod::Repr, arena)?;
140+
// let msg = call_function_1_arg_min()
141+
// Err(arena.exceptions.assertion_error.instantiate())
142+
// }
143+
// }
144+
// }
145+
130146
fn eval_defn(define: &Define, arena: &mut PyArena) -> EmptyFuncReturnType {
131147
match define {
132148
Define::PlusEq(var_name, expr) => eval_op_equals(var_name, expr, Add {right: false}, arena),

tests/test_while_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
while j < 1000:
33
total = 0
44
i = 0
5-
while i < 100:
5+
while i < 1000:
66
total += i
77
i += 1
88
j += 1

0 commit comments

Comments
 (0)