summaryrefslogtreecommitdiff
path: root/boot/stage13.elna
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-09-25 10:38:19 +0200
committerEugen Wissner <belka@caraus.de>2025-09-25 10:38:19 +0200
commit8ccb63530238f90e1d6611a6e1132d12c40962fe (patch)
tree8603d6f644e1f532af2b8f78eb69282405b55bd3 /boot/stage13.elna
parent0cc41f2d838630f5117d57e1491ffd4a6d613832 (diff)
downloadelna-8ccb63530238f90e1d6611a6e1132d12c40962fe.tar.gz
Make begin optional in procedures with only return
Diffstat (limited to 'boot/stage13.elna')
-rw-r--r--boot/stage13.elna43
1 files changed, 27 insertions, 16 deletions
diff --git a/boot/stage13.elna b/boot/stage13.elna
index 925a1cd..f4fa817 100644
--- a/boot/stage13.elna
+++ b/boot/stage13.elna
@@ -6,6 +6,7 @@
(* - Multiline comments. *)
(* - elsif conditions. *)
+(* - Optional "begin" if the procedure body is a single return statement. *)
const
symbol_builtin_name_int := "Int";
@@ -71,7 +72,7 @@ begin
if _load_byte(string) <> '"' then
counter := counter + 1;
- goto .string_length_loop;
+ goto .string_length_loop
end;
return counter
@@ -100,9 +101,9 @@ begin
contents := contents + 1;
if current_byte <> '\\' then
- compiler_strings_length := compiler_strings_length + 1;
+ compiler_strings_length := compiler_strings_length + 1
end;
- goto .add_string_loop;
+ goto .add_string_loop
end;
return result
@@ -145,10 +146,10 @@ begin
local_buffer := @result + 11;
if number >= 0 then
- is_negative := 0;
+ is_negative := 0
else
number = -number;
- is_negative := 1;
+ is_negative := 1
end;
.print_i_digit10;
@@ -159,11 +160,11 @@ begin
local_buffer := local_buffer + -1;
if number <> 0 then
- goto .print_i_digit10;
+ goto .print_i_digit10
end;
if is_negative = 1 then
_store_byte('-', local_buffer);
- local_buffer := local_buffer + -1;
+ local_buffer := local_buffer + -1
end;
result := @result + 11;
result := result + -local_buffer;
@@ -210,7 +211,7 @@ begin
_write_c(next_byte);
(* Advance the input string by one byte. *)
- _write_z(string + 1);
+ _write_z(string + 1)
end;
end;
@@ -314,8 +315,8 @@ begin
count := count + -1;
if result = 0 then
- goto .memcmp_loop;
- end;
+ goto .memcmp_loop
+ end
end;
return result
@@ -341,7 +342,7 @@ begin
destination := destination + 1;
source := source + 1;
count := count + -1;
- goto .memcpy_loop;
+ goto .memcpy_loop
end;
return destination
@@ -383,7 +384,7 @@ begin
character := _load_byte(source_code_position);
if character = '\\' then
_write_c('\\');
- source_code_position := source_code_position + 1;
+ source_code_position := source_code_position + 1
end;
_write_s(source_code_position, 1);
_write_s("'\n", 2);
@@ -981,9 +982,14 @@ end;
proc _skip_spaces();
var
current_byte: Word;
+ lhs: Word;
+ rhs: Word;
begin
current_byte := _load_byte(source_code_position);
- if current_byte = '\t' then
+ lhs := current_byte = '\t';
+ rhs := current_byte = ' ';
+
+ if lhs or rhs then
source_code_position := source_code_position + 1;
_skip_spaces();
end;
@@ -1194,9 +1200,14 @@ begin
_read_procedure_temporaries();
(* Skip semicolon, "begin" and newline. *)
- source_code_position := source_code_position + 6;
-
- _compile_procedure_body();
+ _lexer_read_token(@token_kind);
+ if token_kind = _lexer_token_kind_begin() then
+ _lexer_skip_token();
+ _compile_procedure_body();
+ end;
+ if token_kind = _lexer_token_kind_return() then
+ _compile_return_statement();
+ end;
(* Write the epilogue. *)
_write_z("\tlw ra, 124(sp)\n\tlw s0, 120(sp)\n\taddi sp, sp, 128\n\tret\n\0");