jckarter/clay — pull request #395 by galchinsky (2012-10-06 11:02:47+00:00)
Title: Basic REPL functionality

1. If '-repl' flag is on, it starts an interactive mode after a module is loaded.
2. Commands are parsed with parseStatements(), packed into an anonymous function with codegenExternalFunction() and JITted with LLVM .
```
build/compiler/src$ ./clay -repl ../../../examples/factorial.clay
Clay interpreter
:q to exit
:print {identifier} to print an identifier
clay>main();
ExprStatement(Call(NameRef(Identifier(main)), ExprList([]), ExprList([])))
factorial(6) = 326
clay>println(1+2);
ExprStatement(...)
3
```
3. Exceptions turned on to avoid crashing after a parser or codegen error. LLVM errors may cause a memory leak because they call SIGABRT.
```
clay>factorial1(7777);
ExprStatement(Call(NameRef(Identifier(factorial1)), ExprList([IntLiteral(7777)]), ExprList([])))
error: invalid integer math: integerMultiplyWithOverflow(13, 479001600)
[0x7fbefd4a248a]
[0x7fbefd4ad0ba]
[0x7fbefd4aff68]
[0x7fbefd4afed0]
SIGABRT called
```
4. Adding '^' to a command makes a toplevel statement. It is parsed with parseTopLevelItems(). Trying to call a toplevel function crashed on vs2010. On my linux it does nothing.
```
clay>^foo1(){println("x");}
0: Procedure(Identifier(foo1))
1: Overload(NameRef(Identifier(foo1)), Code([], NULL, [], 0, [], NULL, Block([
ExprStatement(Call(NameRef(Identifier(println)), ExprList([StringLiteral(Identifier(x))]), ExprList([])))])), 0, 0)
clay>foo1();
ExprStatement(Call(NameRef(Identifier(foo1)), ExprList([]), ExprList([])))
clay>
```

5. optimizeLLVM() is not called, because it causes an error
```
clay>main();
ExprStatement(Call(NameRef(Identifier(main)), ExprList([]), ExprList([])))
clay: /usr/local/include/llvm/Support/Casting.h:194: typename llvm::cast_retty::ret_type llvm::cast(const Y&) [with X = llvm::PointerType, Y = llvm::Type*]: Assertion `isa(Val) && "cast() argument of incompatible type!"' failed.
SIGABRT called
```

5. Shoud fix the mess of llvm::errs and std::cin, but i dont know an llvm analog for std::cin, and printer module needs llvm::errs