Commit Graph

6605 Commits

Author SHA1 Message Date
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
Dave Zarzycki
40f97d48ce Unbreak the 'make' build system on 10.9
Swift SVN r4080
2013-02-19 18:52:19 +00:00
Joe Groff
22c3f0fcae REPL: Scan balanced brackets for context.
Walk backward from a '.' through balanced () [] <> to find context. Fix a problem with parseCompletionContextExpr where UnresolvedIdentifierTypes wasn't getting properly transferred to the TranslationUnit after parsing, causing 'Foo<T>.' completion to blow up.

Swift SVN r4075
2013-02-18 19:32:17 +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
bd59da3e9e REPL: Find completions from Clang modules.
Integrating Clang's FindVisibleDecls with Swift's by importing every decl created too much per-repl-entry compile time overhead, so as a workaround, just wire completions directly to FindVisibleDecls on the clang translation unit itself. Unfortunately this means we get completions for things Swift can't import yet, but it also means we don't have to wait 30 seconds to compile every entry after doing a completion.

Swift SVN r4061
2013-02-15 22:30:29 +00:00
Joe Groff
2d6c72662d Completion: Complete operators.
Walk back through a chain either of operator characters or named identifier characters to find the completion prefix.

Swift SVN r4059
2013-02-15 22:30:26 +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
Jordan Rose
56ea1e8fea If Swift is configured with a modules SDK, have it automatically use that SDK.
This may not be what we want to do in the long run, but for now it makes
development that much easier. If you want to test behavior with no SDK
available, please explicitly pass -sdk= to swift.

Swift SVN r4019
2013-02-12 01:35:09 +00:00
Joe Groff
86d1e1dc2e REPL: Have ^W delete word, ^_ undo.
Like Emacs.

Swift SVN r3996
2013-02-08 23:49:28 +00:00
Joe Groff
d047248436 Completions: style
'namespace swift { ... }' -> 'using namespace swift; ...'

Swift SVN r3994
2013-02-08 21:50:10 +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
Joe Groff
ff6138f357 asmparser now depends on bitreader (CMake edition)
Swift SVN r3800
2013-01-18 14:24:57 +00:00
John McCall
8e4e57e8c8 Apparently the LLVM asm reader now depends on the bitcode reader.
Swift SVN r3799
2013-01-18 09:06:17 +00:00
Jordan Rose
fa197bff3a The latest OSX 10.9 SDKs have changed name of the ObjC module to ObjectiveC.
Update everywhere in Swift that refers to this module accordingly.

This change is backwards-incompatible and will require rebuilding any
Objective-C-based object files. I recommend a clean of swiftFoundation
and NSStringDemo at the very least. The swiftObjC target is also being
renamed to swiftObjectiveC for consistency.

Swift SVN r3784
2013-01-17 19:46:39 +00:00
Joe Groff
662afeaeef Add '-sil-i' option to driver.
Will allow immediate execution through SIL-irgen when SIL-irgen actually exists. Also add NeedsOutput_{First,Last} symbols to the ActionType enum so that the insidious enum ordering significance there is more obvious.

Swift SVN r3757
2013-01-14 02:57:04 +00:00
Joe Groff
aba47a6b90 Add a '-sil-emit-llvm' option to the driver.
It doesn't do anything but crash yet. Also add an entry point fo SILGen to Subsystems so that it can be invoked without dependency on SIL or SILGen.

