Skip to content

Commit c4e43b4

Browse files
committed
---
yaml --- r: 143262 b: refs/heads/try2 c: 7cc8f4b h: refs/heads/master v: v3
1 parent dd7e462 commit c4e43b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1676
-1516
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 382b037252c213150f2a298524db2c7674804126
8+
refs/heads/try2: 7cc8f4bae0ed20aad04e03e5f3812fb7b8288f78
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/tutorial-container.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,12 @@ impl Iterator<int> for ZeroStream {
108108
## Container iterators
109109
110110
Containers implement iteration over the contained elements by returning an
111-
iterator object. For example, vector slices several iterators available:
111+
iterator object. For example, vector slices have four iterators available:
112112
113-
* `iter()` and `rev_iter()`, for immutable references to the elements
114-
* `mut_iter()` and `mut_rev_iter()`, for mutable references to the elements
115-
* `consume_iter()` and `consume_rev_iter`, to move the elements out by-value
116-
117-
A typical mutable container will implement at least `iter()`, `mut_iter()` and
118-
`consume_iter()` along with the reverse variants if it maintains an order.
113+
* `vector.iter()`, for immutable references to the elements
114+
* `vector.mut_iter()`, for mutable references to the elements
115+
* `vector.rev_iter()`, for immutable references to the elements in reverse order
116+
* `vector.mut_rev_iter()`, for mutable references to the elements in reverse order
119117
120118
### Freezing
121119

branches/try2/mk/tests.mk

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,6 @@ TEST_SREQ$(1)_T_$(2)_H_$(3) = \
537537

538538
# Rules for the cfail/rfail/rpass/bench/perf test runner
539539

540-
# The tests select when to use debug configuration on their own;
541-
# remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
542-
CTEST_RUSTC_FLAGS = $$(subst --cfg debug,,$$(CFG_RUSTC_FLAGS))
543-
544540
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
545541
--compile-lib-path $$(HLIB$(1)_H_$(3)) \
546542
--run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
@@ -552,7 +548,7 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
552548
--target $(2) \
553549
--adb-path=$(CFG_ADB) \
554550
--adb-test-dir=$(CFG_ADB_TEST_DIR) \
555-
--rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) --target=$(2)" \
551+
--rustcflags "$(RUSTC_FLAGS_$(2)) $$(CFG_RUSTC_FLAGS) --target=$(2)" \
556552
$$(CTEST_TESTARGS)
557553

558554
CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)

branches/try2/src/etc/emacs/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
E=@echo
2+
TEMP=temp.el
3+
4+
EMACS ?= emacs
5+
6+
all: $(TEMP)
7+
$(EMACS) -batch -q -no-site-file -l ./$(TEMP) -f rustmode-compile
8+
rm -f $(TEMP)
9+
$(TEMP):
10+
$(E) '(setq load-path (cons "." load-path))' >> $(TEMP)
11+
$(E) '(defun rustmode-compile () (mapcar (lambda (x) (byte-compile-file x))' >> $(TEMP)
12+
$(E) ' (list "cm-mode.el" "rust-mode.el")))' >> $(TEMP)
13+
clean:
14+
rm -f *.elc $(TEMP)

