diff --git a/src/classic/clvm/mod.rs b/src/classic/clvm/mod.rs index 00ae33adc..bb269fa56 100644 --- a/src/classic/clvm/mod.rs +++ b/src/classic/clvm/mod.rs @@ -20,7 +20,7 @@ struct KwAtomPair { version: usize, } -const KW_PAIRS: [KwAtomPair; 46] = [ +const KW_PAIRS: [KwAtomPair; 48] = [ KwAtomPair { v: &[0x01], n: "q", @@ -246,6 +246,11 @@ const KW_PAIRS: [KwAtomPair; 46] = [ n: "modpow", version: 1, }, + KwAtomPair { + v: &[0x3d], + n: "%", + version: 1, + }, KwAtomPair { v: &[0x13, 0xd6, 0x1f, 0x00], n: "secp256k1_verify", diff --git a/src/compiler/prims.rs b/src/compiler/prims.rs index 57d9b0790..c0f9a7f85 100644 --- a/src/compiler/prims.rs +++ b/src/compiler/prims.rs @@ -199,6 +199,10 @@ pub fn prims() -> Vec<(Vec, SExp)> { "modpow".as_bytes().to_vec(), SExp::Integer(primloc.clone(), 60_u32.to_bigint().unwrap()), ), + ( + "%".as_bytes().to_vec(), + SExp::Integer(primloc.clone(), 61_u32.to_bigint().unwrap()), + ), ] } diff --git a/src/tests/classic/run.rs b/src/tests/classic/run.rs index 66456484d..1a7dd16bc 100644 --- a/src/tests/classic/run.rs +++ b/src/tests/classic/run.rs @@ -88,25 +88,25 @@ fn brun_y_1_test() { ) ).trim(), indoc! {"0x375f00 - + (\"fact\" 10) => 0x375f00 - + (\"fact\" 9) => 0x058980 - + (\"fact\" 8) => 0x009d80 - + (\"fact\" 7) => 5040 - + (\"fact\" 6) => 720 - + (\"fact\" 5) => 120 - + (\"fact\" 4) => 24 - + (\"fact\" 3) => 6 - + (\"fact\" 2) => 2 - + (\"fact\" 1) => 1"} ); } @@ -121,23 +121,23 @@ fn brun_v_test() { )) .trim(), indoc! {"8 - + (a 2 3) [((a (q 16 (q . 3) (q . 5)) 1))] => 8 - + 3 [((a (q 16 (q . 3) (q . 5)) 1))] => () - + 2 [((a (q 16 (q . 3) (q . 5)) 1))] => (a (q 16 (q . 3) (q . 5)) 1) - + (a (q 16 (q . 3) (q . 5)) 1) [()] => 8 - + 1 [()] => () - + (q 16 (q . 3) (q . 5)) [()] => (+ (q . 3) (q . 5)) - + (+ (q . 3) (q . 5)) [()] => 8 - + (q . 5) [()] => 5 - + (q . 3) [()] => 3"} ); } @@ -2573,3 +2573,23 @@ fn test_classic_obeys_operator_choice_at_compile_time_version_0() { .to_string(); assert_eq!(compiled, "FAIL: unimplemented operator 48"); } + +#[test] +fn test_op_mod_modern() { + let program = "(mod (S) (include *standard-cl-21*) (% 101 S))"; + let compiled = do_basic_run(&vec!["run".to_string(), program.to_string()]); + let output = do_basic_brun(&vec!["brun".to_string(), compiled, "(10)".to_string()]) + .trim() + .to_string(); + assert_eq!(output, "1"); +} + +#[test] +fn test_op_modpow_modern() { + let program = "(mod (S) (include *standard-cl-21*) (modpow 2 4 S))"; // 2^4 % S + let compiled = do_basic_run(&vec!["run".to_string(), program.to_string()]); + let output = do_basic_brun(&vec!["brun".to_string(), compiled, "(10)".to_string()]) + .trim() + .to_string(); + assert_eq!(output, "6"); +}