Swift SVN r3738
2013-01-11 01:51:54 +00:00
Jordan Rose
9f5ba4223e Update for SMRange becoming half-open instead of inclusive.
Swift SVN r3701
2013-01-07 19:01:11 +00:00
Doug Gregor
6de1444c8e Build/install the Swift ObjC module.
Swift SVN r3658
2013-01-03 18:55:58 +00:00
Chris Lattner
47dbc4051c update for mainline LLVM header file moves.
Swift SVN r3634
2013-01-02 14:38:42 +00:00
Chris Lattner
5c126a8443 fix some typos in the REPL :help command's output.
Swift SVN r3622
2012-12-30 10:34:21 +00:00
Doug Gregor
c9ff336043 Add :print_decl <name> option to the REPL.
This REPL option is great for taking a quick peek at APIs, especially
imported ones. For example, NSMutableArray:
swift> :print_decl NSMutableArray
class [objc] NSMutableArray {
  func [objc] addObject(anObject : id)
  func [objc] insertObject(anObject : id, atIndex : NSUInteger)
  func [objc] removeLastObject()
  func [objc] removeObjectAtIndex(index : NSUInteger)
  func [objc] replaceObjectAtIndex(index : NSUInteger, withObject :
  id)
}
extension NSMutableArray {
  func [objc] filterUsingPredicate(predicate : NSPredicate)
}
extension NSMutableArray {
  func [objc] sortUsingDescriptors(sortDescriptors : NSArray)
}
extension NSMutableArray {
  static func [objc] arrayWithCapacity(numItems : NSUInteger) -> id
  constructor (initWithCapacity : NSUInteger)
  func [objc] initWithCapacity(numItems : NSUInteger) -> id
}
extension NSMutableArray {
  func [objc] addObjectsFromArray(otherArray : NSArray)
  func [objc] exchangeObjectAtIndex(idx1 : NSUInteger,
  withObjectAtIndex : NSUInteger)
  func [objc] removeAllObjects()
  func [objc] removeObject(anObject : id, inRange : NSRange)
  func [objc] removeObject(anObject : id)
  func [objc] removeObjectIdenticalTo(anObject : id, inRange :
  NSRange)
  func [objc] removeObjectIdenticalTo(anObject : id)
  func [objc] removeObjectsFromIndices(indices : CPointer<NSUInteger>,
  numIndices : NSUInteger)
  func [objc] removeObjectsInArray(otherArray : NSArray)
  func [objc] removeObjectsInRange(range : NSRange)
  func [objc] replaceObjectsInRange(range : NSRange,
  withObjectsFromArray : NSArray, range : NSRange)
  func [objc] replaceObjectsInRange(range : NSRange,
  withObjectsFromArray : NSArray)
  func [objc] setArray(otherArray : NSArray)
  func [objc] insertObjects(objects : NSArray, atIndexes : NSIndexSet)
  func [objc] removeObjectsAtIndexes(indexes : NSIndexSet)
  func [objc] replaceObjectsAtIndexes(indexes : NSIndexSet,
  withObjects : NSArray)
  subscript (idx : NSUInteger) : id {
    get

    set
  }
  func [objc] setObject(obj : id, atIndexedSubscript : NSUInteger)
  func [objc] sortUsingComparator(cmptr : NSComparator)
  func [objc] sortWithOptions(opts : NSSortOptions, usingComparator :
  NSComparator)
}



Swift SVN r3581
2012-12-21 22:13:57 +00:00
Doug Gregor
bfcd8274fe Every Swift file is a module; let name lookup find the name of the current module.
Swift SVN r3531
2012-12-18 21:41:58 +00:00
Jordan Rose
2dbbb79df4 When parsing in script mode, the file name may not be a valid identifier.
This patch makes it so we substitute 'main' instead of warning. Eventually
we probably want to make this an error in library mode and a pedantic
warning in script mode.

Swift SVN r3516
2012-12-16 22:53:11 +00:00
Doug Gregor
608b2d8a5b Allow a Swift and a Clang module to have the same name, and load both.
This change allows client code to just use, e.g.,

  import Foundation

to get both the Clang Foundation module and the Swift Foundation
module that provides various adaptation (typically via
extensions). At some point later, we can consider whether the modules
will end up in different namespaces somehow, or whether this is best
tackled by some kind of module re-export directive, but for now it's
convenient while we await the design of a real module system for
Swift.



Swift SVN r3405
2012-12-07 18:23:35 +00:00
Doug Gregor
07be3f3e7f Use the Objective-C runtime to unique selectors in JIT'd code.
When generating IR for the JIT, use sel_registerName() to unique the
selector references we generate. Static code doesn't need this
pessimization. Fixes <rdar://problem/12764732>.


