Skip to content

Commit 8f9fc67

Browse files
---
yaml --- r: 124359 b: refs/heads/auto c: 83fe455 h: refs/heads/master i: 124357: 9d69c6e 124355: fc510dd 124351: 92aa676 v: v3
1 parent 3ef7e99 commit 8f9fc67

File tree

24 files changed

+427
-218
lines changed

24 files changed

+427
-218
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 316719e625d975f1f29104e78101f2b3521291f4
16+
refs/heads/auto: 83fe455e3c2e1d603fdbb28c800023b7a32e3c13
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/guide.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,59 @@ program doesn't have any dependencies, so we'll only be using the first part of
279279
its functionality. Eventually, we'll add more. Since we started off by using
280280
Cargo, it'll be easy to add later.
281281

282-
Let's convert Hello World to Cargo. The first thing we need to do to begin
283-
using Cargo is to install Cargo. Luckily for us, the script we ran to install
284-
Rust includes Cargo by default. If you installed Rust some other way, you may
285-
want to [check the Cargo
286-
README](https://github.com/rust-lang/cargo#installing-cargo-from-nightlies)
287-
for specific instructions about installing it.
282+
Let's convert Hello World to Cargo. The first thing we need to do to begin using Cargo
283+
is to install Cargo. To do this, we need to build it from source. There are no binaries
284+
yet.
285+
286+
First, let's go back to our projects directory. We don't want Cargo to
287+
live in our project!
288+
289+
```{bash}
290+
$ cd ..
291+
```
292+
293+
Next, we need these commands:
294+
295+
```{bash}
296+
$ git clone --recursive https://github.com/rust-lang/cargo
297+
$ cd cargo
298+
$ make
299+
$ make install # may need sudo or admin permissions
300+
```
301+
302+
The `--recursive` downloads Cargo's own dependencies. You can't use Cargo to
303+
fetch dependencies until you have Cargo installed! Also, you will need to have
304+
`git` installed. Much of the Rust world assumes `git` usage, so it's a good
305+
thing to have around. Please check out [the git
306+
documentation](http://git-scm.com/book/en/Getting-Started-Installing-Git) for
307+
more on installing `git`.
308+
309+
We hope to give Cargo a binary installer, similar to Rust's own, so that
310+
this will not be necessary in the future.
311+
312+
Let's see if that worked. Try this:
313+
314+
```{bash}
315+
$ cargo
316+
Commands:
317+
build # compile the current project
318+
319+
Options (for all commands):
320+
321+
-v, [--verbose]
322+
-h, [--help]
323+
```
324+
325+
If you see this output when you run `cargo`, congrats! Cargo is working. If
326+
not, please [open an issue](https://github.com/rust-lang/cargo/issues/new) or
327+
drop by the Rust IRC, and we can help you out.
328+
329+
Let's move back into our `hello_world` directory now:
330+
331+
```{bash}
332+
$ cd .. # move back up into projects
333+
$ cd hello_world # move into hello_world
334+
```
288335

289336
To Cargo-ify our project, we need to do two things: Make a `Cargo.toml`
290337
configuration file, and put our source file in the right place. Let's
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
# file at the top-level directory of this distribution and at
3+
# http://rust-lang.org/COPYRIGHT.
4+
#
5+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
# option. This file may not be copied, modified, or distributed
9+
# except according to those terms.
10+
11+
import lldb
12+
13+
def print_val(val, internal_dict):
14+
'''Prints the given value with Rust syntax'''
15+
type_class = val.GetType().GetTypeClass()
16+
17+
if type_class == lldb.eTypeClassStruct:
18+
return print_struct_val(val, internal_dict)
19+
20+
if type_class == lldb.eTypeClassUnion:
21+
return print_enum_val(val, internal_dict)
22+
23+
if type_class == lldb.eTypeClassPointer:
24+
return print_pointer_val(val, internal_dict)
25+
26+
if type_class == lldb.eTypeClassArray:
27+
return print_fixed_size_vec_val(val, internal_dict)
28+
29+
return val.GetValue()
30+
31+
32+
#=--------------------------------------------------------------------------------------------------
33+
# Type-Specialized Printing Functions
34+
#=--------------------------------------------------------------------------------------------------
35+
36+
def print_struct_val(val, internal_dict):
37+
'''Prints a struct, tuple, or tuple struct value with Rust syntax'''
38+
assert val.GetType().GetTypeClass() == lldb.eTypeClassStruct
39+
40+
if is_vec_slice(val):
41+
return print_vec_slice_val(val, internal_dict)
42+
else:
43+
return print_struct_val_starting_from(0, val, internal_dict)
44+
45+
def print_vec_slice_val(val, internal_dict):
46+
output = "&["
47+
48+
length = val.GetChildAtIndex(1).GetValueAsUnsigned()
49+
50+
data_ptr_val = val.GetChildAtIndex(0)
51+
data_ptr_type = data_ptr_val.GetType()
52+
assert data_ptr_type.IsPointerType()
53+
54+
element_type = data_ptr_type.GetPointeeType()
55+
element_type_size = element_type.GetByteSize()
56+
57+
start_address = data_ptr_val.GetValueAsUnsigned()
58+
59+
for i in range(length):
60+
address = start_address + i * element_type_size
61+
element_val = val.CreateValueFromAddress( val.GetName() + ("[%s]" % i), address, element_type )
62+
output += print_val(element_val, internal_dict)
63+
64+
if i != length - 1:
65+
output += ", "
66+
67+
output += "]"
68+
return output
69+
70+
def print_struct_val_starting_from(field_start_index, val, internal_dict):
71+
'''
72+
Prints a struct, tuple, or tuple struct value with Rust syntax.
73+
Ignores any fields before field_start_index.
74+
'''
75+
assert val.GetType().GetTypeClass() == lldb.eTypeClassStruct
76+
77+
t = val.GetType()
78+
has_field_names = type_has_field_names(t)
79+
type_name = extract_type_name(t.GetName())
80+
output = ""
81+
82+
if not type_name.startswith("("):
83+
# this is a tuple, so don't print the type name
84+
output += type_name
85+
86+
if has_field_names:
87+
output += " { \n"
88+
else:
89+
output += "("
90+
91+
num_children = val.num_children
92+
93+
for child_index in range(field_start_index, num_children):
94+
if has_field_names:
95+
field_name = t.GetFieldAtIndex(child_index).GetName()
96+
output += field_name + ": "
97+
98+
field_val = val.GetChildAtIndex(child_index)
99+
output += print_val(field_val, internal_dict)
100+
101+
if child_index != num_children - 1:
102+
output += ", "
103+
104+
if has_field_names:
105+
output += "\n"
106+
107+
if has_field_names:
108+
output += "}"
109+
else:
110+
output += ")"
111+
112+
return output
113+
114+
115+
def print_enum_val(val, internal_dict):
116+
'''Prints an enum value with Rust syntax'''
117+
118+
assert val.GetType().GetTypeClass() == lldb.eTypeClassUnion
119+
120+
if val.num_children == 1:
121+
first_variant_name = val.GetChildAtIndex(0).GetName()
122+
if first_variant_name and first_variant_name.startswith("RUST$ENCODED$ENUM$"):
123+
# Try to extract the
124+
125+
last_separator_index = first_variant_name.rfind("$")
126+
if last_separator_index == -1:
127+
return "<invalid enum encoding: %s>" % first_variant_name
128+
129+
second_last_separator_index = first_variant_name.rfind("$", 0, last_separator_index)
130+
if second_last_separator_index == -1:
131+
return "<invalid enum encoding: %s>" % first_variant_name
132+
133+
try:
134+
disr_field_index = first_variant_name[second_last_separator_index + 1 :
135+
last_separator_index]
136+
disr_field_index = int(disr_field_index)
137+
except:
138+
return "<invalid enum encoding: %s>" % first_variant_name
139+
140+
disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index).GetValueAsUnsigned()
141+
142+
if disr_val == 0:
143+
null_variant_name = first_variant_name[last_separator_index + 1:]
144+
return null_variant_name
145+
else:
146+
return print_struct_val_starting_from(0, val.GetChildAtIndex(0), internal_dict)
147+
else:
148+
return print_struct_val_starting_from(0, val.GetChildAtIndex(0), internal_dict)
149+
150+
# extract the discriminator value by
151+
disr_val = val.GetChildAtIndex(0).GetChildAtIndex(0)
152+
disr_type = disr_val.GetType()
153+
154+
if disr_type.GetTypeClass() != lldb.eTypeClassEnumeration:
155+
return "<Invalid enum value encountered: Discriminator is not an enum>"
156+
157+
variant_index = disr_val.GetValueAsUnsigned()
158+
return print_struct_val_starting_from(1, val.GetChildAtIndex(variant_index), internal_dict)
159+
160+
161+
def print_pointer_val(val, internal_dict):
162+
'''Prints a pointer value with Rust syntax'''
163+
assert val.GetType().IsPointerType()
164+
sigil = "&"
165+
type_name = extract_type_name(val.GetType().GetName())
166+
if type_name and type_name[0:1] in ["&", "~", "*"]:
167+
sigil = type_name[0:1]
168+
169+
return sigil + hex(val.GetValueAsUnsigned()) #print_val(val.Dereference(), internal_dict)
170+
171+
172+
def print_fixed_size_vec_val(val, internal_dict):
173+
assert val.GetType().GetTypeClass() == lldb.eTypeClassArray
174+
175+
output = "["
176+
177+
for i in range(val.num_children):
178+
output += print_val(val.GetChildAtIndex(i), internal_dict)
179+
if i != val.num_children - 1:
180+
output += ", "
181+
182+
output += "]"
183+
return output
184+
185+
186+
#=--------------------------------------------------------------------------------------------------
187+
# Helper Functions
188+
#=--------------------------------------------------------------------------------------------------
189+
190+
unqualified_type_markers = frozenset(["(", "[", "&", "*"])
191+
192+
def extract_type_name(qualified_type_name):
193+
'''Extracts the type name from a fully qualified path'''
194+
if qualified_type_name[0] in unqualified_type_markers:
195+
return qualified_type_name
196+
197+
end_of_search = qualified_type_name.find("<")
198+
if end_of_search < 0:
199+
end_of_search = len(qualified_type_name)
200+
201+
index = qualified_type_name.rfind("::", 0, end_of_search)
202+
if index < 0:
203+
return qualified_type_name
204+
else:
205+
return qualified_type_name[index + 2:]
206+
207+
208+
def type_has_field_names(ty):
209+
'''Returns true of this is a type with field names (struct, struct-like enum variant)'''
210+
# This may also be an enum variant where the first field doesn't have a name but the rest has
211+
if ty.GetNumberOfFields() > 1:
212+
return ty.GetFieldAtIndex(1).GetName() != None
213+
else:
214+
return ty.GetFieldAtIndex(0).GetName() != None
215+
216+
217+
def is_vec_slice(val):
218+
ty = val.GetType()
219+
if ty.GetTypeClass() != lldb.eTypeClassStruct:
220+
return False
221+
222+
if ty.GetNumberOfFields() != 2:
223+
return False
224+
225+
if ty.GetFieldAtIndex(0).GetName() != "data_ptr":
226+
return False
227+
228+
if ty.GetFieldAtIndex(1).GetName() != "length":
229+
return False
230+
231+
type_name = extract_type_name(ty.GetName()).replace("&'static", "&").replace(" ", "")
232+
return type_name.startswith("&[") and type_name.endswith("]")

branches/auto/src/etc/vim/doc/rust.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*rust.txt* Filetype plugin for Rust
22

33
==============================================================================
4-
CONTENTS *rust* *ft-rust*
4+
CONTENTS *rust*
55

66
1. Introduction |rust-intro|
77
2. Settings |rust-settings|
@@ -53,18 +53,6 @@ g:rust_conceal_pub~
5353
let g:rust_conceal_pub = 1
5454
<
5555

56-
*g:rust_fold*
57-
g:rust_fold~
58-
Set this option to turn on |folding|: >
59-
let g:rust_fold = 1
60-
<
61-
Value Effect ~
62-
0 No folding
63-
1 Braced blocks are folded. All folds are open by
64-
default.
65-
2 Braced blocks are folded. 'foldlevel' is left at the
66-
global value (all folds are closed by default).
67-
6856
*g:rust_bang_comment_leader*
6957
g:rust_bang_comment_leader~
7058
Set this option to 1 to preserve the leader on multi-line doc comments

branches/auto/src/etc/vim/ftplugin/rust.vim

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Description: Vim syntax file for Rust
33
" Maintainer: Chris Morgan <[email protected]>
44
" Maintainer: Kevin Ballard <[email protected]>
5-
" Last Change: Jul 07, 2014
5+
" Last Change: May 27, 2014
66

77
if exists("b:did_ftplugin")
88
finish
@@ -35,9 +35,7 @@ silent! setlocal formatoptions+=j
3535
" otherwise it's better than nothing.
3636
setlocal smartindent nocindent
3737

38-
setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab
39-
40-
setlocal textwidth=99
38+
setlocal tabstop=4 shiftwidth=4 expandtab
4139

4240
" This includeexpr isn't perfect, but it's a good start
4341
setlocal includeexpr=substitute(v:fname,'::','/','g')
@@ -95,8 +93,7 @@ endif
9593
" Cleanup {{{1
9694

9795
let b:undo_ftplugin = "
98-
\ setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
99-
\|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth<
96+
\setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
10097
\|if exists('b:rust_original_delimitMate_excluded_regions')
10198
\|let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions
10299
\|unlet b:rust_original_delimitMate_excluded_regions

0 commit comments

Comments
 (0)