branches/try2/src/etc/emacs/README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,21 @@ file:
1313
(add-to-list 'load-path "/path/to/rust-mode/")
1414
(require 'rust-mode)
1515

16-
Rust mode will automatically be associated with .rs files. To enable it
17-
explicitly, do `M-x rust-mode`.
16+
Make sure you byte-compile the .el files first, or the mode will be
17+
painfully slow. There is an included `Makefile` which will do it for
18+
you, so in the simplest case you can just run `make` and everything
19+
should Just Work.
20+
21+
If for some reason that doesn't work, you can byte compile manually,
22+
by pasting this in your `*scratch*` buffer, moving the cursor below
23+
it, and pressing `C-j`:
24+
25+
(progn
26+
(byte-compile-file "/path/to/rust-mode/cm-mode.el" t)
27+
(byte-compile-file "/path/to/rust-mode/rust-mode.el" t))
28+
29+
Rust mode will automatically be associated with .rs and .rc files. To
30+
enable it explicitly, do `M-x rust-mode`.
1831

1932
### package.el installation via Marmalade or MELPA
2033

@@ -54,6 +67,24 @@ should upgrade in order to support installation from multiple sources.
5467
The ELPA archive is deprecated and no longer accepting new packages,
5568
so the version there (1.7.1) is very outdated.
5669

70+
#### Important
71+
72+
In order to have cm-mode properly initialized after compilation prior
73+
to rust-mode.el compilation you will need to add these `advices` to
74+
your init file or if you are a melpa user install the `melpa` package.
75+
76+
```lisp
77+
(defadvice package-download-tar
78+
(after package-download-tar-initialize activate compile)
79+
"initialize the package after compilation"
80+
(package-initialize))
81+
82+
(defadvice package-download-single
83+
(after package-download-single-initialize activate compile)
84+
"initialize the package after compilation"
85+
(package-initialize))
86+
```
87+
5788
#### Install rust-mode
5889

5990
From there you can install rust-mode or any other modes by choosing
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
;;; cm-mode.el --- Wrapper for CodeMirror-style Emacs modes
2+
3+
;; Version: 0.1.0
4+
;; Author: Mozilla
5+
;; Url: https://github.com/mozilla/rust
6+
;; Highlighting is done by running a stateful parser (with first-class
7+
;; state object) over the buffer, line by line, using the output to
8+
;; add 'face properties, and storing the parser state at the end of
9+
;; each line. Indentation is done based on the parser state at the
10+
;; start of the line.
11+
12+
(eval-when-compile (require 'cl))
13+
14+
;; Mode data structure
15+
16+
(defun make-cm-mode (token &optional start-state copy-state
17+
compare-state indent)
18+
(vector token
19+
(or start-state (lambda () 'null))
20+
(or copy-state 'cm-default-copy-state)
21+
(or compare-state 'eq)
22+
indent))
23+
(defmacro cm-mode-token (x) `(aref ,x 0))
24+
(defmacro cm-mode-start-state (x) `(aref ,x 1))
25+
(defmacro cm-mode-copy-state (x) `(aref ,x 2))
26+
(defmacro cm-mode-compare-state (x) `(aref ,x 3))
27+
(defmacro cm-mode-indent (x) `(aref ,x 4))
28+
29+
(defvar cm-cur-mode nil)
30+
(defvar cm-worklist nil)
31+
32+
(defun cm-default-copy-state (state)
33+
(if (consp state) (copy-sequence state) state))
34+
35+
(defun cm-clear-work-items (from to)
36+
(let ((prev-cons nil)
37+
(rem cm-worklist))
38+
(while rem
39+
(let ((pos (marker-position (car rem))))
40+
(cond ((or (< pos from) (> pos to)) (setf prev-cons rem))
41+
(prev-cons (setf (cdr prev-cons) (cdr rem)))
42+
(t (setf cm-worklist (cdr rem))))
43+
(setf rem (cdr rem))))))
44+
45+
(defun cm-min-worklist-item ()
46+
(let ((rest cm-worklist) (min most-positive-fixnum))
47+
(while rest
48+
(let ((pos (marker-position (car rest))))
49+
(when (< pos min) (setf min pos)))
50+
(setf rest (cdr rest)))
51+
min))
52+
53+
;; Indentation
54+
55+
(defun cm-indent ()
56+
(let (indent-pos)
57+
(save-excursion
58+
(beginning-of-line)
59+
(let* ((buf (current-buffer))
60+
(state (cm-preserve-state buf 'cm-state-for-point))
61+
(old-indent (current-indentation)))
62+
(back-to-indentation)
63+
(setf indent-pos (point))
64+
(let ((new-indent (funcall (cm-mode-indent cm-cur-mode) state)))
65+
(unless (= old-indent new-indent)
66+
(indent-line-to new-indent)
67+
(setf indent-pos (point))
68+
(beginning-of-line)
69+
(cm-preserve-state buf
70+
(lambda ()
71+
(cm-highlight-line state)
72+
(when (< (point) (point-max))
73+
(put-text-property (point) (+ (point) 1) 'cm-parse-state state))))))))
74+
(when (< (point) indent-pos)
75+
(goto-char indent-pos))))
76+
77+
(defun cm-backtrack-to-state ()
78+
(let ((backtracked 0)
79+
(min-indent most-positive-fixnum)
80+
min-indented)
81+
(loop
82+
(when (= (point) (point-min))
83+
(return (funcall (cm-mode-start-state cm-cur-mode))))
84+
(let ((st (get-text-property (- (point) 1) 'cm-parse-state)))
85+
(when (and st (save-excursion
86+
(backward-char)
87+
(beginning-of-line)
88+
(not (looking-at "[ ]*$"))))
89+
(return (funcall (cm-mode-copy-state cm-cur-mode) st))))
90+
(let ((i (current-indentation)))
91+
(when (< i min-indent)
92+
(setf min-indent i min-indented (point))))
93+
(when (> (incf backtracked) 30)
94+
(goto-char min-indented)
95+
(return (funcall (cm-mode-start-state cm-cur-mode))))
96+
(forward-line -1))))
97+
98+
(defun cm-state-for-point ()
99+
(let ((pos (point))
100+
(state (cm-backtrack-to-state)))
101+
(while (< (point) pos)
102+
(cm-highlight-line state)
103+
(put-text-property (point) (+ (point) 1) 'cm-parse-state
104+
(funcall (cm-mode-copy-state cm-cur-mode) state))
105+
(forward-char))
106+
state))
107+
108+
;; Highlighting
109+
110+
(defun cm-highlight-line (state)
111+
(let ((eol (point-at-eol)))
112+
(remove-text-properties (point) eol '(face))
113+
(loop
114+
(let ((p (point)))
115+
(when (= p eol) (return))
116+
(let ((style (funcall (cm-mode-token cm-cur-mode) state)))
117+
(when (= p (point)) (print (point)) (error "Nothing consumed."))
118+
(when (> p eol) (error "Parser moved past EOL"))
119+
(when style
120+
(put-text-property p (point) 'face style)))))))
121+
122+
(defun cm-find-state-before-point ()
123+
(loop
124+
(beginning-of-line)
125+
(when (= (point) 1)
126+
(return (funcall (cm-mode-start-state cm-cur-mode))))
127+
(let ((cur (get-text-property (- (point) 1) 'cm-parse-state)))
128+
(when cur (return (funcall (cm-mode-copy-state cm-cur-mode) cur))))
129+
(backward-char)))
130+
131+
(defun cm-schedule-work (delay)
132+
(run-with-idle-timer delay nil 'cm-preserve-state (current-buffer) 'cm-do-some-work))
133+
134+
(defun cm-preserve-state (buffer f &rest args)
135+
(with-current-buffer buffer
136+
(let ((modified (buffer-modified-p))
137+
(buffer-undo-list t)
138+
(inhibit-read-only t)
139+
(inhibit-point-motion-hooks t)
140+
(inhibit-modification-hooks t))
141+
(unwind-protect (apply f args)
142+
(unless modified
143+
(restore-buffer-modified-p nil))))))
144+
145+
(defun cm-do-some-work-inner ()
146+
(let ((end-time (time-add (current-time) (list 0 0 500)))
147+
(quitting nil))
148+
(while (and (not quitting) cm-worklist)
149+
(goto-char (cm-min-worklist-item))
150+
(let ((state (cm-find-state-before-point))
151+
(startpos (point))
152+
(timer-idle-list nil))
153+
(loop
154+
(cm-highlight-line state)
155+
(when (= (point) (point-max)) (return))
156+
(let ((old (get-text-property (point) 'cm-parse-state)))
157+
(when (and old (funcall (cm-mode-compare-state cm-cur-mode) state old))
158+
(return))
159+
(put-text-property (point) (+ (point) 1) 'cm-parse-state
160+
(funcall (cm-mode-copy-state cm-cur-mode) state)))
161+
(when (or (let ((timer-idle-list nil)) (input-pending-p))
162+
(time-less-p end-time (current-time)))
163+
(setf quitting t) (return))
164+
(forward-char))
165+
(cm-clear-work-items startpos (point)))
166+
(when quitting
167+
(push (copy-marker (+ (point) 1)) cm-worklist)
168+
(cm-schedule-work 0.05)))))
169+
170+
(defun cm-do-some-work ()
171+
(save-excursion
172+
(condition-case cnd (cm-do-some-work-inner)
173+
(error (print cnd) (error cnd)))))
174+
175+
(defun cm-after-change-function (from to oldlen)
176+
(cm-preserve-state (current-buffer) 'remove-text-properties from to '(cm-parse-state))
177+
(push (copy-marker from) cm-worklist)
178+
(cm-schedule-work 0.2))
179+
180+
;; Entry function
181+
182+
;;;###autoload
183+
(defun cm-mode (mode)
184+
(set (make-local-variable 'cm-cur-mode) mode)
185+
(set (make-local-variable 'cm-worklist) (list (copy-marker 1)))
186+
(when (cm-mode-indent mode)
187+
(set (make-local-variable 'indent-line-function) 'cm-indent))
188+
(add-hook 'after-change-functions 'cm-after-change-function t t)
189+
(add-hook 'after-revert-hook (lambda () (cm-after-change-function 1 (point-max) nil)) t t)
190+
(cm-schedule-work 0.05))
191+
192+
(provide 'cm-mode)
193+
194+
;;; cm-mode.el ends here

0 commit comments

Comments
 (0)