Commit Graph

107 Commits

Author SHA1 Message Date
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
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
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
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
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
Eli Friedman
dd299a35af Fix for LLVM TargetData -> DataLayout rename.
Swift SVN r2959
2012-10-09 23:18:24 +00:00
Doug Gregor
0f27e2885e In the REPL, it's fine now to run when we're type-checking with the
constraint solver.


Swift SVN r2950
2012-10-08 20:37:58 +00:00
Eli Friedman
8a2ede5b82 Zap extra semicolon which clang warns about.
Swift SVN r2896
2012-09-22 01:53:41 +00:00
Doug Gregor
c13ef4777e Replace the REPL command :dump_constraints with a way to toggle the
LangOptions bits for using the constraint solver and emitting its
diagnostics.


Swift SVN r2839
2012-09-12 20:56:03 +00:00
Doug Gregor
f059cfd22d Add a few more hacks to layer the application of a solved constraint system to an expression tree on the existing type checker.
Swift SVN r2838
2012-09-12 20:43:05 +00:00
Doug Gregor
39b9f431ee Separate out the setting of the "debug constraints" from "use the constraint solver" option; we want these to be independent. No functionality change, yet.
Swift SVN r2837
2012-09-12 20:22:48 +00:00
Doug Gregor
42b1ab6fbd Introduce a LangOptions class to capture various type-checker-tweaking flags. For now, introduce bits to enable the constraint solver and to enable debugging of the constraint solver, and use those to eliminate the "useConstraintSolver" bit that was threaded through too much of the type checker.
Swift SVN r2836
2012-09-12 20:19:33 +00:00
Doug Gregor
81d8f27bde When dumping constraints via TypeChecker::typeCheckExpression(), don't
rely at all on the existing type checker. Instead, just fold sequence
expressions (which are effectively a delayed parsing phase) and then
hand off the expression to the constraint solver.

Allows us to type-check expressions with operators, e.g., f + 1.


Swift SVN r2793
2012-08-27 18:33:20 +00:00
Doug Gregor
5999348a5a When we're dumping constraints for an expression in the REPL, don't
execute that expression.


Swift SVN r2717
2012-08-23 00:27:42 +00:00
Doug Gregor
0d7afbe5e0 Introduce an almost completely untested implementation of constraint
generation from an expression that has not been type-checked. One can
see the constraints introduced by an expression by using

  :dump_constraints <expression>

within the REPL. We're still missing several major pieces of
constraint generation:
  - We don't yet "open up" references to polymorphic types
  - We don't print out the child constraint systems in the dump, so
  it's not at all obvious what happens within overloading (and I'm not
  convinced I like my representation anyway)
  - There are no tests whatsoever
  - Member constraints are still very, very weird



Swift SVN r2624
2012-08-13 22:59:41 +00:00
Ted Kremenek
928924728a Delay initialization of 'LastValidLineEnd', as it was unconditionally
overwritten later.

Swift SVN r2493
2012-07-30 18:30:27 +00:00
Eli Friedman
b3a9da6fef MCJIT broke again... just turn it off until we can actually take it seriously.
Swift SVN r1879
2012-05-17 01:22:15 +00:00
Eli Friedman
8f290b63a8 Extend the ugly standard library hack so it works for static compilation. We should be inlining from the standard library now everywhere except the REPL.
Swift SVN r1792
2012-05-10 01:14:56 +00:00
Eli Friedman
760b49f4c6 Remove unused bit from IRGen options.
Swift SVN r1750
2012-05-05 03:19:11 +00:00