Skip to content

Commit a5d2459

Browse files
Refactoring changes.
Refactoring changes, to resolve Rust warnings.
1 parent 4ab5d51 commit a5d2459

File tree

11 files changed

+171
-188
lines changed

11 files changed

+171
-188
lines changed

Cargo.lock

+135-135
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

evilang_lib/src/lib/interpreter/environment/native_items/classes/vector.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::interpreter::environment::Environment;
88
use crate::interpreter::environment::native_items::classes::object::ObjectSuperclass;
99
use crate::interpreter::runtime_values::functions::GcPtrToFunction;
1010
use crate::interpreter::runtime_values::functions::ifunction::IFunction;
11-
use crate::interpreter::runtime_values::i_native_struct::{INativeClass, INativeClass_BuildClass, INativeClass_GetClassCached, native_wrap, NativeClassMemberFunctionContext, NativeClassStaticFunctionContext, auto_unwrap_exec_fn};
11+
use crate::interpreter::runtime_values::i_native_struct::{auto_unwrap_exec_fn, INativeClass, INativeClass_BuildClass, INativeClass_GetClassCached, native_wrap, NativeClassMemberFunctionContext, NativeClassStaticFunctionContext};
1212
use crate::interpreter::runtime_values::i_native_struct::INativeClass_IsStructWrapper;
1313
use crate::interpreter::runtime_values::i_native_struct::INativeStruct;
1414
use crate::interpreter::runtime_values::objects::runtime_object::{GcPtrToObject, RuntimeObject};
@@ -32,7 +32,7 @@ implement_get_class_cached!(Vector);
3232

3333
impl INativeStruct for Vector {}
3434

