difftreelog
refactor move modules from root
in: master
31 files changed
bindings/jsonnet/src/native.rsdiffbeforeafterboth8use gcmodule::Cc;8use gcmodule::Cc;9use jrsonnet_evaluator::{9use jrsonnet_evaluator::{10 error::{Error, LocError},10 error::{Error, LocError},11 function::BuiltinParam,11 function::builtin::{BuiltinParam, NativeCallback, NativeCallbackHandler},12 gc::TraceBox,12 gc::TraceBox,13 native::{NativeCallback, NativeCallbackHandler},14 typed::Typed,13 typed::Typed,15 IStr, State, Val,14 IStr, State, Val,16};15};crates/jrsonnet-evaluator/src/builtin/format.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/builtin/manifest.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/builtin/sort.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/builtin/stdlib.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth11use thiserror::Error;11use thiserror::Error;121213use crate::{13use crate::{14 builtin::{format::FormatError, sort::SortError},14 stdlib::{format::FormatError, sort::SortError},15 typed::TypeLocError,15 typed::TypeLocError,16};16};1717crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth7use jrsonnet_types::ValType;7use jrsonnet_types::ValType;889use crate::{9use crate::{10 builtin::{std_slice, BUILTINS},11 error::Error::*,10 error::Error::*,12 evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op},11 evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op},13 function::CallLocation,12 function::{CallLocation, FuncDesc, FuncVal},14 gc::TraceBox,13 gc::TraceBox,14 stdlib::{std_slice, BUILTINS},15 throw,15 throw,16 typed::Typed,16 typed::Typed,17 val::{ArrValue, FuncDesc, FuncVal, LazyValValue},17 val::{ArrValue, LazyValValue},18 Bindable, Context, ContextCreator, FutureWrapper, GcHashMap, LazyBinding, LazyVal, ObjValue,18 Bindable, Context, ContextCreator, FutureWrapper, GcHashMap, LazyBinding, LazyVal, ObjValue,19 ObjValueBuilder, ObjectAssertion, Result, State, Val,19 ObjValueBuilder, ObjectAssertion, Result, State, Val,20};20};676 .ok_or_else(|| IntrinsicNotFound(name.clone()))?,676 .ok_or_else(|| IntrinsicNotFound(name.clone()))?,677 )),677 )),678 IntrinsicThisFile => return Err(MagicThisFileUsed.into()),678 IntrinsicThisFile => return Err(MagicThisFileUsed.into()),679 IntrinsicId => Val::Func(FuncVal::identity()),679 AssertExpr(assert, returned) => {680 AssertExpr(assert, returned) => {680 evaluate_assert(s.clone(), ctx.clone(), assert)?;681 evaluate_assert(s.clone(), ctx.clone(), assert)?;681 evaluate(s, ctx, returned)?682 evaluate(s, ctx, returned)?crates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth3use jrsonnet_parser::{BinaryOpType, LocExpr, UnaryOpType};3use jrsonnet_parser::{BinaryOpType, LocExpr, UnaryOpType};445use crate::{5use crate::{6 builtin::std_format, error::Error::*, evaluate, throw, typed::Typed, val::equals, Context,6 error::Error::*, evaluate, stdlib::std_format, throw, typed::Typed, val::equals, Context,7 Result, State, Val,7 Result, State, Val,8};8};99crates/jrsonnet-evaluator/src/function.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/function/arglike.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/function/builtin.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/function/native.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/function/parse.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth22// For jrsonnet-macros22// For jrsonnet-macros23extern crate self as jrsonnet_evaluator;23extern crate self as jrsonnet_evaluator;242425mod builtin;26mod ctx;25mod ctx;27mod dynamic;26mod dynamic;28pub mod error;27pub mod error;32mod import;31mod import;33mod integrations;32mod integrations;34mod map;33mod map;35pub mod native;34mod obj;36mod obj;35mod stdlib;37pub mod trace;36pub mod trace;38pub mod typed;37pub mod typed;39pub mod val;38pub mod val;403941use std::{40use std::{42 cell::{Ref, RefCell, RefMut},41 cell::{Ref, RefCell, RefMut},43 collections::HashMap,42 collections::HashMap,44 fmt::Debug,43 fmt::{self, Debug},45 path::{Path, PathBuf},44 path::{Path, PathBuf},46 rc::Rc,45 rc::Rc,47};46};50pub use dynamic::*;49pub use dynamic::*;51use error::{Error::*, LocError, Result, StackTraceElement};50use error::{Error::*, LocError, Result, StackTraceElement};52pub use evaluate::*;51pub use evaluate::*;53use function::{Builtin, CallLocation, TlaArg};52use function::{builtin::Builtin, CallLocation, TlaArg};54use gc::{GcHashMap, TraceBox};53use gc::{GcHashMap, TraceBox};55use gcmodule::{Cc, Trace, Weak};54use gcmodule::{Cc, Trace, Weak};56pub use import::*;55pub use import::*;77}76}787779impl Debug for LazyBinding {78impl Debug for LazyBinding {80 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {79 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {81 write!(f, "LazyBinding")80 write!(f, "LazyBinding")82 }81 }83}82}329 self.add_parsed_file(328 self.add_parsed_file(330 std_path.clone(),329 std_path.clone(),331 STDLIB_STR.to_owned().into(),330 STDLIB_STR.to_owned().into(),332 builtin::get_parsed_stdlib(),331 stdlib::get_parsed_stdlib(),333 )332 )334 .expect("stdlib is correct");333 .expect("stdlib is correct");335 let val = self334 let val = selfcrates/jrsonnet-evaluator/src/native.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/stdlib/expr.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/stdlib/format.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/stdlib/manifest.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/stdlib/mod.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/stdlib/sort.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth778use crate::{8use crate::{9 error::{Error::*, Result},9 error::{Error::*, Result},10 function::{FuncDesc, FuncVal},10 throw,11 throw,11 typed::CheckType,12 typed::CheckType,12 val::{ArrValue, FuncDesc, FuncVal, IndexableVal},13 val::{ArrValue, IndexableVal},13 ObjValue, ObjValueBuilder, State, Val,14 ObjValue, ObjValueBuilder, State, Val,14};15};1516crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth223use gcmodule::{Cc, Trace};3use gcmodule::{Cc, Trace};4use jrsonnet_interner::IStr;4use jrsonnet_interner::IStr;5use jrsonnet_parser::{LocExpr, ParamsDesc};6use jrsonnet_types::ValType;5use jrsonnet_types::ValType;768use crate::{7use crate::{9 builtin::manifest::{10 manifest_json_ex, manifest_yaml_ex, ManifestJsonOptions, ManifestType, ManifestYamlOptions,11 },12 cc_ptr_eq,8 cc_ptr_eq,13 error::{Error::*, LocError},9 error::{Error::*, LocError},14 evaluate,15 function::{10 function::FuncVal,16 parse_default_function_call, parse_function_call, ArgsLike, Builtin, CallLocation,17 StaticBuiltin,18 },19 gc::TraceBox,11 gc::TraceBox,12 stdlib::manifest::{13 manifest_json_ex, manifest_yaml_ex, ManifestJsonOptions, ManifestType, ManifestYamlOptions,14 },20 throw, Context, ObjValue, Result, State,15 throw, ObjValue, Result, State,21};16};221723pub trait LazyValValue: Trace {18pub trait LazyValValue: Trace {83 }78 }84}79}8586#[derive(Debug, PartialEq, Trace)]87pub struct FuncDesc {88 pub name: IStr,89 pub ctx: Context,90 pub params: ParamsDesc,91 pub body: LocExpr,92}93impl FuncDesc {94 /// Create body context, but fill arguments without defaults with lazy error95 pub fn default_body_context(&self) -> Context {96 parse_default_function_call(self.ctx.clone(), &self.params)97 }9899 /// Create context, with which body code will run100 pub fn call_body_context(101 &self,102 s: State,103 call_ctx: Context,104 args: &dyn ArgsLike,105 tailstrict: bool,106 ) -> Result<Context> {107 parse_function_call(108 s,109 call_ctx,110 self.ctx.clone(),111 &self.params,112 args,113 tailstrict,114 )115 }116}117118#[allow(clippy::module_name_repetitions)]119#[derive(Trace, Clone)]120pub enum FuncVal {121 /// Plain function implemented in jsonnet122 Normal(Cc<FuncDesc>),123 /// Standard library function124 StaticBuiltin(#[skip_trace] &'static dyn StaticBuiltin),125 /// User-provided function126 Builtin(Cc<TraceBox<dyn Builtin>>),127}128129impl Debug for FuncVal {130 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {131 match self {132 Self::Normal(arg0) => f.debug_tuple("Normal").field(arg0).finish(),133 Self::StaticBuiltin(arg0) => {134 f.debug_tuple("StaticBuiltin").field(&arg0.name()).finish()135 }136 Self::Builtin(arg0) => f.debug_tuple("Builtin").field(&arg0.name()).finish(),137 }138 }139}140141impl FuncVal {142 pub fn args_len(&self) -> usize {143 match self {144 Self::Normal(n) => n.params.iter().filter(|p| p.1.is_none()).count(),145 Self::StaticBuiltin(i) => i.params().iter().filter(|p| !p.has_default).count(),146 Self::Builtin(i) => i.params().iter().filter(|p| !p.has_default).count(),147 }148 }149 pub fn name(&self) -> IStr {150 match self {151 Self::Normal(normal) => normal.name.clone(),152 Self::StaticBuiltin(builtin) => builtin.name().into(),153 Self::Builtin(builtin) => builtin.name().into(),154 }155 }156 pub fn evaluate(157 &self,158 s: State,159 call_ctx: Context,160 loc: CallLocation,161 args: &dyn ArgsLike,162 tailstrict: bool,163 ) -> Result<Val> {164 match self {165 Self::Normal(func) => {166 let body_ctx = func.call_body_context(s.clone(), call_ctx, args, tailstrict)?;167 evaluate(s, body_ctx, &func.body)168 }169 Self::StaticBuiltin(b) => b.call(s, call_ctx, loc, args),170 Self::Builtin(b) => b.call(s, call_ctx, loc, args),171 }172 }173 pub fn evaluate_simple(&self, s: State, args: &dyn ArgsLike) -> Result<Val> {174 self.evaluate(s, Context::default(), CallLocation::native(), args, true)175 }176}17780178#[derive(Clone)]81#[derive(Clone)]179pub enum ManifestFormat {82pub enum ManifestFormat {crates/jrsonnet-evaluator/tests/as_native.rsdiffbeforeafterbothno changes
crates/jrsonnet-evaluator/tests/builtin.rsdiffbeforeafterboth5use gcmodule::Cc;5use gcmodule::Cc;6use jrsonnet_evaluator::{6use jrsonnet_evaluator::{7 error::Result,7 error::Result,8 function::{builtin, Builtin, CallLocation},8 function::{builtin, builtin::Builtin, CallLocation, FuncVal},9 gc::TraceBox,9 gc::TraceBox,10 typed::Typed,10 typed::Typed,11 val::FuncVal,12 State, Val,11 State, Val,13};12};141326 s.clone(),25 s.clone(),27 s.create_default_context(),26 s.create_default_context(),28 CallLocation::native(),27 CallLocation::native(),29 &[],28 &(),30 )?,29 )?,31 s.clone(),30 s.clone(),32 )?;31 )?;crates/jrsonnet-evaluator/tests/common.rsdiffbeforeafterboth1use jrsonnet_evaluator::{1use jrsonnet_evaluator::{2 error::Result, function::builtin, throw_runtime, val::FuncVal, LazyVal, ObjValueBuilder, State,2 error::Result,3 function::{builtin, FuncVal},3 Val,4 throw_runtime, LazyVal, ObjValueBuilder, State, Val,4};5};566#[macro_export]7#[macro_export]7macro_rules! ensure_eq {8macro_rules! ensure_eq {8 ($a:expr, $b:expr $(,)?) => {{9 ($a:expr, $b:expr $(,)?) => {{10 let a = &$a;11 let b = &$b;9 if $a != $b {12 if a != b {10 ::jrsonnet_evaluator::throw_runtime!(13 ::jrsonnet_evaluator::throw_runtime!("assertion failed: a != b\na={:#?}\nb={:#?}", a, b)11 "assertion failed: a != b\na={:#?}\nb={:#?}",12 $a,13 $b,crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth349 const _: () = {349 const _: () = {350 use ::jrsonnet_evaluator::{350 use ::jrsonnet_evaluator::{351 State, Val,351 State, Val,352 function::{Builtin, CallLocation, StaticBuiltin, BuiltinParam, ArgsLike, parse_builtin_call},352 function::{builtin::{Builtin, StaticBuiltin, BuiltinParam}, CallLocation, ArgsLike, parse::parse_builtin_call},353 error::Result, Context, typed::Typed,353 error::Result, Context, typed::Typed,354 parser::ExprLocation,354 parser::ExprLocation,355 };355 };crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth298 Function(ParamsDesc, LocExpr),298 Function(ParamsDesc, LocExpr),299 /// std.thisFile299 /// std.thisFile300 IntrinsicThisFile,300 IntrinsicThisFile,301 /// std.id,302 IntrinsicId,301 /// std.primitiveEquals303 /// std.primitiveEquals302 Intrinsic(IStr),304 Intrinsic(IStr),303 /// if true == false then 1 else 2305 /// if true == false then 1 else 2crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth211 = literal(s)211 = literal(s)212212213 / quiet!{"$intrinsicThisFile" {Expr::IntrinsicThisFile}}213 / quiet!{"$intrinsicThisFile" {Expr::IntrinsicThisFile}}214 / quiet!{"$intrinsic(" name:$(id()) ")" {Expr::Intrinsic(name.into())}}214 / quiet!{"$intrinsicId" {Expr::IntrinsicId}}215 / quiet!{"$intrinsic(" name:$(id()) ")" {Expr::Intrinsic(name.into())}}215216216 / string_expr(s) / number_expr(s)217 / string_expr(s) / number_expr(s)217 / array_expr(s)218 / array_expr(s)crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth445 # Magic legacy field5 # Magic legacy field6 thisFile:: $intrinsicThisFile,6 thisFile:: $intrinsicThisFile,7 id:: $intrinsicId,788 # Those functions aren't normally located in stdlib9 # Those functions aren't normally located in stdlib9 length:: $intrinsic(length),10 length:: $intrinsic(length),24 decodeUTF8:: $intrinsic(decodeUTF8),25 decodeUTF8:: $intrinsic(decodeUTF8),25 md5:: $intrinsic(md5),26 md5:: $intrinsic(md5),26 trace:: $intrinsic(trace),27 trace:: $intrinsic(trace),27 id:: $intrinsic(id),28 parseJson:: $intrinsic(parseJson),28 parseJson:: $intrinsic(parseJson),29 parseYaml:: $intrinsic(parseYaml),29 parseYaml:: $intrinsic(parseYaml),3030