MCPcopy Index your code
hub / github.com/endbasic/endbasic / test_temp_scope

Function test_temp_scope

core/src/compiler/syms.rs:880–915  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

878
879 #[test]
880 fn test_temp_scope() -> Result<()> {
881 let upcalls = HashMap::default();
882 let mut global = GlobalSymtable::new(upcalls);
883 let mut local = global.enter_scope();
884 assert_eq!(
885 Register::local(0).unwrap(),
886 local.put_local(SymbolKey::from("foo"), SymbolPrototype::Scalar(ExprType::Integer))?
887 );
888 {
889 let temp = local.frozen();
890 {
891 let mut scope = temp.temp_scope();
892 assert_eq!(Register::local(1).unwrap(), scope.alloc()?);
893 {
894 let mut scope = temp.temp_scope();
895 assert_eq!(Register::local(2).unwrap(), scope.alloc()?);
896 assert_eq!(Register::local(3).unwrap(), scope.alloc()?);
897 assert_eq!(Register::local(4).unwrap(), scope.alloc()?);
898 }
899 {
900 let mut scope = temp.temp_scope();
901 assert_eq!(Register::local(2).unwrap(), scope.alloc()?);
902 assert_eq!(Register::local(3).unwrap(), scope.alloc()?);
903 }
904 assert_eq!(Register::local(2).unwrap(), scope.alloc()?);
905 }
906 }
907 {
908 let temp = local.frozen();
909 {
910 let mut scope = temp.temp_scope();
911 assert_eq!(Register::local(1).unwrap(), scope.alloc()?);
912 }
913 }
914 Ok(())
915 }
916
917 #[test]
918 fn test_with_reserved_temp_register_index() -> Result<()> {

Callers

nothing calls this directly

Calls 3

enter_scopeMethod · 0.80
frozenMethod · 0.80
temp_scopeMethod · 0.80

Tested by

no test coverage detected