git.delta.rocks / jrsonnet / refs/commits / d0fb5f4781e5

difftreelog

feat exp-bigint

Yaroslav Bolyukin2023-04-17parent: #205090d.patch.diff
in: master

16 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -298,6 +298,7 @@
  "jrsonnet-macros",
  "jrsonnet-parser",
  "jrsonnet-types",
+ "num-bigint",
  "pathdiff",
  "rustc-hash",
  "serde",
@@ -370,6 +371,7 @@
  "jrsonnet-macros",
  "jrsonnet-parser",
  "md5",
+ "num-bigint",
  "serde",
  "serde_json",
  "serde_yaml_with_quirks",
@@ -449,6 +451,37 @@
 ]
 
 [[package]]
+name = "num-bigint"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
+dependencies = [
+ "autocfg",
+ "num-integer",
+ "num-traits",
+ "serde",
+]
+
+[[package]]
+name = "num-integer"
+version = "0.1.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
+dependencies = [
+ "autocfg",
+ "num-traits",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
 name = "once_cell"
 version = "1.17.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
modifiedCargo.tomldiffbeforeafterboth
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,5 @@
 [workspace]
-package.version = "0.5.0"
+package.version = "0.5.0-pre7"
 members = ["crates/*", "bindings/jsonnet", "cmds/jrsonnet", "tests"]
 default-members = ["cmds/jrsonnet"]
 
modifiedcmds/jrsonnet/Cargo.tomldiffbeforeafterboth
--- a/cmds/jrsonnet/Cargo.toml
+++ b/cmds/jrsonnet/Cargo.toml
@@ -19,6 +19,8 @@
 exp-destruct = ["jrsonnet-evaluator/exp-destruct"]
 # Iteration over objects yields [key, value] elements
 exp-object-iteration = ["jrsonnet-evaluator/exp-object-iteration"]
+# Bigint type
+exp-bigint = ["jrsonnet-evaluator/exp-bigint", "jrsonnet-cli/exp-bigint"]
 
 # std.thisFile support
 legacy-this-file = ["jrsonnet-cli/legacy-this-file"]
modifiedcrates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-cli/Cargo.toml
+++ b/crates/jrsonnet-cli/Cargo.toml
@@ -11,6 +11,10 @@
     "jrsonnet-evaluator/exp-preserve-order",
     "jrsonnet-stdlib/exp-preserve-order",
 ]
+exp-bigint = [
+    "jrsonnet-evaluator/exp-bigint",
+    "jrsonnet-stdlib/exp-bigint",
+]
 legacy-this-file = ["jrsonnet-stdlib/legacy-this-file"]
 
 [dependencies]
modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -24,6 +24,8 @@
 exp-destruct = ["jrsonnet-parser/exp-destruct"]
 # Iteration over objects yields [key, value] elements
 exp-object-iteration = []
+# Bigint type
+exp-bigint = ["num-bigint"]
 
 # Improves performance, and implements some useful things using nightly-only features
 nightly = ["hashbrown/nightly"]
@@ -54,3 +56,5 @@
 annotate-snippets = { version = "0.9.1", features = ["color"], optional = true }
 # Async imports
 async-trait = { version = "0.1.60", optional = true }
+# Bigint
+num-bigint = { version = "0.4.3", features = ["serde"], optional = true }
modifiedcrates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/operator.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/operator.rs
@@ -47,6 +47,8 @@
 		(Arr(a), Arr(b)) => Val::Arr(ArrValue::extended(a.clone(), b.clone())),
 
 		(Num(v1), Num(v2)) => Val::new_checked_num(v1 + v2)?,
