From 6e97e9667967f90c66ff71f2c5468d5700887f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sat, 20 Feb 2021 20:30:58 +0100 Subject: store linked functions in proc macro runtime and return them --- src/main.rs | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 69af682..21785a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,8 @@ use std::path::{Path, PathBuf}; use sylt::run_file; +mod linked; + struct Args { file: Option, print: bool, @@ -15,10 +17,21 @@ macro_rules! link { } } +sylt_macro::extern_function!( + extern_test + [sylt::Value::Float(x), sylt::Value::Float(y)] -> sylt::Type::Float => { + Ok(sylt::Value::Float(x + y)) + }, + [sylt::Value::Float(x)] -> sylt::Type::Float => { + Ok(sylt::Value::Float(*x)) + }, +); + fn main() { let args = parse_args(); let file = args.file.unwrap_or_else(|| Path::new("progs/tests/simple.sy").to_owned()); - let errs = match run_file(&file, args.print, link!([extern_test])) { + println!("{:?}", sylt_macro::links!()); + let errs = match run_file(&file, args.print, vec![]) { Err(it) => it, _ => return, }; @@ -46,32 +59,3 @@ fn parse_args() -> Args { }; args } - -#[sylt_macro::extern_link] -pub fn f(x: sylt::Value, _typecheck: bool) -> Result { - Ok(x) -} - -#[sylt_macro::extern_link(g)] -pub fn f2(x: sylt::Value, _typecheck: bool) -> Result { - Ok(x) -} - -mod m1 { - mod m2 { - #[sylt_macro::extern_link(h)] - pub fn f2(x: sylt::Value, _typecheck: bool) -> Result { - Ok(x) - } - } -} - -sylt_macro::extern_function!( - extern_test - [sylt::Value::Float(x), sylt::Value::Float(y)] -> sylt::Type::Float => { - Ok(sylt::Value::Float(x + y)) - }, - [sylt::Value::Float(x)] -> sylt::Type::Float => { - Ok(sylt::Value::Float(*x)) - }, -); -- cgit v1.2.1