Skip to content

Instantly share code, notes, and snippets.

@lqd
Created June 21, 2016 00:37
Show Gist options
  • Save lqd/7cb274f1cb21c3d40da010842c3764a4 to your computer and use it in GitHub Desktop.
Save lqd/7cb274f1cb21c3d40da010842c3764a4 to your computer and use it in GitHub Desktop.
#![allow(unused_features)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![feature(intrinsics, lang_items, start, no_core, libc, fundamental)]
#![no_core]
#[lang = "sized"]
#[fundamental]
pub trait Sized { }
#[lang = "copy"]
pub trait Copy : Clone { }
pub trait Clone : Sized { }
#[lang = "add"]
pub trait Add<RHS = Self> {
type Output;
fn add(self, rhs: RHS) -> Self::Output;
}
impl Add for isize {
type Output = isize;
fn add(self, rhs: isize) -> Self::Output { self + rhs }
}
#[lang = "add_assign"]
pub trait AddAssign<Rhs=Self> {
/// The method for the `+=` operator
fn add_assign(&mut self, Rhs);
}
impl AddAssign for isize {
#[inline]
fn add_assign(&mut self, other: isize) { *self += other }
}
#[lang = "sub"]
pub trait Sub<RHS=Self> {
type Output;
fn sub(self, rhs: RHS) -> Self::Output;
}
impl Sub for isize {
type Output = isize;
fn sub(self, rhs: isize) -> Self::Output { self - rhs }
}
#[lang = "mul"]
pub trait Mul<RHS=Self> {
type Output;
fn mul(self, rhs: RHS) -> Self::Output;
}
impl Mul for isize {
type Output = isize;
fn mul(self, rhs: isize) -> Self::Output { self * rhs }
}
#[lang = "div"]
pub trait Div<RHS=Self> {
type Output;
fn div(self, rhs: RHS) -> Self::Output;
}
impl Div for isize {
type Output = isize;
fn div(self, rhs: isize) -> Self::Output { self / rhs }
}
#[lang = "eq"]
pub trait PartialEq<Rhs: ?Sized = Self> {
fn eq(&self, other: &Rhs) -> bool;
#[inline]
fn ne(&self, other: &Rhs) -> bool { !self.eq(other) }
}
impl PartialEq for isize {
#[inline]
fn eq(&self, other: &isize) -> bool { (*self) == (*other) }
#[inline]
fn ne(&self, other: &isize) -> bool { (*self) != (*other) }
}
#[start]
fn main(i: isize, _: *const *const u8) -> isize {
// let a = 5;
// (1 + a) * 2 / 4
2 + 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment