From 36711f22e4d3449d75f8412654330a7ca5c3275a Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Mon, 19 Nov 2018 23:44:40 +0200 Subject: Can assemble to files --- spasm/src/asm/assembler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spasm/src/asm/assembler.cpp') diff --git a/spasm/src/asm/assembler.cpp b/spasm/src/asm/assembler.cpp index fbe6675..aad2911 100644 --- a/spasm/src/asm/assembler.cpp +++ b/spasm/src/asm/assembler.cpp @@ -105,7 +105,7 @@ void Assembler::assemble_identifier(const Lexer::Token& token) _bytecode->push_location(symbol->definition()); } -bool compile(std::istream& istr, Bytecode_Memory& bytecode) +bool compile(std::istream& istr, Bytecode_Stream& bytecode) { Lexer::Tokenizer tokenizer(istr); Assembler assembler(tokenizer, bytecode); -- cgit v1.3.1-23-gd82d From 3ce342b97b6c22b7ce6dded7be7b5c6bf9edcc04 Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Mon, 19 Nov 2018 23:49:15 +0200 Subject: Support for doubles in the assembler --- spasm/src/asm/assembler.cpp | 106 +++++++-- spasm/src/asm/bytecode.cpp | 40 ++-- spasm/src/asm/bytecode.hpp | 9 +- spasm/src/asm/lexer.cpp | 522 ++++++++++++++++++++++++-------------------- spasm/src/asm/lexer.re | 436 ++++++++++++++++++------------------ spasm/src/asm/token.cpp | 31 ++- spasm/src/asm/token.hpp | 4 + spasm/src/spasm.cpp | 57 ++++- 8 files changed, 701 insertions(+), 504 deletions(-) (limited to 'spasm/src/asm/assembler.cpp') diff --git a/spasm/src/asm/assembler.cpp b/spasm/src/asm/assembler.cpp index aad2911..2ec988f 100644 --- a/spasm/src/asm/assembler.cpp +++ b/spasm/src/asm/assembler.cpp @@ -14,6 +14,54 @@ Assembler::Assembler(Lexer::Tokenizer& tokenizer, Bytecode_Stream& bytecode) { } +int get_arg_size(const Lexer::Token args[]) +{ + int size = 0; + for (int i = 0; i < 3; ++i) + { + switch (args[i].type()) + { + case Lexer::Token::Integer: + case Lexer::Token::XInteger: + { + if (args[i].value_int() > 0xffffffff) + { + size = std::max(size, 3); + } + else if (args[i].value_int() > 0xffff) + { + size = std::max(size, 2); + } + else if (args[i].value_int() > 0xff) + { + size = std::max(size, 1); + } + else if (args[i].value_int() < -0xffffffffLL) + { + size = std::max(size, 3); + } + else if (args[i].value_int() < -0xffff) + { + size = std::max(size, 2); + } + else if (args[i].value_int() < -0xff) + { + size = std::max(size, 1); + } + break; + } + case Lexer::Token::FloatingPoint: + { + size = std::max(size, 3); + break; + } + default: + break; + } + } + return size; +} + void Assembler::assemble() { Lexer::Token token = _tokenizer->next_token(); @@ -39,42 +87,64 @@ void Assembler::assemble() } else { - _bytecode->push_opcode((Bytecode_Stream::Opcode_t)token.type()); + Lexer::Token args[3]; if (type >= Lexer::Token::_OneArgBegin) + { + args[0] = _tokenizer->next_token(); + } + if (type >= Lexer::Token::_TwoArgBegin) + { + args[1] = _tokenizer->next_token(); + } + if (type >= Lexer::Token::_ThreeArgBegin) + { + args[2] = _tokenizer->next_token(); + } + const auto size = get_arg_size(args); + _bytecode->push_opcode((Bytecode_Stream::Opcode_t)((size << 6) | + token.type())); + const auto arg_size = 1 << size; + + if (args[0].type() != Lexer::Token::NotUsed) { if (type == Lexer::Token::Call || type == Lexer::Token::Jump) { - token = _tokenizer->next_token(); - assert(token.type() == Lexer::Token::Ident); - assemble_identifier(token); + assert(args[0].type() == Lexer::Token::Ident); + assemble_identifier(args[0]); } else { - token = _tokenizer->next_token(); - assert(token.type() == Lexer::Token::Integer); - _bytecode->push_integer(token.value_int()); + assert(args[0].type() == Lexer::Token::Integer); + _bytecode->push_integer(args[0].value_int(), arg_size); } } - if (type >= Lexer::Token::_TwoArgBegin) + if (args[1].type() != Lexer::Token::NotUsed) { if (type == Lexer::Token::JumpF || type == Lexer::Token::JumpT) { - token = _tokenizer->next_token(); - assert(token.type() == Lexer::Token::Ident); - assemble_identifier(token); + assert(args[1].type() == Lexer::Token::Ident); + assemble_identifier(args[1]); } else { - token = _tokenizer->next_token(); - assert(token.type() == Lexer::Token::Integer); - _bytecode->push_integer(token.value_int()); + if (args[1].type() == Lexer::Token::Integer) + { + _bytecode->push_integer(args[1].value_int(), arg_size); + } + else if (args[1].type() == Lexer::Token::FloatingPoint) + { + _bytecode->push_double(args[1].value_double()); + } + else + { + assert(false && "expected a number type"); + } } } - if (type >= Lexer::Token::_ThreeArgBegin) + if (args[2].type() != Lexer::Token::NotUsed) { - token = _tokenizer->next_token(); - assert(token.type() == Lexer::Token::Integer); - _bytecode->push_integer(token.value_int()); + assert(args[2].type() == Lexer::Token::Integer); + _bytecode->push_integer(args[2].value_int(), arg_size); } } diff --git a/spasm/src/asm/bytecode.cpp b/spasm/src/asm/bytecode.cpp index 39f1de6..ad436ce 100644 --- a/spasm/src/asm/bytecode.cpp +++ b/spasm/src/asm/bytecode.cpp @@ -26,17 +26,17 @@ void Bytecode_File::push_opcode(Bytecode_Stream::Opcode_t opcode) push_byte(opcode); } -void Bytecode_File::push_integer(int number) +void Bytecode_File::push_integer(int number, int size) { - if (number <= 0xff) - { - push_byte((byte)number); - } - else - { - for (size_t i = 0; i < sizeof(int); ++i) - push_byte((number >> (i << 3)) & 0xff); - } + for (int i = 0; i < size; ++i) + push_byte((number >> (i << 3)) & 0xff); +} + +void Bytecode_File::push_double(double number) +{ + auto bits = *reinterpret_cast(&number); + for (size_t i = 0; i < sizeof(size_t); ++i) + push_byte((bits >> (i << 3)) & 0xff); } void Bytecode_Memory::push_byte(Bytecode_Stream::byte byte) @@ -49,17 +49,17 @@ void Bytecode_Memory::push_opcode(Bytecode_Stream::Opcode_t opcode) push_byte(opcode); } -void Bytecode_Memory::push_integer(int number) +void Bytecode_Memory::push_integer(int number, int size) { - if (number <= 0xff) - { - push_byte((byte)number); - } - else - { - for (size_t i = 0; i < sizeof(int); ++i) - push_byte((number >> (i << 3)) & 0xff); - } + for (int i = 0; i < size; ++i) + push_byte((number >> (i << 3)) & 0xff); +} + +void Bytecode_Memory::push_double(double number) +{ + auto bits = *reinterpret_cast(&number); + for (size_t i = 0; i < sizeof(size_t); ++i) + push_byte((bits >> (i << 3)) & 0xff); } void Bytecode_Memory::set_location(size_t index, size_t location) diff --git a/spasm/src/asm/bytecode.hpp b/spasm/src/asm/bytecode.hpp index 374ccef..345b7a8 100644 --- a/spasm/src/asm/bytecode.hpp +++ b/spasm/src/asm/bytecode.hpp @@ -18,7 +18,8 @@ class Bytecode_Stream virtual ~Bytecode_Stream(); virtual void push_opcode(Opcode_t) = 0; - virtual void push_integer(int) = 0; + virtual void push_integer(int, int size) = 0; + virtual void push_double(double) = 0; virtual void push_location(size_t) = 0; virtual void set_location(size_t, size_t) = 0; virtual size_t size() const = 0; @@ -30,7 +31,8 @@ class Bytecode_File : public Bytecode_Stream Bytecode_File(const std::string&); virtual void push_opcode(Opcode_t); - virtual void push_integer(int); + virtual void push_integer(int, int size); + virtual void push_double(double) override; private: Bytecode_File(const Bytecode_File&); @@ -45,7 +47,8 @@ class Bytecode_Memory : public Bytecode_Stream { public: virtual void push_opcode(Opcode_t); - virtual void push_integer(int); + virtual void push_integer(int, int) override; + virtual void push_double(double) override; virtual void push_location(size_t); virtual void set_location(size_t, size_t); virtual size_t size() const; diff --git a/spasm/src/asm/lexer.cpp b/spasm/src/asm/lexer.cpp index 3af83c7..0a51b2f 100644 --- a/spasm/src/asm/lexer.cpp +++ b/spasm/src/asm/lexer.cpp @@ -1,4 +1,4 @@ -/* Generated by re2c 1.1.1 on Thu Nov 15 10:01:26 2018 */ +/* Generated by re2c 1.1.1 on Mon Nov 19 23:46:47 2018 */ #line 1 "lexer.re" #include @@ -41,11 +41,10 @@ bool Lexer::tokenize(TokenStream& ts) { case 0x00: goto yy2; - case '\t': - case ' ': - goto yy6; case '\n': - goto yy9; + goto yy6; + case ' ': + goto yy8; case '-': goto yy11; case '0': @@ -128,52 +127,51 @@ bool Lexer::tokenize(TokenStream& ts) } yy2: ++cursor; -#line 254 "lexer.re" +#line 264 "lexer.re" { ts.push_token(Token(Token::EndInput, lineno)); break; } -#line 125 "lexer.cpp" +#line 124 "lexer.cpp" yy4: ++cursor; yy5: -#line 260 "lexer.re" +#line 270 "lexer.re" { return false; } -#line 133 "lexer.cpp" +#line 132 "lexer.cpp" yy6: ++cursor; +#line 257 "lexer.re" + { + ++lineno; + token_start = cursor; + + continue; + } +#line 142 "lexer.cpp" + yy8: + ++cursor; if (limit <= cursor) return true; yych = *cursor; switch (yych) { - case '\t': case ' ': - goto yy6; - default: goto yy8; + default: + goto yy10; } - yy8: -#line 241 "lexer.re" + yy10: +#line 251 "lexer.re" { token_start = cursor; continue; } -#line 150 "lexer.cpp" - yy9: - ++cursor; -#line 247 "lexer.re" - { - ++lineno; - token_start = cursor; - - continue; - } -#line 160 "lexer.cpp" +#line 158 "lexer.cpp" yy11: yych = *++cursor; switch (yych) @@ -194,21 +192,23 @@ bool Lexer::tokenize(TokenStream& ts) goto yy13; } yy13: -#line 59 "lexer.re" +#line 60 "lexer.re" { ts.push_token(Token(Token::Integer, lineno, token_start, cursor)); token_start = cursor; continue; } -#line 183 "lexer.cpp" +#line 181 "lexer.cpp" yy14: - ++cursor; - if (limit <= cursor) + marker = ++cursor; + if ((limit - cursor) < 2) return true; yych = *cursor; switch (yych) { + case '.': + goto yy31; case '0': case '1': case '2': @@ -299,20 +299,20 @@ bool Lexer::tokenize(TokenStream& ts) goto yy18; } yy18: -#line 233 "lexer.re" +#line 243 "lexer.re" { ts.push_token(Token(Token::Ident, lineno, token_start, cursor)); token_start = cursor; continue; } -#line 281 "lexer.cpp" +#line 280 "lexer.cpp" yy19: yych = *++cursor; switch (yych) { case '0': - goto yy31; + goto yy32; case '1': case '2': case '3': @@ -322,9 +322,9 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy33; + goto yy34; case 'd': - goto yy35; + goto yy36; default: goto yy17; } @@ -333,9 +333,9 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'a': - goto yy36; - case 'o': goto yy37; + case 'o': + goto yy38; default: goto yy17; } @@ -344,9 +344,9 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'i': - goto yy38; - case 'u': goto yy39; + case 'u': + goto yy40; default: goto yy17; } @@ -355,7 +355,7 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'm': - goto yy40; + goto yy41; default: goto yy17; } @@ -364,9 +364,9 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'a': - goto yy41; - case 'e': goto yy42; + case 'e': + goto yy43; default: goto yy17; } @@ -375,9 +375,9 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'o': - goto yy43; - case 'u': goto yy44; + case 'u': + goto yy45; default: goto yy17; } @@ -386,11 +386,11 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'o': - goto yy45; - case 'r': goto yy46; - case 'u': + case 'r': goto yy47; + case 'u': + goto yy48; default: goto yy17; } @@ -399,7 +399,7 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case '0': - goto yy48; + goto yy49; case '1': case '2': case '3': @@ -409,9 +409,9 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy50; + goto yy51; case 'e': - goto yy52; + goto yy53; default: goto yy17; } @@ -420,7 +420,7 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case 'u': - goto yy53; + goto yy54; default: goto yy17; } @@ -453,7 +453,7 @@ bool Lexer::tokenize(TokenStream& ts) case 'd': case 'e': case 'f': - goto yy54; + goto yy55; default: goto yy30; } @@ -461,6 +461,25 @@ bool Lexer::tokenize(TokenStream& ts) cursor = marker; goto yy13; yy31: + yych = *++cursor; + switch (yych) + { + case '0': + goto yy58; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + goto yy60; + default: + goto yy30; + } + yy32: yych = *++cursor; switch (yych) { @@ -529,10 +548,10 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy32; + goto yy33; } - yy32: -#line 74 "lexer.re" + yy33: +#line 84 "lexer.re" { Token t(Token::Integer, lineno, token_start + 1, cursor); t.set_int(-t.value_int()); @@ -540,8 +559,8 @@ bool Lexer::tokenize(TokenStream& ts) token_start = cursor; continue; } -#line 473 "lexer.cpp" - yy33: +#line 487 "lexer.cpp" + yy34: ++cursor; if (limit <= cursor) return true; @@ -558,7 +577,7 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy33; + goto yy34; case 'A': case 'B': case 'C': @@ -614,128 +633,128 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy32; + goto yy33; } - yy35: + yy36: yych = *++cursor; switch (yych) { case 'd': - goto yy57; + goto yy62; default: goto yy17; } - yy36: + yy37: yych = *++cursor; switch (yych) { case 'l': - goto yy59; + goto yy64; default: goto yy17; } - yy37: + yy38: yych = *++cursor; switch (yych) { case 'n': - goto yy60; + goto yy65; default: goto yy17; } - yy38: + yy39: yych = *++cursor; switch (yych) { case 'v': - goto yy61; + goto yy66; default: goto yy17; } - yy39: + yy40: yych = *++cursor; switch (yych) { case 'p': - goto yy63; + goto yy68; default: goto yy17; } - yy40: + yy41: yych = *++cursor; switch (yych) { case 'p': - goto yy65; + goto yy70; default: goto yy17; } - yy41: + yy42: yych = *++cursor; switch (yych) { case 'b': - goto yy67; + goto yy72; default: goto yy17; } - yy42: + yy43: yych = *++cursor; switch (yych) { case 'q': - goto yy68; + goto yy73; case 's': - goto yy70; + goto yy75; default: goto yy17; } - yy43: + yy44: yych = *++cursor; switch (yych) { case 'd': - goto yy71; + goto yy76; default: goto yy17; } - yy44: + yy45: yych = *++cursor; switch (yych) { case 'l': - goto yy73; + goto yy78; default: goto yy17; } - yy45: + yy46: yych = *++cursor; switch (yych) { case 'p': - goto yy75; + goto yy80; default: goto yy17; } - yy46: + yy47: yych = *++cursor; switch (yych) { case 'i': - goto yy77; + goto yy82; default: goto yy17; } - yy47: + yy48: yych = *++cursor; switch (yych) { case 's': - goto yy78; + goto yy83; default: goto yy17; } - yy48: + yy49: yych = *++cursor; switch (yych) { @@ -804,10 +823,10 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy49; + goto yy50; } - yy49: -#line 67 "lexer.re" + yy50: +#line 77 "lexer.re" { ts.push_token( Token(Token::Integer, lineno, token_start + 1, cursor)); @@ -815,8 +834,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 700 "lexer.cpp" - yy50: +#line 714 "lexer.cpp" + yy51: ++cursor; if (limit <= cursor) return true; @@ -833,7 +852,7 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy50; + goto yy51; case 'A': case 'B': case 'C': @@ -889,29 +908,29 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy49; + goto yy50; } - yy52: + yy53: yych = *++cursor; switch (yych) { case 'a': - goto yy79; + goto yy84; case 't': - goto yy80; + goto yy85; default: goto yy17; } - yy53: + yy54: yych = *++cursor; switch (yych) { case 'b': - goto yy82; + goto yy87; default: goto yy17; } - yy54: + yy55: ++cursor; if (limit <= cursor) return true; @@ -940,20 +959,53 @@ bool Lexer::tokenize(TokenStream& ts) case 'd': case 'e': case 'f': - goto yy54; + goto yy55; default: - goto yy56; + goto yy57; } - yy56: -#line 83 "lexer.re" + yy57: +#line 93 "lexer.re" { ts.push_token(Token(Token::XInteger, lineno, token_start, cursor)); token_start = cursor; continue; } -#line 822 "lexer.cpp" - yy57: +#line 836 "lexer.cpp" + yy58: + ++cursor; + yy59: +#line 68 "lexer.re" + { + ts.push_token( + Token(Token::FloatingPoint, lineno, token_start, cursor)); + token_start = cursor; + + continue; + } +#line 849 "lexer.cpp" + yy60: + ++cursor; + if (limit <= cursor) + return true; + yych = *cursor; + switch (yych) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + goto yy60; + default: + goto yy59; + } + yy62: yych = *++cursor; switch (yych) { @@ -1022,36 +1074,36 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy58; + goto yy63; } - yy58: -#line 137 "lexer.re" + yy63: +#line 147 "lexer.re" { ts.push_token(Token(Token::Add, lineno)); token_start = cursor; continue; } -#line 899 "lexer.cpp" - yy59: +#line 943 "lexer.cpp" + yy64: yych = *++cursor; switch (yych) { case 'l': - goto yy84; + goto yy89; default: goto yy17; } - yy60: + yy65: yych = *++cursor; switch (yych) { case 's': - goto yy86; + goto yy91; default: goto yy17; } - yy61: + yy66: yych = *++cursor; switch (yych) { @@ -1120,18 +1172,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy62; + goto yy67; } - yy62: -#line 158 "lexer.re" + yy67: +#line 168 "lexer.re" { ts.push_token(Token(Token::Div, lineno)); token_start = cursor; continue; } -#line 988 "lexer.cpp" - yy63: +#line 1032 "lexer.cpp" + yy68: yych = *++cursor; switch (yych) { @@ -1200,18 +1252,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy64; + goto yy69; } - yy64: -#line 116 "lexer.re" + yy69: +#line 126 "lexer.re" { ts.push_token(Token(Token::Dup, lineno)); token_start = cursor; continue; } -#line 1065 "lexer.cpp" - yy65: +#line 1109 "lexer.cpp" + yy70: yych = *++cursor; switch (yych) { @@ -1278,31 +1330,31 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; case 'f': - goto yy87; + goto yy92; case 't': - goto yy89; + goto yy94; default: - goto yy66; + goto yy71; } - yy66: -#line 186 "lexer.re" + yy71: +#line 196 "lexer.re" { ts.push_token(Token(Token::Jump, lineno)); token_start = cursor; continue; } -#line 1142 "lexer.cpp" - yy67: +#line 1186 "lexer.cpp" + yy72: yych = *++cursor; switch (yych) { case 'e': - goto yy91; + goto yy96; default: goto yy17; } - yy68: + yy73: yych = *++cursor; switch (yych) { @@ -1371,27 +1423,27 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy69; + goto yy74; } - yy69: -#line 213 "lexer.re" + yy74: +#line 223 "lexer.re" { ts.push_token(Token(Token::LessEq, lineno)); token_start = cursor; continue; } -#line 1225 "lexer.cpp" - yy70: +#line 1269 "lexer.cpp" + yy75: yych = *++cursor; switch (yych) { case 's': - goto yy92; + goto yy97; default: goto yy17; } - yy71: + yy76: yych = *++cursor; switch (yych) { @@ -1460,18 +1512,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy72; + goto yy77; } - yy72: -#line 165 "lexer.re" + yy77: +#line 175 "lexer.re" { ts.push_token(Token(Token::Mod, lineno)); token_start = cursor; continue; } -#line 1308 "lexer.cpp" - yy73: +#line 1352 "lexer.cpp" + yy78: yych = *++cursor; switch (yych) { @@ -1540,18 +1592,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy74; + goto yy79; } - yy74: -#line 151 "lexer.re" + yy79: +#line 161 "lexer.re" { ts.push_token(Token(Token::Mul, lineno)); token_start = cursor; continue; } -#line 1385 "lexer.cpp" - yy75: +#line 1429 "lexer.cpp" + yy80: yych = *++cursor; switch (yych) { @@ -1619,47 +1671,47 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; case 'r': - goto yy94; + goto yy99; default: - goto yy76; + goto yy81; } - yy76: -#line 103 "lexer.re" + yy81: +#line 113 "lexer.re" { ts.push_token(Token(Token::Pop, lineno)); token_start = cursor; continue; } -#line 1462 "lexer.cpp" - yy77: +#line 1506 "lexer.cpp" + yy82: yych = *++cursor; switch (yych) { case 'n': - goto yy96; + goto yy101; default: goto yy17; } - yy78: + yy83: yych = *++cursor; switch (yych) { case 'h': - goto yy97; + goto yy102; default: goto yy17; } - yy79: + yy84: yych = *++cursor; switch (yych) { case 'd': - goto yy99; + goto yy104; default: goto yy17; } - yy80: + yy85: yych = *++cursor; switch (yych) { @@ -1728,18 +1780,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy81; + goto yy86; } - yy81: -#line 206 "lexer.re" + yy86: +#line 216 "lexer.re" { ts.push_token(Token(Token::Ret, lineno)); token_start = cursor; continue; } -#line 1557 "lexer.cpp" - yy82: +#line 1601 "lexer.cpp" + yy87: yych = *++cursor; switch (yych) { @@ -1808,18 +1860,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy83; + goto yy88; } - yy83: -#line 144 "lexer.re" + yy88: +#line 154 "lexer.re" { ts.push_token(Token(Token::Sub, lineno)); token_start = cursor; continue; } -#line 1634 "lexer.cpp" - yy84: +#line 1678 "lexer.cpp" + yy89: yych = *++cursor; switch (yych) { @@ -1888,27 +1940,27 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy85; + goto yy90; } - yy85: -#line 199 "lexer.re" + yy90: +#line 209 "lexer.re" { ts.push_token(Token(Token::Call, lineno)); token_start = cursor; continue; } -#line 1711 "lexer.cpp" - yy86: +#line 1755 "lexer.cpp" + yy91: yych = *++cursor; switch (yych) { case 't': - goto yy101; + goto yy106; default: goto yy17; } - yy87: + yy92: yych = *++cursor; switch (yych) { @@ -1977,18 +2029,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy88; + goto yy93; } - yy88: -#line 179 "lexer.re" + yy93: +#line 189 "lexer.re" { ts.push_token(Token(Token::JumpF, lineno)); token_start = cursor; continue; } -#line 1794 "lexer.cpp" - yy89: +#line 1838 "lexer.cpp" + yy94: yych = *++cursor; switch (yych) { @@ -2057,27 +2109,27 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy90; + goto yy95; } - yy90: -#line 172 "lexer.re" + yy95: +#line 182 "lexer.re" { ts.push_token(Token(Token::JumpT, lineno)); token_start = cursor; continue; } -#line 1871 "lexer.cpp" - yy91: +#line 1915 "lexer.cpp" + yy96: yych = *++cursor; switch (yych) { case 'l': - goto yy103; + goto yy108; default: goto yy17; } - yy92: + yy97: yych = *++cursor; switch (yych) { @@ -2146,18 +2198,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy93; + goto yy98; } - yy93: -#line 219 "lexer.re" + yy98: +#line 229 "lexer.re" { ts.push_token(Token(Token::Less, lineno)); token_start = cursor; continue; } -#line 1954 "lexer.cpp" - yy94: +#line 1998 "lexer.cpp" + yy99: yych = *++cursor; switch (yych) { @@ -2226,27 +2278,27 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy95; + goto yy100; } - yy95: -#line 109 "lexer.re" + yy100: +#line 119 "lexer.re" { ts.push_token(Token(Token::PopTo, lineno)); token_start = cursor; continue; } -#line 2031 "lexer.cpp" - yy96: +#line 2075 "lexer.cpp" + yy101: yych = *++cursor; switch (yych) { case 't': - goto yy105; + goto yy110; default: goto yy17; } - yy97: + yy102: yych = *++cursor; switch (yych) { @@ -2314,20 +2366,20 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; case 'r': - goto yy107; + goto yy112; default: - goto yy98; + goto yy103; } - yy98: -#line 97 "lexer.re" + yy103: +#line 107 "lexer.re" { ts.push_token(Token(Token::Push, lineno)); token_start = cursor; continue; } -#line 2114 "lexer.cpp" - yy99: +#line 2158 "lexer.cpp" + yy104: yych = *++cursor; switch (yych) { @@ -2396,18 +2448,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy100; + goto yy105; } - yy100: -#line 123 "lexer.re" + yy105: +#line 133 "lexer.re" { ts.push_token(Token(Token::Read, lineno)); token_start = cursor; continue; } -#line 2191 "lexer.cpp" - yy101: +#line 2235 "lexer.cpp" + yy106: yych = *++cursor; switch (yych) { @@ -2476,18 +2528,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy102; + goto yy107; } - yy102: -#line 192 "lexer.re" + yy107: +#line 202 "lexer.re" { ts.push_token(Token(Token::Const, lineno)); token_start = cursor; continue; } -#line 2268 "lexer.cpp" - yy103: +#line 2312 "lexer.cpp" + yy108: yych = *++cursor; switch (yych) { @@ -2556,18 +2608,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy104; + goto yy109; } - yy104: -#line 226 "lexer.re" + yy109: +#line 236 "lexer.re" { ts.push_token(Token(Token::Label, lineno)); token_start = cursor; continue; } -#line 2345 "lexer.cpp" - yy105: +#line 2389 "lexer.cpp" + yy110: yych = *++cursor; switch (yych) { @@ -2636,18 +2688,18 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy106; + goto yy111; } - yy106: -#line 130 "lexer.re" + yy111: +#line 140 "lexer.re" { ts.push_token(Token(Token::Print, lineno)); token_start = cursor; continue; } -#line 2422 "lexer.cpp" - yy107: +#line 2466 "lexer.cpp" + yy112: yych = *++cursor; switch (yych) { @@ -2716,19 +2768,19 @@ bool Lexer::tokenize(TokenStream& ts) case 'z': goto yy16; default: - goto yy108; + goto yy113; } - yy108: -#line 91 "lexer.re" + yy113: +#line 101 "lexer.re" { ts.push_token(Token(Token::PushFrom, lineno)); token_start = cursor; continue; } -#line 2499 "lexer.cpp" +#line 2543 "lexer.cpp" } -#line 264 "lexer.re" +#line 274 "lexer.re" } return true; } @@ -2738,7 +2790,7 @@ bool Lexer::tokenize(TokenStream& ts) ** Note the buffer is always filled to the maximum, not just the ** number of bytes neccessary for the lexer to continue. ** -** \param nbytes - the number of bytes +** \param nbytes - the number of bytes */ void Lexer::buffer_grow(size_t new_size) diff --git a/spasm/src/asm/lexer.re b/spasm/src/asm/lexer.re index c182653..4ab16d1 100644 --- a/spasm/src/asm/lexer.re +++ b/spasm/src/asm/lexer.re @@ -13,16 +13,16 @@ namespace Lexer { Lexer::Lexer (std::istream & _file, size_t _buffer_size) - : file (&_file), buffer_size (_buffer_size), state (unsigned(-1)), - lineno (0) + : file (&_file), buffer_size (_buffer_size), state (unsigned(-1)), + lineno (0) { - buffer = new char[buffer_size]; - cursor = limit = marker = token_start = NULL; + buffer = new char[buffer_size]; + cursor = limit = marker = token_start = NULL; } Lexer::~Lexer () { - delete [] buffer; + delete [] buffer; } bool Lexer::tokenize (TokenStream &ts) @@ -44,285 +44,295 @@ re2c:define:YYSETSTATE:naked=1; /*!getstate:re2c */ - while (1) { + while (1) { /*!re2c -DIGIT = [0-9] ; -XDIGIT = [0-9a-fA-F] ; - -INTEGER = "-"? "0" | ([1-9] DIGIT*) ; -NONNEGATIVE = "0" | ([1-9] DIGIT*) ; -XINTEGER = "0" [xX] XDIGIT+ ; -IDENTIFIER = [a-zA-Z_] [0-9a-zA-Z_]* ; - -INTEGER { - ts.push_token (Token (Token::Integer, lineno, - token_start, cursor)); - token_start = cursor; - - continue; - } - -"r" NONNEGATIVE { - ts.push_token (Token (Token::Integer, lineno, - token_start + 1, cursor)); - token_start = cursor; +DIGIT = [0-9] ; +XDIGIT = [0-9a-fA-F] ; + +INTEGER = "-"? "0" | ([1-9] DIGIT*) ; +NONNEGATIVE = "0" | ([1-9] DIGIT*) ; +XINTEGER = "0" [xX] XDIGIT+ ; +FLOATING = "-"? "0" | ([1-9] DIGIT*) "." NONNEGATIVE ; +IDENTIFIER = [a-zA-Z_] [0-9a-zA-Z_]* ; + +INTEGER { + ts.push_token (Token (Token::Integer, lineno, + token_start, cursor)); + token_start = cursor; + + continue; + } + +FLOATING { + ts.push_token (Token (Token::FloatingPoint, + lineno, token_start, + cursor)); + token_start = cursor; + + continue; + } + +"r" NONNEGATIVE { + ts.push_token (Token (Token::Integer, lineno, + token_start + 1, cursor)); + token_start = cursor; + + continue; + } +"a" NONNEGATIVE { + Token t(Token::Integer, lineno, + token_start + 1, cursor); + t.set_int(-t.value_int()); + ts.push_token(t); + token_start = cursor; + continue; + } - continue; - } -"a" NONNEGATIVE { - Token t(Token::Integer, lineno, - token_start + 1, cursor); - t.set_int(-t.value_int()); - ts.push_token(t); - token_start = cursor; - continue; - } +XINTEGER { + ts.push_token (Token (Token::XInteger, lineno, + token_start, cursor)); + token_start = cursor; + + continue; + } -XINTEGER { - ts.push_token (Token (Token::XInteger, lineno, - token_start, cursor)); - token_start = cursor; +"pushr" { + ts.push_token (Token (Token::PushFrom, lineno)); + token_start = cursor; + + continue; + } +"push" { + ts.push_token (Token (Token::Push, lineno)); + token_start = cursor; + + continue; + } +"pop" { + ts.push_token (Token (Token::Pop, lineno)); + token_start = cursor; - continue; - } + continue; + } +"popr" { + ts.push_token (Token (Token::PopTo, lineno)); + token_start = cursor; -"pushr" { - ts.push_token (Token (Token::PushFrom, lineno)); - token_start = cursor; - - continue; - } -"push" { - ts.push_token (Token (Token::Push, lineno)); - token_start = cursor; + continue; + } + +"dup" { + ts.push_token (Token (Token::Dup, lineno)); + token_start = cursor; + + continue; + } - continue; - } -"pop" { - ts.push_token (Token (Token::Pop, lineno)); - token_start = cursor; +"read" { + ts.push_token (Token (Token::Read, lineno)); + token_start = cursor; - continue; - } -"popr" { - ts.push_token (Token (Token::PopTo, lineno)); - token_start = cursor; + continue; + } - continue; - } +"print" { + ts.push_token (Token (Token::Print, lineno)); + token_start = cursor; -"dup" { - ts.push_token (Token (Token::Dup, lineno)); - token_start = cursor; + continue; + } + +"add" { + ts.push_token (Token (Token::Add, lineno)); + token_start = cursor; - continue; - } + continue; + } -"read" { - ts.push_token (Token (Token::Read, lineno)); - token_start = cursor; +"sub" { + ts.push_token (Token (Token::Sub, lineno)); + token_start = cursor; - continue; - } + continue; + } -"print" { - ts.push_token (Token (Token::Print, lineno)); - token_start = cursor; +"mul" { + ts.push_token (Token (Token::Mul, lineno)); + token_start = cursor; - continue; - } + continue; + } -"add" { - ts.push_token (Token (Token::Add, lineno)); - token_start = cursor; +"div" { + ts.push_token (Token (Token::Div, lineno)); + token_start = cursor; - continue; - } + continue; + } -"sub" { - ts.push_token (Token (Token::Sub, lineno)); - token_start = cursor; +"mod" { + ts.push_token (Token (Token::Mod, lineno)); + token_start = cursor; - continue; - } + continue; + } -"mul" { - ts.push_token (Token (Token::Mul, lineno)); - token_start = cursor; +"jmpt" { + ts.push_token (Token (Token::JumpT, lineno)); + token_start = cursor; - continue; - } + continue; + } -"div" { - ts.push_token (Token (Token::Div, lineno)); - token_start = cursor; +"jmpf" { + ts.push_token (Token (Token::JumpF, lineno)); + token_start = cursor; - continue; - } + continue; + } -"mod" { - ts.push_token (Token (Token::Mod, lineno)); - token_start = cursor; +"jmp" { + ts.push_token (Token (Token::Jump, lineno)); + token_start = cursor; - continue; - } + continue; + } +"const" { + ts.push_token (Token (Token::Const, lineno)); + token_start = cursor; -"jmpt" { - ts.push_token (Token (Token::JumpT, lineno)); - token_start = cursor; + continue; + } - continue; - } +"call" { + ts.push_token (Token (Token::Call, lineno)); + token_start = cursor; -"jmpf" { - ts.push_token (Token (Token::JumpF, lineno)); - token_start = cursor; + continue; + } - continue; - } +"ret" { + ts.push_token (Token (Token::Ret, lineno)); + token_start = cursor; -"jmp" { - ts.push_token (Token (Token::Jump, lineno)); - token_start = cursor; + continue; + } - continue; - } -"const" { - ts.push_token (Token (Token::Const, lineno)); - token_start = cursor; +"leq" { + ts.push_token (Token (Token::LessEq, lineno)); + token_start = cursor; - continue; - } + continue; + } +"less" { + ts.push_token (Token (Token::Less, lineno)); + token_start = cursor; -"call" { - ts.push_token (Token (Token::Call, lineno)); - token_start = cursor; + continue; + } - continue; - } +"label" { + ts.push_token (Token (Token::Label, lineno)); + token_start = cursor; -"ret" { - ts.push_token (Token (Token::Ret, lineno)); - token_start = cursor; + continue; + } - continue; - } +IDENTIFIER { + ts.push_token (Token (Token::Ident, lineno, token_start, + cursor)); + token_start = cursor; -"leq" { - ts.push_token (Token (Token::LessEq, lineno)); - token_start = cursor; + continue; + } - continue; - } -"less" { - ts.push_token (Token (Token::Less, lineno)); - token_start = cursor; +[ ]+ { + token_start = cursor; - continue; - } + continue; + } -"label" { - ts.push_token (Token (Token::Label, lineno)); - token_start = cursor; +"\n" { + ++lineno; + token_start = cursor; - continue; - } + continue; + } -IDENTIFIER { - ts.push_token (Token (Token::Ident, lineno, token_start, - cursor)); - token_start = cursor; +"\000" { + ts.push_token (Token (Token::EndInput, lineno)); - continue; - } + break; + } -[ ]+ { - token_start = cursor; - - continue; - } - -"\n" { - ++lineno; - token_start = cursor; - - continue; - } - -"\000" { - ts.push_token (Token (Token::EndInput, lineno)); - - break; - } - -[^] { - return false; - } +[^] { + return false; + } */ - } - return true; - } + } + return true; + } /*! ** Fills up the buffer when neccessary. ** Note the buffer is always filled to the maximum, not just the ** number of bytes neccessary for the lexer to continue. ** -** \param nbytes - the number of bytes +** \param nbytes - the number of bytes */ void Lexer::buffer_grow (size_t new_size) { - char *new_buffer = new char[new_size]; + char *new_buffer = new char[new_size]; - std::copy (buffer, limit, new_buffer); + std::copy (buffer, limit, new_buffer); - token_start = new_buffer + (token_start - buffer); - cursor = new_buffer + (cursor - buffer); - limit = new_buffer + new_size; + token_start = new_buffer + (token_start - buffer); + cursor = new_buffer + (cursor - buffer); + limit = new_buffer + new_size; - buffer_size = new_size; + buffer_size = new_size; - delete [] buffer; - buffer = new_buffer; + delete [] buffer; + buffer = new_buffer; } void Lexer::read (size_t nbytes) { - if (token_start + nbytes > limit) { // we need larger buffer - buffer_grow (token_start - buffer + nbytes); - } - - std::copy (token_start, limit, buffer); - cursor -= token_start - buffer; - char *old_limit = limit - (token_start - buffer); - token_start = buffer; - - file->read (old_limit, limit - old_limit); - if (file->eof ()) { - size_t bytes = file->gcount (); - std::fill (old_limit + bytes, limit, '\0'); - } + if (token_start + nbytes > limit) { // we need larger buffer + buffer_grow (token_start - buffer + nbytes); + } + + std::copy (token_start, limit, buffer); + cursor -= token_start - buffer; + char *old_limit = limit - (token_start - buffer); + token_start = buffer; + + file->read (old_limit, limit - old_limit); + if (file->eof ()) { + size_t bytes = file->gcount (); + std::fill (old_limit + bytes, limit, '\0'); + } } void Lexer::buffer_init () { - file->read (buffer, buffer_size); - if (file->eof ()) { - size_t bytes = file->gcount (); - std::fill (buffer + bytes, buffer + buffer_size, '\0'); - } - - cursor = marker = token_start = buffer; - limit = buffer + buffer_size; + file->read (buffer, buffer_size); + if (file->eof ()) { + size_t bytes = file->gcount (); + std::fill (buffer + bytes, buffer + buffer_size, '\0'); + } + + cursor = marker = token_start = buffer; + limit = buffer + buffer_size; } -} // namespace Lexer +} // namespace Lexer -} // namespace ASM -} // namespace SpasmImpl +} // namespace ASM +} // namespace SpasmImpl diff --git a/spasm/src/asm/token.cpp b/spasm/src/asm/token.cpp index 4f298cf..3f8980d 100644 --- a/spasm/src/asm/token.cpp +++ b/spasm/src/asm/token.cpp @@ -22,20 +22,33 @@ Token::Token(Token::Token_type type, const char* end) : _type(type), _lineno(lineno) { - if (_type == Integer || _type == XInteger) + switch (_type) { - _value_int = strtol(start, NULL, 0); - } - else if (_type == Ident) - { - if (end) + case Integer: + case XInteger: + { + _value_int = strtol(start, NULL, 0); + break; + } + case FloatingPoint: { - _value_str = std::string(start, end); + _value_double = strtod(start, NULL); + break; } - else + case Ident: { - _value_str = std::string(start); + if (end) + { + _value_str = std::string(start, end); + } + else + { + _value_str = std::string(start); + } + break; } + default: + break; } } diff --git a/spasm/src/asm/token.hpp b/spasm/src/asm/token.hpp index 364b315..6c64e89 100644 --- a/spasm/src/asm/token.hpp +++ b/spasm/src/asm/token.hpp @@ -45,6 +45,7 @@ class Token // Register, Integer, XInteger, + FloatingPoint, EndInput, NotUsed }; @@ -60,6 +61,8 @@ class Token int value_int() const; void set_int(int v) { _value_int = v; } + double value_double() const { return _value_double; } + const std::string& value_str() const; private: @@ -68,6 +71,7 @@ class Token size_t _lineno; int _value_int; + double _value_double; std::string _value_str; }; diff --git a/spasm/src/spasm.cpp b/spasm/src/spasm.cpp index 6e09be9..58fb6d4 100644 --- a/spasm/src/spasm.cpp +++ b/spasm/src/spasm.cpp @@ -46,7 +46,6 @@ Spasm::RunResult Spasm::run() const auto instruction = m_ByteCode[m_PC++]; const auto opcode = OpCodes(instruction & 0x3f); const auto size = instruction >> 6; - assert(size == 0 && "no long args yet"); switch (opcode) { case OpCodes::Halt: @@ -281,7 +280,7 @@ void Spasm::divide(reg_t a0, reg_t a1, reg_t a2) */ void Spasm::modulus(reg_t a0, reg_t a1, reg_t a2) { - set_local(a0, int64_t(get_local(a1)) % int64_t(get_local(a2))); + set_local(a0, data_t(int64_t(get_local(a1)) % int64_t(get_local(a2)))); } /*! @@ -410,14 +409,60 @@ void Spasm::push_data(data_t data) reg_t Spasm::read_reg(size_t size) { - assert(size == 0); - return m_ByteCode[m_PC++]; + switch (size) + { + case 0: + return m_ByteCode[m_PC++]; + case 1: + { + auto result = *reinterpret_cast(&m_ByteCode[0] + m_PC); + m_PC += 2; + return result; + } + case 2: + { + auto result = *reinterpret_cast(&m_ByteCode[0] + m_PC); + m_PC += 4; + return result; + } + case 3: + { + auto result = *reinterpret_cast(&m_ByteCode[0] + m_PC); + m_PC += 8; + return result; + } + } + assert(false && "not reached"); + return 0; } data_t Spasm::read_number(size_t size) { - assert(size == 0); - return m_ByteCode[m_PC++]; + switch (size) + { + case 0: + return m_ByteCode[m_PC++]; + case 1: + { + auto result = *reinterpret_cast(&m_ByteCode[0] + m_PC); + m_PC += 2; + return result; + } + case 2: + { + auto result = *reinterpret_cast(&m_ByteCode[0] + m_PC); + m_PC += 4; + return result; + } + case 3: + { + auto result = *reinterpret_cast(&m_ByteCode[0] + m_PC); + m_PC += 8; + return result; + } + } + assert(false && "not reached"); + return 0; } } // namespace SpasmImpl -- cgit v1.3.1-23-gd82d From ddc50fe944df0a33386a3213c8021f07ac8ffdd9 Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Thu, 22 Nov 2018 14:32:02 +0200 Subject: Support for line numbers and comments --- JSImpl/test/sprtTests.cpp | 36 +-- spasm/src/asm/assembler.cpp | 4 +- spasm/src/asm/bytecode.cpp | 3 +- spasm/src/asm/lexer.cpp | 677 ++++++++++++++++++++++++-------------------- spasm/src/asm/lexer.re | 12 +- 5 files changed, 407 insertions(+), 325 deletions(-) (limited to 'spasm/src/asm/assembler.cpp') diff --git a/JSImpl/test/sprtTests.cpp b/JSImpl/test/sprtTests.cpp index 787d9eb..8480554 100644 --- a/JSImpl/test/sprtTests.cpp +++ b/JSImpl/test/sprtTests.cpp @@ -235,24 +235,24 @@ TEST_F(SPRTTest, Read) TEST_F(SPASMTest, RSyntax) { const char* program = - "push 5" "\n" - "const r1 0" "\n" - "const r2 6" "\n" - "const r3 7" "\n" - "const r4 2" "\n" - "pushr r3" "\n" - "pushr r2" "\n" - "pushr r4" "\n" - "call mult" "\n" - "popr r1" "\n" - "print r1" "\n" - "halt" "\n" - "label mult" "\n" - "print a0" "\n" - "print a1" "\n" - "print a2" "\n" - "mul r1 a2 a1" "\n" - "ret r1" "\n" + "00: push 5" "\n" + "01: const r1 0" "\n" + "02: const r2 6" "\n" + "03: const r3 7" "\n" + "04: const r4 2" "\n" + "05: pushr r3" "\n" + "06: pushr r2" "\n" + "07: pushr r4" "\n" + "08: call mult # *" "\n" + "09: popr r1" "\n" + "10: print r1" "\n" + "11: halt" "\n" + "12: label mult" "\n" + "13: print a0" "\n" + "14: print a1" "\n" + "15: print a2" "\n" + "16: mul r1 a2 a1" "\n" + "17: ret r1" "\n" "" ; CompileAndRun(program); diff --git a/spasm/src/asm/assembler.cpp b/spasm/src/asm/assembler.cpp index 2ec988f..fadd747 100644 --- a/spasm/src/asm/assembler.cpp +++ b/spasm/src/asm/assembler.cpp @@ -101,8 +101,8 @@ void Assembler::assemble() args[2] = _tokenizer->next_token(); } const auto size = get_arg_size(args); - _bytecode->push_opcode((Bytecode_Stream::Opcode_t)((size << 6) | - token.type())); + _bytecode->push_opcode( + (Bytecode_Stream::Opcode_t)((size << 6) | token.type())); const auto arg_size = 1 << size; if (args[0].type() != Lexer::Token::NotUsed) diff --git a/spasm/src/asm/bytecode.cpp b/spasm/src/asm/bytecode.cpp index a4a1e6e..cc250ba 100644 --- a/spasm/src/asm/bytecode.cpp +++ b/spasm/src/asm/bytecode.cpp @@ -26,8 +26,7 @@ void Bytecode_File::push_opcode(Bytecode_Stream::Opcode_t opcode) push_byte(opcode); } -union DoubleToBits -{ +union DoubleToBits { double as_double; int64_t as_bits; }; diff --git a/spasm/src/asm/lexer.cpp b/spasm/src/asm/lexer.cpp index 0a51b2f..5be7836 100644 --- a/spasm/src/asm/lexer.cpp +++ b/spasm/src/asm/lexer.cpp @@ -1,4 +1,4 @@ -/* Generated by re2c 1.1.1 on Mon Nov 19 23:46:47 2018 */ +/* Generated by re2c 1.1.1 on Thu Nov 22 14:23:32 2018 */ #line 1 "lexer.re" #include @@ -45,10 +45,12 @@ bool Lexer::tokenize(TokenStream& ts) goto yy6; case ' ': goto yy8; - case '-': + case '#': goto yy11; + case '-': + goto yy13; case '0': - goto yy12; + goto yy14; case '1': case '2': case '3': @@ -58,7 +60,9 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy14; + goto yy16; + case ':': + goto yy18; case 'A': case 'B': case 'C': @@ -103,55 +107,55 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; case 'a': - goto yy19; + goto yy23; case 'c': - goto yy20; + goto yy24; case 'd': - goto yy21; + goto yy25; case 'j': - goto yy22; + goto yy26; case 'l': - goto yy23; + goto yy27; case 'm': - goto yy24; + goto yy28; case 'p': - goto yy25; + goto yy29; case 'r': - goto yy26; + goto yy30; case 's': - goto yy27; + goto yy31; default: goto yy4; } yy2: ++cursor; -#line 264 "lexer.re" +#line 274 "lexer.re" { ts.push_token(Token(Token::EndInput, lineno)); break; } -#line 124 "lexer.cpp" +#line 126 "lexer.cpp" yy4: ++cursor; yy5: -#line 270 "lexer.re" +#line 280 "lexer.re" { return false; } -#line 132 "lexer.cpp" +#line 134 "lexer.cpp" yy6: ++cursor; -#line 257 "lexer.re" +#line 267 "lexer.re" { ++lineno; token_start = cursor; continue; } -#line 142 "lexer.cpp" +#line 144 "lexer.cpp" yy8: ++cursor; if (limit <= cursor) @@ -171,27 +175,51 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 158 "lexer.cpp" +#line 160 "lexer.cpp" yy11: + ++cursor; + if (limit <= cursor) + return true; + yych = *cursor; + switch (yych) + { + case '\n': + goto yy32; + default: + goto yy11; + } + yy13: yych = *++cursor; switch (yych) { case '0': - goto yy28; + goto yy34; default: goto yy5; } - yy12: + yy14: yych = *(marker = ++cursor); switch (yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case ':': + goto yy36; case 'X': case 'x': - goto yy29; + goto yy38; default: - goto yy13; + goto yy15; } - yy13: + yy15: #line 60 "lexer.re" { ts.push_token(Token(Token::Integer, lineno, token_start, cursor)); @@ -199,8 +227,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 181 "lexer.cpp" - yy14: +#line 202 "lexer.cpp" + yy16: marker = ++cursor; if ((limit - cursor) < 2) return true; @@ -208,7 +236,7 @@ bool Lexer::tokenize(TokenStream& ts) switch (yych) { case '.': - goto yy31; + goto yy39; case '0': case '1': case '2': @@ -219,16 +247,27 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy14; + goto yy16; + case ':': + goto yy18; default: - goto yy13; + goto yy15; } - yy16: + yy18: + ++cursor; +#line 256 "lexer.re" + { + token_start = cursor; + + continue; + } +#line 230 "lexer.cpp" + yy20: ++cursor; if (limit <= cursor) return true; yych = *cursor; - yy17: + yy21: switch (yych) { case '0': @@ -294,11 +333,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy18; + goto yy22; } - yy18: + yy22: #line 243 "lexer.re" { ts.push_token(Token(Token::Ident, lineno, token_start, cursor)); @@ -306,13 +345,13 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 280 "lexer.cpp" - yy19: +#line 311 "lexer.cpp" + yy23: yych = *++cursor; switch (yych) { case '0': - goto yy32; + goto yy40; case '1': case '2': case '3': @@ -322,84 +361,84 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy34; + goto yy42; case 'd': - goto yy36; + goto yy44; default: - goto yy17; + goto yy21; } - yy20: + yy24: yych = *++cursor; switch (yych) { case 'a': - goto yy37; + goto yy45; case 'o': - goto yy38; + goto yy46; default: - goto yy17; + goto yy21; } - yy21: + yy25: yych = *++cursor; switch (yych) { case 'i': - goto yy39; + goto yy47; case 'u': - goto yy40; + goto yy48; default: - goto yy17; + goto yy21; } - yy22: + yy26: yych = *++cursor; switch (yych) { case 'm': - goto yy41; + goto yy49; default: - goto yy17; + goto yy21; } - yy23: + yy27: yych = *++cursor; switch (yych) { case 'a': - goto yy42; + goto yy50; case 'e': - goto yy43; + goto yy51; default: - goto yy17; + goto yy21; } - yy24: + yy28: yych = *++cursor; switch (yych) { case 'o': - goto yy44; + goto yy52; case 'u': - goto yy45; + goto yy53; default: - goto yy17; + goto yy21; } - yy25: + yy29: yych = *++cursor; switch (yych) { case 'o': - goto yy46; + goto yy54; case 'r': - goto yy47; + goto yy55; case 'u': - goto yy48; + goto yy56; default: - goto yy17; + goto yy21; } - yy26: + yy30: yych = *++cursor; switch (yych) { case '0': - goto yy49; + goto yy57; case '1': case '2': case '3': @@ -409,25 +448,62 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy51; + goto yy59; case 'e': - goto yy53; + goto yy61; default: - goto yy17; + goto yy21; } - yy27: + yy31: yych = *++cursor; switch (yych) { case 'u': - goto yy54; + goto yy62; default: - goto yy17; + goto yy21; } - yy28: + yy32: ++cursor; - goto yy13; - yy29: +#line 261 "lexer.re" + { + ++lineno; + token_start = cursor; + + continue; + } +#line 401 "lexer.cpp" + yy34: + ++cursor; + goto yy15; + yy35: + ++cursor; + if (limit <= cursor) + return true; + yych = *cursor; + yy36: + switch (yych) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + goto yy35; + case ':': + goto yy18; + default: + goto yy37; + } + yy37: + cursor = marker; + goto yy15; + yy38: yych = *++cursor; switch (yych) { @@ -453,19 +529,16 @@ bool Lexer::tokenize(TokenStream& ts) case 'd': case 'e': case 'f': - goto yy55; + goto yy63; default: - goto yy30; + goto yy37; } - yy30: - cursor = marker; - goto yy13; - yy31: + yy39: yych = *++cursor; switch (yych) { case '0': - goto yy58; + goto yy66; case '1': case '2': case '3': @@ -475,11 +548,11 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy60; + goto yy68; default: - goto yy30; + goto yy37; } - yy32: + yy40: yych = *++cursor; switch (yych) { @@ -546,11 +619,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy33; + goto yy41; } - yy33: + yy41: #line 84 "lexer.re" { Token t(Token::Integer, lineno, token_start + 1, cursor); @@ -559,8 +632,8 @@ bool Lexer::tokenize(TokenStream& ts) token_start = cursor; continue; } -#line 487 "lexer.cpp" - yy34: +#line 547 "lexer.cpp" + yy42: ++cursor; if (limit <= cursor) return true; @@ -577,7 +650,7 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy34; + goto yy42; case 'A': case 'B': case 'C': @@ -631,130 +704,130 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy33; + goto yy41; } - yy36: + yy44: yych = *++cursor; switch (yych) { case 'd': - goto yy62; + goto yy70; default: - goto yy17; + goto yy21; } - yy37: + yy45: yych = *++cursor; switch (yych) { case 'l': - goto yy64; + goto yy72; default: - goto yy17; + goto yy21; } - yy38: + yy46: yych = *++cursor; switch (yych) { case 'n': - goto yy65; + goto yy73; default: - goto yy17; + goto yy21; } - yy39: + yy47: yych = *++cursor; switch (yych) { case 'v': - goto yy66; + goto yy74; default: - goto yy17; + goto yy21; } - yy40: + yy48: yych = *++cursor; switch (yych) { case 'p': - goto yy68; + goto yy76; default: - goto yy17; + goto yy21; } - yy41: + yy49: yych = *++cursor; switch (yych) { case 'p': - goto yy70; + goto yy78; default: - goto yy17; + goto yy21; } - yy42: + yy50: yych = *++cursor; switch (yych) { case 'b': - goto yy72; + goto yy80; default: - goto yy17; + goto yy21; } - yy43: + yy51: yych = *++cursor; switch (yych) { case 'q': - goto yy73; + goto yy81; case 's': - goto yy75; + goto yy83; default: - goto yy17; + goto yy21; } - yy44: + yy52: yych = *++cursor; switch (yych) { case 'd': - goto yy76; + goto yy84; default: - goto yy17; + goto yy21; } - yy45: + yy53: yych = *++cursor; switch (yych) { case 'l': - goto yy78; + goto yy86; default: - goto yy17; + goto yy21; } - yy46: + yy54: yych = *++cursor; switch (yych) { case 'p': - goto yy80; + goto yy88; default: - goto yy17; + goto yy21; } - yy47: + yy55: yych = *++cursor; switch (yych) { case 'i': - goto yy82; + goto yy90; default: - goto yy17; + goto yy21; } - yy48: + yy56: yych = *++cursor; switch (yych) { case 's': - goto yy83; + goto yy91; default: - goto yy17; + goto yy21; } - yy49: + yy57: yych = *++cursor; switch (yych) { @@ -821,11 +894,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy50; + goto yy58; } - yy50: + yy58: #line 77 "lexer.re" { ts.push_token( @@ -834,8 +907,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 714 "lexer.cpp" - yy51: +#line 774 "lexer.cpp" + yy59: ++cursor; if (limit <= cursor) return true; @@ -852,7 +925,7 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy51; + goto yy59; case 'A': case 'B': case 'C': @@ -906,31 +979,31 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy50; + goto yy58; } - yy53: + yy61: yych = *++cursor; switch (yych) { case 'a': - goto yy84; + goto yy92; case 't': - goto yy85; + goto yy93; default: - goto yy17; + goto yy21; } - yy54: + yy62: yych = *++cursor; switch (yych) { case 'b': - goto yy87; + goto yy95; default: - goto yy17; + goto yy21; } - yy55: + yy63: ++cursor; if (limit <= cursor) return true; @@ -959,11 +1032,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'd': case 'e': case 'f': - goto yy55; + goto yy63; default: - goto yy57; + goto yy65; } - yy57: + yy65: #line 93 "lexer.re" { ts.push_token(Token(Token::XInteger, lineno, token_start, cursor)); @@ -971,10 +1044,10 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 836 "lexer.cpp" - yy58: +#line 896 "lexer.cpp" + yy66: ++cursor; - yy59: + yy67: #line 68 "lexer.re" { ts.push_token( @@ -983,8 +1056,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 849 "lexer.cpp" - yy60: +#line 909 "lexer.cpp" + yy68: ++cursor; if (limit <= cursor) return true; @@ -1001,11 +1074,11 @@ bool Lexer::tokenize(TokenStream& ts) case '7': case '8': case '9': - goto yy60; + goto yy68; default: - goto yy59; + goto yy67; } - yy62: + yy70: yych = *++cursor; switch (yych) { @@ -1072,11 +1145,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy63; + goto yy71; } - yy63: + yy71: #line 147 "lexer.re" { ts.push_token(Token(Token::Add, lineno)); @@ -1084,26 +1157,26 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 943 "lexer.cpp" - yy64: +#line 1003 "lexer.cpp" + yy72: yych = *++cursor; switch (yych) { case 'l': - goto yy89; + goto yy97; default: - goto yy17; + goto yy21; } - yy65: + yy73: yych = *++cursor; switch (yych) { case 's': - goto yy91; + goto yy99; default: - goto yy17; + goto yy21; } - yy66: + yy74: yych = *++cursor; switch (yych) { @@ -1170,11 +1243,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy67; + goto yy75; } - yy67: + yy75: #line 168 "lexer.re" { ts.push_token(Token(Token::Div, lineno)); @@ -1182,8 +1255,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1032 "lexer.cpp" - yy68: +#line 1092 "lexer.cpp" + yy76: yych = *++cursor; switch (yych) { @@ -1250,11 +1323,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy69; + goto yy77; } - yy69: + yy77: #line 126 "lexer.re" { ts.push_token(Token(Token::Dup, lineno)); @@ -1262,8 +1335,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1109 "lexer.cpp" - yy70: +#line 1169 "lexer.cpp" + yy78: yych = *++cursor; switch (yych) { @@ -1328,15 +1401,15 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; case 'f': - goto yy92; + goto yy100; case 't': - goto yy94; + goto yy102; default: - goto yy71; + goto yy79; } - yy71: + yy79: #line 196 "lexer.re" { ts.push_token(Token(Token::Jump, lineno)); @@ -1344,17 +1417,17 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1186 "lexer.cpp" - yy72: +#line 1246 "lexer.cpp" + yy80: yych = *++cursor; switch (yych) { case 'e': - goto yy96; + goto yy104; default: - goto yy17; + goto yy21; } - yy73: + yy81: yych = *++cursor; switch (yych) { @@ -1421,11 +1494,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy74; + goto yy82; } - yy74: + yy82: #line 223 "lexer.re" { ts.push_token(Token(Token::LessEq, lineno)); @@ -1433,17 +1506,17 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1269 "lexer.cpp" - yy75: +#line 1329 "lexer.cpp" + yy83: yych = *++cursor; switch (yych) { case 's': - goto yy97; + goto yy105; default: - goto yy17; + goto yy21; } - yy76: + yy84: yych = *++cursor; switch (yych) { @@ -1510,11 +1583,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy77; + goto yy85; } - yy77: + yy85: #line 175 "lexer.re" { ts.push_token(Token(Token::Mod, lineno)); @@ -1522,8 +1595,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1352 "lexer.cpp" - yy78: +#line 1412 "lexer.cpp" + yy86: yych = *++cursor; switch (yych) { @@ -1590,11 +1663,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy79; + goto yy87; } - yy79: + yy87: #line 161 "lexer.re" { ts.push_token(Token(Token::Mul, lineno)); @@ -1602,8 +1675,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1429 "lexer.cpp" - yy80: +#line 1489 "lexer.cpp" + yy88: yych = *++cursor; switch (yych) { @@ -1669,13 +1742,13 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; case 'r': - goto yy99; + goto yy107; default: - goto yy81; + goto yy89; } - yy81: + yy89: #line 113 "lexer.re" { ts.push_token(Token(Token::Pop, lineno)); @@ -1683,35 +1756,35 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1506 "lexer.cpp" - yy82: +#line 1566 "lexer.cpp" + yy90: yych = *++cursor; switch (yych) { case 'n': - goto yy101; + goto yy109; default: - goto yy17; + goto yy21; } - yy83: + yy91: yych = *++cursor; switch (yych) { case 'h': - goto yy102; + goto yy110; default: - goto yy17; + goto yy21; } - yy84: + yy92: yych = *++cursor; switch (yych) { case 'd': - goto yy104; + goto yy112; default: - goto yy17; + goto yy21; } - yy85: + yy93: yych = *++cursor; switch (yych) { @@ -1778,11 +1851,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy86; + goto yy94; } - yy86: + yy94: #line 216 "lexer.re" { ts.push_token(Token(Token::Ret, lineno)); @@ -1790,8 +1863,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1601 "lexer.cpp" - yy87: +#line 1661 "lexer.cpp" + yy95: yych = *++cursor; switch (yych) { @@ -1858,11 +1931,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy88; + goto yy96; } - yy88: + yy96: #line 154 "lexer.re" { ts.push_token(Token(Token::Sub, lineno)); @@ -1870,8 +1943,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1678 "lexer.cpp" - yy89: +#line 1738 "lexer.cpp" + yy97: yych = *++cursor; switch (yych) { @@ -1938,11 +2011,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy90; + goto yy98; } - yy90: + yy98: #line 209 "lexer.re" { ts.push_token(Token(Token::Call, lineno)); @@ -1950,17 +2023,17 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1755 "lexer.cpp" - yy91: +#line 1815 "lexer.cpp" + yy99: yych = *++cursor; switch (yych) { case 't': - goto yy106; + goto yy114; default: - goto yy17; + goto yy21; } - yy92: + yy100: yych = *++cursor; switch (yych) { @@ -2027,11 +2100,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy93; + goto yy101; } - yy93: + yy101: #line 189 "lexer.re" { ts.push_token(Token(Token::JumpF, lineno)); @@ -2039,8 +2112,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1838 "lexer.cpp" - yy94: +#line 1898 "lexer.cpp" + yy102: yych = *++cursor; switch (yych) { @@ -2107,11 +2180,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy95; + goto yy103; } - yy95: + yy103: #line 182 "lexer.re" { ts.push_token(Token(Token::JumpT, lineno)); @@ -2119,17 +2192,17 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1915 "lexer.cpp" - yy96: +#line 1975 "lexer.cpp" + yy104: yych = *++cursor; switch (yych) { case 'l': - goto yy108; + goto yy116; default: - goto yy17; + goto yy21; } - yy97: + yy105: yych = *++cursor; switch (yych) { @@ -2196,11 +2269,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy98; + goto yy106; } - yy98: + yy106: #line 229 "lexer.re" { ts.push_token(Token(Token::Less, lineno)); @@ -2208,8 +2281,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 1998 "lexer.cpp" - yy99: +#line 2058 "lexer.cpp" + yy107: yych = *++cursor; switch (yych) { @@ -2276,11 +2349,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy100; + goto yy108; } - yy100: + yy108: #line 119 "lexer.re" { ts.push_token(Token(Token::PopTo, lineno)); @@ -2288,17 +2361,17 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 2075 "lexer.cpp" - yy101: +#line 2135 "lexer.cpp" + yy109: yych = *++cursor; switch (yych) { case 't': - goto yy110; + goto yy118; default: - goto yy17; + goto yy21; } - yy102: + yy110: yych = *++cursor; switch (yych) { @@ -2364,13 +2437,13 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; case 'r': - goto yy112; + goto yy120; default: - goto yy103; + goto yy111; } - yy103: + yy111: #line 107 "lexer.re" { ts.push_token(Token(Token::Push, lineno)); @@ -2378,8 +2451,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 2158 "lexer.cpp" - yy104: +#line 2218 "lexer.cpp" + yy112: yych = *++cursor; switch (yych) { @@ -2446,11 +2519,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy105; + goto yy113; } - yy105: + yy113: #line 133 "lexer.re" { ts.push_token(Token(Token::Read, lineno)); @@ -2458,8 +2531,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 2235 "lexer.cpp" - yy106: +#line 2295 "lexer.cpp" + yy114: yych = *++cursor; switch (yych) { @@ -2526,11 +2599,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy107; + goto yy115; } - yy107: + yy115: #line 202 "lexer.re" { ts.push_token(Token(Token::Const, lineno)); @@ -2538,8 +2611,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 2312 "lexer.cpp" - yy108: +#line 2372 "lexer.cpp" + yy116: yych = *++cursor; switch (yych) { @@ -2606,11 +2679,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy109; + goto yy117; } - yy109: + yy117: #line 236 "lexer.re" { ts.push_token(Token(Token::Label, lineno)); @@ -2618,8 +2691,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 2389 "lexer.cpp" - yy110: +#line 2449 "lexer.cpp" + yy118: yych = *++cursor; switch (yych) { @@ -2686,11 +2759,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy111; + goto yy119; } - yy111: + yy119: #line 140 "lexer.re" { ts.push_token(Token(Token::Print, lineno)); @@ -2698,8 +2771,8 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 2466 "lexer.cpp" - yy112: +#line 2526 "lexer.cpp" + yy120: yych = *++cursor; switch (yych) { @@ -2766,11 +2839,11 @@ bool Lexer::tokenize(TokenStream& ts) case 'x': case 'y': case 'z': - goto yy16; + goto yy20; default: - goto yy113; + goto yy121; } - yy113: + yy121: #line 101 "lexer.re" { ts.push_token(Token(Token::PushFrom, lineno)); @@ -2778,9 +2851,9 @@ bool Lexer::tokenize(TokenStream& ts) continue; } -#line 2543 "lexer.cpp" +#line 2603 "lexer.cpp" } -#line 274 "lexer.re" +#line 284 "lexer.re" } return true; } diff --git a/spasm/src/asm/lexer.re b/spasm/src/asm/lexer.re index 4ab16d1..fabeaf7 100644 --- a/spasm/src/asm/lexer.re +++ b/spasm/src/asm/lexer.re @@ -253,8 +253,18 @@ IDENTIFIER { continue; } +DIGIT* ":" { + token_start = cursor; + + continue; + } +"#" .* "\n" { + ++lineno; + token_start = cursor; -"\n" { + continue; + } +"\n" { ++lineno; token_start = cursor; -- cgit v1.3.1-23-gd82d