diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-02-20 21:42:25 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-02-20 21:42:25 +0100 |
| commit | ef38892cb0c8245d65a07518e080849795016755 (patch) | |
| tree | b6df2df8fee78972f9a1fd3578a4f8a643bc614e /src | |
| parent | 6e97e9667967f90c66ff71f2c5468d5700887f24 (diff) | |
| download | sylt-automatic-link.tar.gz | |
cool linky macroautomatic-link
Diffstat (limited to 'src')
| -rw-r--r-- | src/linked.rs | 18 | ||||
| -rw-r--r-- | src/main.rs | 33 |
2 files changed, 11 insertions, 40 deletions
diff --git a/src/linked.rs b/src/linked.rs deleted file mode 100644 index 6d6621c..0000000 --- a/src/linked.rs +++ /dev/null @@ -1,18 +0,0 @@ -#[sylt_macro::extern_link] -pub fn f(x: sylt::Value, _typecheck: bool) -> Result<sylt::Value, sylt::error::ErrorKind> { - Ok(x) -} - -#[sylt_macro::extern_link(g)] -pub fn f2(x: sylt::Value, _typecheck: bool) -> Result<sylt::Value, sylt::error::ErrorKind> { - Ok(x) -} - -mod m1 { - mod m2 { - #[sylt_macro::extern_link(h)] - pub fn f2(x: sylt::Value, _typecheck: bool) -> Result<sylt::Value, sylt::error::ErrorKind> { - Ok(x) - } - } -} 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<PathBuf>, 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)) + }, +); |
