Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed to compile with rustc 0.13.0-nightly 2015-01-02 #27

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LD=i386-elf-ld
LD=ld
RUSTC=rustc
NASM=nasm
QEMU=qemu-system-i386
Expand All @@ -10,7 +10,7 @@ all: floppy.img
.PHONY: clean run

.rs.o:
$(RUSTC) -O --target i386-intel-linux --crate-type lib -o $@ --emit obj $<
$(RUSTC) -O --target i686-unknown-linux-gnu --crate-type lib -o $@ --emit obj $<

.asm.o:
$(NASM) -f elf32 -o $@ $<
Expand Down
40 changes: 28 additions & 12 deletions main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#![no_std]
#![allow(ctypes)]
#![allow(improper_ctypes)]

#![feature(lang_items)]
#[lang="sized"]
trait Sized {}

#[lang="copy"]
trait Copy {}

impl Copy for Color {}

#[allow(dead_code)]
enum Color {
Black = 0,
Blue = 1,
Expand All @@ -26,35 +36,41 @@ enum Option<T> {
}

struct IntRange {
cur: int,
max: int
cur: isize,
max: isize
}

impl IntRange {
fn next(&mut self) -> Option<int> {
fn next(&mut self) -> Option<isize> {
if self.cur < self.max {
self.cur += 1;
Some(self.cur - 1)
Option::Some(self.cur - 1)
} else {
None
Option::None
}
}
}

fn range(lo: int, hi: int) -> IntRange {
fn range(lo: isize, hi: isize) -> IntRange {
IntRange { cur: lo, max: hi }
}

fn clear_screen(background: Color) {
for i in range(0, 80 * 25) {
unsafe {
*((0xb8000 + i * 2) as *mut u16) = (background as u16) << 12;
let mut r = range(0, 80 * 25);
loop {
match r.next() {
Option::Some(x) => {
unsafe {
*((0xb8000 + x * 2) as *mut u16) = (background as u16) << 12;
}
},
Option::None =>{break}
}
}
}

#[no_mangle]
#[no_split_stack]
#[no_stack_check]
pub fn main() {
clear_screen(LightRed);
clear_screen(Color::LightRed);
}