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

big json rewrite, and other misc features #1904

Closed
wants to merge 5 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
28 changes: 16 additions & 12 deletions src/cargo/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import rustc::util::filesearch::{get_cargo_root, get_cargo_root_nearest,
get_cargo_sysroot, libdir};
import rustc::driver::diagnostic;

import result::{ok, err};
import std::fs;
import std::io;
import io::writer_util;
Expand Down Expand Up @@ -225,15 +226,15 @@ fn parse_source(name: str, j: json::json) -> source {
fn try_parse_sources(filename: str, sources: map::hashmap<str, source>) {
if !fs::path_exists(filename) { ret; }
let c = io::read_whole_file_str(filename);
let j = json::from_str(result::get(c));
alt j {
some(json::dict(_j)) {
_j.items { |k, v|
alt json::from_str(result::get(c)) {
ok(json::dict(j)) {
j.items { |k, v|
sources.insert(k, parse_source(k, v));
#debug("source: %s", k);
}
}
_ { fail "malformed sources.json"; }
ok(_) { fail "malformed sources.json"; }
err(e) { fail #fmt("%s:%u:%u: %s", filename, e.line, e.col, e.msg); }
}
}

Expand Down Expand Up @@ -278,7 +279,7 @@ fn load_one_source_package(&src: source, p: map::hashmap<str, json::json>) {
let tags = [];
alt p.find("tags") {
some(json::list(js)) {
for j in *js {
for j in js {
alt j {
json::string(_j) { vec::grow(tags, 1u, _j); }
_ { }
Expand Down Expand Up @@ -316,10 +317,9 @@ fn load_source_packages(&c: cargo, &src: source) {
let pkgfile = fs::connect(dir, "packages.json");
if !fs::path_exists(pkgfile) { ret; }
let pkgstr = io::read_whole_file_str(pkgfile);
let j = json::from_str(result::get(pkgstr));
alt j {
some(json::list(js)) {
for _j: json::json in *js {
alt json::from_str(result::get(pkgstr)) {
ok(json::list(js)) {
for _j: json::json in js {
alt _j {
json::dict(_p) {
load_one_source_package(src, _p);
Expand All @@ -331,8 +331,12 @@ fn load_source_packages(&c: cargo, &src: source) {
}
}
}
_ {
warn("Malformed source json: " + src.name);
ok(_) {
warn("Malformed source json: " + src.name +
"(packages is not a list)");
}
err(e) {
warn(#fmt("%s:%u:%u: %s", src.name, e.line, e.col, e.msg));
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/etc/vim/syntax/rust.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ endif
syn keyword rustKeyword alt as assert be bind break
syn keyword rustKeyword check claim cont const copy do else enum export fail
syn keyword rustKeyword fn for if iface impl import in inline lambda let log
syn keyword rustKeyword mod mutable native note of prove pure
syn keyword rustKeyword resource ret self syntax type unchecked
syn keyword rustKeyword mod mut mutable native note of prove pure
syn keyword rustKeyword resource ret self syntax to type unchecked
syn keyword rustKeyword unsafe use while with

" Reserved words
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Export type option as a synonym for option and export the some and none
// enum constructors.

import option::{some, none};
import option::{some, none};
import option = option::t;
import vec::vec_len;
export option, some, none, vec_len;
Expand Down
13 changes: 7 additions & 6 deletions src/libcore/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export mul_add, fmax, fmin, nextafter, frexp, hypot, ldexp;
export lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix;
export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
export signbit;
export pow_with_uint;

// export when m_float == c_double

Expand Down Expand Up @@ -55,7 +56,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> str {
if (frac < epsilon && !exact) || digits == 0u { ret accum; }
accum += ".";
let i = digits;
let epsilon = 1. / pow_uint_to_uint_as_float(10u, i);
let epsilon = 1. / pow_with_uint(10u, i);
while i > 0u && (frac >= epsilon || exact) {
frac *= 10.0;
epsilon *= 10.0;
Expand Down Expand Up @@ -228,7 +229,7 @@ fn from_str(num: str) -> option<float> {
}
pos = char_range.next;
}
let multiplier = pow_uint_to_uint_as_float(10u, exponent);
let multiplier = pow_with_uint(10u, exponent);
//Note: not [int::pow], otherwise, we'll quickly
//end up with a nice overflow
if neg_exponent {
Expand Down Expand Up @@ -256,7 +257,7 @@ fn from_str(num: str) -> option<float> {
*/

/*
Function: pow_uint_to_uint_as_float
Function: pow_with_uint

Compute the exponentiation of an integer by another integer as a float.

Expand All @@ -267,16 +268,16 @@ pow - The exponent.
Returns:
<NaN> of both `x` and `pow` are `0u`, otherwise `x^pow`.
*/
fn pow_uint_to_uint_as_float(x: uint, pow: uint) -> float {
if x == 0u {
fn pow_with_uint(base: uint, pow: uint) -> float {
if base == 0u {
if pow == 0u {
ret NaN;
}
ret 0.;
}
let my_pow = pow;
let total = 1f;
let multiplier = x as float;
let multiplier = base as float;
while (my_pow > 0u) {
if my_pow % 2u == 1u {
total = total * multiplier;
Expand Down
18 changes: 16 additions & 2 deletions src/libstd/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,22 @@ fn mk_mem_buffer() -> mem_buffer {
fn mem_buffer_writer(b: mem_buffer) -> writer { b as writer }
fn mem_buffer_buf(b: mem_buffer) -> [u8] { vec::from_mut(b.buf) }
fn mem_buffer_str(b: mem_buffer) -> str {
let b_ = vec::from_mut(b.buf);
str::from_bytes(b_)
let b_ = vec::from_mut(b.buf);
str::from_bytes(b_)
}

fn with_str_writer(f: fn(writer)) -> str {
let buf = mk_mem_buffer();
let wr = mem_buffer_writer(buf);
f(wr);
io::mem_buffer_str(buf)
}

fn with_buf_writer(f: fn(writer)) -> [u8] {
let buf = mk_mem_buffer();
let wr = mem_buffer_writer(buf);
f(wr);
io::mem_buffer_buf(buf)
}

// Utility functions
Expand Down
Loading