35-
#[derive_build_class(name = "Vector", evilang_lib_crate = crate)]
35+
#[derive_build_class(evilang_lib_crate = crate)]
3636
impl Vector {
3737
#[export = "constructor"]
3838
pub fn constructor(_ctx: NativeClassMemberFunctionContext) -> ResultWithError<Self> {
@@ -57,7 +57,7 @@ impl Vector {
5757
#[export]
5858
pub fn repeat(ctx: NativeClassStaticFunctionContext, v: PrimitiveValue, n: NumberT) -> ResultWithError<PrimitiveValue> {
5959
let res = Self {
60-
vec: (0..(n.floor_to_int() as usize)).map(|i| v.try_clone_err()).collect::<ResultWithError<Vec<_>>>()?
60+
vec: (0..(n.floor_to_int() as usize)).map(|_i| v.try_clone_err()).collect::<ResultWithError<Vec<_>>>()?
6161
};
6262
let obj = RuntimeObject::allocate_instance(
6363
Vector::get_class_cached(ctx.env)?,

evilang_lib/src/lib/interpreter/environment/native_items/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::HashMap;
2-
use std::ops::Deref;
32

43
use crate::ast::expression::IdentifierT;
54
use crate::errors::{Descriptor, ResultWithError, RuntimeError};
@@ -19,7 +18,7 @@ pub fn push_res_stack(env: &mut Environment, params: FunctionParameters) -> Resu
1918
Ok(PrimitiveValue::Null.into())
2019
}
2120

22-
pub fn to_string(env: &mut Environment, params: FunctionParameters) -> ResultWithError<FunctionReturnValue> {
21+
pub fn to_string(_env: &mut Environment, params: FunctionParameters) -> ResultWithError<FunctionReturnValue> {
2322
Ok(PrimitiveValue::String(match params.first().unwrap() {
2423
PrimitiveValue::Null => { "null".to_string() }
2524
PrimitiveValue::Boolean(v) => { if *v { "true" } else { "false" }.to_string() }
@@ -35,14 +34,14 @@ pub fn to_string(env: &mut Environment, params: FunctionParameters) -> ResultWit
3534
}))
3635
}
3736

38-
pub fn print(env: &mut Environment, params: FunctionParameters) -> ResultWithError<FunctionReturnValue> {
37+
pub fn print(_env: &mut Environment, params: FunctionParameters) -> ResultWithError<FunctionReturnValue> {
3938
for x in params.into_iter() {
4039
print!("{}", x);
4140
}
4241
Ok(PrimitiveValue::Null.into())
4342
}
4443

45-
pub fn debug(env: &mut Environment, params: FunctionParameters) -> ResultWithError<FunctionReturnValue> {
44+
pub fn debug(_env: &mut Environment, params: FunctionParameters) -> ResultWithError<FunctionReturnValue> {
4645
println!("{0:#?}", params);
4746
Ok(PrimitiveValue::Null.into())
4847
}

evilang_lib/src/lib/interpreter/environment/resolver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl PartialEq for dyn IResolver {
5656

5757
impl PartialEq<&BoxIResolver> for BoxIResolver {
5858
fn eq(&self, other: &&Self) -> bool {
59-
self.equals_resolver(other.deref().deref().deref())
59+
self.equals_resolver(&***other)
6060
}
6161
}
6262

@@ -112,7 +112,7 @@ impl DefaultResolver {
112112
.and_then(|env| env.get_actual(CURRENT_FILE.into()))
113113
.and_then(|v| if v.borrow().deref() == &PrimitiveValue::Null { None } else { Some(v) }) else {
114114
return fs::canonicalize(file_name).map_err(EvilangError::from);
115-
return Ok(normalize_path(Path::new(&file_name)).to_path_buf());//.map_err(EvilangError::from);
115+
//return Ok(normalize_path(Path::new(&file_name)).to_path_buf());//.map_err(EvilangError::from);
116116
};
117117
let this_file_path_borr = this_file_path_box.borrow();
118118
let PrimitiveValue::String(this_file_path_str_ref) = this_file_path_borr.deref() else {

evilang_lib/src/lib/interpreter/runtime_values/functions/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::{Display, Formatter, Write};
1+
use std::fmt::{Display, Formatter};
22

33
use gc::{Finalize, Trace};
44

@@ -28,7 +28,7 @@ impl Display for Function {
2828
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
2929
match self {
3030
Function::NativeFunction(nf) => {
31-
let mut res = std::fmt::Result::Ok(());
31+
let mut res = Ok(());
3232
backtrace::resolve(nf.f as *mut std::os::raw::c_void, |v| {
3333
res = if let Some(name) = v.name() {
3434
std::fmt::Display::fmt(&name, f)

evilang_lib/src/lib/interpreter/runtime_values/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::{Display, Formatter, Write};
1+
use std::fmt::{Display, Formatter};
22
use std::mem::swap;
33
use std::ops::Deref;
44

@@ -48,14 +48,14 @@ pub enum PrimitiveValue {
4848
impl Display for PrimitiveValue {
4949
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
5050
match self {
51-
PrimitiveValue::_HoistedVariable => {f.write_str("<hoisted_variable>")}
52-
PrimitiveValue::Null => {f.write_str("null")}
53-
PrimitiveValue::Boolean(b) => {std::fmt::Display::fmt(b, f)}
54-
PrimitiveValue::Number(n) => {std::fmt::Display::fmt(n, f)}
55-
PrimitiveValue::String(s) => {std::fmt::Display::fmt(s, f)}
56-
PrimitiveValue::Function(fnc) => {std::fmt::Display::fmt(fnc.deref().deref(), f)}
57-
PrimitiveValue::Object(o) => {std::fmt::Display::fmt(&o.name, f)}
58-
PrimitiveValue::NativeStruct(ns) => {f.write_str("<native_struct>")}
51+
PrimitiveValue::_HoistedVariable => { f.write_str("<hoisted_variable>") }
52+
PrimitiveValue::Null => { f.write_str("null") }
53+
PrimitiveValue::Boolean(b) => { std::fmt::Display::fmt(b, f) }
54+
PrimitiveValue::Number(n) => { std::fmt::Display::fmt(n, f) }
55+
PrimitiveValue::String(s) => { std::fmt::Display::fmt(s, f) }
56+
PrimitiveValue::Function(fnc) => { std::fmt::Display::fmt(fnc.deref().deref(), f) }
57+
PrimitiveValue::Object(o) => { std::fmt::Display::fmt(&o.name, f) }
58+
PrimitiveValue::NativeStruct(_ns) => { f.write_str("<native_struct>") }
5959
}
6060
}
6161
}

evilang_lib/src/lib/interpreter/utils/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn expect_object_fn<T>(object: &PrimitiveValue, desc_fn: T) -> ResultWithErr
2121
return if let PrimitiveValue::Object(object_class_ref) = object {
2222
Ok(object_class_ref)
2323
} else {
24-
Err(RuntimeError::ExpectedClassObject(desc_fn().with_value(object.deref().deref().into())).into())
24+
Err(RuntimeError::ExpectedClassObject(desc_fn().with_value(object.into())).into())
2525
};
2626
}
2727

evilang_proc_macros/src/derive_build_class/mod.rs

+13-23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(non_snake_case)]
2+
13
use std::borrow::Cow;
24
use std::ops::Deref;
35

@@ -16,7 +18,6 @@ use crate::utils::crate_imports::CrateImports;
1618
fn define_alias_exports<'a, TIter: Iterator<Item=&'a FnExportData>>(
1719
imports: &CrateImports,
1820
iter: TIter,
19-
orig_name: Cow<str>,
2021
export_name: &Ident,
2122
) -> Vec<TokenStream> {
2223
let CrateImports { ResultWithError, Environment, FunctionParameters, FunctionReturnValue, .. } = imports;
@@ -98,7 +99,7 @@ fn define_export_for_constructor(
9899
const THIS_PARAM_NAME: &'static str = #concat_str!("this parameter of ", FUNC_NAME);
99100
let mut drain = params.drain(..);
100101
let this_val = drain.next().unwrap();
101-
#(#params_decl_list)*;
102+
#(#params_decl_list)*
102103
let this_obj = #expect_object_fn(
103104
&this_val,
104105
|| #Descriptor::Name(THIS_PARAM_NAME.into())
@@ -140,7 +141,6 @@ fn define_export_for_member_function(
140141
let mut iter = fn_dat.exports.iter();
141142
let main_export = iter.next().expect("Expected an export");
142143
let orig_name = &fn_dat.signature.ident;
143-
let orig_name_str = orig_name.to_string();
144144
let export_name = &main_export.export_ident;
145145
let first_arg = fn_dat.signature.inputs.first().expect("Expected at-least one argument");
146146
let FnArg::Receiver(self_param) = first_arg else {
@@ -160,7 +160,6 @@ fn define_export_for_member_function(
160160
let rest_exports = define_alias_exports(
161161
&imports,
162162
iter,
163-
orig_name_str.into(),
164163
&export_name,
165164
);
166165
let res = quote_spanned! { main_export.attribute.get_span() =>
@@ -181,7 +180,7 @@ fn define_export_for_member_function(
181180
// }
182181
let mut drain = params.drain(..);
183182
let this_val = drain.next().unwrap();
184-
#(#params_decl_list)*;
183+
#(#params_decl_list)*
185184
let this_val_ref = &this_val;
186185
let result = #native_unwrap_exec_fn::<#ExpT, _, _, _>(
187186
&this_val,
@@ -202,7 +201,6 @@ fn define_export_for_member_function(
202201
fn define_export_for_static_function(
203202
imports: &CrateImports,
204203
ExpT: &TokenStream,
205-
NATIVE_BOX_WRAP_NAME: &TokenStream,
206204
fn_dat: &FunctionData,
207205
) -> TokenStream {
208206
if fn_dat.exports.len() == 0 {
@@ -221,7 +219,6 @@ fn define_export_for_static_function(
221219
let mut iter = fn_dat.exports.iter();
222220
let main_export = iter.next().expect("Expected an export");
223221
let orig_name = &fn_dat.signature.ident;
224-
let orig_name_str = orig_name.to_string();
225222
let export_name = &main_export.export_ident;
226223
let (params_decl_list, param_names_list) = for_params(
227224
fn_dat.signature.inputs.iter().skip(1/*skip ctx*/),
@@ -232,14 +229,13 @@ fn define_export_for_static_function(
232229
let rest_exports = define_alias_exports(
233230
&imports,
234231
iter,
235-
orig_name_str.into(),
236232
&export_name,
237233
);
238234
let res = quote_spanned! { main_export.attribute.get_span() =>
239235
pub fn #export_name(env: &mut #Environment, mut params: #FunctionParameters) ->
240236
#ResultWithError<#FunctionReturnValue> {
241237
let mut drain = params.drain(..);
242-
#(#params_decl_list)*;
238+
#(#params_decl_list)*
243239
let result = #ExpT::#orig_name(
244240
#NativeClassStaticFunctionContext::new(env),
245241
#(#param_names_list),*
@@ -254,7 +250,6 @@ fn define_export_for_static_function(
254250
fn define_export_for_raw_native_function(
255251
imports: &CrateImports,
256252
ExpT: &TokenStream,
257-
NATIVE_BOX_WRAP_NAME: &TokenStream,
258253
fn_dat: &FunctionData,
259254
) -> TokenStream {
260255
if fn_dat.exports.len() == 0 {
@@ -270,12 +265,10 @@ fn define_export_for_raw_native_function(
270265
let mut iter = fn_dat.exports.iter();
271266
let main_export = iter.next().expect("Expected an export");
272267
let orig_name = &fn_dat.signature.ident;
273-
let orig_name_str = orig_name.to_string();
274268
let export_name = &main_export.export_ident;
275269
let rest_exports = define_alias_exports(
276270
&imports,
277271
iter,
278-
orig_name_str.into(),
279272
&export_name,
280273
);
281274
let res = quote_spanned! { main_export.attribute.get_span() =>
@@ -291,8 +284,8 @@ fn define_export_for_raw_native_function(
291284

292285
#[derive(FromMeta, Debug, Default)]
293286
pub(crate) struct RootAttributes {
294-
#[darling(default)]
295-
name: Option<String>,
287+
// #[darling(default)]
288+
// name: Option<String>,
296289
#[darling(default)]
297290
evilang_lib_crate: Option<Path>,
298291
}
@@ -319,7 +312,7 @@ impl TryParseAttribute for ExportAttribute {
319312
Self {
320313
export_as: Some(expr_as_string(expr)),
321314
attribute: None,
322-
raw: false
315+
raw: false,
323316
}
324317
}
325318

@@ -390,7 +383,7 @@ impl RootData {
390383
items: implementation.items.into_iter().map(|impl_item| match impl_item {
391384
ImplItem::Fn(f) => {
392385
// dbg!(&f.attrs);
393-
let (mut exports_iter, attrs_iter) =
386+
let (exports_iter, attrs_iter) =
394387
f.attrs
395388
.into_iter()
396389
.map(ExportAttribute::try_parse_attribute)
@@ -418,14 +411,13 @@ impl RootData {
418411
}, implementation)
419412
}
420413

421-
#[allow(non_snake_case)]
422-
pub fn generate_implementation(mut self) -> TokenStream {
414+
pub fn generate_implementation(self) -> TokenStream {
423415
let module = self.attributes.evilang_lib_crate
424416
.as_ref()
425417
.map(Path::to_token_stream)
426418
.unwrap_or_else(|| quote! {::#MODULE_NAME});
427419
let imports = CrateImports::new(module);
428-
let CrateImports { ResultWithError, Descriptor, ErrorT, EvilangError, RuntimeError, Environment, GcPtrToObject, PrimitiveValue, expect_object_fn, FunctionReturnValue, FunctionParameters, concat_str, INativeClass, INativeClass_BuildClass, from_option_of_primitive_value, NativeClassMemberFunctionContext, native_wrap, native_unwrap_exec_fn, Some_, None_, Err_, Ok_, gc_ptr_cell_from, RuntimeObject, VariablesMap, HashMap, INativeClass_IsStructWrapper, .. } = &imports;
420+
let CrateImports { ResultWithError, Environment, GcPtrToObject, PrimitiveValue, concat_str, INativeClass, INativeClass_BuildClass, Ok_, gc_ptr_cell_from, RuntimeObject, VariablesMap, HashMap, INativeClass_IsStructWrapper, .. } = &imports;
429421
let SelfT = &self.self_ty;
430422
let ExpT = quote! {super::#SelfT};
431423
let Self_exports = str_concat_token_stream(
@@ -490,14 +482,12 @@ impl RootData {
490482
return define_export_for_raw_native_function(
491483
&imports,
492484
&ExpT,
493-
&NATIVE_BOX_WRAP_NAME,
494485
func,
495486
);
496487
}
497488
return define_export_for_static_function(
498489
&imports,
499490
&ExpT,
500-
&NATIVE_BOX_WRAP_NAME,
501491
func,
502492
);
503493
};
@@ -513,9 +503,9 @@ impl RootData {
513503
}
514504
impl #INativeClass_BuildClass for #SelfT {
515505
fn build_class(env: &mut #Environment) -> #ResultWithError<#GcPtrToObject> {
516-
#Ok_(#RuntimeObject::new_gc(#VariablesMap::new_direct(#HashMap::from([
506+
return #Ok_(#RuntimeObject::new_gc(#VariablesMap::new_direct(#HashMap::from([
517507
#(#export_tuples_for_functions),*
518-
])), <#SelfT as #INativeClass>::get_parent_class(env)?, <#SelfT as #INativeClass>::NAME.into()))
508+
])), <#SelfT as #INativeClass>::get_parent_class(env)?, <#SelfT as #INativeClass>::NAME.into()));
519509
}
520510
}
521511
#[allow(non_snake_case)]

evilang_proc_macros/src/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
#[macro_use]
21
extern crate darling;
32

4-
use proc_macro2;
5-
use quote::{quote, ToTokens};
3+
use quote::quote;
64
use syn::{ItemImpl, parse_macro_input};
7-
use syn::spanned::Spanned;
85

96
use crate::derive_build_class::RootData;
107

@@ -15,7 +12,7 @@ mod utils;
1512
pub fn derive_build_class(attr: proc_macro::TokenStream, item: proc_macro::TokenStream) -> proc_macro::TokenStream {
1613
let ic = item.clone();
1714
let input = parse_macro_input!(ic as ItemImpl);
18-
let (mut rv, item_impl) = RootData::parse_and_strip_extra_attributes(attr.clone(), input.clone());
15+
let (rv, item_impl) = RootData::parse_and_strip_extra_attributes(attr.clone(), input.clone());
1916
// println!("{0:#?}\n{1:#?}\n{2:#?}", attr, rv, input);
2017
let new_impl = rv.generate_implementation();
2118
// println!("{}", new_impl.to_string());

resources/tests/import_test/sub/point.evil

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class Point {
55
}
66

77
fn calc(this) {
8-
debug(this.x);
98
return this.x + this.y;
109
}
1110
}

tests/vector.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use evilang_lib::interpreter::runtime_values::PrimitiveValue;
2-
3-
use crate::common::{run_asserts_in_file, TestData, TestRes};
1+
use crate::common::{run_asserts_in_file, TestRes};
42

53
mod common;
64

0 commit comments

Comments
 (0)