bitwise operations

This commit is contained in:
2026-07-19 00:36:31 +02:00
parent f9448363e4
commit c7e3162ecb
21 changed files with 219439 additions and 140077 deletions
+48 -4
View File
@@ -35,6 +35,7 @@ keyword_kind :: proc(text: string) -> token.Kind {
case "orelse": return .Keyword_Orelse
case "and": return .Keyword_And
case "or": return .Keyword_Or
case "xor": return .Keyword_Xor
case "if": return .Keyword_If
case "while": return .Keyword_While
case "for": return .Keyword_For
@@ -156,7 +157,23 @@ lex :: proc(
case '<':
start := cursor
cursor += 1
if cursor < len(bytes) && bytes[cursor] == '=' {
if cursor < len(bytes) && bytes[cursor] == '<' {
cursor += 1
if cursor < len(bytes) && bytes[cursor] == '|' {
cursor += 1
if cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
append_token(&stream, source_file, .Less_Less_Pipe_Equal, start, cursor)
} else {
append_token(&stream, source_file, .Less_Less_Pipe, start, cursor)
}
} else if cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
append_token(&stream, source_file, .Less_Less_Equal, start, cursor)
} else {
append_token(&stream, source_file, .Less_Less, start, cursor)
}
} else if cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
append_token(&stream, source_file, .Less_Equal, start, cursor)
} else {
@@ -165,7 +182,15 @@ lex :: proc(
case '>':
start := cursor
cursor += 1
if cursor < len(bytes) && bytes[cursor] == '=' {
if cursor < len(bytes) && bytes[cursor] == '>' {
cursor += 1
if cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
append_token(&stream, source_file, .Greater_Greater_Equal, start, cursor)
} else {
append_token(&stream, source_file, .Greater_Greater, start, cursor)
}
} else if cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
append_token(&stream, source_file, .Greater_Equal, start, cursor)
} else {
@@ -231,11 +256,20 @@ lex :: proc(
append_token(&stream, source_file, .Slash, start, cursor)
}
case '&':
append_token(&stream, source_file, .Ampersand, cursor, cursor+1)
start := cursor
cursor += 1
if cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
append_token(&stream, source_file, .Ampersand_Equal, start, cursor)
} else {
append_token(&stream, source_file, .Ampersand, start, cursor)
}
case '^':
append_token(&stream, source_file, .Caret, cursor, cursor+1)
cursor += 1
case '~':
append_token(&stream, source_file, .Tilde, cursor, cursor+1)
cursor += 1
case '?':
append_token(&stream, source_file, .Question, cursor, cursor+1)
cursor += 1
@@ -261,8 +295,14 @@ lex :: proc(
append_token(&stream, source_file, .Comma, cursor, cursor+1)
cursor += 1
case '|':
append_token(&stream, source_file, .Pipe, cursor, cursor+1)
start := cursor
cursor += 1
if cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
append_token(&stream, source_file, .Pipe_Equal, start, cursor)
} else {
append_token(&stream, source_file, .Pipe, start, cursor)
}
case '"':
start := cursor
cursor += 1
@@ -370,6 +410,10 @@ lex :: proc(
}
text := source_file.text[start:cursor]
kind := keyword_kind(text)
if kind == .Keyword_Xor && cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
kind = .Xor_Equal
}
id := symbol.INVALID
if kind == .Identifier || kind == .Underscore {
id = symbol.intern(symbols, text)