Skip to content

Commit 17f9d3f

Browse files
committed
fmt
1 parent 9c6fe33 commit 17f9d3f

File tree

6 files changed

+183
-112
lines changed

6 files changed

+183
-112
lines changed

crates/benda/src/benda_ffi/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use bend::{
2-
diagnostics::{Diagnostics, DiagnosticsConfig},
3-
fun::{Book, Term},
4-
CompileOpts, RunOpts,
5-
};
1+
use bend::diagnostics::{Diagnostics, DiagnosticsConfig};
2+
use bend::fun::{Book, Term};
3+
use bend::{CompileOpts, RunOpts};
64

75
pub fn run(book: &Book) -> Option<(Term, String, Diagnostics)> {
86
let run_opts = RunOpts::default();

crates/benda/src/lib.rs

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
use bend::imp;
22
use num_traits::ToPrimitive;
33
use parser::Parser;
4-
use pyo3::{
5-
prelude::*,
6-
types::{PyDict, PyFunction, PyString, PyTuple},
7-
};
4+
use pyo3::prelude::*;
5+
use pyo3::types::{PyDict, PyFunction, PyString, PyTuple};
86
use rustpython_parser::{parse, Mode};
9-
use types::tree::Tree;
10-
use types::{
11-
extract_type,
12-
tree::{Leaf, Node},
13-
u24::u24,
14-
};
7+
use types::extract_type;
8+
use types::tree::{Leaf, Node, Tree};
9+
use types::u24::u24;
1510
mod benda_ffi;
1611
mod parser;
1712
mod types;
@@ -49,7 +44,8 @@ impl PyBjit {
4944
let filename = code.getattr("co_filename").unwrap();
5045

5146
arg_names_temp = code.getattr("co_varnames").unwrap();
52-
let arg_names = arg_names_temp.downcast::<PyTuple>().unwrap();
47+
let arg_names =
48+
arg_names_temp.downcast::<PyTuple>().unwrap();
5349
let argcount = code
5450
.getattr("co_argcount")
5551
.unwrap()
@@ -74,7 +70,9 @@ impl PyBjit {
7470

7571
let mut parsed_types: Vec<(String, imp::Expr)> = vec![];
7672

77-
for (index, arg) in args.downcast::<PyTuple>().unwrap().iter().enumerate() {
73+
for (index, arg) in
74+
args.downcast::<PyTuple>().unwrap().iter().enumerate()
75+
{
7876
parsed_types.push((
7977
arg_list.get(index).unwrap().to_string(),
8078
extract_type(arg).unwrap(),
@@ -89,12 +87,21 @@ impl PyBjit {
8987
match module {
9088
rustpython_parser::ast::Mod::Module(mods) => {
9189
for (index, stmt) in mods.body.iter().enumerate() {
92-
if let rustpython_parser::ast::Stmt::FunctionDef(fun_def) = stmt {
90+
if let rustpython_parser::ast::Stmt::FunctionDef(fun_def) =
91+
stmt
92+
{
9393
if fun_def.name == name.to_string() {
94-
let mut parser =
95-
Parser::new(mods.body.clone(), index, parsed_types.clone());
96-
let return_val = parser.parse(fun_def.name.as_ref(), &[]);
97-
val = Some(PyString::new_bound(py, return_val.as_str()));
94+
let mut parser = Parser::new(
95+
mods.body.clone(),
96+
index,
97+
parsed_types.clone(),
98+
);
99+
let return_val =
100+
parser.parse(fun_def.name.as_ref(), &[]);
101+
val = Some(PyString::new_bound(
102+
py,
103+
return_val.as_str(),
104+
));
98105
break;
99106
}
100107
}
@@ -111,25 +118,26 @@ impl PyBjit {
111118
fn bjit_test(fun: Bound<PyFunction>, py: Python) -> PyResult<Py<PyAny>> {
112119
let arg_names_temp: Bound<PyAny>;
113120

114-
let (name, filename, arg_names, argcount) = match fun.clone().downcast::<PyFunction>() {
115-
Ok(inner) => {
116-
let name = inner.getattr("__name__").unwrap();
117-
let code = inner.getattr("__code__").unwrap();
118-
let filename = code.getattr("co_filename").unwrap();
119-
120-
arg_names_temp = code.getattr("co_varnames").unwrap();
121-
let arg_names = arg_names_temp.downcast::<PyTuple>().unwrap();
122-
let argcount = code
123-
.getattr("co_argcount")
124-
.unwrap()
125-
.to_string()
126-
.parse::<u32>()
127-
.unwrap();
128-
129-
(name, filename, arg_names, argcount)
130-
}
131-
Err(_) => todo!(),
132-
};
121+
let (name, filename, arg_names, argcount) =
122+
match fun.clone().downcast::<PyFunction>() {
123+
Ok(inner) => {
124+
let name = inner.getattr("__name__").unwrap();
125+
let code = inner.getattr("__code__").unwrap();
126+
let filename = code.getattr("co_filename").unwrap();
127+
128+
arg_names_temp = code.getattr("co_varnames").unwrap();
129+
let arg_names = arg_names_temp.downcast::<PyTuple>().unwrap();
130+
let argcount = code
131+
.getattr("co_argcount")
132+
.unwrap()
133+
.to_string()
134+
.parse::<u32>()
135+
.unwrap();
136+
137+
(name, filename, arg_names, argcount)
138+
}
139+
Err(_) => todo!(),
140+
};
133141

134142
let code = std::fs::read_to_string(filename.to_string()).unwrap();
135143
let module = parse(code.as_str(), Mode::Module, "main.py").unwrap();
@@ -149,7 +157,8 @@ fn bjit_test(fun: Bound<PyFunction>, py: Python) -> PyResult<Py<PyAny>> {
149157
match module {
150158
rustpython_parser::ast::Mod::Module(mods) => {
151159
for stmt in mods.body.iter() {
152-
if let rustpython_parser::ast::Stmt::FunctionDef(fun_def) = stmt {
160+
if let rustpython_parser::ast::Stmt::FunctionDef(fun_def) = stmt
161+
{
153162
if fun_def.name == name.to_string() {
154163
//let mut parser = Parser::new(mods.body.clone(), 0);
155164
//let return_val = parser.parse(fun_def.name.as_ref(), &arg_list);

crates/benda/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod parser;
22

33
use pyo3::prelude::*;
4-
54
use rustpython_parser::{parse, Mode};
65

76
mod benda_ffi;

0 commit comments

Comments
 (0)