Commit Graph

134 Commits

Author SHA1 Message Date
Chris Lattner
aa5a195477 Fix the repl when stdout is redirected.
The repl is sometimes failing to write anything to stdout when it is
being redirected to a file (as in test/Interpreter/repl.swift).  it
looks like an editline bug on 10.8.  explicitly fflushing stdout
seems to help.


Swift SVN r4669
2013-04-10 23:32:27 +00:00
Dave Abrahams
ad12dd6f9e Style fix: Use prevailing const& placement
Swift SVN r4627
2013-04-07 01:35:24 +00:00
Chris Lattner
db522fe7db thoroughly rework how the REPL synthesizes code to print values. This centralizes the
logic in Sema (previously, some of it was in tools/Swift/Frontend.cpp) and eliminates
redundancy between expr and pattern printing.  This also eliminates most of the invalid
ASTs that the repl was producing (there is still one left).

This commit reenables the disabled REPL testcase from my last big change.



Swift SVN r4622
2013-04-06 20:05:46 +00:00
Dave Abrahams
3ec813c71b Explicitly pass an argv to LLVM's execution engine
This commit touches many more interfaces than you might expect.  Tant pis.

Swift SVN r4618
2013-04-06 03:40:32 +00:00
Dave Abrahams
19a590617a Add a "--" option that allows arguments to be passed to scripts
Swift SVN r4565
2013-04-01 22:47:24 +00:00
Joe Groff
1a8b35d383 REPL: Support -sil-irgen.
Add a 'startElem' option to SILModule::constructSIL so that it can be used with REPL input.

Swift SVN r4519
2013-03-28 18:38:29 +00:00
Joe Groff
25e370fcce Frontend: Pass down -O level in -i mode.
'-i' code was always getting emitted at -O2 regardless of the -O flag, which enables the "standard library hack" that pulls in IR for all of swift.swift. For -i optimization is often less important than responsiveness, so allow the optimization level to be specified by a flag and default to -O0 normally.

Swift SVN r4518
2013-03-28 17:56:29 +00:00
Joe Groff
e2dd3974b7 CMake: Put Swift libraries in lib/swift.
Compiling with an -isysroot prevents the linker from considering libraries in the system /usr/lib.

Swift SVN r4322
2013-03-07 21:13:36 +00:00
Joe Groff
18df5de96a REPL: Reset colors on process exit.
Fixes <rdar://problem/13328404>.

Swift SVN r4268
2013-03-02 19:32:54 +00:00
Doug Gregor
6c647535ad REPL: automatically run replApplicationMain() the first time it becomes available.
Now, importing AppKit (or anything that depends on it) under
-repl-run-loop will set up the environment to do interactive UIs.


Swift SVN r4230
2013-02-27 22:13:44 +00:00
Joe Groff
aefdb8a480 REPL: Try to reset color when quitting or crashing
Also :dump_source on a crash so it's easier to c&p and get your context back. Fixes <rdar://problem/13306302>.

Swift SVN r4227
2013-02-27 20:05:07 +00:00
Joe Groff
c4aeffd69d REPL: Don't bold inputs after entry.
Dave didn't like it, and hopefully highlighting responses should be sufficient on its own to make REPL scripts easier to spectate.

Swift SVN r4223
2013-02-27 02:33:33 +00:00
Joe Groff
0afc1d4a62 REPL: Make :autoindent switchable.
If you're pasting blocks of prewritten code into the REPL, you don't want it to double-indent. Saying ':autoindent off' before you paste now disables the automatic indentation so you can paste preformatted code.

Swift SVN r4222
2013-02-27 02:29:39 +00:00
Joe Groff
0bdbcefef7 REPL: Fix output artifact with line continuations.
Swift SVN r4218
2013-02-27 01:38:29 +00:00
Joe Groff
021e10df6c REPL: Colorize inputs and responses.
Rerender inputs in bold after they've been entered. Colorize non-REPL output, cyan for normal responses, and green for REPL directive responses. (In my terminal setup these were the least retina-searing members of the vast and nuanced ANSI color palette.)

Swift SVN r4217
2013-02-27 01:35:36 +00:00
Joe Groff
321af9f090 Some frontend cleanup.
Package up some useful REPL context into a header-able REPLContext class. Move the response metavar index there instead of having it as a gross mutable static variable.

Swift SVN r4203
2013-02-26 00:05:00 +00:00
Joe Groff
687c61ad1b REPL: Bind top-level expressions to result vars.
If a REPL input parses to an expression, bind it to the next available variable 'r<n>', and print the result as if it were a name binding. Don't bind a variable if the expression consists of a lone DeclRef, and don't print the binding if it has void type.