+		#[cfg(feature = "exp-bigint")]
+		(BigInt(a), BigInt(b)) => BigInt(Box::new((&**a).clone() + (&**b).clone())),
 		_ => throw!(BinaryOperatorDoesNotOperateOnValues(
 			BinaryOpType::Add,
 			a.value_type(),
@@ -95,6 +97,8 @@
 	Ok(match (a, b) {
 		(Str(a), Str(b)) => a.cmp(b),
 		(Num(a), Num(b)) => a.partial_cmp(b).expect("jsonnet numbers are non NaN"),
+		#[cfg(feature = "exp-bigint")]
+		(BigInt(a), BigInt(b)) => a.cmp(b),
 		(Arr(a), Arr(b)) => {
 			if let (Some(ai), Some(bi)) = (a.iter_cheap(), b.iter_cheap()) {
 				for (a, b) in ai.zip(bi) {
@@ -174,6 +178,12 @@
 			Num(f64::from((*v1 as i32) >> (*v2 as i32)))
 		}
 
+		// Bigint X Bigint
+		#[cfg(feature = "exp-bigint")]
+		(BigInt(a), Mul, BigInt(b)) => BigInt(Box::new((&**a).clone() * (&**b).clone())),
+		#[cfg(feature = "exp-bigint")]
+		(BigInt(a), Sub, BigInt(b)) => BigInt(Box::new((&**a).clone() - (&**b).clone())),
+
 		_ => throw!(BinaryOperatorDoesNotOperateOnValues(
 			op,
 			a.value_type(),
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -162,6 +162,8 @@
 			Val::Null => serializer.serialize_none(),
 			Val::Str(s) => serializer.serialize_str(&s.clone().into_flat()),
 			Val::Num(n) => serializer.serialize_f64(*n),
+			#[cfg(feature = "exp-bigint")]
+			Val::BigInt(b) => b.serialize(serializer),
 			Val::Arr(arr) => {
 				let mut seq = serializer.serialize_seq(Some(arr.len()))?;
 				for (i, element) in arr.iter().enumerate() {
modifiedcrates/jrsonnet-evaluator/src/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/manifest.rs
@@ -149,6 +149,8 @@
 		Val::Null => buf.push_str("null"),
 		Val::Str(s) => escape_string_json_buf(&s.clone().into_flat(), buf),
 		Val::Num(n) => write!(buf, "{n}").unwrap(),
+		#[cfg(feature = "exp-bigint")]
+		Val::BigInt(n) => write!(buf, "{n}").unwrap(),
 		Val::Arr(items) => {
 			buf.push('[');
 			if !items.is_empty() {
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -311,6 +311,9 @@
 	/// Should be finite, and not NaN
 	/// This restriction isn't enforced by enum, as enum field can't be marked as private
 	Num(f64),
+	/// Experimental bigint
+	#[cfg(feature = "exp-bigint")]
+	BigInt(#[trace(skip)] Box<num_bigint::BigInt>),
 	/// Represents a Jsonnet array.
 	Arr(ArrValue),
 	/// Represents a Jsonnet object.
@@ -389,6 +392,8 @@
 		match self {
 			Self::Str(..) => ValType::Str,
 			Self::Num(..) => ValType::Num,
+			#[cfg(feature = "exp-bigint")]
+			Self::BigInt(..) => ValType::BigInt,
 			Self::Arr(..) => ValType::Arr,
 			Self::Obj(..) => ValType::Obj,
 			Self::Bool(_) => ValType::Bool,
modifiedcrates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/Cargo.toml
+++ b/crates/jrsonnet-stdlib/Cargo.toml
@@ -17,6 +17,8 @@
 exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order"]
 # Add nonstandard `std.sha256` function
 exp-more-hashes = ["dep:sha2"]
+# Bigint type
+exp-bigint = ["num-bigint", "jrsonnet-evaluator/exp-bigint"]
 
 [dependencies]
 jrsonnet-evaluator.workspace = true
@@ -39,6 +41,7 @@
 serde_yaml_with_quirks = "0.8.24"
 
 sha2 = { version = "0.10.6", optional = true }
+num-bigint = { version = "0.4.3", optional = true }
 
 [build-dependencies]
 jrsonnet-parser.workspace = true
modifiedcrates/jrsonnet-stdlib/src/expr.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/expr.rs
+++ b/crates/jrsonnet-stdlib/src/expr.rs
@@ -83,7 +83,7 @@
 			pub(super) use std::{option::Option, rc::Rc, vec};
 
 			pub(super) use jrsonnet_parser::*;
-		};
+		}
 
 		include!(concat!(env!("OUT_DIR"), "/stdlib.rs"))
 	}
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
before · crates/jrsonnet-stdlib/src/lib.rs
1use std::{2	cell::{Ref, RefCell, RefMut},3	collections::HashMap,4	rc::Rc,5};67use jrsonnet_evaluator::{8	error::{ErrorKind::*, Result},9	function::{builtin::Builtin, CallLocation, FuncVal, TlaArg},10	gc::{GcHashMap, TraceBox},11	tb,12	trace::PathResolver,13	Context, ContextBuilder, IStr, ObjValue, ObjValueBuilder, State, Thunk, Val,14};15use jrsonnet_gcmodule::{Cc, Trace};16use jrsonnet_parser::Source;1718mod expr;19mod types;20pub use types::*;21mod arrays;22pub use arrays::*;23mod math;24pub use math::*;25mod operator;26pub use operator::*;27mod sort;28pub use sort::*;29mod hash;30pub use hash::*;31mod encoding;32pub use encoding::*;33mod objects;34pub use objects::*;35mod manifest;36pub use manifest::*;37mod parse;38pub use parse::*;39mod strings;40pub use strings::*;41mod misc;42pub use misc::*;43mod sets;44pub use sets::*;45mod compat;46pub use compat::*;4748pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {49	let mut builder = ObjValueBuilder::new();5051	let expr = expr::stdlib_expr();52	let eval = jrsonnet_evaluator::evaluate(ContextBuilder::dangerous_empty_state().build(), &expr)53		.expect("stdlib.jsonnet should have no errors")54		.as_obj()55		.expect("stdlib.jsonnet should evaluate to object");5657	builder.with_super(eval);5859	for (name, builtin) in [60		// Types61		("type", builtin_type::INST),62		("isString", builtin_is_string::INST),63		("isNumber", builtin_is_number::INST),64		("isBoolean", builtin_is_boolean::INST),65		("isObject", builtin_is_object::INST),66		("isArray", builtin_is_array::INST),67		("isFunction", builtin_is_function::INST),68		// Arrays69		("makeArray", builtin_make_array::INST),70		("repeat", builtin_repeat::INST),71		("slice", builtin_slice::INST),72		("map", builtin_map::INST),73		("flatMap", builtin_flatmap::INST),74		("filter", builtin_filter::INST),75		("foldl", builtin_foldl::INST),76		("foldr", builtin_foldr::INST),77		("range", builtin_range::INST),78		("join", builtin_join::INST),79		("reverse", builtin_reverse::INST),80		("any", builtin_any::INST),81		("all", builtin_all::INST),82		("member", builtin_member::INST),83		("count", builtin_count::INST),84		// Math85		("abs", builtin_abs::INST),86		("sign", builtin_sign::INST),87		("max", builtin_max::INST),88		("min", builtin_min::INST),89		("sum", builtin_sum::INST),90		("modulo", builtin_modulo::INST),91		("floor", builtin_floor::INST),92		("ceil", builtin_ceil::INST),93		("log", builtin_log::INST),94		("pow", builtin_pow::INST),95		("sqrt", builtin_sqrt::INST),96		("sin", builtin_sin::INST),97		("cos", builtin_cos::INST),98		("tan", builtin_tan::INST),99		("asin", builtin_asin::INST),100		("acos", builtin_acos::INST),101		("atan", builtin_atan::INST),102		("exp", builtin_exp::INST),103		("mantissa", builtin_mantissa::INST),104		("exponent", builtin_exponent::INST),105		// Operator106		("mod", builtin_mod::INST),107		("primitiveEquals", builtin_primitive_equals::INST),108		("equals", builtin_equals::INST),109		("xor", builtin_xor::INST),110		("format", builtin_format::INST),111		// Sort112		("sort", builtin_sort::INST),113		("uniq", builtin_uniq::INST),114		("set", builtin_set::INST),115		// Hash116		("md5", builtin_md5::INST),117		#[cfg(feature = "exp-more-hashes")]118		("sha256", builtin_sha256::INST),119		// Encoding120		("encodeUTF8", builtin_encode_utf8::INST),121		("decodeUTF8", builtin_decode_utf8::INST),122		("base64", builtin_base64::INST),123		("base64Decode", builtin_base64_decode::INST),124		("base64DecodeBytes", builtin_base64_decode_bytes::INST),125		// Objects126		("objectFieldsEx", builtin_object_fields_ex::INST),127		("objectHasEx", builtin_object_has_ex::INST),128		// Manifest129		("escapeStringJson", builtin_escape_string_json::INST),130		("manifestJsonEx", builtin_manifest_json_ex::INST),131		("manifestYamlDoc", builtin_manifest_yaml_doc::INST),132		("manifestTomlEx", builtin_manifest_toml_ex::INST),133		// Parsing134		("parseJson", builtin_parse_json::INST),135		("parseYaml", builtin_parse_yaml::INST),136		// Strings137		("codepoint", builtin_codepoint::INST),138		("substr", builtin_substr::INST),139		("char", builtin_char::INST),140		("strReplace", builtin_str_replace::INST),141		("splitLimit", builtin_splitlimit::INST),142		("asciiUpper", builtin_ascii_upper::INST),143		("asciiLower", builtin_ascii_lower::INST),144		("findSubstr", builtin_find_substr::INST),145		("parseInt", builtin_parse_int::INST),146		("parseOctal", builtin_parse_octal::INST),147		("parseHex", builtin_parse_hex::INST),148		// Misc149		("length", builtin_length::INST),150		("startsWith", builtin_starts_with::INST),151		("endsWith", builtin_ends_with::INST),152		// Sets153		("setMember", builtin_set_member::INST),154		("setInter", builtin_set_inter::INST),155		// Compat156		("__compare", builtin___compare::INST),157	]158	.iter()159	.cloned()160	{161		builder162			.member(name.into())163			.hide()164			.value(Val::Func(FuncVal::StaticBuiltin(builtin)))165			.expect("no conflict");166	}167168	builder169		.member("extVar".into())170		.hide()171		.value(Val::Func(FuncVal::builtin(builtin_ext_var {172			settings: settings.clone(),173		})))174		.expect("no conflict");175	builder176		.member("native".into())177		.hide()178		.value(Val::Func(FuncVal::builtin(builtin_native {179			settings: settings.clone(),180		})))181		.expect("no conflict");182	builder183		.member("trace".into())184		.hide()185		.value(Val::Func(FuncVal::builtin(builtin_trace { settings })))186		.expect("no conflict");187188	builder189		.member("id".into())190		.hide()191		.value(Val::Func(FuncVal::Id))192		.expect("no conflict");193194	builder.build()195}196197pub trait TracePrinter {198	fn print_trace(&self, loc: CallLocation, value: IStr);199}200201pub struct StdTracePrinter {202	resolver: PathResolver,203}204impl StdTracePrinter {205	pub fn new(resolver: PathResolver) -> Self {206		Self { resolver }207	}208}209impl TracePrinter for StdTracePrinter {210	fn print_trace(&self, loc: CallLocation, value: IStr) {211		eprint!("TRACE:");212		if let Some(loc) = loc.0 {213			let locs = loc.0.map_source_locations(&[loc.1]);214			eprint!(215				" {}:{}",216				match loc.0.source_path().path() {217					Some(p) => self.resolver.resolve(p),218					None => loc.0.source_path().to_string(),219				},220				locs[0].line221			);222		}223		eprintln!(" {value}");224	}225}226227pub struct Settings {228	/// Used for `std.extVar`229	pub ext_vars: HashMap<IStr, TlaArg>,230	/// Used for `std.native`231	pub ext_natives: HashMap<IStr, Cc<TraceBox<dyn Builtin>>>,232	/// Helper to add globals without implementing custom ContextInitializer233	pub globals: GcHashMap<IStr, Thunk<Val>>,234	/// Used for `std.trace`235	pub trace_printer: Box<dyn TracePrinter>,236	/// Used for `std.thisFile`237	pub path_resolver: PathResolver,238}239240fn extvar_source(name: &str, code: impl Into<IStr>) -> Source {241	let source_name = format!("<extvar:{name}>");242	Source::new_virtual(source_name.into(), code.into())243}244245#[derive(Trace, Clone)]246pub struct ContextInitializer {247	// When we don't need to support legacy-this-file, we can reuse same context for all files248	#[cfg(not(feature = "legacy-this-file"))]249	context: Context,250	// Otherwise, we can only keep first stdlib layer, and then stack thisFile on top of it251	#[cfg(feature = "legacy-this-file")]252	stdlib_obj: ObjValue,253	settings: Rc<RefCell<Settings>>,254}255impl ContextInitializer {256	pub fn new(_s: State, resolver: PathResolver) -> Self {257		let settings = Settings {258			ext_vars: Default::default(),259			ext_natives: Default::default(),260			globals: Default::default(),261			trace_printer: Box::new(StdTracePrinter::new(resolver.clone())),262			path_resolver: resolver,263		};264		let settings = Rc::new(RefCell::new(settings));265		Self {266			#[cfg(not(feature = "legacy-this-file"))]267			context: {268				let mut context = ContextBuilder::with_capacity(_s, 1);269				context.bind(270					"std".into(),271					Thunk::evaluated(Val::Obj(stdlib_uncached(settings.clone()))),272				);273				context.build()274			},275			#[cfg(feature = "legacy-this-file")]276			stdlib_obj: stdlib_uncached(settings.clone()),277			settings,278		}279	}280	pub fn settings(&self) -> Ref<Settings> {281		self.settings.borrow()282	}283	pub fn settings_mut(&self) -> RefMut<Settings> {284		self.settings.borrow_mut()285	}286	pub fn add_ext_var(&self, name: IStr, value: Val) {287		self.settings_mut()288			.ext_vars289			.insert(name, TlaArg::Val(value));290	}291	pub fn add_ext_str(&self, name: IStr, value: IStr) {292		self.settings_mut()293			.ext_vars294			.insert(name, TlaArg::String(value));295	}296	pub fn add_ext_code(&self, name: &str, code: impl Into<IStr>) -> Result<()> {297		let code = code.into();298		let source = extvar_source(name, code.clone());299		let parsed = jrsonnet_parser::parse(300			&code,301			&jrsonnet_parser::ParserSettings {302				source: source.clone(),303			},304		)305		.map_err(|e| ImportSyntaxError {306			path: source,307			error: Box::new(e),308		})?;309		// self.data_mut().volatile_files.insert(source_name, code);310		self.settings_mut()311			.ext_vars312			.insert(name.into(), TlaArg::Code(parsed));313		Ok(())314	}315	pub fn add_native(&self, name: IStr, cb: impl Builtin) {316		self.settings_mut()317			.ext_natives318			.insert(name, Cc::new(tb!(cb)));319	}320}321impl jrsonnet_evaluator::ContextInitializer for ContextInitializer {322	#[cfg(not(feature = "legacy-this-file"))]323	fn initialize(&self, _s: State, _source: Source) -> jrsonnet_evaluator::Context {324		let out = self.context.clone();325		let globals = &self.settings().globals;326		if globals.is_empty() {327			return out;328		}329330		let mut out = ContextBuilder::extend(out);331		for (k, v) in globals.iter() {332			out.bind(k.clone(), v.clone());333		}334		out.build()335	}336	#[cfg(feature = "legacy-this-file")]337	fn initialize(&self, s: State, source: Source) -> Context {338		use jrsonnet_evaluator::val::StrValue;339340		let mut builder = ObjValueBuilder::new();341		builder.with_super(self.stdlib_obj.clone());342		builder343			.member("thisFile".into())344			.hide()345			.value(Val::Str(StrValue::Flat(346				match source.source_path().path() {347					Some(p) => self.settings().path_resolver.resolve(p).into(),348					None => source.source_path().to_string().into(),349				},350			)))351			.expect("this object builder is empty");352		let stdlib_with_this_file = builder.build();353354		let mut context = ContextBuilder::with_capacity(s, 1);355		context.bind(356			"std".into(),357			Thunk::evaluated(Val::Obj(stdlib_with_this_file)),358		);359		for (k, v) in self.settings().globals.iter() {360			context.bind(k.clone(), v.clone());361		}362		context.build()363	}364	fn as_any(&self) -> &dyn std::any::Any {365		self366	}367}368369pub trait StateExt {370	/// This method was previously implemented in jrsonnet-evaluator itself371	fn with_stdlib(&self);372	fn add_global(&self, name: IStr, value: Thunk<Val>);373}374375impl StateExt for State {376	fn with_stdlib(&self) {377		let initializer = ContextInitializer::new(self.clone(), PathResolver::new_cwd_fallback());378		self.settings_mut().context_initializer = tb!(initializer)379	}380	fn add_global(&self, name: IStr, value: Thunk<Val>) {381		self.settings()382			.context_initializer383			.as_any()384			.downcast_ref::<ContextInitializer>()385			.expect("not standard context initializer")386			.settings_mut()387			.globals388			.insert(name, value);389	}390}
modifiedcrates/jrsonnet-stdlib/src/manifest/toml.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/manifest/toml.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/toml.rs
@@ -103,6 +103,8 @@
 			escape_string_json_buf(&s.clone().into_flat(), buf);
 		}
 		Val::Num(n) => write!(buf, "{n}").unwrap(),
+		#[cfg(feature = "exp-bigint")]
+		Val::BigInt(n) => write!(buf, "{n}").unwrap(),
 		Val::Arr(a) => {
 			if a.is_empty() {
 				buf.push_str("[]");
modifiedcrates/jrsonnet-stdlib/src/manifest/yaml.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/manifest/yaml.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/yaml.rs
@@ -140,6 +140,8 @@
 			}
 		}
 		Val::Num(n) => write!(buf, "{}", *n).unwrap(),
+		#[cfg(feature = "exp-bigint")]
+		Val::BigInt(n) => write!(buf, "{}", *n).unwrap(),
 		Val::Arr(a) => {
 			if a.is_empty() {
 				buf.push_str("[]");
modifiedcrates/jrsonnet-stdlib/src/strings.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/strings.rs
+++ b/crates/jrsonnet-stdlib/src/strings.rs
@@ -151,6 +151,20 @@
 	})
 }
 
+#[cfg(feature = "exp-bigint")]
+#[builtin]
+pub fn builtin_bigint(v: Either![f64, IStr]) -> Result<Val> {
+	use Either2::*;
+	Ok(match v {
+		A(a) => Val::BigInt(Box::new((a as i64).into())),
+		B(b) => Val::BigInt(Box::new(
+			b.as_str()
+				.parse()
+				.map_err(|e| RuntimeError(format!("bad bigint: {e}").into()))?,
+		)),
+	})
+}
+
 #[cfg(test)]
 mod tests {
 	use super::*;
modifiedcrates/jrsonnet-types/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-types/src/lib.rs
+++ b/crates/jrsonnet-types/src/lib.rs
@@ -88,6 +88,8 @@
 	Null,
 	Str,
 	Num,
+	#[cfg(feature = "exp-bigint")]
+	BigInt,
 	Arr,
 	Obj,
 	Func,
@@ -101,6 +103,8 @@
 			Null => "null",
 			Str => "string",
 			Num => "number",
+			#[cfg(feature = "exp-bigint")]
+			BigInt => "bigint",
 			Arr => "array",
 			Obj => "object",
 			Func => "function",