Goose  Diff

Differences From Artifact [0c858bc425]:

  • File bs/lex/lexer.cpp — part of check-in [c7b1aea0a6] at 2019-08-03 14:10:49 on branch trunk — Added support for signed runtime integers and fixed multiple issues with ct_integer to runtime integer conversion. (user: achavasse size: 5670)

To Artifact [a2f7352ae5]:

  • File bs/lex/lexer.cpp — part of check-in [bd7954bf0c] at 2019-08-03 17:16:14 on branch trunk —
    • lexer: handle hex and binary integer literals.
    • builtins: implemented the logic and the compile-time bitwise xor operator.
    (user: achavasse size: 7441)

87
88
89
90
91
92
93




















































94
95
96
97
98
99
100
    }

    return result;
}

Term Lexer::readIntegerLiteral( Location&& loc )
{




















































    // skip leading zeros
    while( m_input.good() )
    {
        auto c = m_input.peek();
        if( c!= '0' )
            break;








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    }

    return result;
}

Term Lexer::readIntegerLiteral( Location&& loc )
{
    // Skip the leading zero, if any, then check for a base marker (x or b)
    // (might add 'o' for octal later but fuck octal for now)
    auto c = m_input.peek();
    if( c == '0' )
    {
        m_input.get();
        c = m_input.peek();
        if( c == 'x' )
        {
            m_input.get();
            return readIntegerLiteralHex( move( loc ) );
        }

        if( c == 'b' )
        {
            m_input.get();
            return readIntegerLiteralBin( move( loc ) );
        }
    }

    return readIntegerLiteralDec( move( loc ) );
}

Term Lexer::readIntegerLiteralBin( Location&& loc )
{
    // skip leading zeros
    while( m_input.good() )
    {
        auto c = m_input.peek();
        if( c!= '0' )
            break;

        m_input.get();
    }

    string str;
    while( m_input.good() )
    {
        auto c = m_input.peek();
        if( c != '0' && c != '1' )
            break;

        m_input.get();

        str.push_back( c );
    }

    return Term( move( loc ), APSInt( llvm::APInt( str.size(), str, 2 ) ) );
}

Term Lexer::readIntegerLiteralDec( Location&& loc )
{
    // skip leading zeros
    while( m_input.good() )
    {
        auto c = m_input.peek();
        if( c!= '0' )
            break;

111
112
113
114
115
116
117

































118
119
120
121
122
123
124
        m_input.get();

        str.push_back( c );
    }

    return Term( move( loc ), APSInt( str ) );
}


































Term Lexer::readAlphanumericIdentifier( Location&& loc )
{
    // TODO this will need to be reworked some day to handle unicode
    // identifiers.

    string str;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
        m_input.get();

        str.push_back( c );
    }

    return Term( move( loc ), APSInt( str ) );
}

Term Lexer::readIntegerLiteralHex( Location&& loc )
{
    // skip leading zeros
    while( m_input.good() )
    {
        auto c = m_input.peek();
        if( c!= '0' )
            break;

        m_input.get();
    }

    string str;
    while( m_input.good() )
    {
        auto c = m_input.peek();

        bool isHexDigit = isdigit( c );
        isHexDigit = isHexDigit || ( c >= 'a' && c <= 'f' );
        isHexDigit = isHexDigit || ( c >= 'A' && c <= 'F' );

        if( !isHexDigit )
            break;

        m_input.get();

        str.push_back( c );
    }

    return Term( move( loc ),
        APSInt( llvm::APInt( str.size() * 4, str, 16 ) ) );
}

Term Lexer::readAlphanumericIdentifier( Location&& loc )
{
    // TODO this will need to be reworked some day to handle unicode
    // identifiers.

    string str;