Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commita7cd9d4f8d83024402bacb39786e5e1a018a0a04 (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-14 23:45:56 +0200
Committer
 Martin Dobrev <martindobrev0@gmail.com>
2018-11-14 23:45:56 +0200
Files1f99c6f8d00d9b94b69c8f3525643344a32d7414
IPL-a7cd9d4f8d83024402bacb39786e5e1a018a0a04.tar
IPL-a7cd9d4f8d83024402bacb39786e5e1a018a0a04.tar.gz
IPL-a7cd9d4f8d83024402bacb39786e5e1a018a0a04.zip
Parent9a7a8a31e75d1b85274ef46ca29714270062809e (diff)
Spasm can assemble programs on with the new instruction set (#47)
* Use checkout as-is, commit as-is * Spasm can assemble programs based on the new instruction set
11 files changed, 795 insertions, 362 deletions
-rw-r--r--.gitattributes2
-rw-r--r--spasm/src/asm/assembler.cpp68
-rw-r--r--spasm/src/asm/bytecode.cpp44
-rw-r--r--spasm/src/asm/bytecode.hpp25
-rw-r--r--spasm/src/asm/lexer.cpp721
-rw-r--r--spasm/src/asm/lexer.re189
-rw-r--r--spasm/src/asm/main.cpp7
-rw-r--r--spasm/src/asm/symbol.cpp3
-rw-r--r--spasm/src/asm/token.cpp4
-rw-r--r--spasm/src/asm/token.hpp90
-rw-r--r--spasm/src/asm/tokenizer.cpp4
diff --git a/.gitattributes b/.gitattributes
index 1ff0c42..dae9abc 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,7 +1,7 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
-* text=auto
+# * text=auto
###############################################################################
# Set default behavior for command prompt diff.
diff --git a/spasm/src/asm/assembler.cpp b/spasm/src/asm/assembler.cpp
index 25ed377..fbe6675 100644
--- a/spasm/src/asm/assembler.cpp
+++ b/spasm/src/asm/assembler.cpp
@@ -18,24 +18,64 @@ void Assembler::assemble()
{
Lexer::Token token = _tokenizer->next_token();
- while (token.type() != Lexer::Token::endinput)
+ while (token.type() != Lexer::Token::EndInput)
{
- switch (token.type())
+ const auto type = token.type();
+ if (type >= Lexer::Token::_NotOpCodeBegin)
{
- case Lexer::Token::ident:
- assemble_identifier(token);
- break;
- case Lexer::Token::label:
+ switch (token.type())
+ {
+ case Lexer::Token::Ident:
+ assemble_identifier(token);
+ break;
+ case Lexer::Token::Label:
+ token = _tokenizer->next_token();
+ assert(token.type() == Lexer::Token::Ident);
+ _symbols.define(token.value_str(), _bytecode->size());
+ break;
+ default:
+ break;
+ }
+ }
+ else
+ {
+ _bytecode->push_opcode((Bytecode_Stream::Opcode_t)token.type());
+ if (type >= Lexer::Token::_OneArgBegin)
+ {
+ if (type == Lexer::Token::Call || type == Lexer::Token::Jump)
+ {
+ token = _tokenizer->next_token();
+ assert(token.type() == Lexer::Token::Ident);
+ assemble_identifier(token);
+ }
+ else
+ {
+ token = _tokenizer->next_token();
+ assert(token.type() == Lexer::Token::Integer);
+ _bytecode->push_integer(token.value_int());
+ }
+ }
+ if (type >= Lexer::Token::_TwoArgBegin)
+ {
+ if (type == Lexer::Token::JumpF || type == Lexer::Token::JumpT)
+ {
+ token = _tokenizer->next_token();
+ assert(token.type() == Lexer::Token::Ident);
+ assemble_identifier(token);
+ }
+ else
+ {
+ token = _tokenizer->next_token();
+ assert(token.type() == Lexer::Token::Integer);
+ _bytecode->push_integer(token.value_int());
+ }
+ }
+ if (type >= Lexer::Token::_ThreeArgBegin)
+ {
token = _tokenizer->next_token();
- assert(token.type() == Lexer::Token::ident);
- _symbols.define(token.value_str(), _bytecode->size());
- break;
- case Lexer::Token::integer:
- case Lexer::Token::xinteger:
+ assert(token.type() == Lexer::Token::Integer);
_bytecode->push_integer(token.value_int());
- break;
- default:
- _bytecode->push_opcode((Bytecode_Stream::Opcode_t)token.type());
+ }
}
token = _tokenizer->next_token();
diff --git a/spasm/src/asm/bytecode.cpp b/spasm/src/asm/bytecode.cpp
index 27fed2b..39f1de6 100644
--- a/spasm/src/asm/bytecode.cpp
+++ b/spasm/src/asm/bytecode.cpp
@@ -28,8 +28,15 @@ void Bytecode_File::push_opcode(Bytecode_Stream::Opcode_t opcode)
void Bytecode_File::push_integer(int number)
{
- for (size_t i = 0; i < sizeof(int); ++i)
- push_byte((number >> (i << 3)) & 0xff);
+ if (number <= 0xff)
+ {
+ push_byte((byte)number);
+ }
+ else
+ {
+ for (size_t i = 0; i < sizeof(int); ++i)
+ push_byte((number >> (i << 3)) & 0xff);
+ }
}
void Bytecode_Memory::push_byte(Bytecode_Stream::byte byte)
@@ -44,20 +51,41 @@ void Bytecode_Memory::push_opcode(Bytecode_Stream::Opcode_t opcode)
void Bytecode_Memory::push_integer(int number)
{
- for (size_t i = 0; i < sizeof(int); ++i)
- push_byte((number >> (i << 3)) & 0xff);
+ if (number <= 0xff)
+ {
+ push_byte((byte)number);
+ }
+ else
+ {
+ for (size_t i = 0; i < sizeof(int); ++i)
+ push_byte((number >> (i << 3)) & 0xff);
+ }
}
void Bytecode_Memory::set_location(size_t index, size_t location)
{
- for (size_t i = 0; i < sizeof(size_t); ++i)
- _bytecode.at(index + i) = ((location >> (i << 3)) & 0xff);
+ if (location <= 0xff)
+ {
+ _bytecode[index] = (byte)location;
+ }
+ else
+ {
+ for (size_t i = 0; i < sizeof(size_t); ++i)
+ _bytecode.at(index + i) = ((location >> (i << 3)) & 0xff);
+ }
}
void Bytecode_Memory::push_location(size_t location)
{
- for (size_t i = 0; i < sizeof(size_t); ++i)
- _bytecode.push_back((location >> (i << 3)) & 0xff);
+ if (location <= 0xff)
+ {
+ push_byte((byte)location);
+ }
+ else
+ {
+ for (size_t i = 0; i < sizeof(size_t); ++i)
+ _bytecode.push_back((location >> (i << 3)) & 0xff);
+ }
}
const Bytecode_Memory::Bytecode& Bytecode_Memory::bytecode() const
diff --git a/spasm/src/asm/bytecode.hpp b/spasm/src/asm/bytecode.hpp
index c08da46..d249db8 100644
--- a/spasm/src/asm/bytecode.hpp
+++ b/spasm/src/asm/bytecode.hpp
@@ -14,30 +14,7 @@ class Bytecode_Stream
{
public:
typedef unsigned char byte;
- enum Opcode_t : byte
- {
- halt = 0,
- push,
- pop,
- dup,
- print,
- read,
- plus,
- minus,
- multiply,
- divide,
- modulus,
- gotrue,
- gofalse,
- go,
- call,
- ret,
- load,
- store,
- less,
- lesseq
- };
-
+ typedef byte Opcode_t;
virtual ~Bytecode_Stream();
virtual void push_opcode(Opcode_t) = 0;
diff --git a/spasm/src/asm/lexer.cpp b/spasm/src/asm/lexer.cpp
index 86384b3..a012650 100644
--- a/spasm/src/asm/lexer.cpp
+++ b/spasm/src/asm/lexer.cpp
@@ -1,5 +1,5 @@
-/* Generated by re2c 1.1.1 on Mon Nov 12 23:00:12 2018 */
-#line 1 "spasm/src/asm/lexer.re"
+/* Generated by re2c 1.1.1 on Wed Nov 14 19:46:01 2018 */
+#line 1 "lexer.re"
#include <iostream>
#include "lexer.hpp"
@@ -27,11 +27,11 @@ Lexer::~Lexer()
bool Lexer::tokenize(TokenStream& ts)
{
-#line 43 "spasm/src/asm/lexer.re"
+#line 43 "lexer.re"
while (1)
{
-#line 41 "spasm/src/asm/lexer.cpp"
+#line 41 "lexer.cpp"
{
char yych;
if ((limit - cursor) < 6)
@@ -128,21 +128,21 @@ bool Lexer::tokenize(TokenStream& ts)
}
yy2:
++cursor;
-#line 220 "spasm/src/asm/lexer.re"
+#line 237 "lexer.re"
{
- ts.push_token(Token(Token::endinput, lineno));
+ ts.push_token(Token(Token::EndInput, lineno));
break;
}
-#line 125 "spasm/src/asm/lexer.cpp"
+#line 125 "lexer.cpp"
yy4:
++cursor;
yy5:
-#line 226 "spasm/src/asm/lexer.re"
+#line 243 "lexer.re"
{
return false;
}
-#line 133 "spasm/src/asm/lexer.cpp"
+#line 133 "lexer.cpp"
yy6:
++cursor;
if (limit <= cursor)
@@ -157,23 +157,24 @@ bool Lexer::tokenize(TokenStream& ts)
goto yy8;
}
yy8:
-#line 207 "spasm/src/asm/lexer.re"
+#line 224 "lexer.re"
{
token_start = cursor;
continue;
}
-#line 150 "spasm/src/asm/lexer.cpp"
+#line 150 "lexer.cpp"
yy9:
++cursor;
-#line 213 "spasm/src/asm/lexer.re"
+#line 230 "lexer.re"
{
++lineno;
+
token_start = cursor;
continue;
}
-#line 160 "spasm/src/asm/lexer.cpp"
+#line 160 "lexer.cpp"
yy11:
yych = *++cursor;
switch (yych)
@@ -194,14 +195,17 @@ bool Lexer::tokenize(TokenStream& ts)
goto yy13;
}
yy13:
-#line 58 "spasm/src/asm/lexer.re"
+#line 58 "lexer.re"
{
- ts.push_token(Token(Token::integer, lineno, token_start, cursor));
+ ts.push_token(Token(Token::Integer, lineno,
+
+ token_start, cursor));
+
token_start = cursor;
continue;
}
-#line 183 "spasm/src/asm/lexer.cpp"
+#line 183 "lexer.cpp"
yy14:
++cursor;
if (limit <= cursor)
@@ -299,20 +303,25 @@ bool Lexer::tokenize(TokenStream& ts)
goto yy18;
}
yy18:
-#line 199 "spasm/src/asm/lexer.re"
+#line 216 "lexer.re"
{
- ts.push_token(Token(Token::ident, lineno, token_start, cursor));
+ ts.push_token(Token(Token::Ident, lineno, token_start,
+
+ cursor));
+
token_start = cursor;
continue;
}
-#line 281 "spasm/src/asm/lexer.cpp"
+#line 281 "lexer.cpp"
yy19:
yych = *++cursor;
switch (yych)
{
case 'd':
goto yy31;
+ case 'l':
+ goto yy32;
default:
goto yy17;
}
@@ -321,7 +330,9 @@ bool Lexer::tokenize(TokenStream& ts)
switch (yych)
{
case 'a':
- goto yy32;
+ goto yy33;
+ case 'o':
+ goto yy34;
default:
goto yy17;
}
@@ -330,9 +341,9 @@ bool Lexer::tokenize(TokenStream& ts)
switch (yych)
{
case 'i':
- goto yy33;
+ goto yy35;
case 'u':
- goto yy34;
+ goto yy36;
default:
goto yy17;
}
@@ -341,7 +352,7 @@ bool Lexer::tokenize(TokenStream& ts)
switch (yych)
{
case 'm':
- goto yy35;
+ goto yy37;
default:
goto yy17;
}
@@ -350,9 +361,9 @@ bool Lexer::tokenize(TokenStream& ts)
switch (yych)
{
case 'a':
- goto yy36;
+ goto yy38;
case 'e':
- goto yy37;
+ goto yy39;
default:
goto yy17;
}
@@ -361,9 +372,9 @@ bool Lexer::tokenize(TokenStream& ts)
switch (yych)
{
case 'o':
- goto yy38;
+ goto yy40;
case 'u':
- goto yy39;
+ goto yy41;
default:
goto yy17;
}
@@ -372,11 +383,11 @@ bool Lexer::tokenize(TokenStream& ts)
switch (yych)
{
case 'o':
- goto yy40;
+ goto yy42;
case 'r':
- goto yy41;
+ goto yy43;
case 'u':
- goto yy42;
+ goto yy44;
default:
goto yy17;
}
@@ -385,7 +396,7 @@ bool Lexer::tokenize(TokenStream& ts)
switch (yych)
{
case 'e':
- goto yy43;
+ goto yy45;
default:
goto yy17;
}
@@ -394,7 +405,7 @@ bool Lexer::tokenize(TokenStream& ts)
switch (yych)
{
case 'u':
- goto yy44;
+ goto yy46;
default:
goto yy17;
}
@@ -427,7 +438,7 @@ bool Lexer::tokenize(TokenStream& ts)
case 'd':
case 'e':
case 'f':
- goto yy45;
+ goto yy47;
default:
goto yy30;
}
@@ -439,7 +450,7 @@ bool Lexer::tokenize(TokenStream& ts)
switch (yych)
{
case 'd':
- goto yy48;
+ goto yy50;
default:
goto yy17;
}
@@ -448,7 +459,7 @@ bool Lexer::tokenize(TokenStream& ts)
switch (yych)
{
case 'l':
- goto yy50;
+ goto yy52;
default:
goto yy17;
}
@@ -456,8 +467,8 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 'v':
- goto yy51;
+ case 'l':
+ goto yy53;
default:
goto yy17;
}
@@ -465,8 +476,8 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 'p':
- goto yy53;
+ case 'n':
+ goto yy54;
default:
goto yy17;
}
@@ -474,7 +485,7 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 'p':
+ case 'v':
goto yy55;
default:
goto yy17;
@@ -483,7 +494,7 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 'b':
+ case 'p':
goto yy57;
default:
goto yy17;
@@ -492,10 +503,8 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 'q':
- goto yy58;
- case 's':
- goto yy60;
+ case 'p':
+ goto yy59;
default:
goto yy17;
}
@@ -503,7 +512,7 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 'd':
+ case 'b':
goto yy61;
default:
goto yy17;
@@ -512,8 +521,10 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 'l':
- goto yy63;
+ case 'q':
+ goto yy62;
+ case 's':
+ goto yy64;
default:
goto yy17;
}
@@ -521,7 +532,7 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 'p':
+ case 'd':
goto yy65;
default:
goto yy17;
@@ -530,7 +541,7 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 'i':
+ case 'l':
goto yy67;
default:
goto yy17;
@@ -539,8 +550,8 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 's':
- goto yy68;
+ case 'p':
+ goto yy69;
default:
goto yy17;
}
@@ -548,10 +559,8 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 'a':
- goto yy69;
- case 't':
- goto yy70;
+ case 'i':
+ goto yy71;
default:
goto yy17;
}
@@ -559,12 +568,32 @@ bool Lexer::tokenize(TokenStream& ts)
yych = *++cursor;
switch (yych)
{
- case 'b':
+ case 's':
goto yy72;
default:
goto yy17;
}
yy45:
+ yych = *++cursor;
+ switch (yych)
+ {
+ case 'a':
+ goto yy73;
+ case 't':
+ goto yy74;
+ default:
+ goto yy17;
+ }
+ yy46:
+ yych = *++cursor;
+ switch (yych)
+ {
+ case 'b':
+ goto yy76;
+ default:
+ goto yy17;
+ }
+ yy47:
++cursor;
if (limit <= cursor)
return true;
@@ -593,20 +622,23 @@ bool Lexer::tokenize(TokenStream& ts)
case 'd':
case 'e':
case 'f':
- goto yy45;
- default:
goto yy47;
+ default:
+ goto yy49;
}
- yy47:
-#line 66 "spasm/src/asm/lexer.re"
+ yy49:
+#line 66 "lexer.re"
{
- ts.push_token(Token(Token::xinteger, lineno, token_start, cursor));
+ ts.push_token(Token(Token::XInteger, lineno,
+
+ token_start, cursor));
+
token_start = cursor;
continue;
}
-#line 498 "spasm/src/asm/lexer.cpp"
- yy48:
+#line 512 "lexer.cpp"
+ yy50:
yych = *++cursor;
switch (yych)
{
@@ -675,27 +707,46 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy49;
+ goto yy51;
}
- yy49:
-#line 109 "spasm/src/asm/lexer.re"
+ yy51:
+#line 120 "lexer.re"
{
- ts.push_token(Token(Token::plus, lineno));
+ ts.push_token(Token(Token::Add, lineno));
+
token_start = cursor;
continue;
}
-#line 575 "spasm/src/asm/lexer.cpp"
- yy50:
+#line 589 "lexer.cpp"
+ yy52:
+ yych = *++cursor;
+ switch (yych)
+ {
+ case 'o':
+ goto yy78;
+ default:
+ goto yy17;
+ }
+ yy53:
yych = *++cursor;
switch (yych)
{
case 'l':
- goto yy74;
+ goto yy79;
default:
goto yy17;
}
- yy51:
+ yy54:
+ yych = *++cursor;
+ switch (yych)
+ {
+ case 's':
+ goto yy81;
+ default:
+ goto yy17;
+ }
+ yy55:
yych = *++cursor;
switch (yych)
{
@@ -764,18 +815,19 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy52;
+ goto yy56;
}
- yy52:
-#line 130 "spasm/src/asm/lexer.re"
+ yy56:
+#line 141 "lexer.re"
{
- ts.push_token(Token(Token::divide, lineno));
+ ts.push_token(Token(Token::Div, lineno));
+
token_start = cursor;
continue;
}
-#line 658 "spasm/src/asm/lexer.cpp"
- yy53:
+#line 684 "lexer.cpp"
+ yy57:
yych = *++cursor;
switch (yych)
{
@@ -844,18 +896,19 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy54;
+ goto yy58;
}
- yy54:
-#line 88 "spasm/src/asm/lexer.re"
+ yy58:
+#line 99 "lexer.re"
{
- ts.push_token(Token(Token::dup, lineno));
+ ts.push_token(Token(Token::Dup, lineno));
+
token_start = cursor;
continue;
}
-#line 735 "spasm/src/asm/lexer.cpp"
- yy55:
+#line 761 "lexer.cpp"
+ yy59:
yych = *++cursor;
switch (yych)
{
@@ -922,31 +975,32 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
case 'f':
- goto yy76;
+ goto yy82;
case 't':
- goto yy78;
+ goto yy84;
default:
- goto yy56;
+ goto yy60;
}
- yy56:
-#line 158 "spasm/src/asm/lexer.re"
+ yy60:
+#line 169 "lexer.re"
{
- ts.push_token(Token(Token::jmp, lineno));
+ ts.push_token(Token(Token::Jump, lineno));
+
token_start = cursor;
continue;
}
-#line 812 "spasm/src/asm/lexer.cpp"
- yy57:
+#line 838 "lexer.cpp"
+ yy61:
yych = *++cursor;
switch (yych)
{
case 'e':
- goto yy80;
+ goto yy86;
default:
goto yy17;
}
- yy58:
+ yy62:
yych = *++cursor;
switch (yych)
{
@@ -1015,27 +1069,28 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy59;
+ goto yy63;
}
- yy59:
-#line 179 "spasm/src/asm/lexer.re"
+ yy63:
+#line 196 "lexer.re"
{
- ts.push_token(Token(Token::lesseq, lineno));
+ ts.push_token(Token(Token::LessEq, lineno));
+
token_start = cursor;
continue;
}
-#line 895 "spasm/src/asm/lexer.cpp"
- yy60:
+#line 921 "lexer.cpp"
+ yy64:
yych = *++cursor;
switch (yych)
{
case 's':
- goto yy81;
+ goto yy87;
default:
goto yy17;
}
- yy61:
+ yy65:
yych = *++cursor;
switch (yych)
{
@@ -1104,18 +1159,19 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy62;
+ goto yy66;
}
- yy62:
-#line 137 "spasm/src/asm/lexer.re"
+ yy66:
+#line 148 "lexer.re"
{
- ts.push_token(Token(Token::modulus, lineno));
+ ts.push_token(Token(Token::Mod, lineno));
+
token_start = cursor;
continue;
}
-#line 978 "spasm/src/asm/lexer.cpp"
- yy63:
+#line 1004 "lexer.cpp"
+ yy67:
yych = *++cursor;
switch (yych)
{
@@ -1184,18 +1240,19 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy64;
+ goto yy68;
}
- yy64:
-#line 123 "spasm/src/asm/lexer.re"
+ yy68:
+#line 134 "lexer.re"
{
- ts.push_token(Token(Token::multiply, lineno));
+ ts.push_token(Token(Token::Mul, lineno));
+
token_start = cursor;
continue;
}
-#line 1055 "spasm/src/asm/lexer.cpp"
- yy65:
+#line 1081 "lexer.cpp"
+ yy69:
yych = *++cursor;
switch (yych)
{
@@ -1255,7 +1312,6 @@ bool Lexer::tokenize(TokenStream& ts)
case 'q':
case 'r':
case 's':
- case 't':
case 'u':
case 'v':
case 'w':
@@ -1263,46 +1319,49 @@ bool Lexer::tokenize(TokenStream& ts)
case 'y':
case 'z':
goto yy16;
+ case 't':
+ goto yy89;
default:
- goto yy66;
+ goto yy70;
}
- yy66:
-#line 81 "spasm/src/asm/lexer.re"
+ yy70:
+#line 86 "lexer.re"
{
- ts.push_token(Token(Token::pop, lineno));
+ ts.push_token(Token(Token::Pop, lineno));
+
token_start = cursor;
continue;
}
-#line 1132 "spasm/src/asm/lexer.cpp"
- yy67:
+#line 1158 "lexer.cpp"
+ yy71:
yych = *++cursor;
switch (yych)
{
case 'n':
- goto yy83;
+ goto yy90;
default:
goto yy17;
}
- yy68:
+ yy72:
yych = *++cursor;
switch (yych)
{
case 'h':
- goto yy84;
+ goto yy91;
default:
goto yy17;
}
- yy69:
+ yy73:
yych = *++cursor;
switch (yych)
{
case 'd':
- goto yy86;
+ goto yy93;
default:
goto yy17;
}
- yy70:
+ yy74:
yych = *++cursor;
switch (yych)
{
@@ -1371,18 +1430,19 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy71;
+ goto yy75;
}
- yy71:
-#line 172 "spasm/src/asm/lexer.re"
+ yy75:
+#line 189 "lexer.re"
{
- ts.push_token(Token(Token::ret, lineno));
+ ts.push_token(Token(Token::Ret, lineno));
+
token_start = cursor;
continue;
}
-#line 1227 "spasm/src/asm/lexer.cpp"
- yy72:
+#line 1253 "lexer.cpp"
+ yy76:
yych = *++cursor;
switch (yych)
{
@@ -1451,18 +1511,28 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy73;
+ goto yy77;
}
- yy73:
-#line 116 "spasm/src/asm/lexer.re"
+ yy77:
+#line 127 "lexer.re"
{
- ts.push_token(Token(Token::minus, lineno));
+ ts.push_token(Token(Token::Sub, lineno));
+
token_start = cursor;
continue;
}
-#line 1304 "spasm/src/asm/lexer.cpp"
- yy74:
+#line 1330 "lexer.cpp"
+ yy78:
+ yych = *++cursor;
+ switch (yych)
+ {
+ case 'c':
+ goto yy95;
+ default:
+ goto yy17;
+ }
+ yy79:
yych = *++cursor;
switch (yych)
{
@@ -1531,18 +1601,28 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy75;
+ goto yy80;
}
- yy75:
-#line 165 "spasm/src/asm/lexer.re"
+ yy80:
+#line 182 "lexer.re"
{
- ts.push_token(Token(Token::call, lineno));
+ ts.push_token(Token(Token::Call, lineno));
+
token_start = cursor;
continue;
}
-#line 1381 "spasm/src/asm/lexer.cpp"
- yy76:
+#line 1413 "lexer.cpp"
+ yy81:
+ yych = *++cursor;
+ switch (yych)
+ {
+ case 't':
+ goto yy97;
+ default:
+ goto yy17;
+ }
+ yy82:
yych = *++cursor;
switch (yych)
{
@@ -1611,18 +1691,19 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy77;
+ goto yy83;
}
- yy77:
-#line 151 "spasm/src/asm/lexer.re"
+ yy83:
+#line 162 "lexer.re"
{
- ts.push_token(Token(Token::jmpf, lineno));
+ ts.push_token(Token(Token::JumpF, lineno));
+
token_start = cursor;
continue;
}
-#line 1458 "spasm/src/asm/lexer.cpp"
- yy78:
+#line 1496 "lexer.cpp"
+ yy84:
yych = *++cursor;
switch (yych)
{
@@ -1691,27 +1772,28 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy79;
+ goto yy85;
}
- yy79:
-#line 144 "spasm/src/asm/lexer.re"
+ yy85:
+#line 155 "lexer.re"
{
- ts.push_token(Token(Token::jmpt, lineno));
+ ts.push_token(Token(Token::JumpT, lineno));
+
token_start = cursor;
continue;
}
-#line 1535 "spasm/src/asm/lexer.cpp"
- yy80:
+#line 1573 "lexer.cpp"
+ yy86:
yych = *++cursor;
switch (yych)
{
case 'l':
- goto yy88;
+ goto yy99;
default:
goto yy17;
}
- yy81:
+ yy87:
yych = *++cursor;
switch (yych)
{
@@ -1780,27 +1862,37 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy82;
+ goto yy88;
}
- yy82:
-#line 185 "spasm/src/asm/lexer.re"
+ yy88:
+#line 202 "lexer.re"
{
- ts.push_token(Token(Token::less, lineno));
+ ts.push_token(Token(Token::Less, lineno));
+
token_start = cursor;
continue;
}
-#line 1618 "spasm/src/asm/lexer.cpp"
- yy83:
+#line 1656 "lexer.cpp"
+ yy89:
+ yych = *++cursor;
+ switch (yych)
+ {
+ case 'o':
+ goto yy101;
+ default:
+ goto yy17;
+ }
+ yy90:
yych = *++cursor;
switch (yych)
{
case 't':
- goto yy90;
+ goto yy103;
default:
goto yy17;
}
- yy84:
+ yy91:
yych = *++cursor;
switch (yych)
{
@@ -1869,18 +1961,19 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy85;
+ goto yy92;
}
- yy85:
-#line 74 "spasm/src/asm/lexer.re"
+ yy92:
+#line 74 "lexer.re"
{
- ts.push_token(Token(Token::push, lineno));
+ ts.push_token(Token(Token::Push, lineno));
+
token_start = cursor;
continue;
}
-#line 1701 "spasm/src/asm/lexer.cpp"
- yy86:
+#line 1745 "lexer.cpp"
+ yy93:
yych = *++cursor;
switch (yych)
{
@@ -1949,18 +2042,19 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy87;
+ goto yy94;
}
- yy87:
-#line 95 "spasm/src/asm/lexer.re"
+ yy94:
+#line 106 "lexer.re"
{
- ts.push_token(Token(Token::read, lineno));
+ ts.push_token(Token(Token::Read, lineno));
+
token_start = cursor;
continue;
}
-#line 1778 "spasm/src/asm/lexer.cpp"
- yy88:
+#line 1822 "lexer.cpp"
+ yy95:
yych = *++cursor;
switch (yych)
{
@@ -2029,18 +2123,19 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy89;
+ goto yy96;
}
- yy89:
-#line 192 "spasm/src/asm/lexer.re"
+ yy96:
+#line 80 "lexer.re"
{
- ts.push_token(Token(Token::label, lineno));
+ ts.push_token(Token(Token::Alloc, lineno));
+
token_start = cursor;
continue;
}
-#line 1855 "spasm/src/asm/lexer.cpp"
- yy90:
+#line 1899 "lexer.cpp"
+ yy97:
yych = *++cursor;
switch (yych)
{
@@ -2109,19 +2204,263 @@ bool Lexer::tokenize(TokenStream& ts)
case 'z':
goto yy16;
default:
- goto yy91;
+ goto yy98;
}
- yy91:
-#line 102 "spasm/src/asm/lexer.re"
+ yy98:
+#line 175 "lexer.re"
+ {
+ ts.push_token(Token(Token::Const, lineno));
+
+ token_start = cursor;
+
+ continue;
+ }
+#line 1976 "lexer.cpp"
+ yy99:
+ yych = *++cursor;
+ switch (yych)
+ {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'D':
+ case 'E':
+ case 'F':
+ case 'G':
+ case 'H':
+ case 'I':
+ case 'J':
+ case 'K':
+ case 'L':
+ case 'M':
+ case 'N':
+ case 'O':
+ case 'P':
+ case 'Q':
+ case 'R':
+ case 'S':
+ case 'T':
+ case 'U':
+ case 'V':
+ case 'W':
+ case 'X':
+ case 'Y':
+ case 'Z':
+ case '_':
+ case 'a':
+ case 'b':
+ case 'c':
+ case 'd':
+ case 'e':
+ case 'f':
+ case 'g':
+ case 'h':
+ case 'i':
+ case 'j':
+ case 'k':
+ case 'l':
+ case 'm':
+ case 'n':
+ case 'o':
+ case 'p':
+ case 'q':
+ case 'r':
+ case 's':
+ case 't':
+ case 'u':
+ case 'v':
+ case 'w':
+ case 'x':
+ case 'y':
+ case 'z':
+ goto yy16;
+ default:
+ goto yy100;
+ }
+ yy100:
+#line 209 "lexer.re"
+ {
+ ts.push_token(Token(Token::Label, lineno));
+
+ token_start = cursor;
+
+ continue;
+ }
+#line 2053 "lexer.cpp"
+ yy101:
+ yych = *++cursor;
+ switch (yych)
+ {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'D':
+ case 'E':
+ case 'F':
+ case 'G':
+ case 'H':
+ case 'I':
+ case 'J':
+ case 'K':
+ case 'L':
+ case 'M':
+ case 'N':
+ case 'O':
+ case 'P':
+ case 'Q':
+ case 'R':
+ case 'S':
+ case 'T':
+ case 'U':
+ case 'V':
+ case 'W':
+ case 'X':
+ case 'Y':
+ case 'Z':
+ case '_':
+ case 'a':
+ case 'b':
+ case 'c':
+ case 'd':
+ case 'e':
+ case 'f':
+ case 'g':
+ case 'h':
+ case 'i':
+ case 'j':
+ case 'k':
+ case 'l':
+ case 'm':
+ case 'n':
+ case 'o':
+ case 'p':
+ case 'q':
+ case 'r':
+ case 's':
+ case 't':
+ case 'u':
+ case 'v':
+ case 'w':
+ case 'x':
+ case 'y':
+ case 'z':
+ goto yy16;
+ default:
+ goto yy102;
+ }
+ yy102:
+#line 92 "lexer.re"
{
- ts.push_token(Token(Token::print, lineno));
+ ts.push_token(Token(Token::PopTo, lineno));
+
+ token_start = cursor;
+
+ continue;
+ }
+#line 2130 "lexer.cpp"
+ yy103:
+ yych = *++cursor;
+ switch (yych)
+ {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'D':
+ case 'E':
+ case 'F':
+ case 'G':
+ case 'H':
+ case 'I':
+ case 'J':
+ case 'K':
+ case 'L':
+ case 'M':
+ case 'N':
+ case 'O':
+ case 'P':
+ case 'Q':
+ case 'R':
+ case 'S':
+ case 'T':
+ case 'U':
+ case 'V':
+ case 'W':
+ case 'X':
+ case 'Y':
+ case 'Z':
+ case '_':
+ case 'a':
+ case 'b':
+ case 'c':
+ case 'd':
+ case 'e':
+ case 'f':
+ case 'g':
+ case 'h':
+ case 'i':
+ case 'j':
+ case 'k':
+ case 'l':
+ case 'm':
+ case 'n':
+ case 'o':
+ case 'p':
+ case 'q':
+ case 'r':
+ case 's':
+ case 't':
+ case 'u':
+ case 'v':
+ case 'w':
+ case 'x':
+ case 'y':
+ case 'z':
+ goto yy16;
+ default:
+ goto yy104;
+ }
+ yy104:
+#line 113 "lexer.re"
+ {
+ ts.push_token(Token(Token::Print, lineno));
+
token_start = cursor;
continue;
}
-#line 1932 "spasm/src/asm/lexer.cpp"
+#line 2207 "lexer.cpp"
}
-#line 230 "spasm/src/asm/lexer.re"
+#line 247 "lexer.re"
}
return true;
}
diff --git a/spasm/src/asm/lexer.re b/spasm/src/asm/lexer.re
index c54d54f..298e340 100644
--- a/spasm/src/asm/lexer.re
+++ b/spasm/src/asm/lexer.re
@@ -6,29 +6,29 @@
namespace SpasmImpl
{
- namespace ASM
- {
- //! Namespace for all lexical analisys classes
- namespace Lexer
- {
+namespace ASM
+{
+//! Namespace for all lexical analisys classes
+namespace Lexer
+{
- Lexer::Lexer (std::istream & _file, size_t _buffer_size)
- : file (&_file), buffer_size (_buffer_size), state (unsigned(-1)),
- lineno (0)
- {
- buffer = new char[buffer_size];
- cursor = limit = marker = token_start = NULL;
- }
+Lexer::Lexer (std::istream & _file, size_t _buffer_size)
+ : file (&_file), buffer_size (_buffer_size), state (unsigned(-1)),
+ lineno (0)
+{
+ buffer = new char[buffer_size];
+ cursor = limit = marker = token_start = NULL;
+}
- Lexer::~Lexer ()
- {
- delete [] buffer;
- }
+Lexer::~Lexer ()
+{
+ delete [] buffer;
+}
- bool Lexer::tokenize (TokenStream &ts)
- {
+bool Lexer::tokenize (TokenStream &ts)
+{
/*!re2c
-re2c:indent:top = 5;
+re2c:indent:top = 1;
re2c:define:YYFILL="return true;";
re2c:define:YYFILL:naked=1;
@@ -56,7 +56,7 @@ XINTEGER = "0" [xX] XDIGIT+ ;
IDENTIFIER = [a-zA-Z_] [0-9a-zA-Z_]* ;
INTEGER {
- ts.push_token (Token (Token::integer, lineno,
+ ts.push_token (Token (Token::Integer, lineno,
token_start, cursor));
token_start = cursor;
@@ -64,7 +64,7 @@ INTEGER {
}
XINTEGER {
- ts.push_token (Token (Token::xinteger, lineno,
+ ts.push_token (Token (Token::XInteger, lineno,
token_start, cursor));
token_start = cursor;
@@ -72,132 +72,149 @@ XINTEGER {
}
"push" {
- ts.push_token (Token (Token::push, lineno));
+ ts.push_token (Token (Token::Push, lineno));
token_start = cursor;
continue;
}
+"alloc" {
+ ts.push_token (Token (Token::Alloc, lineno));
+ token_start = cursor;
+ continue;
+ }
"pop" {
- ts.push_token (Token (Token::pop, lineno));
+ ts.push_token (Token (Token::Pop, lineno));
+ token_start = cursor;
+
+ continue;
+ }
+"popto" {
+ ts.push_token (Token (Token::PopTo, lineno));
token_start = cursor;
continue;
}
"dup" {
- ts.push_token (Token (Token::dup, lineno));
+ ts.push_token (Token (Token::Dup, lineno));
token_start = cursor;
continue;
}
"read" {
- ts.push_token (Token (Token::read, lineno));
+ ts.push_token (Token (Token::Read, lineno));
token_start = cursor;
continue;
}
"print" {
- ts.push_token (Token (Token::print, lineno));
+ ts.push_token (Token (Token::Print, lineno));
token_start = cursor;
continue;
}
"add" {
- ts.push_token (Token (Token::plus, lineno));
+ ts.push_token (Token (Token::Add, lineno));
token_start = cursor;
continue;
}
"sub" {
- ts.push_token (Token (Token::minus, lineno));
+ ts.push_token (Token (Token::Sub, lineno));
token_start = cursor;
continue;
}
"mul" {
- ts.push_token (Token (Token::multiply, lineno));
+ ts.push_token (Token (Token::Mul, lineno));
token_start = cursor;
continue;
}
"div" {
- ts.push_token (Token (Token::divide, lineno));
+ ts.push_token (Token (Token::Div, lineno));
token_start = cursor;
continue;
}
"mod" {
- ts.push_token (Token (Token::modulus, lineno));
+ ts.push_token (Token (Token::Mod, lineno));
token_start = cursor;
continue;
}
"jmpt" {
- ts.push_token (Token (Token::jmpt, lineno));
+ ts.push_token (Token (Token::JumpT, lineno));
token_start = cursor;
continue;
}
"jmpf" {
- ts.push_token (Token (Token::jmpf, lineno));
+ ts.push_token (Token (Token::JumpF, lineno));
token_start = cursor;
continue;
}
"jmp" {
- ts.push_token (Token (Token::jmp, lineno));
+ ts.push_token (Token (Token::Jump, lineno));
+ token_start = cursor;
+
+ continue;
+ }
+"const" {
+ ts.push_token (Token (Token::Const, lineno));
token_start = cursor;
continue;
}
"call" {
- ts.push_token (Token (Token::call, lineno));
+ ts.push_token (Token (Token::Call, lineno));
token_start = cursor;
continue;
}
"ret" {
- ts.push_token (Token (Token::ret, lineno));
+ ts.push_token (Token (Token::Ret, lineno));
token_start = cursor;
continue;
}
"leq" {
- ts.push_token (Token (Token::lesseq, lineno));
+ ts.push_token (Token (Token::LessEq, lineno));
token_start = cursor;
continue;
}
"less" {
- ts.push_token (Token (Token::less, lineno));
+ ts.push_token (Token (Token::Less, lineno));
token_start = cursor;
continue;
}
"label" {
- ts.push_token (Token (Token::label, lineno));
+ ts.push_token (Token (Token::Label, lineno));
token_start = cursor;
continue;
}
IDENTIFIER {
- ts.push_token (Token (Token::ident, lineno, token_start,
+ ts.push_token (Token (Token::Ident, lineno, token_start,
cursor));
token_start = cursor;
@@ -218,7 +235,7 @@ IDENTIFIER {
}
"\000" {
- ts.push_token (Token (Token::endinput, lineno));
+ ts.push_token (Token (Token::EndInput, lineno));
break;
}
@@ -232,63 +249,63 @@ IDENTIFIER {
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
- */
+/*!
+** 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
+*/
- void Lexer::buffer_grow (size_t new_size)
- {
- char *new_buffer = new char[new_size];
+void Lexer::buffer_grow (size_t 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);
- }
+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;
+ 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');
- }
- }
+ 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');
- }
+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;
- }
+ cursor = marker = token_start = buffer;
+ limit = buffer + buffer_size;
+}
- } // namespace Lexer
+} // namespace Lexer
- } // namespace ASM
+} // namespace ASM
} // namespace SpasmImpl
diff --git a/spasm/src/asm/main.cpp b/spasm/src/asm/main.cpp
index da8fcf6..2b33a12 100644
--- a/spasm/src/asm/main.cpp
+++ b/spasm/src/asm/main.cpp
@@ -4,12 +4,13 @@
int main(int argc, const char* argv[])
{
- if (argc != 2)
+ if (argc != 3)
return 1;
SpasmImpl::ASM::Bytecode_Memory bytecode;
- SpasmImpl::ASM::compile(std::cin, bytecode);
+ std::ifstream input(argv[1]);
+ SpasmImpl::ASM::compile(input, bytecode);
- std::ofstream output(argv[1], std::ios_base::out | std::ios_base::binary);
+ std::ofstream output(argv[2], std::ios_base::out | std::ios_base::binary);
// output.write ("SPASM", 5);
auto& bc = bytecode.bytecode();
diff --git a/spasm/src/asm/symbol.cpp b/spasm/src/asm/symbol.cpp
index 7964142..d434060 100644
--- a/spasm/src/asm/symbol.cpp
+++ b/spasm/src/asm/symbol.cpp
@@ -7,7 +7,8 @@ namespace SpasmImpl
{
namespace ASM
{
-const size_t Symbol::notdefined = ~0ull;
+const size_t Symbol::notdefined = 0xff;
+// const size_t Symbol::notdefined = ~0ull;
Symbol::Symbol() : _definition(notdefined) {}
diff --git a/spasm/src/asm/token.cpp b/spasm/src/asm/token.cpp
index 6c88bef..4f298cf 100644
--- a/spasm/src/asm/token.cpp
+++ b/spasm/src/asm/token.cpp
@@ -22,11 +22,11 @@ Token::Token(Token::Token_type type,
const char* end)
: _type(type), _lineno(lineno)
{
- if (_type == integer || _type == xinteger)
+ if (_type == Integer || _type == XInteger)
{
_value_int = strtol(start, NULL, 0);
}
- else if (_type == ident)
+ else if (_type == Ident)
{
if (end)
{
diff --git a/spasm/src/asm/token.hpp b/spasm/src/asm/token.hpp
index 5f3b6b9..a763196 100644
--- a/spasm/src/asm/token.hpp
+++ b/spasm/src/asm/token.hpp
@@ -4,30 +4,32 @@
#include <string>
#define TOKENS \
- TOK(dup) \
- TOK(push) \
- TOK(pop) \
- TOK(print) \
- TOK(read) \
- TOK(plus) \
- TOK(minus) \
- TOK(multiply) \
- TOK(divide) \
- TOK(modulus) \
- TOK(jmpt) \
- TOK(jmpf) \
- TOK(jmp) \
- TOK(call) \
- TOK(ret) \
- TOK(load) \
- TOK(store) \
- TOK(less) \
- TOK(lesseq) \
- TOK(label) \
- TOK(ident) \
- TOK(integer) \
- TOK(xinteger) \
- TOK(endinput)
+ TOK(Halt) \
+ TOK(Dup) \
+ TOK(Pop) \
+ TOK(PopTo) \
+ TOK(Push) \
+ TOK(Alloc) \
+ TOK(Print) \
+ TOK(Read) \
+ TOK(Call) \
+ TOK(Ret) \
+ TOK(Jump) \
+ TOK(JumpT) \
+ TOK(JumpF) \
+ TOK(Const) \
+ TOK(Add) \
+ TOK(Sub) \
+ TOK(Mul) \
+ TOK(Div) \
+ TOK(Mod) \
+ TOK(Less) \
+ TOK(LessEq) \
+ TOK(Label) \
+ TOK(Ident) \
+ TOK(Integer) \
+ TOK(XInteger) \
+ TOK(EndInput)
namespace SpasmImpl
{
@@ -40,14 +42,42 @@ class Token
public:
enum Token_type
{
- halt = 0,
-#define TOK(x) x,
- TOKENS
-#undef TOK
- notused
+ _NoArgBegin,
+ Halt = _NoArgBegin,
+ Dup,
+ Pop,
+ _OneArgBegin,
+ PopTo = _OneArgBegin,
+ Push,
+ Alloc,
+ Print,
+ Read,
+ Call,
+ Ret,
+ Jump,
+ _TwoArgBegin,
+ JumpT = _TwoArgBegin,
+ JumpF,
+ Const,
+ _ThreeArgBegin,
+ Add = _ThreeArgBegin,
+ Sub,
+ Mul,
+ Div,
+ Mod,
+ Less,
+ LessEq,
+ _NotOpCodeBegin,
+ Label = _NotOpCodeBegin,
+ Ident,
+ //Register,
+ Integer,
+ XInteger,
+ EndInput,
+ NotUsed
};
- Token(Token_type = notused);
+ Token(Token_type = NotUsed);
Token(Token_type, size_t, const char* = NULL, const char* = NULL);
diff --git a/spasm/src/asm/tokenizer.cpp b/spasm/src/asm/tokenizer.cpp
index 8694ccf..b394da9 100644
--- a/spasm/src/asm/tokenizer.cpp
+++ b/spasm/src/asm/tokenizer.cpp
@@ -21,13 +21,13 @@ Tokenizer::Tokenizer(std::istream& istr)
void Tokenizer::push_token(const Token& token)
{
_tokens.push(token);
- if (token.type() == Token::endinput)
+ if (token.type() == Token::EndInput)
end_input = true;
}
Token Tokenizer::next_token()
{
- Token t(Token::endinput);
+ Token t(Token::EndInput);
if (!_tokens.empty())
{
t = _tokens.front();