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/bytecode.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'spasm/src/asm/bytecode.cpp') 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) -- cgit v1.3.1-23-gd82d From 9468ccb2024e850bacfcddcabc5402968c29b956 Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Thu, 22 Nov 2018 14:17:21 +0200 Subject: Fixed linux build --- spasm/src/asm/bytecode.cpp | 21 +++++++++++++++++---- spasm/src/asm/bytecode.hpp | 6 +++--- spasm/src/asm/token.cpp | 2 +- spasm/src/asm/token.hpp | 6 +++--- 4 files changed, 24 insertions(+), 11 deletions(-) (limited to 'spasm/src/asm/bytecode.cpp') diff --git a/spasm/src/asm/bytecode.cpp b/spasm/src/asm/bytecode.cpp index ad436ce..a4a1e6e 100644 --- a/spasm/src/asm/bytecode.cpp +++ b/spasm/src/asm/bytecode.cpp @@ -26,7 +26,20 @@ void Bytecode_File::push_opcode(Bytecode_Stream::Opcode_t opcode) push_byte(opcode); } -void Bytecode_File::push_integer(int number, int size) +union DoubleToBits +{ + double as_double; + int64_t as_bits; +}; + +int64_t to_bits(double d) +{ + DoubleToBits v; + v.as_double = d; + return v.as_bits; +}; + +void Bytecode_File::push_integer(int64_t number, int size) { for (int i = 0; i < size; ++i) push_byte((number >> (i << 3)) & 0xff); @@ -34,7 +47,7 @@ void Bytecode_File::push_integer(int number, int size) void Bytecode_File::push_double(double number) { - auto bits = *reinterpret_cast(&number); + auto bits = to_bits(number); for (size_t i = 0; i < sizeof(size_t); ++i) push_byte((bits >> (i << 3)) & 0xff); } @@ -49,7 +62,7 @@ void Bytecode_Memory::push_opcode(Bytecode_Stream::Opcode_t opcode) push_byte(opcode); } -void Bytecode_Memory::push_integer(int number, int size) +void Bytecode_Memory::push_integer(int64_t number, int size) { for (int i = 0; i < size; ++i) push_byte((number >> (i << 3)) & 0xff); @@ -57,7 +70,7 @@ void Bytecode_Memory::push_integer(int number, int size) void Bytecode_Memory::push_double(double number) { - auto bits = *reinterpret_cast(&number); + auto bits = to_bits(number); for (size_t i = 0; i < sizeof(size_t); ++i) push_byte((bits >> (i << 3)) & 0xff); } diff --git a/spasm/src/asm/bytecode.hpp b/spasm/src/asm/bytecode.hpp index 345b7a8..fb80122 100644 --- a/spasm/src/asm/bytecode.hpp +++ b/spasm/src/asm/bytecode.hpp @@ -18,7 +18,7 @@ class Bytecode_Stream virtual ~Bytecode_Stream(); virtual void push_opcode(Opcode_t) = 0; - virtual void push_integer(int, int size) = 0; + virtual void push_integer(int64_t, 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; @@ -31,7 +31,7 @@ class Bytecode_File : public Bytecode_Stream Bytecode_File(const std::string&); virtual void push_opcode(Opcode_t); - virtual void push_integer(int, int size); + virtual void push_integer(int64_t, int size) override; virtual void push_double(double) override; private: @@ -47,7 +47,7 @@ class Bytecode_Memory : public Bytecode_Stream { public: virtual void push_opcode(Opcode_t); - virtual void push_integer(int, int) override; + virtual void push_integer(int64_t, int) override; virtual void push_double(double) override; virtual void push_location(size_t); virtual void set_location(size_t, size_t); diff --git a/spasm/src/asm/token.cpp b/spasm/src/asm/token.cpp index 3f8980d..fa612e3 100644 --- a/spasm/src/asm/token.cpp +++ b/spasm/src/asm/token.cpp @@ -57,7 +57,7 @@ Token::Token_type Token::type() const return _type; } -int Token::value_int() const +int64_t Token::value_int() const { return _value_int; } diff --git a/spasm/src/asm/token.hpp b/spasm/src/asm/token.hpp index 6c64e89..8f18768 100644 --- a/spasm/src/asm/token.hpp +++ b/spasm/src/asm/token.hpp @@ -58,8 +58,8 @@ class Token size_t lineno() const; - int value_int() const; - void set_int(int v) { _value_int = v; } + int64_t value_int() const; + void set_int(int64_t v) { _value_int = v; } double value_double() const { return _value_double; } @@ -70,7 +70,7 @@ class Token size_t _lineno; - int _value_int; + int64_t _value_int; double _value_double; std::string _value_str; -- 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/bytecode.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