From ef38892cb0c8245d65a07518e080849795016755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sat, 20 Feb 2021 21:42:25 +0100 Subject: cool linky macro --- src/main.rs | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 21785a2..28e4e79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,36 +2,15 @@ use std::path::{Path, PathBuf}; use sylt::run_file; -mod linked; - struct Args { file: Option, print: bool, } -macro_rules! link { - ([ $( $ident:tt ),* ]) => { - vec![ - $( (stringify!($ident).to_string(), $ident), )* - ] - } -} - -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()); - println!("{:?}", sylt_macro::links!()); - let errs = match run_file(&file, args.print, vec![]) { + let errs = match run_file(&file, args.print, sylt_macro::link!(extern_test as test)) { Err(it) => it, _ => return, }; @@ -59,3 +38,13 @@ fn parse_args() -> Args { }; args } + +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