feat: beta compiling to fasm (codegen) + hello world example let's goooo
This commit is contained in:
@ -51,7 +51,7 @@ struct Token
|
||||
TokenType token;
|
||||
long int_number;
|
||||
// null-terminated
|
||||
char* string;
|
||||
StringView string;
|
||||
long line_number;
|
||||
long offset_start;
|
||||
long offset_end;
|
||||
@ -90,15 +90,10 @@ public:
|
||||
: m_filename(filename), m_code(code) {}
|
||||
|
||||
Lexer(const Lexer&) = delete;
|
||||
Lexer(Lexer&& other)
|
||||
{
|
||||
m_code = other.m_code;
|
||||
other.m_code = StringView();
|
||||
}
|
||||
public:
|
||||
bool NextToken()
|
||||
{
|
||||
if (m_pos >= m_code.size)
|
||||
if (m_pos >= m_code.size || m_code.data[m_pos] == '\0')
|
||||
{
|
||||
m_token = Token(TokenType::Eof);
|
||||
return false;
|
||||
@ -119,27 +114,27 @@ public:
|
||||
{
|
||||
StringBuilder s;
|
||||
long offset_start = m_pos - m_last_newline;
|
||||
s.PushChar(c);
|
||||
s.Push(c);
|
||||
// id
|
||||
while (std::isalpha(m_code.data[m_pos]) != 0)
|
||||
{
|
||||
s.PushChar(m_code.data[m_pos++]);
|
||||
s.Push(m_code.data[m_pos++]);
|
||||
}
|
||||
s.PushChar('\0');
|
||||
s.Push('\0');
|
||||
m_token = Token(TokenType::Id, m_line, offset_start, m_pos - m_last_newline);
|
||||
m_token.string = s.data;
|
||||
m_token.string = s.view();
|
||||
|
||||
if (strcmp("extern", m_token.string) == 0)
|
||||
if (strcmp("extern", m_token.string.c_str()) == 0)
|
||||
{
|
||||
m_token.token = TokenType::Extern;
|
||||
}
|
||||
|
||||
if (strcmp("fn", m_token.string) == 0)
|
||||
if (strcmp("fn", m_token.string.c_str()) == 0)
|
||||
{
|
||||
m_token.token = TokenType::Fn;
|
||||
}
|
||||
|
||||
if (strcmp("local", m_token.string) == 0)
|
||||
if (strcmp("local", m_token.string.c_str()) == 0)
|
||||
{
|
||||
m_token.token = TokenType::Local;
|
||||
}
|
||||
@ -152,13 +147,13 @@ public:
|
||||
StringBuilder s;
|
||||
long offset_start = m_pos - m_last_newline;
|
||||
bool hex = c == '0' && m_code.data[m_pos] == 'x';
|
||||
s.PushChar(c);
|
||||
s.Push(c);
|
||||
// integer (could be hex)
|
||||
while (std::isdigit(m_code.data[m_pos]) != 0 || (hex && std::isalpha(m_code.data[m_pos]) != 0))
|
||||
{
|
||||
s.PushChar(m_code.data[m_pos++]);
|
||||
s.Push(m_code.data[m_pos++]);
|
||||
}
|
||||
s.PushChar('\0');
|
||||
s.Push('\0');
|
||||
m_token = Token(TokenType::IntLiteral, m_line, offset_start, m_pos - m_last_newline);
|
||||
m_token.int_number = std::strtol(s.data, nullptr, hex ? 16 : 10);
|
||||
m_token.string = s.data;
|
||||
|
||||
Reference in New Issue
Block a user