Swift SVN r3403
2012-12-07 17:13:27 +00:00
Doug Gregor
1e689a936d Load the SwiftFoundation dylib when the corresponding Swift module is used.
This is a horrible, hard-coded hack so that the REPL and interpreter
will get the ObjC bridging definitions from the SwiftFoundation dylib
when the SwiftFoundation module is imported.



Swift SVN r3402
2012-12-07 16:20:01 +00:00
Doug Gregor
9fd5749835 Add a ":dump_decl <name>" command to the REPL, for debugging purposes.
This particular command is useful for exploring the ASTs generated by
the Clang importer. For example

  import Cocoa
  :dump_decl NSArray

shows all of the imported methods in both NSArray (which only has two
methods) and its categories (which have many, many methods).


Swift SVN r3275
2012-11-28 00:37:50 +00:00
Doug Gregor
83f2874ba1 Implement support for calling imported C functions from Swift.
There is no protection whatsoever if the Clang-to-Swift type
conversion produces something that Swift doesn't lower in an
ABI-compatible way. That will be dealt with later.


Swift SVN r3249
2012-11-27 00:34:48 +00:00
Doug Gregor
beba49506a Fix makefile build for Clang module imports.
Swift SVN r3200
2012-11-16 18:25:42 +00:00
Doug Gregor
bb26f52585 Initial support for loading Clang modules into Swift.
From a user's perspective, one imports Clang modules using the normal
Swift syntax for module imports, e.g.,

  import Cocoa

However, to enable importing Clang modules, one needs to point Swift
at a particular SDK with the -sdk= argument, e.g.,

  swift -sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9M.sdk

and, of course, that SDK needs to provide support for modules.

There are a number of moving parts here. The major pieces are:

CMake support for linking Clang into Swift: CMake users will now need
to set the SWIFT_PATH_TO_CLANG_SOURCE and SWIFT_PATH_TO_CLANG_BUILD
to the locations of the Clang source tree (which defaults to
tools/clang under your LLVM source tree) and the Clang build tree.

Makefile support for linking Clang into Swift: Makefile users will
need to have Clang located in tools/clang and Swift located in
tools/swift, and builds should just work.

Module loader abstraction: similar to Clang's module loader,
a module loader is responsible for resolving a module name to an
actual module, loading that module in the process. It will also be
responsible for performing name lookup into that module.

Clang importer: the only implementation of the module loader
abstraction, the importer creates a Clang compiler instance capable of
building and loading Clang modules. The approach we take here is to
parse a dummy .m file in Objective-C ARC mode with modules enabled,
but never tear down that compilation unit. Then, when we get a request
to import a Clang module, we turn that into a module-load request to
Clang's module loader, which will build an appropriate module
on-the-fly or used a cached module file.

Note that name lookup into Clang modules is not yet
implemented. That's the next major step.



Swift SVN r3199
2012-11-16 18:17:05 +00:00
Jordan Rose
ac5abd95d0 [CMake] Automagically add private headers in Xcode as well as public headers.
Swift SVN r3167
2012-11-13 19:05:17 +00:00
Chris Lattner
818de63f96 rename the CFG libraries to SIL
Swift SVN r3125
2012-11-07 00:46:49 +00:00
Dave Zarzycki
4d8739f083 Accept limitations of LLVM build system
1) Move the low-level runtime code into swift/runtime
2) Move the high-level "standard library" code into swift/stdlib

The key difference is that the 'runtime' contains language support logic
(like retain/release logic) that the compiler assumes to always exist
and may assume intimate details about the implementation. This library
will have intimate knowledge of the swift ABI.

In contrast, the 'stdlib' can be completely rewritten and the
language/compiler make little if any assumptions about it. It is
expected to reexport fundamental types and operators, and implement
fundamental policies (precedence, implicit conversions, etc).

Swift SVN r3045
2012-10-23 21:33:52 +00:00