From 12232668d931b0f3593807d2096a2c2f26844b0b Mon Sep 17 00:00:00 2001 From: Martin Dobrev Date: Sun, 18 Nov 2018 20:32:58 +0200 Subject: Code generation improvements (#56) * Implement code generation for some unary expressions Implement debug code augmentation. Now part of expresions have source location. Extend Tokens with Column information. Refactor byte code generation. Add options for byte code generator. * Fix linux build * Little refactoring in byte code generation * Fix couple bugs in byte code generation and add some tests. * Fix some linux warnings. --- JSImpl/src/Lexer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'JSImpl/src/Lexer.cpp') diff --git a/JSImpl/src/Lexer.cpp b/JSImpl/src/Lexer.cpp index 8b3b909..dbbf92d 100644 --- a/JSImpl/src/Lexer.cpp +++ b/JSImpl/src/Lexer.cpp @@ -105,6 +105,7 @@ private: unsigned m_Line; unsigned m_Column; unsigned m_Current; + unsigned m_LastTokenPozition; const char* m_Code; IPLError m_Error; @@ -132,6 +133,7 @@ Tokenizer::Tokenizer(const char* code, const LexerSettings& settings) : m_Line(0) , m_Column(0) , m_Current(0) + , m_LastTokenPozition(0) , m_Code(code) , m_Error() , m_GenerationState(State::Success) @@ -253,12 +255,14 @@ inline void Tokenizer::NextLine() { ++m_Current; ++m_Line; - m_Column = 0; + m_LastTokenPozition = m_Column = 0; } inline Token Tokenizer::ProduceToken(TokenType type, IPLString lexeme, double number = 0.0) { - return Token{ type, m_Line, lexeme, number }; + auto token = Token{ type, m_Line, m_LastTokenPozition, lexeme, number }; + m_LastTokenPozition = m_Column; + return token; } inline Token Tokenizer::ProduceSkipToken() -- cgit v1.3.1-23-gd82d