aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/cctype.elna12
-rw-r--r--source/command_line_interface.elna2
-rw-r--r--source/common.elna6
-rw-r--r--source/cstdio.elna26
-rw-r--r--source/cstdlib.elna10
-rw-r--r--source/cstring.elna14
-rw-r--r--source/lexer.elna29
-rw-r--r--source/main.elna56
8 files changed, 85 insertions, 70 deletions
diff --git a/source/cctype.elna b/source/cctype.elna
index 1296a10..13dc50a 100644
--- a/source/cctype.elna
+++ b/source/cctype.elna
@@ -2,22 +2,22 @@
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at https://mozilla.org/MPL/2.0/. *)
-proc isdigit*(c: Int ): Int
+proc isdigit*(c: Int ) -> Int
extern
-proc isalnum*(c: Int): Int
+proc isalnum*(c: Int) -> Int
extern
-proc isalpha*(c: Int): Int
+proc isalpha*(c: Int) -> Int
extern
-proc isspace*(c: Int): Int
+proc isspace*(c: Int) -> Int
extern
-proc tolower*(c: Int): Int
+proc tolower*(c: Int) -> Int
extern
-proc toupper*(c: Int): Int
+proc toupper*(c: Int) -> Int
extern
end.
diff --git a/source/command_line_interface.elna b/source/command_line_interface.elna
index 62965db..0feb53b 100644
--- a/source/command_line_interface.elna
+++ b/source/command_line_interface.elna
@@ -15,7 +15,7 @@ type
parse: Bool
end
-proc parse_command_line*(argc: Int; argv: ^^Word8): ^CommandLine
+proc parse_command_line*(argc: Int; argv: ^^Word8) -> ^CommandLine
var
parameter: ^Word8
i: Int
diff --git a/source/common.elna b/source/common.elna
index c5b67f8..0a50fe1 100644
--- a/source/common.elna
+++ b/source/common.elna
@@ -14,7 +14,7 @@ type
end_location: ElnaLocation
end
-proc write*(fd: Int; buf: Pointer; Word: Int): Int
+proc write*(fd: Int; buf: Pointer; Word: Int) -> Int
extern
proc write_s*(value: []const Word8)
@@ -72,13 +72,13 @@ begin
write_i(cast(value: Int))
return
-proc free_and_nil*(pointer: Pointer): Pointer
+proc free_and_nil*(pointer: Pointer) -> Pointer
begin
free(pointer)
return nil
(* Returns true or false depending whether two strings are equal. *)
-proc string_compare*(lhs_pointer: ^Word8; lhs_length: Word; rhs_pointer: []const Word8): Bool
+proc string_compare*(lhs_pointer: ^Word8; lhs_length: Word; rhs_pointer: []const Word8) -> Bool
var
result: Bool
begin
diff --git a/source/cstdio.elna b/source/cstdio.elna
index 78c3a24..bf74234 100644
--- a/source/cstdio.elna
+++ b/source/cstdio.elna
@@ -10,49 +10,49 @@ var
stdout*: ^FILE := extern
stderr*: ^FILE := extern
-proc fopen*(pathname, mode: ^const Word8): ^FILE
+proc fopen*(pathname, mode: ^const Word8) -> ^FILE
extern
-proc fclose*(stream: ^FILE): Int
+proc fclose*(stream: ^FILE) -> Int
extern
-proc fseek*(stream: ^FILE; off: Int; whence: Int): Int
+proc fseek*(stream: ^FILE; off: Int; whence: Int) -> Int
extern
proc rewind*(stream: ^FILE)
extern
-proc ftell*(stream: ^FILE): Int
+proc ftell*(stream: ^FILE) -> Int
extern
-proc fflush*(stream: ^FILE): Int
+proc fflush*(stream: ^FILE) -> Int
extern
-proc fread*(ptr: Pointer; size: Word; nmemb: Word; stream: ^FILE): Word
+proc fread*(ptr: Pointer; size: Word; nmemb: Word; stream: ^FILE) -> Word
extern
-proc fwrite*(ptr: const Pointer; size: Word; nitems: Word; stream: ^FILE): Word
+proc fwrite*(ptr: const Pointer; size: Word; nitems: Word; stream: ^FILE) -> Word
extern
-proc fputc*(c: Int; stream: ^FILE): Word
+proc fputc*(c: Int; stream: ^FILE) -> Word
extern
proc perror*(s: ^const Word8)
extern
-proc puts*(s: ^const Word8): Int
+proc puts*(s: ^const Word8) -> Int
extern
-proc putchar*(c: Int): Int
+proc putchar*(c: Int) -> Int
extern
-proc sprintf*(str: Pointer; format: ^const Word8; number: Word): Int
+proc sprintf*(str: Pointer; format: ^const Word8; number: Word) -> Int
extern
-proc fprintf*(stream: Pointer; format: ^const Word8; number: Word): Int
+proc fprintf*(stream: Pointer; format: ^const Word8; number: Word) -> Int
extern
-proc fdopen*(fildes: Int; mode: ^const Word8): Pointer
+proc fdopen*(fildes: Int; mode: ^const Word8) -> Pointer
extern
end.
diff --git a/source/cstdlib.elna b/source/cstdlib.elna
index 0f78c8e..09b1ddf 100644
--- a/source/cstdlib.elna
+++ b/source/cstdlib.elna
@@ -2,22 +2,22 @@
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at https://mozilla.org/MPL/2.0/. *)
-proc malloc*(size: Word): Pointer
+proc malloc*(size: Word) -> Pointer
extern
proc free*(ptr: Pointer)
extern
-proc calloc*(nmemb: Word; size: Word): Pointer
+proc calloc*(nmemb: Word; size: Word) -> Pointer
extern
-proc realloc*(ptr: Pointer; size: Word): Pointer
+proc realloc*(ptr: Pointer; size: Word) -> Pointer
extern
-proc atoi*(str: ^Word8): Int
+proc atoi*(str: ^Word8) -> Int
extern
-proc exit*(code: Int): !
+proc exit*(code: Int) -> !
extern
end.
diff --git a/source/cstring.elna b/source/cstring.elna
index 9290a5c..70c468c 100644
--- a/source/cstring.elna
+++ b/source/cstring.elna
@@ -2,28 +2,28 @@
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at https://mozilla.org/MPL/2.0/. *)
-proc memset*(ptr: Pointer; c: Int; n: Word): ^Word8
+proc memset*(ptr: Pointer; c: Int; n: Word) -> ^Word8
extern
proc memcpy*(dst: Pointer; src: const Pointer; n: Word)
extern
-proc memcmp*(s1, s2: const Pointer; n: Word): Int
+proc memcmp*(s1, s2: const Pointer; n: Word) -> Int
extern
-proc strcmp*(s1: ^const Word8; s2: ^const Word8): Int
+proc strcmp*(s1: ^const Word8; s2: ^const Word8) -> Int
extern
-proc strncmp*(s1: ^const Word8; s2: ^const Word8; n: Word): Int
+proc strncmp*(s1: ^const Word8; s2: ^const Word8; n: Word) -> Int
extern
-proc strncpy*(dst: ^Word8; src: ^const Word8; dsize: Word): ^Word8
+proc strncpy*(dst: ^Word8; src: ^const Word8; dsize: Word) -> ^Word8
extern
-proc strcpy*(dst: ^Word8; src: ^const Word8): ^Word8
+proc strcpy*(dst: ^Word8; src: ^const Word8) -> ^Word8
extern
-proc strlen*(ptr: ^const Word8): Word
+proc strlen*(ptr: ^const Word8) -> Word
extern
end.
diff --git a/source/lexer.elna b/source/lexer.elna
index 83e89df..1cfe097 100644
--- a/source/lexer.elna
+++ b/source/lexer.elna
@@ -135,6 +135,7 @@ type
_case,
_do,
_of,
+ arrow,
eof
)
(**
@@ -313,7 +314,7 @@ begin
end
return
-proc elna_lexer_get_transition(current_state: ElnaLexerState; character_class: ElnaLexerClass): ^ElnaLexerTransition
+proc elna_lexer_get_transition(current_state: ElnaLexerState; character_class: ElnaLexerClass) -> ^ElnaLexerTransition
(* Each state is 8 bytes long (2 words: action and next state).
There are 23 character classes, so a transition row 8 * 23 = 184 bytes long. *)
return @transition_table[cast(current_state: Word)][cast(character_class: Word)]
@@ -523,7 +524,7 @@ begin
end
return
-proc elna_lexer_token_create(kind: ElnaLexerKind; position: ^ElnaPosition): ^ElnaLexerToken
+proc elna_lexer_token_create(kind: ElnaLexerKind; position: ^ElnaPosition) -> ^ElnaLexerToken
var
result: ^ElnaLexerToken
begin
@@ -532,7 +533,7 @@ begin
result^.position := position^
return result
-proc elna_lexer_classify_keyword(position_start, position_end: ^Word8; position: ^ElnaPosition): ^ElnaLexerToken
+proc elna_lexer_classify_keyword(position_start, position_end: ^Word8; position: ^ElnaPosition) -> ^ElnaLexerToken
var
result: ^ElnaLexerToken
result_length: Word
@@ -587,7 +588,7 @@ begin
end
return result
-proc elna_lexer_classify_delimited(start_position, end_position: ^Word8; position: ^ElnaPosition): ^ElnaLexerToken
+proc elna_lexer_classify_delimited(start_position, end_position: ^Word8; position: ^ElnaPosition) -> ^ElnaLexerToken
var
delimiter: Word8
result: ^ElnaLexerToken
@@ -604,7 +605,7 @@ begin
result^.start := start_position[1 to cast(end_position - start_position: Word)]
return result
-proc elna_lexer_classify_integer(start_position, end_position: ^Word8; position: ^ElnaPosition): ^ElnaLexerToken
+proc elna_lexer_classify_integer(start_position, end_position: ^Word8; position: ^ElnaPosition) -> ^ElnaLexerToken
var
result: ^ElnaLexerToken
begin
@@ -612,7 +613,7 @@ begin
result^.start := start_position[1 to cast(end_position - start_position: Word)]
return result
-proc elna_lexer_classify_finalize(start_position: ^Word8; position: ^ElnaPosition): ^ElnaLexerToken
+proc elna_lexer_classify_finalize(start_position: ^Word8; position: ^ElnaPosition) -> ^ElnaLexerToken
var
character: Word8
result: ^ElnaLexerToken
@@ -634,7 +635,7 @@ begin
end
return result
-proc elna_lexer_classify_single(start_position: ^Word8; position: ^ElnaPosition): ^ElnaLexerToken
+proc elna_lexer_classify_single(start_position: ^Word8; position: ^ElnaPosition) -> ^ElnaLexerToken
var
character: Word8
result: ^ElnaLexerToken
@@ -675,7 +676,7 @@ begin
end
return result
-proc elna_lexer_classify_composite(start_position, one_before_last: ^Word8; position: ^ElnaPosition): ^ElnaLexerToken
+proc elna_lexer_classify_composite(start_position, one_before_last: ^Word8; position: ^ElnaPosition) -> ^ElnaLexerToken
var
first_character: Word8
last_character: Word8
@@ -696,10 +697,14 @@ begin
if last_character = '=' then
result := elna_lexer_token_create(ElnaLexerKind.greater_equal, position)
end
+ elsif first_character = '-' then
+ if last_character = '>' then
+ result := elna_lexer_token_create(ElnaLexerKind.arrow, position)
+ end
end
return result
-proc elna_lexer_execute_action(cursor: ^ElnaLexerCursor; action_to_perform: ElnaLexerAction): ^ElnaLexerToken
+proc elna_lexer_execute_action(cursor: ^ElnaLexerCursor; action_to_perform: ElnaLexerAction) -> ^ElnaLexerToken
var
token: ^ElnaLexerToken
begin
@@ -736,7 +741,7 @@ begin
end
return token
-proc elna_lexer_execute_transition(cursor: ^ElnaLexerCursor): ^ElnaLexerToken
+proc elna_lexer_execute_transition(cursor: ^ElnaLexerCursor) -> ^ElnaLexerToken
var
next_transition: ^ElnaLexerTransition
current_character: Word8
@@ -766,7 +771,7 @@ return
* Reads the next token and writes its type into the address in the kind parameter.
* Resets the lexer state for reading the next token.
*)
-proc elna_lexer_peek(cursor: ^ElnaLexerCursor): ^ElnaLexerToken
+proc elna_lexer_peek(cursor: ^ElnaLexerCursor) -> ^ElnaLexerToken
var
token: ^ElnaLexerToken
begin
@@ -783,7 +788,7 @@ return cursor^.token
(**
* Reads the token and advance the lexer.
*)
-proc elna_lexer_read(cursor: ^ElnaLexerCursor): ^ElnaLexerToken
+proc elna_lexer_read(cursor: ^ElnaLexerCursor) -> ^ElnaLexerToken
var
token: ^ElnaLexerToken
begin
diff --git a/source/main.elna b/source/main.elna
index bdcaf34..23fdc97 100644
--- a/source/main.elna
+++ b/source/main.elna
@@ -20,9 +20,9 @@ type
position: ElnaLocation;
input: Pointer;
- empty: proc(stream: Pointer): Bool;
+ empty: proc(stream: Pointer) -> Bool;
advance: proc(stream: Pointer);
- head: proc(stream: Pointer): Word8
+ head: proc(stream: Pointer) -> Word8
end
Tokenizer* = record
length: Word;
@@ -32,10 +32,10 @@ type
(*
Standard procedures.
*)
-proc reallocarray(ptr: Pointer; n: Word; size: Word): Pointer
+proc reallocarray(ptr: Pointer; n: Word; size: Word) -> Pointer
return realloc(ptr, n * size)
-proc string_dup(origin: []const Word8): []const Word8
+proc string_dup(origin: []const Word8) -> []const Word8
var
copy: ^Word8
begin
@@ -43,7 +43,7 @@ begin
strncpy(copy, origin.ptr, origin.length)
return copy[1 to origin.length]
-proc string_buffer_new(): StringBuffer
+proc string_buffer_new() -> StringBuffer
var
result: StringBuffer
begin
@@ -67,7 +67,7 @@ begin
buffer^.size := buffer^.size - count
return
-proc string_buffer_clear(buffer: ^StringBuffer): []const Word8
+proc string_buffer_clear(buffer: ^StringBuffer) -> []const Word8
var
result: []const Word8
begin
@@ -79,7 +79,7 @@ return result
Source code stream procedures.
*)
-proc read_source(filename: ^Word8): ^SourceFile
+proc read_source(filename: ^Word8) -> ^SourceFile
var
result: ^SourceFile
file_handle: ^FILE
@@ -94,7 +94,7 @@ begin
end
return result
-proc source_file_empty(source_input: Pointer): Bool
+proc source_file_empty(source_input: Pointer) -> Bool
var
source_file: ^SourceFile
begin
@@ -106,7 +106,7 @@ begin
end
return source_file^.size = 0u
-proc source_file_head(source_input: Pointer): Word8
+proc source_file_head(source_input: Pointer) -> Word8
var
source_file: ^SourceFile
begin
@@ -122,10 +122,10 @@ begin
source_file^.index := source_file^.index + 1u
return
-proc source_code_empty(source_code: ^SourceCode): Bool
+proc source_code_empty(source_code: ^SourceCode) -> Bool
return source_code^.empty(source_code^.input)
-proc source_code_head(source_code: SourceCode): Word8
+proc source_code_head(source_code: SourceCode) -> Word8
return source_code.head(source_code.input)
proc source_code_advance(source_code: ^SourceCode)
@@ -140,14 +140,14 @@ begin
source_code^.position.column := 0u
return
-proc source_code_expect(source_code: ^SourceCode; expected: Word8): 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: Word8; result: ^Word8): Bool
+proc lexer_escape(escape: Word8; result: ^Word8) -> Bool
var
successful: Bool
begin
@@ -200,7 +200,7 @@ begin
return
(* Checker whether the character is allowed in an identificator. *)
-proc lexer_is_ident(char: Word8): 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)
@@ -213,7 +213,7 @@ begin
end
return
-proc lexer_comment(source_code: ^SourceCode; token_content: ^StringBuffer): Bool
+proc lexer_comment(source_code: ^SourceCode; token_content: ^StringBuffer) -> Bool
var
trailing: Word
begin
@@ -234,7 +234,7 @@ begin
end
return trailing = 2u
-proc lexer_character(source_code: ^SourceCode; token_content: ^Word8): Bool
+proc lexer_character(source_code: ^SourceCode; token_content: ^Word8) -> Bool
var
successful: Bool
begin
@@ -255,7 +255,7 @@ begin
end
return successful
-proc lexer_string(source_code: ^SourceCode; token_content: ^StringBuffer): Bool
+proc lexer_string(source_code: ^SourceCode; token_content: ^StringBuffer) -> Bool
var
token_end, constructed_string: ^Word8
token_length: Word
@@ -289,7 +289,7 @@ begin
return
(* Categorize an identifier. *)
-proc lexer_categorize(token_content: []const Word8): ^ElnaLexerToken
+proc lexer_categorize(token_content: []const Word8) -> ^ElnaLexerToken
var
current_token: ^ElnaLexerToken
begin
@@ -385,7 +385,7 @@ begin
return
(* Read the next token from the input. *)
-proc lexer_next(source_code: SourceCode; token_buffer: ^StringBuffer): ^ElnaLexerToken
+proc lexer_next(source_code: SourceCode; token_buffer: ^StringBuffer) -> ^ElnaLexerToken
var
current_token: ^ElnaLexerToken := nil
first_char: Word8
@@ -523,7 +523,15 @@ begin
elsif first_char = '-' then
source_code_advance(@source_code);
current_token := malloc(#size(ElnaLexerToken));
- current_token^.kind := ElnaLexerKind.minus
+
+ if source_code_empty(@source_code) then
+ current_token^.kind := ElnaLexerKind.minus
+ elsif source_code_head(source_code) = '>' then
+ current_token^.kind := ElnaLexerKind.arrow;
+ source_code_advance(@source_code)
+ else
+ current_token^.kind := ElnaLexerKind.minus
+ end
elsif first_char = '*' then
current_token := malloc(#size(ElnaLexerToken));
current_token^.kind := ElnaLexerKind.multiplication;
@@ -576,7 +584,7 @@ begin
return current_token
(* Split the source text into tokens. *)
-proc lexer_text(source_code: SourceCode): Tokenizer
+proc lexer_text(source_code: SourceCode) -> Tokenizer
var
current_token: ^ElnaLexerToken
token_buffer: StringBuffer
@@ -739,6 +747,8 @@ begin
write_s("DEFER")
| ElnaLexerKind.exclamation:
write_c('!')
+ | ElnaLexerKind.arrow:
+ write_s("->")
| ElnaLexerKind._import:
write_s("IMPORT")
else
@@ -757,7 +767,7 @@ return
Compilation entry.
*)
-proc compile_in_stages(command_line: ^CommandLine; source_code: SourceCode): Int
+proc compile_in_stages(command_line: ^CommandLine; source_code: SourceCode) -> Int
var
return_code: Int := 0
lexer: Tokenizer
@@ -770,7 +780,7 @@ begin
end
return return_code
-proc process(argc: Int; argv: ^^Word8): Int
+proc process(argc: Int; argv: ^^Word8) -> Int
var
tokens: ^ElnaLexerToken
tokens_size: Word