Commit f49bc77e authored by Ronald Charles Moore's avatar Ronald Charles Moore
Browse files

Got test9 to work (by borrowing 'main' hack from test8)!


Signed-off-by: Ronald Charles Moore's avatarProf. Ronald Moore <ronald.moore@h-da.de>
parent 7c15aefe
......@@ -26,7 +26,6 @@ LLVM_FLAGS := `llvm-config --cxxflags --ldflags --system-libs --libs all `
CFLAGS := $(LLVM_FLAGS) -rdynamic -O3
### Gnu Make Preliminaries -- See also
# https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
......@@ -56,10 +55,10 @@ $(PROGS): %: %.cpp
$(CC) -g $< $(CFLAGS) -o $@
clean: testclean
$(RM) -fv *~ $(PROGS) ModuleMaker.bc fib test8 test8.o test9
$(RM) -fv *~ $(PROGS) ModuleMaker.bc fib test8 test9
testclean:
rm -fv *~ *.output test8.o test9
rm -fv *~ *.output test8.o test9.o
tests: $(TESTS)
......@@ -96,14 +95,15 @@ test7: toy7 tests/test7.kal
echo && echo "\n===================> Testing toy7...\n"
-./toy7 <tests/test7.kal
test8: toy8 tests/test8.kal toy8.cpp
test8: toy8 tests/test8.kal tests/test8.cpp
echo && echo "\n===================> Testing toy8... (expect 42, of course)\n"
-./toy8 <tests/test8.kal
-clang++ tests/test8.cpp test8.o -o test8
-./test8
test9: toy9 tests/test9.kal
echo && echo "\n===================> Testing toy9...\n"
-./toy9 <tests/test9.kal |& clang -x ir - -o test9
test9: toy9 tests/test9.kal tests/test9.cpp
echo && echo "\n===================> Testing toy9...(expect fib(12) == 144)\n"
-./toy9 <tests/test9.kal |& clang -x ir -c - -o test9.o
-clang++ tests/test9.cpp test9.o -o test9
-./test9
#include <iostream>
extern "C" {
double repl( );
}
int main() {
std::cout << "REPL output =" << repl( ) << std::endl;
}
......@@ -4,4 +4,4 @@ def fib(x)
else
fib(x-1)+fib(x-2);
fib(2)
fib(12)
......@@ -801,8 +801,8 @@ static std::unique_ptr<FunctionAST> ParseDefinition() {
static std::unique_ptr<FunctionAST> ParseTopLevelExpr() {
SourceLocation FnLoc = CurLoc;
if (auto E = ParseExpression()) {
// Make an anonymous proto.
auto Proto = std::make_unique<PrototypeAST>(FnLoc, "main", // "__anon_expr",
// Make an top level proto called "repl"
auto Proto = std::make_unique<PrototypeAST>(FnLoc, "repl", // "__anon_expr",
std::vector<std::string>());
return std::make_unique<FunctionAST>(std::move(Proto), std::move(E));
}
......@@ -1343,6 +1343,7 @@ static void HandleExtern() {
static void HandleTopLevelExpression() {
// Evaluate a top-level expression into an anonymous function.
// ...which is not really anonymous but rather "repl" ...
if (auto FnAST = ParseTopLevelExpr()) {
if (!FnAST->codegen()) {
fprintf(stderr, "Error generating code for top level expr");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment