1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! # ndless
//!
//! See [here] for examples. Additionally, don't forget to check out the [book].
//!
//! [here]: https://github.com/lights0123/example-nspire
//! [book]: https://lights0123.com/ndless-rust/index.html
#![no_std]
#![allow(clippy::tabs_in_doc_comments, clippy::needless_doctest_main)]
#![feature(alloc_prelude, allocator_api)]
#![feature(core_intrinsics)]
#![feature(llvm_asm)]
#![feature(never_type)]
#![feature(maybe_uninit_ref)]
pub extern crate alloc;

pub use bindings::*;

mod bindings;
mod file_io;
mod libc;
pub use file_io::*;

pub mod ffi {
	pub use core::ffi::*;

	pub use embedded_ffi::*;
}

pub use cty;

#[macro_export]
macro_rules! print {
	($($arg:tt)*) => (
		match $crate::out::print_fmt(format_args!($($arg)*)) {
			_ => {}
		}
	)
}

#[macro_export]
macro_rules! println {
    () => (
        match $crate::out::print_fmt(format_args!("\n")) {
            _ => {}
        }
    );
	($($arg:tt)*) => (
		match $crate::out::print_fmt(format_args!("{}\n", format_args!($($arg)*))) {
			_ => {}
		}
	)
}

#[macro_export]
macro_rules! dbg {
    () => {
        $crate::println!("[{}:{}]", file!(), line!());
    };
    ($val:expr) => {
        // Use of `match` here is intentional because it affects the lifetimes
        // of temporaries - https://stackoverflow.com/a/48732525/1063961
        match $val {
            tmp => {
                $crate::println!("[{}:{}] {} = {:#?}",
                    file!(), line!(), stringify!($val), &tmp);
                tmp
            }
        }
    };
    // Trailing comma with single argument is ignored
    ($val:expr,) => { dbg!($val) };
    ($($val:expr),+ $(,)?) => {
        ($($crate::dbg!($val)),+,)
    };
}

pub mod prelude {
	//! # Ndless prelude
	//! At the top of your code, add
	//! ```rust
	//! use ndless::prelude::*;
	//! ```
	//! to get commonly-used functions.
	pub use alloc::format;
	pub use alloc::prelude::v1::*;
	pub use alloc::vec;

	pub use ndless_macros::entry;

	pub use dbg;
	pub use print;
	pub use println;

	pub use crate::math::Float;
}

/// This macro takes a string and returns a CString
#[macro_export]
macro_rules! cstr {
	($str:expr) => {
		cstr_core::CString::new($str).expect("The passed string contains a null pointer")
	};
}

#[doc(hidden)]
pub use ndless_static_vars::ARGUMENTS;

#[doc(hidden)]
pub unsafe fn __init(args: &'static [*const cty::c_char]) {
	ARGUMENTS = Some(args);
	env::args()
		.next()
		.map(path::PathBuf::from)
		.and_then(|path| path.parent().map(env::set_current_dir));
	timer::__init();
}