Created
February 12, 2012 18:20
-
-
Save berak/1810014 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std; | |
import std::io; | |
import std::io::writer_util; | |
import std::io::writer; | |
import std::run; | |
fn run_rust(s: str) -> str { | |
let blacklist = ["run:","run :", "run\t:", "run :","while true","io::file", "for ;;", "fs::", "tempfile::"]; | |
for i in blacklist { if str::contains(s,i) { ret "xD"; } } | |
let code = #fmt("use std;\nimport std::{io,dbg};\n\nfn main(){\n%s\n}\n", s); | |
let writer = result::get( io::file_writer( "out.rs", [io::create, io::truncate] ) ); | |
writer.write_str(code); | |
let r1 = run::program_output("rustc", ["out.rs"]); | |
if r1.status != 0i { | |
let e = str::split(r1.out, '\n' as u8 ); | |
let i = str::find(e[0],"error:"); | |
if i == -1 { i = str::find(e[0],"warning:"); } | |
if i != -1 { ret str::slice(e[0],i as uint,str::byte_len(e[0])); } | |
} | |
let r2 = run::program_output("./out",[]); | |
ret r2.err + " " + r2.out + "\n"; | |
} | |
fn main() { | |
let inp = io::stdin(); | |
let s = ""; | |
while true { | |
let b = inp.read_byte(); | |
if ( b < 1 ) { break; } | |
if b == 10 { | |
let r = run_rust(s); | |
io::println(r); | |
s = ""; | |
} else { | |
s += #fmt("%c", b as char); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment