From 170f638a715adef2f9e15b6df563fb209cdf7afb Mon Sep 17 00:00:00 2001 From: peefy Date: Mon, 29 Jan 2024 13:44:37 +0800 Subject: [PATCH] refactor: remove runtime unsound codes Signed-off-by: peefy --- kclvm/runtime/src/_kcl_run.rs | 2 +- kclvm/runtime/src/_kclvm.rs | 2 +- kclvm/runtime/src/_kclvm_addr.rs | 2 +- kclvm/runtime/src/_kclvm_api_spec.rs | 2 +- kclvm/runtime/src/_kclvm_main_win.c | 2 +- kclvm/runtime/src/api/err_type.rs | 54 ------------------- kclvm/runtime/src/api/error.rs | 16 ++++++ kclvm/runtime/src/api/kclvm.rs | 20 ++----- kclvm/runtime/src/api/mod.rs | 6 +-- kclvm/runtime/src/api/utils.rs | 9 +++- kclvm/runtime/src/base64/mod.rs | 6 +-- kclvm/runtime/src/collection/mod.rs | 2 +- kclvm/runtime/src/context/api.rs | 2 +- kclvm/runtime/src/context/mod.rs | 6 +-- kclvm/runtime/src/crypto/mod.rs | 2 +- kclvm/runtime/src/datetime/mod.rs | 2 +- kclvm/runtime/src/json/mod.rs | 2 +- kclvm/runtime/src/lib.rs | 2 +- kclvm/runtime/src/manifests/mod.rs | 2 +- kclvm/runtime/src/manifests/tests.rs | 16 ++---- kclvm/runtime/src/math/mod.rs | 2 +- kclvm/runtime/src/net/mod.rs | 17 +++--- kclvm/runtime/src/regex/mod.rs | 2 +- kclvm/runtime/src/stdlib/assert_api.rs | 4 +- kclvm/runtime/src/stdlib/builtin.rs | 14 ++--- kclvm/runtime/src/stdlib/builtin_api.rs | 2 +- kclvm/runtime/src/stdlib/mod.rs | 2 +- kclvm/runtime/src/stdlib/plugin.rs | 5 +- .../src/types/{typ_new.rs => constructor.rs} | 2 +- .../src/types/{typ_kind.rs => kind.rs} | 2 +- kclvm/runtime/src/types/mod.rs | 10 ++-- .../src/types/{typ_type_str.rs => str.rs} | 2 +- kclvm/runtime/src/unification/mod.rs | 2 +- kclvm/runtime/src/unification/subsume.rs | 2 +- kclvm/runtime/src/units/mod.rs | 2 +- kclvm/runtime/src/value/api.rs | 41 ++++++-------- kclvm/runtime/src/value/iter.rs | 2 +- kclvm/runtime/src/value/mod.rs | 2 +- kclvm/runtime/src/value/val.rs | 2 +- kclvm/runtime/src/value/val_args.rs | 2 +- kclvm/runtime/src/value/val_as_val.rs | 2 +- kclvm/runtime/src/value/val_bin.rs | 2 +- kclvm/runtime/src/value/val_bin_aug.rs | 2 +- kclvm/runtime/src/value/val_clone.rs | 2 +- kclvm/runtime/src/value/val_cmp.rs | 2 +- kclvm/runtime/src/value/val_decorator.rs | 10 ++-- kclvm/runtime/src/value/val_dict.rs | 6 +-- kclvm/runtime/src/value/val_fmt.rs | 2 +- kclvm/runtime/src/value/val_from.rs | 12 ++--- kclvm/runtime/src/value/val_get_set.rs | 2 +- kclvm/runtime/src/value/val_is_in.rs | 2 +- kclvm/runtime/src/value/val_json.rs | 2 +- kclvm/runtime/src/value/val_kind.rs | 2 +- kclvm/runtime/src/value/val_len.rs | 4 +- kclvm/runtime/src/value/val_list.rs | 2 +- kclvm/runtime/src/value/val_logic.rs | 2 +- kclvm/runtime/src/value/val_overflow.rs | 2 +- kclvm/runtime/src/value/val_panic.rs | 8 +-- kclvm/runtime/src/value/val_plan.rs | 10 ++-- kclvm/runtime/src/value/val_schema.rs | 4 +- kclvm/runtime/src/value/val_str.rs | 2 +- kclvm/runtime/src/value/val_type.rs | 2 +- kclvm/runtime/src/value/val_unary.rs | 2 +- kclvm/runtime/src/value/val_union.rs | 2 +- kclvm/runtime/src/value/val_yaml.rs | 2 +- kclvm/runtime/src/value/walker.rs | 4 +- kclvm/runtime/src/yaml/mod.rs | 2 +- .../tools/kclvm-runtime-gen-api/main.go | 10 ++-- .../tools/kclvm-runtime-gen-err-type/Makefile | 6 --- .../tools/kclvm-runtime-gen-err-type/main.py | 24 --------- 70 files changed, 157 insertions(+), 255 deletions(-) delete mode 100644 kclvm/runtime/src/api/err_type.rs create mode 100644 kclvm/runtime/src/api/error.rs rename kclvm/runtime/src/types/{typ_new.rs => constructor.rs} (96%) rename kclvm/runtime/src/types/{typ_kind.rs => kind.rs} (93%) rename kclvm/runtime/src/types/{typ_type_str.rs => str.rs} (96%) delete mode 100644 kclvm/runtime/tools/kclvm-runtime-gen-err-type/Makefile delete mode 100644 kclvm/runtime/tools/kclvm-runtime-gen-err-type/main.py diff --git a/kclvm/runtime/src/_kcl_run.rs b/kclvm/runtime/src/_kcl_run.rs index 254385421..89b5c97be 100644 --- a/kclvm/runtime/src/_kcl_run.rs +++ b/kclvm/runtime/src/_kcl_run.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. #![allow(clippy::missing_safety_doc)] use std::os::raw::c_char; diff --git a/kclvm/runtime/src/_kclvm.rs b/kclvm/runtime/src/_kclvm.rs index e0a15b075..2b46c3eb0 100644 --- a/kclvm/runtime/src/_kclvm.rs +++ b/kclvm/runtime/src/_kclvm.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. // Auto generated, DONOT EDIT!!! diff --git a/kclvm/runtime/src/_kclvm_addr.rs b/kclvm/runtime/src/_kclvm_addr.rs index 72329bc0d..450bd44c5 100644 --- a/kclvm/runtime/src/_kclvm_addr.rs +++ b/kclvm/runtime/src/_kclvm_addr.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. // Auto generated, DONOT EDIT!!! diff --git a/kclvm/runtime/src/_kclvm_api_spec.rs b/kclvm/runtime/src/_kclvm_api_spec.rs index 3e62f9116..9d4397eab 100644 --- a/kclvm/runtime/src/_kclvm_api_spec.rs +++ b/kclvm/runtime/src/_kclvm_api_spec.rs @@ -1,4 +1,4 @@ -// Copyright 2023 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. // Auto generated by command, DONOT EDIT!!! diff --git a/kclvm/runtime/src/_kclvm_main_win.c b/kclvm/runtime/src/_kclvm_main_win.c index 917efac53..4e6473fdb 100644 --- a/kclvm/runtime/src/_kclvm_main_win.c +++ b/kclvm/runtime/src/_kclvm_main_win.c @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +// Copyright The KCL Authors. All rights reserved. extern void* kclvm_main(void* ctx); diff --git a/kclvm/runtime/src/api/err_type.rs b/kclvm/runtime/src/api/err_type.rs deleted file mode 100644 index b36faf3e0..000000000 --- a/kclvm/runtime/src/api/err_type.rs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2021 The KCL Authors. All rights reserved. - -// Auto generated, DONOT EDIT!!! - -// python: kclvm.kcl.error.ErrType - -#[derive(Copy, Clone)] -#[allow(non_camel_case_types)] -pub enum ErrType { - InvalidSyntax_TYPE = 0, - TabError_TYPE = 1, - IndentationError_TYPE = 2, - CannotFindModule_TYPE = 3, - FailedLoadModule_TYPE = 4, - CompileError_TYPE = 5, - EvaluationError_TYPE = 6, - RecursiveLoad_TYPE = 7, - FloatOverflow_TYPE = 8, - FloatUnderflow_TYPE = 9, - IntOverflow_TYPE = 10, - InvalidDocstring_TYPE = 11, - Deprecated_TYPE = 12, - UnKnownDecorator_TYPE = 13, - InvalidDecoratorTarget_TYPE = 14, - InvalidFormatSpec_TYPE = 15, - SelectorError_TYPE = 16, - SchemaCheckFailure_TYPE = 17, - MixinNamingError_TYPE = 18, - MixinStructureIllegal_TYPE = 19, - IndexSignatureError_TYPE = 20, - TypeError_Runtime_TYPE = 21, - TypeError_Compile_TYPE = 22, - NameError_TYPE = 23, - ValueError_TYPE = 24, - KeyError_TYPE = 25, - UniqueKeyError_TYPE = 26, - AttributeError_TYPE = 27, - AttributeError_Runtime_TYPE = 28, - AssertionError_TYPE = 29, - ImmutableCompileError_TYPE = 30, - ImmutableRuntimeError_TYPE = 31, - MultiInheritError_TYPE = 32, - CycleInheritError_TYPE = 33, - IllegalInheritError_TYPE = 34, - IllegalAttributeError_TYPE = 35, - IllegalArgumentError_TYPE = 36, - IllegalArgumentError_Complie_TYPE = 37, - IllegalArgumentError_Syntax_TYPE = 38, - RecursionError_TYPE = 39, - PlanError_TYPE = 40, - Deprecated_Warning_TYPE = 41, - CannotAddMembers_TYPE = 42, - CannotAddMembers_Runtime_TYPE = 43, -} diff --git a/kclvm/runtime/src/api/error.rs b/kclvm/runtime/src/api/error.rs new file mode 100644 index 000000000..5a5578493 --- /dev/null +++ b/kclvm/runtime/src/api/error.rs @@ -0,0 +1,16 @@ +//! Copyright The KCL Authors. All rights reserved. + +#[derive(Copy, Clone)] +#[allow(non_camel_case_types)] +pub enum RuntimeErrorType { + EvaluationError = 1, + RecursiveLoad = 2, + FloatOverflow = 3, + FloatUnderflow = 4, + IntOverflow = 5, + TypeError = 6, + AssertionError = 7, + Deprecated = 8, + DeprecatedWarning = 9, + SchemaCheckFailure = 10, +} diff --git a/kclvm/runtime/src/api/kclvm.rs b/kclvm/runtime/src/api/kclvm.rs index 1cf186934..c0092e811 100644 --- a/kclvm/runtime/src/api/kclvm.rs +++ b/kclvm/runtime/src/api/kclvm.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. #[allow(non_camel_case_types)] type kclvm_value_ref_t = crate::ValueRef; @@ -37,8 +37,9 @@ pub struct KclError { } #[allow(non_camel_case_types)] -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug, Default)] pub enum Type { + #[default] any_type, bool_type, bool_lit_type(bool), @@ -55,12 +56,6 @@ pub enum Type { func_type(FuncType), } -impl Default for Type { - fn default() -> Self { - Type::any_type - } -} - #[derive(PartialEq, Clone, Default, Debug)] pub struct ListType { pub elem_type: Box, @@ -461,19 +456,14 @@ pub enum Kind { Func = 18, } -#[derive(Clone, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash, Default)] pub enum ConfigEntryOperationKind { + #[default] Union = 0, Override = 1, Insert = 2, } -impl Default for ConfigEntryOperationKind { - fn default() -> Self { - ConfigEntryOperationKind::Union - } -} - impl ConfigEntryOperationKind { pub fn from_i32(v: i32) -> Self { match v { diff --git a/kclvm/runtime/src/api/mod.rs b/kclvm/runtime/src/api/mod.rs index 853933fe2..d9ceae469 100644 --- a/kclvm/runtime/src/api/mod.rs +++ b/kclvm/runtime/src/api/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. pub mod kclvm; pub use self::kclvm::*; @@ -6,5 +6,5 @@ pub use self::kclvm::*; pub mod utils; pub use self::utils::*; -pub mod err_type; -pub use self::err_type::*; +pub mod error; +pub use self::error::*; diff --git a/kclvm/runtime/src/api/utils.rs b/kclvm/runtime/src/api/utils.rs index 184e84d87..2ae37ff95 100644 --- a/kclvm/runtime/src/api/utils.rs +++ b/kclvm/runtime/src/api/utils.rs @@ -1,11 +1,12 @@ -// Copyright 2021 The KCL Authors. All rights reserved. -#![allow(clippy::missing_safety_doc)] +//! Copyright The KCL Authors. All rights reserved. use std::os::raw::c_char; use crate::{Context, ValueRef}; /// New a mutable raw pointer. +/// Safety: The caller must ensure that `ctx` lives longer than the returned pointer +/// and that the pointer is properly deallocated by calling `free_mut_ptr`. pub fn new_mut_ptr(ctx: &mut Context, x: ValueRef) -> *mut ValueRef { let ptr = Box::into_raw(Box::new(x)); // Store the object pointer address to @@ -15,6 +16,7 @@ pub fn new_mut_ptr(ctx: &mut Context, x: ValueRef) -> *mut ValueRef { } /// Free a mutable raw pointer. +/// Safety: The caller must ensure `p` is a valid pointer obtained from `new_mut_ptr`. pub(crate) fn free_mut_ptr(p: *mut T) { if !p.is_null() { unsafe { @@ -24,12 +26,14 @@ pub(crate) fn free_mut_ptr(p: *mut T) { } /// Convert a const raw pointer to a immutable borrow. +/// Safety: The caller must ensure that `p` is valid for the lifetime `'a`. pub(crate) fn ptr_as_ref<'a, T>(p: *const T) -> &'a T { assert!(!p.is_null()); unsafe { &*p } } /// Convert a mutable raw pointer to a mutable borrow. +/// Safety: The caller must ensure that `p` is valid for the lifetime `'a`. pub(crate) fn mut_ptr_as_ref<'a, T>(p: *mut T) -> &'a mut T { assert!(!p.is_null()); @@ -37,6 +41,7 @@ pub(crate) fn mut_ptr_as_ref<'a, T>(p: *mut T) -> &'a mut T { } /// Convert a C str pointer to a Rust &str. +/// Safety: The caller must ensure that `s` is a valid null-terminated C string. pub(crate) fn c2str<'a>(s: *const c_char) -> &'a str { let s = unsafe { std::ffi::CStr::from_ptr(s) }.to_str().unwrap(); s diff --git a/kclvm/runtime/src/base64/mod.rs b/kclvm/runtime/src/base64/mod.rs index c94b6f2ac..66db598f4 100644 --- a/kclvm/runtime/src/base64/mod.rs +++ b/kclvm/runtime/src/base64/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. extern crate base64; use base64::{decode, encode}; @@ -21,7 +21,7 @@ pub extern "C" fn kclvm_base64_encode( return ValueRef::str(s.as_str()).into_raw(ctx); } _ => { - ctx.set_err_type(&ErrType::TypeError_Runtime_TYPE); + ctx.set_err_type(&RuntimeErrorType::TypeError); panic!("a bytes-like object is required, not '{}'", p.as_str()); } @@ -44,7 +44,7 @@ pub extern "C" fn kclvm_base64_decode( return ValueRef::str(std::str::from_utf8(&de_str).unwrap()).into_raw(ctx); } _ => { - ctx.set_err_type(&ErrType::TypeError_Runtime_TYPE); + ctx.set_err_type(&RuntimeErrorType::TypeError); panic!( "argument should be a bytes-like object or ASCII string, not '{}'", diff --git a/kclvm/runtime/src/collection/mod.rs b/kclvm/runtime/src/collection/mod.rs index cab511188..7f4a02aa1 100644 --- a/kclvm/runtime/src/collection/mod.rs +++ b/kclvm/runtime/src/collection/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/context/api.rs b/kclvm/runtime/src/context/api.rs index 39eca48dc..27581d145 100644 --- a/kclvm/runtime/src/context/api.rs +++ b/kclvm/runtime/src/context/api.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. #![allow(clippy::missing_safety_doc)] use crate::*; diff --git a/kclvm/runtime/src/context/mod.rs b/kclvm/runtime/src/context/mod.rs index 7bd9d4994..037920c5a 100644 --- a/kclvm/runtime/src/context/mod.rs +++ b/kclvm/runtime/src/context/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. pub mod api; pub use api::*; @@ -45,7 +45,7 @@ impl PanicInfo { Err(_) => PanicInfo { __kcl_PanicInfo__: true, message: s.to_string(), - err_type_code: crate::ErrType::CompileError_TYPE as i32, + err_type_code: crate::RuntimeErrorType::EvaluationError as i32, ..Default::default() }, } @@ -162,7 +162,7 @@ impl crate::Context { } } - pub fn set_err_type(&mut self, err_type: &crate::ErrType) { + pub fn set_err_type(&mut self, err_type: &crate::RuntimeErrorType) { self.panic_info.__kcl_PanicInfo__ = true; self.panic_info.err_type_code = *err_type as i32; } diff --git a/kclvm/runtime/src/crypto/mod.rs b/kclvm/runtime/src/crypto/mod.rs index 297557dae..72730f1a2 100644 --- a/kclvm/runtime/src/crypto/mod.rs +++ b/kclvm/runtime/src/crypto/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. extern crate md5; extern crate sha1; diff --git a/kclvm/runtime/src/datetime/mod.rs b/kclvm/runtime/src/datetime/mod.rs index 400fb3b68..2a7dbe4f7 100644 --- a/kclvm/runtime/src/datetime/mod.rs +++ b/kclvm/runtime/src/datetime/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. extern crate chrono; diff --git a/kclvm/runtime/src/json/mod.rs b/kclvm/runtime/src/json/mod.rs index e0948e97d..efd32831b 100644 --- a/kclvm/runtime/src/json/mod.rs +++ b/kclvm/runtime/src/json/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/lib.rs b/kclvm/runtime/src/lib.rs index 1a2f398f3..80681407b 100644 --- a/kclvm/runtime/src/lib.rs +++ b/kclvm/runtime/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use kclvm_runtime_internal_macros::runtime_fn; diff --git a/kclvm/runtime/src/manifests/mod.rs b/kclvm/runtime/src/manifests/mod.rs index 4f682b16e..fd2409fe4 100644 --- a/kclvm/runtime/src/manifests/mod.rs +++ b/kclvm/runtime/src/manifests/mod.rs @@ -51,7 +51,7 @@ type kclvm_value_ref_t = ValueRef; /// TODO: more options on the function `yaml_stream`. #[no_mangle] #[runtime_fn] -pub unsafe extern "C" fn kclvm_manifests_yaml_stream( +pub extern "C" fn kclvm_manifests_yaml_stream( ctx: *mut kclvm_context_t, args: *const kclvm_value_ref_t, kwargs: *const kclvm_value_ref_t, diff --git a/kclvm/runtime/src/manifests/tests.rs b/kclvm/runtime/src/manifests/tests.rs index 4ddf84776..aa7923c4b 100644 --- a/kclvm/runtime/src/manifests/tests.rs +++ b/kclvm/runtime/src/manifests/tests.rs @@ -76,9 +76,7 @@ fn test_kclvm_manifests_yaml_stream() { ConfigEntryOperationKind::Override, -1, ); - unsafe { - kclvm_manifests_yaml_stream(&mut ctx, &args, &kwargs); - } + kclvm_manifests_yaml_stream(&mut ctx, &args, &kwargs); assert_eq!( Some(yaml_str.to_string()), ctx.buffer.custom_manifests_output @@ -97,9 +95,7 @@ fn test_kclvm_manifests_yaml_stream_invalid() { let mut ctx = Context::new(); let args = ValueRef::list(None).into_raw(&mut ctx); let kwargs = ValueRef::dict(None).into_raw(&mut ctx); - unsafe { - kclvm_manifests_yaml_stream(ctx.into_raw(), args, kwargs); - } + kclvm_manifests_yaml_stream(ctx.into_raw(), args, kwargs); }, ); assert_panic( @@ -109,9 +105,7 @@ fn test_kclvm_manifests_yaml_stream_invalid() { let args = ValueRef::list(None).into_raw(&mut ctx); let kwargs = ValueRef::dict(Some(&[("opts", &ValueRef::str("invalid_kwarg"))])) .into_raw(&mut ctx); - unsafe { - kclvm_manifests_yaml_stream(ctx.into_raw(), args, kwargs); - } + kclvm_manifests_yaml_stream(ctx.into_raw(), args, kwargs); }, ); assert_panic( @@ -120,9 +114,7 @@ fn test_kclvm_manifests_yaml_stream_invalid() { let mut ctx = Context::new(); let args = ValueRef::list(None).into_raw(&mut ctx); let kwargs = ValueRef::dict(Some(&[("opts", &ValueRef::none())])).into_raw(&mut ctx); - unsafe { - kclvm_manifests_yaml_stream(ctx.into_raw(), args, kwargs); - } + kclvm_manifests_yaml_stream(ctx.into_raw(), args, kwargs); }, ); std::panic::set_hook(prev_hook); diff --git a/kclvm/runtime/src/math/mod.rs b/kclvm/runtime/src/math/mod.rs index 69d8ba5c9..ab0ba6b35 100644 --- a/kclvm/runtime/src/math/mod.rs +++ b/kclvm/runtime/src/math/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. extern crate num_integer; diff --git a/kclvm/runtime/src/net/mod.rs b/kclvm/runtime/src/net/mod.rs index 067d4def7..17fb1355b 100644 --- a/kclvm/runtime/src/net/mod.rs +++ b/kclvm/runtime/src/net/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use std::net::Ipv4Addr; use std::net::Ipv6Addr; @@ -171,17 +171,14 @@ pub extern "C" fn kclvm_net_is_IP( let args = ptr_as_ref(args); if let Some(ip) = args.arg_i_str(0, None) { - if let Ok(..) = Ipv4Addr::from_str(ip.as_ref()) { - return kclvm_value_True(ctx); - } - if let Ok(..) = Ipv6Addr::from_str(ip.as_ref()) { - return kclvm_value_True(ctx); + if Ipv4Addr::from_str(ip.as_ref()).is_ok() || Ipv6Addr::from_str(ip.as_ref()).is_ok() { + kclvm_value_True(ctx) + } else { + kclvm_value_False(ctx) } - - return kclvm_value_False(ctx); + } else { + panic!("is_IP() missing 1 required positional argument: 'ip'"); } - - panic!("is_IP() missing 1 required positional argument: 'ip'"); } // is_loopback_IP(ip: str) -> bool diff --git a/kclvm/runtime/src/regex/mod.rs b/kclvm/runtime/src/regex/mod.rs index f79fe92a6..6192bfaa4 100644 --- a/kclvm/runtime/src/regex/mod.rs +++ b/kclvm/runtime/src/regex/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. extern crate fancy_regex; diff --git a/kclvm/runtime/src/stdlib/assert_api.rs b/kclvm/runtime/src/stdlib/assert_api.rs index 007456bce..34c6cb007 100644 --- a/kclvm/runtime/src/stdlib/assert_api.rs +++ b/kclvm/runtime/src/stdlib/assert_api.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; @@ -17,7 +17,7 @@ pub extern "C" fn kclvm_assert( if !value.is_truthy() { let ctx = mut_ptr_as_ref(ctx); - ctx.set_err_type(&ErrType::AssertionError_TYPE); + ctx.set_err_type(&RuntimeErrorType::AssertionError); let msg = msg.as_str(); panic!("{}", msg); diff --git a/kclvm/runtime/src/stdlib/builtin.rs b/kclvm/runtime/src/stdlib/builtin.rs index a70ce23c4..16256894d 100644 --- a/kclvm/runtime/src/stdlib/builtin.rs +++ b/kclvm/runtime/src/stdlib/builtin.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use std::{collections::HashSet, ops::Index}; @@ -168,12 +168,12 @@ impl ValueRef { if ctx.cfg.debug_mode { if int_32_overflow { - ctx.set_err_type(&ErrType::IntOverflow_TYPE); + ctx.set_err_type(&RuntimeErrorType::IntOverflow); panic!("{v_i128}: A 32 bit integer overflow"); } if int_64_overflow { - ctx.set_err_type(&ErrType::IntOverflow_TYPE); + ctx.set_err_type(&RuntimeErrorType::IntOverflow); panic!("{v_i128}: A 64 bit integer overflow"); } @@ -209,12 +209,12 @@ impl ValueRef { let float64_overflow = strict_range_check_i64 && (*v).is_infinite(); if float32_overflow { - ctx.set_err_type(&ErrType::FloatOverflow_TYPE); + ctx.set_err_type(&RuntimeErrorType::FloatOverflow); panic!("inf: A 32-bit floating point number overflow"); } if float64_overflow { - ctx.set_err_type(&ErrType::FloatOverflow_TYPE); + ctx.set_err_type(&RuntimeErrorType::FloatOverflow); panic!("inf: A 64-bit floating point number overflow"); } @@ -229,12 +229,12 @@ impl ValueRef { let float32_overflow = strict_range_check_i32 && (v as f32).is_infinite(); let float64_overflow = strict_range_check_i64 && (v).is_infinite(); if float32_overflow { - ctx.set_err_type(&ErrType::FloatOverflow_TYPE); + ctx.set_err_type(&RuntimeErrorType::FloatOverflow); panic!("inf: A 32-bit floating point number overflow"); } if float64_overflow { - ctx.set_err_type(&ErrType::FloatOverflow_TYPE); + ctx.set_err_type(&RuntimeErrorType::FloatOverflow); panic!("inf: A 64-bit floating point number overflow"); } diff --git a/kclvm/runtime/src/stdlib/builtin_api.rs b/kclvm/runtime/src/stdlib/builtin_api.rs index c66551915..5a977f53c 100644 --- a/kclvm/runtime/src/stdlib/builtin_api.rs +++ b/kclvm/runtime/src/stdlib/builtin_api.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. #![allow(clippy::missing_safety_doc)] use std::os::raw::c_char; diff --git a/kclvm/runtime/src/stdlib/mod.rs b/kclvm/runtime/src/stdlib/mod.rs index 74325147a..1b30846d6 100644 --- a/kclvm/runtime/src/stdlib/mod.rs +++ b/kclvm/runtime/src/stdlib/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. pub mod assert_api; pub use assert_api::*; diff --git a/kclvm/runtime/src/stdlib/plugin.rs b/kclvm/runtime/src/stdlib/plugin.rs index 6b15d7c2d..5e70586bb 100644 --- a/kclvm/runtime/src/stdlib/plugin.rs +++ b/kclvm/runtime/src/stdlib/plugin.rs @@ -1,4 +1,5 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. + #![allow(clippy::missing_safety_doc)] use crate::*; @@ -51,7 +52,7 @@ pub unsafe extern "C" fn kclvm_plugin_invoke( { if let Some(msg) = ptr_as_ref(ptr).dict_get_value("__kcl_PanicInfo__") { let ctx = mut_ptr_as_ref(ctx); - ctx.set_err_type(&ErrType::EvaluationError_TYPE); + ctx.set_err_type(&RuntimeErrorType::EvaluationError); panic!("{}", msg.as_str()); } diff --git a/kclvm/runtime/src/types/typ_new.rs b/kclvm/runtime/src/types/constructor.rs similarity index 96% rename from kclvm/runtime/src/types/typ_new.rs rename to kclvm/runtime/src/types/constructor.rs index eec4df3ff..f3c5227e0 100644 --- a/kclvm/runtime/src/types/typ_new.rs +++ b/kclvm/runtime/src/types/constructor.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/types/typ_kind.rs b/kclvm/runtime/src/types/kind.rs similarity index 93% rename from kclvm/runtime/src/types/typ_kind.rs rename to kclvm/runtime/src/types/kind.rs index 3c11d8fa2..ce88786c3 100644 --- a/kclvm/runtime/src/types/typ_kind.rs +++ b/kclvm/runtime/src/types/kind.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/types/mod.rs b/kclvm/runtime/src/types/mod.rs index 560b722bf..851a5e286 100644 --- a/kclvm/runtime/src/types/mod.rs +++ b/kclvm/runtime/src/types/mod.rs @@ -1,7 +1,5 @@ -// Copyright The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. -pub mod typ_kind; - -pub mod typ_new; - -pub mod typ_type_str; +pub mod constructor; +pub mod kind; +pub mod str; diff --git a/kclvm/runtime/src/types/typ_type_str.rs b/kclvm/runtime/src/types/str.rs similarity index 96% rename from kclvm/runtime/src/types/typ_type_str.rs rename to kclvm/runtime/src/types/str.rs index 2c369bebe..5b83c5e35 100644 --- a/kclvm/runtime/src/types/typ_type_str.rs +++ b/kclvm/runtime/src/types/str.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/unification/mod.rs b/kclvm/runtime/src/unification/mod.rs index ff06983fc..55d8d4141 100644 --- a/kclvm/runtime/src/unification/mod.rs +++ b/kclvm/runtime/src/unification/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. pub mod subsume; pub use subsume::*; diff --git a/kclvm/runtime/src/unification/subsume.rs b/kclvm/runtime/src/unification/subsume.rs index 94b7c150b..25140be6c 100644 --- a/kclvm/runtime/src/unification/subsume.rs +++ b/kclvm/runtime/src/unification/subsume.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/units/mod.rs b/kclvm/runtime/src/units/mod.rs index 6edec3825..2dc4091bc 100644 --- a/kclvm/runtime/src/units/mod.rs +++ b/kclvm/runtime/src/units/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/api.rs b/kclvm/runtime/src/value/api.rs index c28d19c3f..f05b2069e 100644 --- a/kclvm/runtime/src/value/api.rs +++ b/kclvm/runtime/src/value/api.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. #![allow(clippy::missing_safety_doc)] use std::{mem::transmute_copy, os::raw::c_char}; @@ -286,13 +286,7 @@ pub unsafe extern "C" fn kclvm_value_schema_with_config( // Config dict let config = ptr_as_ref(config); let config_meta = ptr_as_ref(config_meta); - let config_keys: Vec = config - .as_dict_ref() - .values - .keys() - .into_iter() - .cloned() - .collect(); + let config_keys: Vec = config.as_dict_ref().values.keys().cloned().collect(); // Schema meta let name = c2str(name); let pkgpath = c2str(pkgpath); @@ -1948,19 +1942,13 @@ pub unsafe extern "C" fn kclvm_value_load_attr( // load_attr including str/dict/schema. if p.is_dict() { match p.dict_get_value(key) { - Some(x) => { - return x.into_raw(ctx_ref); - } - None => { - return kclvm_value_Undefined(ctx); - } + Some(x) => x.into_raw(ctx_ref), + None => kclvm_value_Undefined(ctx), } } else if p.is_schema() { let dict = p.schema_to_dict(); match dict.dict_get_value(key) { - Some(x) => { - return x.into_raw(ctx_ref); - } + Some(x) => x.into_raw(ctx_ref), None => panic!("schema '{}' attribute '{}' not found", p.type_str(), key), } } else if p.is_str() { @@ -1997,10 +1985,10 @@ pub unsafe extern "C" fn kclvm_value_load_attr( _ => panic!("str object attr '{key}' not found"), }; let closure = ValueRef::list(Some(&[p])); - return new_mut_ptr( + new_mut_ptr( ctx_ref, ValueRef::func(function as usize as u64, 0, closure, "", "", false), - ); + ) } // schema instance else if p.is_func() { @@ -2009,16 +1997,17 @@ pub unsafe extern "C" fn kclvm_value_load_attr( _ => panic!("schema object attr '{key}' not found"), }; let closure = ValueRef::list(Some(&[p])); - return new_mut_ptr( + new_mut_ptr( ctx_ref, ValueRef::func(function as usize as u64, 0, closure, "", "", false), + ) + } else { + panic!( + "invalid value '{}' to load attribute '{}'", + p.type_str(), + key ); } - panic!( - "invalid value '{}' to load attribute '{}'", - p.type_str(), - key - ); } #[no_mangle] @@ -2338,7 +2327,7 @@ pub unsafe extern "C" fn kclvm_schema_assert( let config_meta = ptr_as_ref(config_meta); if !value.is_truthy() { let ctx = mut_ptr_as_ref(ctx); - ctx.set_err_type(&ErrType::SchemaCheckFailure_TYPE); + ctx.set_err_type(&RuntimeErrorType::SchemaCheckFailure); if let Some(config_meta_file) = config_meta.get_by_key(CONFIG_META_FILENAME) { let config_meta_line = config_meta.get_by_key(CONFIG_META_LINE).unwrap(); let config_meta_column = config_meta.get_by_key(CONFIG_META_COLUMN).unwrap(); diff --git a/kclvm/runtime/src/value/iter.rs b/kclvm/runtime/src/value/iter.rs index 224bab593..2aa5467ca 100644 --- a/kclvm/runtime/src/value/iter.rs +++ b/kclvm/runtime/src/value/iter.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/mod.rs b/kclvm/runtime/src/value/mod.rs index a474d855b..009c0b968 100644 --- a/kclvm/runtime/src/value/mod.rs +++ b/kclvm/runtime/src/value/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. pub mod val_panic; diff --git a/kclvm/runtime/src/value/val.rs b/kclvm/runtime/src/value/val.rs index 958373dc4..7371ced5c 100644 --- a/kclvm/runtime/src/value/val.rs +++ b/kclvm/runtime/src/value/val.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/val_args.rs b/kclvm/runtime/src/value/val_args.rs index 3702a0658..2e9a83169 100644 --- a/kclvm/runtime/src/value/val_args.rs +++ b/kclvm/runtime/src/value/val_args.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/val_as_val.rs b/kclvm/runtime/src/value/val_as_val.rs index 73ffd66dc..a6cdeb92e 100644 --- a/kclvm/runtime/src/value/val_as_val.rs +++ b/kclvm/runtime/src/value/val_as_val.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; use std::cell::Ref; diff --git a/kclvm/runtime/src/value/val_bin.rs b/kclvm/runtime/src/value/val_bin.rs index 2654535ff..fe2e07767 100644 --- a/kclvm/runtime/src/value/val_bin.rs +++ b/kclvm/runtime/src/value/val_bin.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/val_bin_aug.rs b/kclvm/runtime/src/value/val_bin_aug.rs index 9dd20e71d..d5e2c4543 100644 --- a/kclvm/runtime/src/value/val_bin_aug.rs +++ b/kclvm/runtime/src/value/val_bin_aug.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/val_clone.rs b/kclvm/runtime/src/value/val_clone.rs index c9348d4ad..3ca591529 100644 --- a/kclvm/runtime/src/value/val_clone.rs +++ b/kclvm/runtime/src/value/val_clone.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use std::boxed::Box; use std::cell::RefCell; diff --git a/kclvm/runtime/src/value/val_cmp.rs b/kclvm/runtime/src/value/val_cmp.rs index 68df1d43e..b4126552d 100644 --- a/kclvm/runtime/src/value/val_cmp.rs +++ b/kclvm/runtime/src/value/val_cmp.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/val_decorator.rs b/kclvm/runtime/src/value/val_decorator.rs index 0a2627c9b..33cf3c2d9 100644 --- a/kclvm/runtime/src/value/val_decorator.rs +++ b/kclvm/runtime/src/value/val_decorator.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; @@ -63,7 +63,7 @@ impl DecoratorValue { ctx.set_kcl_filename(&filename.as_str()); ctx.panic_info.kcl_line = line.as_int() as i32; } - ctx.set_err_type(&ErrType::Deprecated_TYPE); + ctx.set_err_type(&RuntimeErrorType::Deprecated); panic!("{}", err_msg) } @@ -72,11 +72,11 @@ impl DecoratorValue { if !msg.is_empty() { err_msg.push_str(&msg); } - ctx.set_err_type(&ErrType::Deprecated_Warning_TYPE); + ctx.set_err_type(&RuntimeErrorType::DeprecatedWarning); ctx.set_warnning_message(err_msg.as_str()); } else { let err_msg = format!("{attr_name} was deprecated "); - ctx.set_err_type(&ErrType::Deprecated_Warning_TYPE); + ctx.set_err_type(&RuntimeErrorType::DeprecatedWarning); ctx.set_warnning_message(err_msg.as_str()); } } @@ -97,7 +97,7 @@ impl DecoratorValue { mod test_value_decorator { use crate::*; - fn assert_panic () + std::panic::UnwindSafe>(func: F) { + fn assert_panic(func: F) { let result = std::panic::catch_unwind(func); assert!(result.is_err()) } diff --git a/kclvm/runtime/src/value/val_dict.rs b/kclvm/runtime/src/value/val_dict.rs index cdc6d801f..e3588f1b7 100644 --- a/kclvm/runtime/src/value/val_dict.rs +++ b/kclvm/runtime/src/value/val_dict.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; use std::cell::Ref; @@ -317,12 +317,12 @@ impl ValueRef { if strict_range_check_i32 { if v_i128 != ((v_i128 as i32) as i128) { - ctx.set_err_type(&ErrType::IntOverflow_TYPE); + ctx.set_err_type(&RuntimeErrorType::IntOverflow); panic!("{v_i128}: A 32 bit integer overflow"); } } else if strict_range_check_i64 && v_i128 != ((v_i128 as i64) as i128) { - ctx.set_err_type(&ErrType::IntOverflow_TYPE); + ctx.set_err_type(&RuntimeErrorType::IntOverflow); panic!("{v_i128}: A 64 bit integer overflow"); } diff --git a/kclvm/runtime/src/value/val_fmt.rs b/kclvm/runtime/src/value/val_fmt.rs index 897c9ea4d..30e3a1e1a 100644 --- a/kclvm/runtime/src/value/val_fmt.rs +++ b/kclvm/runtime/src/value/val_fmt.rs @@ -1,6 +1,6 @@ //! Ref: https://github.com/RustPython/RustPython/blob/main/vm/src/format.rs //! -//! Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use itertools::{Itertools, PeekingNext}; use std::cmp; diff --git a/kclvm/runtime/src/value/val_from.rs b/kclvm/runtime/src/value/val_from.rs index 331cf4f14..01fa21eba 100644 --- a/kclvm/runtime/src/value/val_from.rs +++ b/kclvm/runtime/src/value/val_from.rs @@ -217,7 +217,7 @@ mod tests_from { fn test_list() { let list = vec![true, false]; - let list_value: ValueRef = ValueRef::from_iter(list.clone().into_iter()); + let list_value: ValueRef = ValueRef::from_iter(list.clone()); assert_eq!(list.len(), list_value.len()); for (i, v) in list.iter().enumerate() { @@ -230,7 +230,7 @@ mod tests_from { fn test_list2() { let list = vec![1, 2, 4, 3]; - let list_value: ValueRef = ValueRef::from_iter(list.clone().into_iter()); + let list_value: ValueRef = ValueRef::from_iter(list.clone()); let list_value: Box = list_value.try_into().unwrap(); assert_eq!( @@ -257,8 +257,8 @@ mod tests_from { }; } - test_try_into!(test_try_into_bool, bool, vec![true, false, true, true]); - test_try_into!(test_try_into_i64, i64, vec![1, 2, 3, -1]); - test_try_into!(test_try_into_f64, f64, vec![1.5, 2.0]); - test_try_into!(test_try_into_str, String, vec!["", "abc"]); + test_try_into!(test_try_into_bool, bool, [true, false, true, true]); + test_try_into!(test_try_into_i64, i64, [1, 2, 3, -1]); + test_try_into!(test_try_into_f64, f64, [1.5, 2.0]); + test_try_into!(test_try_into_str, String, ["", "abc"]); } diff --git a/kclvm/runtime/src/value/val_get_set.rs b/kclvm/runtime/src/value/val_get_set.rs index c1d2ee3ce..67b3bf377 100644 --- a/kclvm/runtime/src/value/val_get_set.rs +++ b/kclvm/runtime/src/value/val_get_set.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/val_is_in.rs b/kclvm/runtime/src/value/val_is_in.rs index 7d627b602..339920755 100644 --- a/kclvm/runtime/src/value/val_is_in.rs +++ b/kclvm/runtime/src/value/val_is_in.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/val_json.rs b/kclvm/runtime/src/value/val_json.rs index c5138798a..8e6901578 100644 --- a/kclvm/runtime/src/value/val_json.rs +++ b/kclvm/runtime/src/value/val_json.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use bstr::ByteSlice; use indexmap::IndexMap; diff --git a/kclvm/runtime/src/value/val_kind.rs b/kclvm/runtime/src/value/val_kind.rs index 0fb305c22..3e36e83d6 100644 --- a/kclvm/runtime/src/value/val_kind.rs +++ b/kclvm/runtime/src/value/val_kind.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/val_len.rs b/kclvm/runtime/src/value/val_len.rs index 846fe14cb..602dc81a4 100644 --- a/kclvm/runtime/src/value/val_len.rs +++ b/kclvm/runtime/src/value/val_len.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; @@ -22,7 +22,7 @@ impl ValueRef { mod test_value_len { use crate::*; - fn assert_panic () + std::panic::UnwindSafe>(func: F) { + fn assert_panic(func: F) { let result = std::panic::catch_unwind(func); assert!(result.is_err()) } diff --git a/kclvm/runtime/src/value/val_list.rs b/kclvm/runtime/src/value/val_list.rs index e1d265df8..b1551293b 100644 --- a/kclvm/runtime/src/value/val_list.rs +++ b/kclvm/runtime/src/value/val_list.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/val_logic.rs b/kclvm/runtime/src/value/val_logic.rs index ea5d0267f..bb9a2179e 100644 --- a/kclvm/runtime/src/value/val_logic.rs +++ b/kclvm/runtime/src/value/val_logic.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/val_overflow.rs b/kclvm/runtime/src/value/val_overflow.rs index 9fd9cc01e..9d584c978 100644 --- a/kclvm/runtime/src/value/val_overflow.rs +++ b/kclvm/runtime/src/value/val_overflow.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. pub fn is_i32_overflow(v: i64) -> bool { v > i32::MAX as i64 || v < i32::MIN as i64 diff --git a/kclvm/runtime/src/value/val_panic.rs b/kclvm/runtime/src/value/val_panic.rs index 8b49544f4..541a37ccd 100644 --- a/kclvm/runtime/src/value/val_panic.rs +++ b/kclvm/runtime/src/value/val_panic.rs @@ -1,10 +1,10 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. #[macro_export] macro_rules! panic_i32_overflow { ($ctx: expr,$v: expr) => { let v = $v as i128; - $ctx.set_err_type(&ErrType::IntOverflow_TYPE); + $ctx.set_err_type(&RuntimeErrorType::IntOverflow); panic!("{}: A 32 bit integer overflow", v) }; } @@ -13,7 +13,7 @@ macro_rules! panic_i32_overflow { macro_rules! panic_i64_overflow { ($ctx: expr,$v: expr) => { let v = $v as i128; - $ctx.set_err_type(&ErrType::IntOverflow_TYPE); + $ctx.set_err_type(&RuntimeErrorType::IntOverflow); panic!("{}: A 64 bit integer overflow", v) }; } @@ -22,7 +22,7 @@ macro_rules! panic_f32_overflow { ($ctx: expr,$v: expr) => { let v = $v as f64; - $ctx.set_err_type(&ErrType::FloatOverflow_TYPE); + $ctx.set_err_type(&RuntimeErrorType::FloatOverflow); let mut s = format!("{:e}: A 32-bit floating point number overflow", v); if !s.contains("e-") { diff --git a/kclvm/runtime/src/value/val_plan.rs b/kclvm/runtime/src/value/val_plan.rs index de79a30ac..82c37cf3e 100644 --- a/kclvm/runtime/src/value/val_plan.rs +++ b/kclvm/runtime/src/value/val_plan.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; use std::boxed::Box; @@ -278,11 +278,9 @@ impl ValueRef { let path = &path_selector[0]; match self.get_by_path(path) { Some(value) => Ok(value), - None => { - return Err(format!( - "invalid path select operand {path}, value not found" - )) - } + None => Err(format!( + "invalid path select operand {path}, value not found" + )), } } else { let mut values = ValueRef::list(None); diff --git a/kclvm/runtime/src/value/val_schema.rs b/kclvm/runtime/src/value/val_schema.rs index 0d8a11426..412594a24 100644 --- a/kclvm/runtime/src/value/val_schema.rs +++ b/kclvm/runtime/src/value/val_schema.rs @@ -1,4 +1,4 @@ -// Copyright The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use indexmap::IndexSet; @@ -167,7 +167,7 @@ impl ValueRef { if recursive { for value in attr_map.values() { // For composite type structures, we recursively check the schema within them. - walk_value_mut(&value, &mut |value: &ValueRef| { + walk_value_mut(value, &mut |value: &ValueRef| { if value.is_schema() { value.schema_check_attr_optional(ctx, true); } diff --git a/kclvm/runtime/src/value/val_str.rs b/kclvm/runtime/src/value/val_str.rs index b97591cda..f961adceb 100644 --- a/kclvm/runtime/src/value/val_str.rs +++ b/kclvm/runtime/src/value/val_str.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; use bstr::ByteSlice; diff --git a/kclvm/runtime/src/value/val_type.rs b/kclvm/runtime/src/value/val_type.rs index 16419d2f3..84ee41860 100644 --- a/kclvm/runtime/src/value/val_type.rs +++ b/kclvm/runtime/src/value/val_type.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. extern crate fancy_regex; diff --git a/kclvm/runtime/src/value/val_unary.rs b/kclvm/runtime/src/value/val_unary.rs index 582f0e2a5..4d964e5c7 100644 --- a/kclvm/runtime/src/value/val_unary.rs +++ b/kclvm/runtime/src/value/val_unary.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; diff --git a/kclvm/runtime/src/value/val_union.rs b/kclvm/runtime/src/value/val_union.rs index e300d7860..5c425030b 100644 --- a/kclvm/runtime/src/value/val_union.rs +++ b/kclvm/runtime/src/value/val_union.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::unification::value_subsume; use crate::*; diff --git a/kclvm/runtime/src/value/val_yaml.rs b/kclvm/runtime/src/value/val_yaml.rs index 0a0b7f379..7b4705845 100644 --- a/kclvm/runtime/src/value/val_yaml.rs +++ b/kclvm/runtime/src/value/val_yaml.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. extern crate serde_json; extern crate serde_yaml; diff --git a/kclvm/runtime/src/value/walker.rs b/kclvm/runtime/src/value/walker.rs index dd61a84ac..f3f233580 100644 --- a/kclvm/runtime/src/value/walker.rs +++ b/kclvm/runtime/src/value/walker.rs @@ -1,7 +1,7 @@ use crate::{Value, ValueRef}; /// Walk the value recursively and deal the type using the `walk_fn` -pub fn walk_value(val: &ValueRef, walk_fn: &impl Fn(&ValueRef) -> ()) { +pub fn walk_value(val: &ValueRef, walk_fn: &impl Fn(&ValueRef)) { walk_fn(val); match &*val.rc.borrow() { Value::list_value(list_value) => { @@ -24,7 +24,7 @@ pub fn walk_value(val: &ValueRef, walk_fn: &impl Fn(&ValueRef) -> ()) { } /// Walk the value recursively and mutably and deal the type using the `walk_fn` -pub fn walk_value_mut(val: &ValueRef, walk_fn: &mut impl FnMut(&ValueRef) -> ()) { +pub fn walk_value_mut(val: &ValueRef, walk_fn: &mut impl FnMut(&ValueRef)) { walk_fn(val); match &*val.rc.borrow() { Value::list_value(list_value) => { diff --git a/kclvm/runtime/src/yaml/mod.rs b/kclvm/runtime/src/yaml/mod.rs index d7841a840..ad384ed42 100644 --- a/kclvm/runtime/src/yaml/mod.rs +++ b/kclvm/runtime/src/yaml/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +//! Copyright The KCL Authors. All rights reserved. use crate::*; pub const YAML_STREAM_SEP: &str = "\n---\n"; diff --git a/kclvm/runtime/tools/kclvm-runtime-gen-api/main.go b/kclvm/runtime/tools/kclvm-runtime-gen-api/main.go index a3831ecaa..fdc4ad5fe 100644 --- a/kclvm/runtime/tools/kclvm-runtime-gen-api/main.go +++ b/kclvm/runtime/tools/kclvm-runtime-gen-api/main.go @@ -1,4 +1,4 @@ -// Copyright 2021 The KCL Authors. All rights reserved. +// Copyright The KCL Authors. All rights reserved. package main @@ -205,7 +205,7 @@ func LoadAllApiSpec(root string) []ApiSpec { const tmplCApi = ` {{$specList := .}} -// Copyright 2021 The KCL Authors. All rights reserved. +// Copyright The KCL Authors. All rights reserved. // Auto generated, DONOT EDIT!!! @@ -281,7 +281,7 @@ enum kclvm_kind_t { const tmplLLApi = ` {{$specList := .}} -; Copyright 2021 The KCL Authors. All rights reserved. +; Copyright The KCL Authors. All rights reserved. ; Auto generated, DONOT EDIT!!! @@ -304,7 +304,7 @@ define void @__kcl_keep_link_runtime(%kclvm_value_ref_t* %_a, %kclvm_context_t* const tmplRustEnum = ` {{$specList := .}} -// Copyright 2021 The KCL Authors. All rights reserved. +// Copyright The KCL Authors. All rights reserved. // Auto generated, DONOT EDIT!!! @@ -356,7 +356,7 @@ impl ApiFunc { const tmplRustAddr = ` {{$specList := .}} -// Copyright 2021 The KCL Authors. All rights reserved. +// Copyright The KCL Authors. All rights reserved. // Auto generated, DONOT EDIT!!! diff --git a/kclvm/runtime/tools/kclvm-runtime-gen-err-type/Makefile b/kclvm/runtime/tools/kclvm-runtime-gen-err-type/Makefile deleted file mode 100644 index 84bc7fbe3..000000000 --- a/kclvm/runtime/tools/kclvm-runtime-gen-err-type/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright 2021 The KCL Authors. All rights reserved. - -default: - kclvm ./main.py > ../../src/api/err_type.rs - -clean: diff --git a/kclvm/runtime/tools/kclvm-runtime-gen-err-type/main.py b/kclvm/runtime/tools/kclvm-runtime-gen-err-type/main.py deleted file mode 100644 index c527cdbf0..000000000 --- a/kclvm/runtime/tools/kclvm-runtime-gen-err-type/main.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2021 The KCL Authors. All rights reserved. - -import kclvm.kcl.error as kcl_error - -# enum -> code -# kcl_error.ErrType.EvaluationError_TYPE.value[0] - -# code -> type -# x = kcl_error.ErrType((6,)) - -print( - """// Copyright 2021 The KCL Authors. All rights reserved. - -// Auto generated, DONOT EDIT!!! - -// python: kclvm.kcl.error.ErrType - -#[derive(Copy, Clone)] -#[allow(non_camel_case_types)] -pub enum ErrType {""" -) -for x in kcl_error.ErrType: - print(f" {x.name} = {x.value[0]},") -print("}")