Skip to content

Commit

Permalink
Rust fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
vkobinski committed Jun 5, 2024
1 parent 874ce76 commit 740cac6
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 255 deletions.
24 changes: 16 additions & 8 deletions crates/benda/src/benda_ffi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
use bend::{
diagnostics::{ Diagnostics, DiagnosticsConfig },
fun::{ Book, Term },
CompileOpts,
RunOpts,
};
use bend::diagnostics::{Diagnostics, DiagnosticsConfig};
use bend::fun::{Book, Term};
use bend::{CompileOpts, RunOpts};

pub fn run(book: &Book) -> Option<(Term, String, Diagnostics)> {
let run_opts = RunOpts { linear_readback: false, pretty: false };
let run_opts = RunOpts {
linear_readback: false,
pretty: false,
};
let compile_opts = CompileOpts::default();
let diagnostics_cfg = DiagnosticsConfig::default();
let args = None;

bend::run_book(book.clone(), run_opts, compile_opts, diagnostics_cfg, args, "run").unwrap()
bend::run_book(
book.clone(),
run_opts,
compile_opts,
diagnostics_cfg,
args,
"run",
)
.unwrap()
}
18 changes: 11 additions & 7 deletions crates/benda/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use parser::Parser;
use pyo3::{ prelude::*, types::{ PyFunction, PyString } };
use rustpython_parser::{ parse, Mode };
use pyo3::prelude::*;
use pyo3::types::{PyFunction, PyString};
use rustpython_parser::{parse, Mode};
use types::u24::u24;
mod types;
mod parser;
mod benda_ffi;
mod parser;
mod types;

#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Expand All @@ -21,7 +22,8 @@ fn bjit(fun: Bound<PyFunction>, py: Python) -> PyResult<PyObject> {
let (name, filename) = match fun.downcast::<PyFunction>() {
Ok(inner) => {
let name = inner.getattr("__name__");
let filename = inner.getattr("__code__").unwrap().getattr("co_filename");
let filename =
inner.getattr("__code__").unwrap().getattr("co_filename");

(name.unwrap(), filename.unwrap())
}
Expand All @@ -36,13 +38,15 @@ fn bjit(fun: Bound<PyFunction>, py: Python) -> PyResult<PyObject> {
match module {
rustpython_parser::ast::Mod::Module(mods) => {
for stmt in mods.body.iter() {
if let rustpython_parser::ast::Stmt::FunctionDef(fun_def) = stmt {
if let rustpython_parser::ast::Stmt::FunctionDef(fun_def) = stmt
{
if fun_def.name == name.to_string() {
//let mut parser = Parser::new(mods.body.clone(), 0);

let mut parser = Parser::new(mods.body.clone(), 0);
let return_val = parser.parse(fun_def.name.as_ref());
val = Some(PyString::new_bound(py, return_val.as_str()));
val =
Some(PyString::new_bound(py, return_val.as_str()));
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/benda/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ mod parser;

use parser::Parser;
use pyo3::prelude::*;

use rustpython_parser::{ parse, Mode };
use rustpython_parser::{parse, Mode};

mod benda_ffi;

Expand Down
Loading

0 comments on commit 740cac6

Please sign in to comment.