From 4f77ad5d019618893c59a0f8d5bfa6b98e50a3be Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 18 Aug 2026 13:31:47 +0200 Subject: Make Int and Word aliases to fixed-size types --- source/main.elna | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'source/main.elna') diff --git a/source/main.elna b/source/main.elna index 369d013..d539d0d 100644 --- a/source/main.elna +++ b/source/main.elna @@ -6,7 +6,7 @@ import cstdio, cstdlib, cstring, cctype, common, command_line_interface, lexer type SourceFile* = record - buffer: [1024]Char; + buffer: [1024]Word8; handle: ^FILE; size: Word; index: Word @@ -22,7 +22,7 @@ type input: Pointer; empty: proc(stream: Pointer): Bool; advance: proc(stream: Pointer); - head: proc(stream: Pointer): Char + head: proc(stream: Pointer): Word8 end Tokenizer* = record length: Word; @@ -42,9 +42,9 @@ var proc reallocarray(ptr: Pointer; n: Word; size: Word): Pointer return realloc(ptr, n * size) -proc string_dup(origin: []const Char): []const Char +proc string_dup(origin: []const Word8): []const Word8 var - copy: ^Char + copy: ^Word8 begin copy := malloc(origin.length); strncpy(copy, origin.ptr, origin.length) @@ -59,13 +59,13 @@ begin result.size := 0u return result -proc string_buffer_push(buffer: ^StringBuffer; char: Char) +proc string_buffer_push(buffer: ^StringBuffer; char: Word8) begin if buffer^.size >= buffer^.capacity then buffer^.capacity := buffer^.capacity + 1024u; buffer^.data := realloc(buffer^.data, buffer^.capacity) end; - cast(buffer^.data + buffer^.size: ^Char)^ := cast(char: Char); + cast(buffer^.data + buffer^.size: ^Word8)^ := cast(char: Word8); buffer^.size := buffer^.size + 1u return @@ -74,11 +74,11 @@ begin buffer^.size := buffer^.size - count return -proc string_buffer_clear(buffer: ^StringBuffer): []const Char +proc string_buffer_clear(buffer: ^StringBuffer): []const Word8 var - result: []const Char + result: []const Word8 begin - result := cast(buffer^.data: ^Char)[1 to buffer^.size]; + result := cast(buffer^.data: ^Word8)[1 to buffer^.size]; buffer^.size := 0u return result @@ -86,7 +86,7 @@ return result Source code stream procedures. *) -proc read_source(filename: ^Char): ^SourceFile +proc read_source(filename: ^Word8): ^SourceFile var result: ^SourceFile file_handle: ^FILE @@ -113,7 +113,7 @@ begin end return source_file^.size = 0u -proc source_file_head(source_input: Pointer): Char +proc source_file_head(source_input: Pointer): Word8 var source_file: ^SourceFile begin @@ -132,7 +132,7 @@ return proc source_code_empty(source_code: ^SourceCode): Bool return source_code^.empty(source_code^.input) -proc source_code_head(source_code: SourceCode): Char +proc source_code_head(source_code: SourceCode): Word8 return source_code.head(source_code.input) proc source_code_advance(source_code: ^SourceCode) @@ -147,14 +147,14 @@ begin source_code^.position.column := 0u return -proc source_code_expect(source_code: ^SourceCode; expected: Char): Bool +proc source_code_expect(source_code: ^SourceCode; expected: Word8): Bool return ~source_code_empty(source_code) & source_code_head(source_code^) = expected (* Token procedures. *) -proc lexer_escape(escape: Char; result: ^Char): Bool +proc lexer_escape(escape: Word8; result: ^Word8): Bool var successful: Bool begin @@ -194,7 +194,7 @@ return successful (* Skip spaces. *) proc lexer_spaces(source_code: ^SourceCode) var - current: Char + current: Word8 begin while ~source_code_empty(source_code) & isspace(cast(source_code_head(source_code^): Int)) <> 0 do current := source_code_head(source_code^); @@ -207,7 +207,7 @@ begin return (* Checker whether the character is allowed in an identificator. *) -proc lexer_is_ident(char: Char): Bool +proc lexer_is_ident(char: Word8): Bool return isalnum(cast(char: Int)) <> 0 or char = '_' proc lexer_identifier(source_code: ^SourceCode; token_content: ^StringBuffer) @@ -241,7 +241,7 @@ begin end return trailing = 2u -proc lexer_character(source_code: ^SourceCode; token_content: ^Char): Bool +proc lexer_character(source_code: ^SourceCode; token_content: ^Word8): Bool var successful: Bool begin @@ -264,10 +264,10 @@ return successful proc lexer_string(source_code: ^SourceCode; token_content: ^StringBuffer): Bool var - token_end, constructed_string: ^Char + token_end, constructed_string: ^Word8 token_length: Word is_valid: Bool := true - next_char: Char + next_char: Word8 begin while is_valid & ~source_code_empty(source_code) & source_code_head(source_code^) <> '"' do is_valid := lexer_character(source_code, @next_char); @@ -296,7 +296,7 @@ begin return (* Categorize an identifier. *) -proc lexer_categorize(token_content: []const Char): ^ElnaLexerToken +proc lexer_categorize(token_content: []const Word8): ^ElnaLexerToken var current_token: ^ElnaLexerToken begin @@ -395,7 +395,7 @@ return proc lexer_next(source_code: SourceCode; token_buffer: ^StringBuffer): ^ElnaLexerToken var current_token: ^ElnaLexerToken := nil - first_char: Char + first_char: Word8 begin first_char := source_code_head(source_code); @@ -777,7 +777,7 @@ begin end return return_code -proc process(argc: Int; argv: ^^Char): Int +proc process(argc: Int; argv: ^^Word8): Int var tokens: ^ElnaLexerToken tokens_size: Word -- cgit v1.2.3