Swift SVN r4201
2013-02-25 23:21:34 +00:00
Doug Gregor
1e80a25322 Automatically link against imported Clang modules in the JIT <rdar://problem/13191437>.
Swift SVN r4195
2013-02-25 18:54:47 +00:00
Dave Zarzycki
f90a57cd2f Fix implicit line continuation regression
We need to see an operator before infer an unfinished infix operator.

Swift SVN r4190
2013-02-25 04:59:35 +00:00
Dave Zarzycki
56ecce271e REPL: getwc() returns WEOF, not EOF
Swift SVN r4182
2013-02-25 02:14:13 +00:00
Joe Groff
9f755c162a REPL: Adjust some comments.
Document how we're relying on the synchronous-ness of CFMessagePortSendRequest to serialize AST access between the REPLInput and REPLEnvironment threads, and remove an inaccurate comment about EL_GETCFN.

Swift SVN r4178
2013-02-24 18:53:37 +00:00
Dave Zarzycki
17c8bbbc52 Unfinished infix expressions imply line continuation
This now works automagically:

(swift) 123 +
        456
// Int64 = 579
(swift) Int .
        max()
// Int64 = 9223372036854775807
(swift)

Swift SVN r4173
2013-02-24 02:13:43 +00:00
Dave Zarzycki
e6ea59785b Empty lines must not prematurely end the continuation prompt
Swift SVN r4172
2013-02-24 01:43:36 +00:00
Joe Groff
38a8b1f7e3 REPL: Don't call global_ctors before each entry.
The REPL was accreting global_ctors and rerunning all global initializers ever registered before every entry. Change it so that it only runs global initializers once and so that the ObjC initialization stuff that needs to happen on a per-entry basis just gets dropped directly into the main() for each entry.

Swift SVN r4154
2013-02-22 22:24:29 +00:00
Joe Groff
d78d95b861 stdlib: Add a 'replExit' hook.
In the repl, if a replExit function is defined, call it when the repl is exiting. In the stdlib, add an atREPLExit function that pushes replExit handlers onto a vector and a replExit function that invokes those handlers. In swiftAppKit, have REPLApplicationMain use atREPLExit to terminate the application when the REPL is exited.

Swift SVN r4132
2013-02-21 20:50:15 +00:00
Joe Groff
585a3b216a REPL: Add a -repl-run-loop mode.
This runs the REPL with the editline interactor in a separate thread while the main thread runs a CFRunLoop. The interactor thread then sends REPL inputs through a CFMessagePort which the main thread run loop responds to.

Swift SVN r4128
2013-02-21 18:09:57 +00:00
Joe Groff
0d9c1b970e REPL: More refactoring.
Separate the input and response code further into separate classes, so the top-level loop is just a getREPLInput/handleREPLInput loop.

Swift SVN r4125
2013-02-21 05:07:14 +00:00
Joe Groff
d1c34dcfd6 REPL: Separate the interface and response code.
Break out the code that actually puts together an editline input from the code that parses, compiles, and executes the code, with an eye toward letting the former run in a thread while the latter becomes a CFRunLoop client.

Swift SVN r4124
2013-02-21 01:49:39 +00:00
Joe Groff
babf12590c REPL: Port to editline's wchar_t interface.
This makes Unicode REPL input work. 💩

Swift SVN r4121
2013-02-20 23:43:01 +00:00
Doug Gregor
56815fd483 Add a stub Swift module for AppKit.
This (indirectly) makes "import AppKit" in the REPL dlopen() the
AppKit dylib, so one can use AppKit from the REPL.


Swift SVN r4092
2013-02-20 01:20:35 +00:00
Joe Groff
ddb7ead55c REPL: Contextual completions.
If the completion prefix has a '.' behind it, guesstimate a context expression by lexing backward through an identifier(.identifier)* dotted path, then attempt to parse and typecheck that expression to decide on a base type in which to find completions.

Swift SVN r4063
2013-02-16 20:07:50 +00:00
Joe Groff
577367e35e REPL: Trim completions to actual terminal size.
Swift SVN r4058
2013-02-15 22:30:25 +00:00
Joe Groff
7a7e3d5615 REPL: Hook up completions to name lookup.
Implement a 'lookupVisibleDecls' API similar to Clang's that replicates the UnqualifiedLookup logic for walking through a given scope looking for decls. Use it to populate the completion list in the repl.

Still to be done: Clang module lookup via Clang's lookupVisibleDecls, and context deduction from dotted path expressions.

Swift SVN r4056
2013-02-15 20:17:44 +00:00
Joe Groff
93d734e2c7 REPL: Outdent 'ident:' labels and 'set(...):'.
Fixes <rdar://problem/13185341>.

Swift SVN r4035
2013-02-13 19:51:05 +00:00
Joe Groff
ce03b19363 REPL: Don't outdent '}' if not at start of line.
Fixes <rdar://problem/13195429>.

