Goose  Diff

Differences From Artifact [2e87d6af79]:

  • File bs/empathy.cpp — part of check-in [093794896f] at 2019-01-12 13:11:32 on branch trunk — Some preliminary work on functions. (user: achavasse size: 1983)

To Artifact [d13d3009df]:

  • File bs/empathy.cpp — part of check-in [a9ae189d74] at 2019-01-13 15:59:14 on branch trunk — Lexer: added some throw away test code, fixed a couple of bugs. (user: achavasse size: 710)

1
2

3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29

30
31
32
33
34
35



36
37
38
39
40
41
42

43
44
45
46
47
48

49

50
51
52


53



54
55
56
57


58
59
60
61
62
1
2
3
4
5
6
7
8
9
10
11



12










13


14



15






16
17
18







19



20


21

22
23


24
25

26
27
28
29



30
31


32
33
34


+








-
-
-
+
-
-
-
-
-
-
-
-
-
-

-
-
+
-
-
-
+
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
+
-
-
-

-
-
+
-
+

-
-
+
+
-
+
+
+

-
-
-
+
+
-
-



#include "ir/ir.h"
#include "sema/sema.h"
#include "lexer/lexer.h"

using namespace std;
using namespace empathy;
using namespace empathy::util;

int main( int argc, char** argv )
{
    // Just a dumping place for simple test code for now.
    auto gg = TVEC( TSTR( "bar" ), TSID( gg ), VECOFLENGTH( N ), REPEAT( ANYTERM( U ) ) );
    cout << gg << endl;

    auto filename = make_shared< string >( "em/lib/empathy.em" );
    ir::Trie<> testTrie;
    testTrie = Merge( testTrie, gg );
    testTrie = Merge( testTrie, TVEC( TSID( blah ), TSTR( "bar" ) ) );
    testTrie = Merge( testTrie, TVEC( TSID( foo ), TSTR( "bar" ) ) );
    testTrie = Merge( testTrie, TVEC( TSID( blah ), TSTR( "meh" ) ) );
    auto testTrie2 = testTrie;
    testTrie = Merge( testTrie, TSTR( "bar" ) );
    testTrie = Merge( testTrie, TSTR( "foo" ) );
    testTrie = Merge( testTrie, TVEC() );
    testTrie = Merge( testTrie, TVEC( TSID( gg ) ) );

    ir::GraphVizDump( "dump2.dot", testTrie );

    ifstream sourcefile( filename->c_str() );
    for( auto&& t : Enumerate( testTrie ) )
        cout << t << endl;

    if( !sourcefile.good() )
    cout << Compare( testTrie, testTrie2 ) << endl;
    cout << Compare( testTrie2, testTrie2 ) << endl;
    cout << Compare( testTrie, testTrie ) << endl;

    cout << "\n";

    {
        cout << "can't open '" << *filename << "'\n";
        return EXIT_FAILURE;
    sema::Hole testHole1( "A"_sid );
    sema::Hole testHole2( 1234 );
    auto holeExpr1 = sema::HoleToIRExpr( testHole1 );
    cout << holeExpr1 << endl;
    auto holeExpr2 = sema::HoleToIRExpr( testHole2 );
    cout << holeExpr2 << endl;

    }
    auto testHole = sema::HoleFromIRExpr( holeExpr1 );
    cout << testHole.has_value() << endl;
    cout << sema::HoleToIRExpr( *testHole ) << endl;

    testHole = sema::HoleFromIRExpr( holeExpr2 );
    cout << testHole.has_value() << endl;
    // Simple lexer test
    cout << sema::HoleToIRExpr( *testHole ) << endl;
    Lexer lex( sourcefile, filename );

    cout << "\n===================================\n\n";

    while( !lex.eos() )
    {
    sema::FunDecl fdecl1( TVEC(), TSID( retType ), TVEC() );
        auto tok = lex.consume();
        if( !tok )
            break;

    auto ruleSet = make_shared< sema::FunRuleSet >();
    auto fun = sema::BuildFun( FunDeclToIRExpr( fdecl1 ), ruleSet );

        cout << *tok << endl;
    }
    if( fun )
        cout << *fun << endl;

    return EXIT_SUCCESS;
}