Actually just three programming languages in a trenchcoat
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ability to pass parameters to the non-main entrypoint

+41 -9
+5
samples/not_main_params.tri
··· 1 + proc not_main!(a, b) { 2 + exit a + b 3 + } 4 + 5 + export not_main
+6 -2
trilogy-codegen/src/context/program_context.rs
··· 40 40 } 41 41 42 42 /// Writes the entrypoint of the program. 43 - pub fn write_main(&mut self, path: &[&str], default_exit: Value) { 43 + pub fn write_main(&mut self, path: &[&str], parameters: Vec<Value>, default_exit: Value) { 44 44 let start = self.ip(); 45 45 self.entrypoint() 46 46 .label("trilogy:__entrypoint__") ··· 50 50 for seg in path { 51 51 self.atom(seg).call_module(); 52 52 } 53 - self.call_procedure(0) 53 + let len = parameters.len(); 54 + for param in parameters { 55 + self.constant(param); 56 + } 57 + self.call_procedure(len) 54 58 .instruction(Instruction::Copy) 55 59 .instruction(Instruction::Unit) 56 60 .instruction(Instruction::ValEq)
+3 -2
trilogy-codegen/src/entrypoint.rs
··· 10 10 builder: &mut ChunkBuilder, 11 11 module: &ir::Module, 12 12 entry_path: &[&str], 13 + parameters: Vec<Value>, 13 14 ) { 14 15 let mut context = ProgramContext::new(file, builder); 15 - context.write_main(entry_path, 0.into()); 16 + context.write_main(entry_path, parameters, 0.into()); 16 17 write_preamble(&mut context); 17 18 18 19 let mut statics = HashMap::default(); ··· 46 47 let mut context = ProgramContext::new(file, builder); 47 48 let mut full_path = path.to_vec(); 48 49 full_path.push("trilogy:__testentry__"); 49 - context.write_main(&full_path, Value::Unit); 50 + context.write_main(&full_path, vec![], Value::Unit); 50 51 write_preamble(&mut context); 51 52 52 53 let mut statics = HashMap::default();
+10 -3
trilogy/src/trilogy/mod.rs
··· 112 112 113 113 /// Runs the loaded Trilogy program by evaluating `main!()`. 114 114 /// 115 - /// This is equivalent to `call("main")`. 115 + /// This is equivalent to `self.call("main", vec![])`. 116 116 pub fn run(&self) -> Result<Value, RuntimeError> { 117 - self.call("main") 117 + self.call("main", vec![]) 118 118 } 119 119 120 120 /// Runs the loaded Trilogy, evaluating the exported 0-arity procedure pointed to by ··· 131 131 /// is returned. Unfortunately at this time, those errors are hard to 132 132 /// diagnose and could be anything from a bug in the compiler to an error 133 133 /// in the Trilogy program. 134 - pub fn call(&self, main: impl ModulePath) -> Result<Value, RuntimeError> { 134 + pub fn call( 135 + &self, 136 + main: impl ModulePath, 137 + parameters: Vec<Value>, 138 + ) -> Result<Value, RuntimeError> { 135 139 let result = match &self.source { 136 140 Source::Asm { asm } => self.vm.run_with_registers( 137 141 &AsmProgram { ··· 149 153 modules, 150 154 entrypoint, 151 155 path: &main.path(), 156 + parameters, 152 157 to_asm: false, 153 158 }, 154 159 Self::default_registers(), ··· 277 282 modules, 278 283 entrypoint, 279 284 path: &["main"], 285 + parameters: vec![], 280 286 to_asm: true, 281 287 }), 282 288 } ··· 297 303 modules, 298 304 entrypoint, 299 305 path: &["main"], 306 + parameters: vec![], 300 307 to_asm: false, 301 308 }), 302 309 }
+2 -1
trilogy/src/trilogy/trilogy_program.rs
··· 8 8 pub libraries: &'a HashMap<Location, Native>, 9 9 pub entrypoint: &'a Location, 10 10 pub path: &'a [&'a str], 11 + pub parameters: Vec<Value>, 11 12 pub to_asm: bool, 12 13 } 13 14 ··· 16 17 let time_generating = Instant::now(); 17 18 let module = self.modules.get(self.entrypoint).unwrap(); 18 19 let url = self.entrypoint.as_ref().as_str(); 19 - trilogy_codegen::write_program(url, chunk, module, self.path); 20 + trilogy_codegen::write_program(url, chunk, module, self.path, self.parameters.clone()); 20 21 log::trace!("entrypoint written: {:?}", time_generating.elapsed()); 21 22 } 22 23
+15 -1
trilogy/tests/samples.rs
··· 401 401 .is_library(true) 402 402 .build_from_source(PathBuf::from(TEST_DIR).join("not_main.tri")) 403 403 .unwrap(); 404 - assert_eq!(program.call("not_main").unwrap(), Value::from(6)); 404 + assert_eq!(program.call("not_main", vec![]).unwrap(), Value::from(6)); 405 + } 406 + 407 + #[test] 408 + fn sample_not_main_params() { 409 + let program = Builder::new() 410 + .is_library(true) 411 + .build_from_source(PathBuf::from(TEST_DIR).join("not_main_params.tri")) 412 + .unwrap(); 413 + assert_eq!( 414 + program 415 + .call("not_main", vec![Value::from(1), Value::from(2)]) 416 + .unwrap(), 417 + Value::from(3) 418 + ); 405 419 }