typ/
lib.rs

1//! TYP is a type-level programming langauge that computes types.
2//! It enables you to write _type operators_, the functions that translates types, in Rust syntax.
3//! Please read the [TYP book](https://github.com/jerry73204/typ-book/) understand the usage.
4
5#![feature(hash_set_entry)]
6
7mod common;
8mod env;
9mod parse;
10mod trans;
11mod tyint;
12mod utils;
13mod var;
14
15use crate::{common::*, parse::ItemVec};
16
17/// The main macro that translates the TYP langauge to actual Rust implementations.
18#[proc_macro]
19pub fn typ(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
20    let ItemVec(items) = parse_macro_input!(tokens as ItemVec);
21    crate::trans::translate_items(&items)
22        .unwrap_or_else(|err| err.to_compile_error())
23        .into()
24}
25
26/// Constructs a signed integer type from an integer literal.
27#[proc_macro]
28pub fn tyint(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
29    tyint::tyint(input)
30}
31
32/// Constructs an unsigned integer type from an integer literal.
33#[proc_macro]
34pub fn tyuint(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
35    tyint::tyuint(input)
36}