18
18
#[license = "MIT/ASL2"];
19
19
#[crate_type = "lib"];
20
20
21
- #[allow(vecs_implicitly_copyable,
22
- non_implicitly_copyable_typarams)];
23
-
24
21
extern mod std(vers = "0.7-pre");
25
22
extern mod rustc(vers = "0.7-pre");
26
23
extern mod syntax(vers = "0.7-pre");
27
24
28
25
use core::*;
26
+ use core::cell::Cell;
29
27
use rustc::driver::{driver, session};
30
28
use syntax::{ast, diagnostic};
31
29
use syntax::ast_util::*;
@@ -71,8 +69,8 @@ fn with_pp(intr: @token::ident_interner,
71
69
* because it has to parse the statements and view_items on each
72
70
* input.
73
71
*/
74
- fn record(repl: Repl, blk: @ ast::blk, intr: @token::ident_interner) -> Repl {
75
- let view_items = if blk.node.view_items.len() > 0 {
72
+ fn record(mut repl: Repl, blk: & ast::blk, intr: @token::ident_interner) -> Repl {
73
+ if blk.node.view_items.len() > 0 {
76
74
let new_view_items = do with_pp(intr) |pp, writer| {
77
75
for blk.node.view_items.each |view_item| {
78
76
pprust::print_view_item(pp, *view_item);
@@ -82,9 +80,9 @@ fn record(repl: Repl, blk: @ast::blk, intr: @token::ident_interner) -> Repl {
82
80
83
81
debug!("new view items %s", new_view_items);
84
82
85
- repl.view_items + "\n" + new_view_items
86
- } else { repl.view_items };
87
- let stmts = if blk.node.stmts.len() > 0 {
83
+ repl.view_items = repl.view_items + "\n" + new_view_items
84
+ }
85
+ if blk.node.stmts.len() > 0 {
88
86
let new_stmts = do with_pp(intr) |pp, writer| {
89
87
for blk.node.stmts.each |stmt| {
90
88
match stmt.node {
@@ -105,24 +103,21 @@ fn record(repl: Repl, blk: @ast::blk, intr: @token::ident_interner) -> Repl {
105
103
106
104
debug!("new stmts %s", new_stmts);
107
105
108
- repl.stmts + "\n" + new_stmts
109
- } else { repl.stmts };
110
-
111
- Repl{
112
- view_items: view_items,
113
- stmts: stmts,
114
- .. repl
106
+ repl.stmts = repl.stmts + "\n" + new_stmts
115
107
}
108
+
109
+ return repl;
116
110
}
117
111
118
112
/// Run an input string in a Repl, returning the new Repl.
119
113
fn run(repl: Repl, input: ~str) -> Repl {
114
+ let binary = @copy repl.binary;
120
115
let options = @session::options {
121
116
crate_type: session::unknown_crate,
122
- binary: @repl. binary,
117
+ binary: binary,
123
118
addl_lib_search_paths: repl.lib_search_paths.map(|p| Path(*p)),
124
119
jit: true,
125
- .. *session::basic_options()
120
+ .. copy *session::basic_options()
126
121
};
127
122
128
123
debug!("building driver input");
@@ -138,7 +133,7 @@ fn run(repl: Repl, input: ~str) -> Repl {
138
133
139
134
debug!("building driver configuration");
140
135
let cfg = driver::build_configuration(sess,
141
- @repl. binary,
136
+ binary,
142
137
&wrapped);
143
138
144
139
let outputs = driver::build_output_filenames(&wrapped, &None, &None, sess);
@@ -151,7 +146,7 @@ fn run(repl: Repl, input: ~str) -> Repl {
151
146
152
147
for crate.node.module.items.each |item| {
153
148
match item.node {
154
- ast::item_fn(_, _, _, _, blk) => {
149
+ ast::item_fn(_, _, _, _, ref blk) => {
155
150
if item.ident == sess.ident_of("main") {
156
151
opt = blk.node.expr;
157
152
}
@@ -160,10 +155,11 @@ fn run(repl: Repl, input: ~str) -> Repl {
160
155
}
161
156
}
162
157
163
- let blk = match opt.get().node {
164
- ast::expr_call(_, exprs, _) => {
158
+ let e = opt.unwrap();
159
+ let blk = match e.node {
160
+ ast::expr_call(_, ref exprs, _) => {
165
161
match exprs[0].node {
166
- ast::expr_block(blk) => @ blk,
162
+ ast::expr_block(ref blk) => blk,
167
163
_ => fail!()
168
164
}
169
165
}
@@ -182,15 +178,16 @@ fn run(repl: Repl, input: ~str) -> Repl {
182
178
fn compile_crate(src_filename: ~str, binary: ~str) -> Option<bool> {
183
179
match do task::try {
184
180
let src_path = Path(src_filename);
181
+ let binary = @copy binary;
185
182
let options = @session::options {
186
- binary: @ binary,
183
+ binary: binary,
187
184
addl_lib_search_paths: ~[os::getcwd()],
188
- .. *session::basic_options()
185
+ .. copy *session::basic_options()
189
186
};
190
- let input = driver::file_input(src_path);
187
+ let input = driver::file_input(copy src_path);
191
188
let sess = driver::build_session(options, diagnostic::emit);
192
189
*sess.building_library = true;
193
- let cfg = driver::build_configuration(sess, @ binary, &input);
190
+ let cfg = driver::build_configuration(sess, binary, &input);
194
191
let outputs = driver::build_output_filenames(
195
192
&input, &None, &None, sess);
196
193
// If the library already exists and is newer than the source
@@ -233,7 +230,7 @@ fn compile_crate(src_filename: ~str, binary: ~str) -> Option<bool> {
233
230
234
231
/// Tries to get a line from rl after outputting a prompt. Returns
235
232
/// None if no input was read (e.g. EOF was reached).
236
- fn get_line(use_rl: bool, prompt: ~ str) -> Option<~str> {
233
+ fn get_line(use_rl: bool, prompt: & str) -> Option<~str> {
237
234
if use_rl {
238
235
let result = unsafe { rl::read(prompt) };
239
236
@@ -280,11 +277,11 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
280
277
for args.each |arg| {
281
278
let (crate, filename) =
282
279
if arg.ends_with(".rs") || arg.ends_with(".rc") {
283
- (arg.substr(0, arg.len() - 3).to_owned(), *arg)
280
+ (arg.substr(0, arg.len() - 3).to_owned(), copy *arg)
284
281
} else {
285
- (*arg, arg + ~ ".rs")
282
+ (copy *arg, arg + ".rs")
286
283
};
287
- match compile_crate(filename, repl.binary) {
284
+ match compile_crate(filename, copy repl.binary) {
288
285
Some(_) => loaded_crates.push(crate),
289
286
None => { }
290
287
}
@@ -311,7 +308,7 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
311
308
let mut multiline_cmd = ~"";
312
309
let mut end_multiline = false;
313
310
while (!end_multiline) {
314
- match get_line(use_rl, ~ "rusti| ") {
311
+ match get_line(use_rl, "rusti| ") {
315
312
None => fail!("unterminated multiline command :{ .. :}"),
316
313
Some(line) => {
317
314
if str::trim(line) == ~":}" {
@@ -334,14 +331,14 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
334
331
fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str,
335
332
use_rl: bool)
336
333
-> Option<Repl> {
337
- if line.starts_with(~ ":") {
334
+ if line.starts_with(":") {
338
335
let full = line.substr(1, line.len() - 1);
339
336
let mut split = ~[];
340
337
for str::each_word(full) |word| { split.push(word.to_owned()) }
341
338
let len = split.len();
342
339
343
340
if len > 0 {
344
- let cmd = split[0];
341
+ let cmd = copy split[0];
345
342
346
343
if !cmd.is_empty() {
347
344
let args = if len > 1 {
@@ -361,9 +358,10 @@ fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str,
361
358
}
362
359
}
363
360
364
- let r = *repl;
361
+ let line = Cell(line);
362
+ let r = Cell(copy *repl);
365
363
let result = do task::try {
366
- run(r, line)
364
+ run(r.take() , line.take() )
367
365
};
368
366
369
367
if result.is_ok() {
@@ -378,7 +376,7 @@ pub fn main() {
378
376
let out = io::stdout();
379
377
let mut repl = Repl {
380
378
prompt: ~"rusti> ",
381
- binary: args[0],
379
+ binary: copy args[0],
382
380
running: true,
383
381
view_items: ~"",
384
382
lib_search_paths: ~[],
0 commit comments