Swift SVN r4032
2013-02-13 19:07:22 +00:00
Joe Groff
42fae3bc9a REPL: Iterate on the parseable prompt.
Nobody really likes '/*swift*/'. '(swift)' happens to parse, and it's to my eyes an improvement...

Swift SVN r4031
2013-02-13 18:51:29 +00:00
Joe Groff
86d1e1dc2e REPL: Have ^W delete word, ^_ undo.
Like Emacs.

Swift SVN r3996
2013-02-08 23:49:28 +00:00
Chris Lattner
0dee611eb3 fix a couple of bugs flagged by clang warnings, and use SmallVector
in insertStringRef instead of a VLA since C++ doesn't have VLAs.


Swift SVN r3991
2013-02-08 19:38:19 +00:00
Joe Groff
14f5ab69a0 REPL: Indent source in-buffer for :dump_source.
Actually indent the source lines we receive from editline when we store them to the buffer so that :dump_source looks right. Fixes <rdar://problem/13171743>.

Swift SVN r3983
2013-02-07 23:18:49 +00:00
Joe Groff
283a17ceee REPL: Groundwork for completions.
Set up a Completion object to extract context and a prefix string from a partial input and then track the state of the user's interaction with the completion system. Wire up tab in editline to trigger completion when pressed. It still needs to be hooked up to name lookup; right now it just looks in a fixed list of completion strings.

Swift SVN r3981
2013-02-07 22:19:00 +00:00
Joe Groff
189bda0450 REPL: Indent when tab is pressed at start of line.
In the middle of a line, we should look for completions, when we have a completion engine...

Swift SVN r3977
2013-02-06 23:50:14 +00:00
Joe Groff
9ec417ec56 REPL: Remove debug crumb.
Swift SVN r3976
2013-02-06 23:22:35 +00:00
Joe Groff
2e1c0394d3 REPL: Outdent when the user types '}'.
Swift SVN r3975
2013-02-06 23:02:31 +00:00
Joe Groff
0a2410e467 REPL: Make the prompts parseable.
Change our PS1 to /*swift*/ and PS2 to /* ... */.

Swift SVN r3974
2013-02-06 23:02:29 +00:00
Joe Groff
6917073c06 REPL: Emit escapes in "literal mode" for editline.
In theory this would colorize the prompt, but editline is broken and doesn't emit literal-mode characters in sequence with cooked characters.

Swift SVN r3973
2013-02-06 23:02:28 +00:00
Jordan Rose
f028cd2b6a Call +load on all classes to register them with the Objective-C runtime.
When an Objective-C class is first used, the runtime will "realize" it,
i.e. create the rw-data and set a couple flags. With pure Swift classes,
though, it's possible to create an instance and then send a message to it
without ever sending a message to the class, in which case the runtime will
try to realize the /instance/ and mess everything up.

This patch "fixes" that by sending the +load message to all Swift classes,
to make sure they get realized before being used. This is a very
unfortunate cost in startup time but will be necessary for id-compatibility.

I will admit that I'm not sure why this is necessary for compiled classes.
I would have expected the object file to contain the necessary information
for the runtime to realize the classes in it by default. But perhaps
classes aren't realized until their first class message even in statically-
compiled code.

<rdar://problem/13154445>

Swift SVN r3951
2013-02-05 19:53:01 +00:00
Joe Groff
9e3724b562 REPL: Factor out 'print-or-dump' logic.
It crossed the "1, 2, or N" threshold.

Swift SVN r3923
2013-02-01 17:25:01 +00:00
Joe Groff
7350051ce7 REPL: Print original decl along with a typealias.
This allows you to print imported structs that were defined as 'typedef struct foo {} foo;', for which the original decl is otherwise inaccessible:

swift> :print_decl NSFastEnumerationState
typealias NSFastEnumerationState = NSFastEnumerationState
struct NSFastEnumerationState {
  ...
}

Swift SVN r3922
2013-02-01 17:19:16 +00:00
Dave Zarzycki
b36678214a Rename l_(paren|square)_(call|subscript)
Thanks Chris and John for the feedback.

Swift SVN r3893
2013-01-29 21:13:39 +00:00
Dave Zarzycki
735294a5c9 Make the lexing of '(', '[', and '.' consistent
The lexer now models tuples, patterns, subscripting, function calls, and
field access robustly. The output tokens are now better named as well:
l_paren and l_paren_call, and l_square and l_square_subscript. It
should be much more clear now which one to use. Also, the use of
l_paren or l_square will not arbitrarily flip flop if the token before
it is a keyword or if the token before it was the trailing ']' of an
attribute list. Similarly, tuples will always cause the lexer to produce
l_paren, regardless if the user typed '((x,y))' or '( (x,y))'.

When we someday add array literals, the right token is now naturally
falling out of the lexer.

Swift SVN r3840
2013-01-23 03:23:17 +00:00