Make begin optional in procedures with only return
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
(* - Multiline comments. *)
|
(* - Multiline comments. *)
|
||||||
(* - elsif conditions. *)
|
(* - elsif conditions. *)
|
||||||
|
(* - Optional "begin" if the procedure body is a single return statement. *)
|
||||||
|
|
||||||
const
|
const
|
||||||
symbol_builtin_name_int := "Int";
|
symbol_builtin_name_int := "Int";
|
||||||
@@ -71,7 +72,7 @@ begin
|
|||||||
|
|
||||||
if _load_byte(string) <> '"' then
|
if _load_byte(string) <> '"' then
|
||||||
counter := counter + 1;
|
counter := counter + 1;
|
||||||
goto .string_length_loop;
|
goto .string_length_loop
|
||||||
end;
|
end;
|
||||||
|
|
||||||
return counter
|
return counter
|
||||||
@@ -100,9 +101,9 @@ begin
|
|||||||
contents := contents + 1;
|
contents := contents + 1;
|
||||||
|
|
||||||
if current_byte <> '\\' then
|
if current_byte <> '\\' then
|
||||||
compiler_strings_length := compiler_strings_length + 1;
|
compiler_strings_length := compiler_strings_length + 1
|
||||||
end;
|
end;
|
||||||
goto .add_string_loop;
|
goto .add_string_loop
|
||||||
end;
|
end;
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -145,10 +146,10 @@ begin
|
|||||||
local_buffer := @result + 11;
|
local_buffer := @result + 11;
|
||||||
|
|
||||||
if number >= 0 then
|
if number >= 0 then
|
||||||
is_negative := 0;
|
is_negative := 0
|
||||||
else
|
else
|
||||||
number = -number;
|
number = -number;
|
||||||
is_negative := 1;
|
is_negative := 1
|
||||||
end;
|
end;
|
||||||
|
|
||||||
.print_i_digit10;
|
.print_i_digit10;
|
||||||
@@ -159,11 +160,11 @@ begin
|
|||||||
local_buffer := local_buffer + -1;
|
local_buffer := local_buffer + -1;
|
||||||
|
|
||||||
if number <> 0 then
|
if number <> 0 then
|
||||||
goto .print_i_digit10;
|
goto .print_i_digit10
|
||||||
end;
|
end;
|
||||||
if is_negative = 1 then
|
if is_negative = 1 then
|
||||||
_store_byte('-', local_buffer);
|
_store_byte('-', local_buffer);
|
||||||
local_buffer := local_buffer + -1;
|
local_buffer := local_buffer + -1
|
||||||
end;
|
end;
|
||||||
result := @result + 11;
|
result := @result + 11;
|
||||||
result := result + -local_buffer;
|
result := result + -local_buffer;
|
||||||
@@ -210,7 +211,7 @@ begin
|
|||||||
_write_c(next_byte);
|
_write_c(next_byte);
|
||||||
|
|
||||||
(* Advance the input string by one byte. *)
|
(* Advance the input string by one byte. *)
|
||||||
_write_z(string + 1);
|
_write_z(string + 1)
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -314,8 +315,8 @@ begin
|
|||||||
count := count + -1;
|
count := count + -1;
|
||||||
|
|
||||||
if result = 0 then
|
if result = 0 then
|
||||||
goto .memcmp_loop;
|
goto .memcmp_loop
|
||||||
end;
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -341,7 +342,7 @@ begin
|
|||||||
destination := destination + 1;
|
destination := destination + 1;
|
||||||
source := source + 1;
|
source := source + 1;
|
||||||
count := count + -1;
|
count := count + -1;
|
||||||
goto .memcpy_loop;
|
goto .memcpy_loop
|
||||||
end;
|
end;
|
||||||
|
|
||||||
return destination
|
return destination
|
||||||
@@ -383,7 +384,7 @@ begin
|
|||||||
character := _load_byte(source_code_position);
|
character := _load_byte(source_code_position);
|
||||||
if character = '\\' then
|
if character = '\\' then
|
||||||
_write_c('\\');
|
_write_c('\\');
|
||||||
source_code_position := source_code_position + 1;
|
source_code_position := source_code_position + 1
|
||||||
end;
|
end;
|
||||||
_write_s(source_code_position, 1);
|
_write_s(source_code_position, 1);
|
||||||
_write_s("'\n", 2);
|
_write_s("'\n", 2);
|
||||||
@@ -981,9 +982,14 @@ end;
|
|||||||
proc _skip_spaces();
|
proc _skip_spaces();
|
||||||
var
|
var
|
||||||
current_byte: Word;
|
current_byte: Word;
|
||||||
|
lhs: Word;
|
||||||
|
rhs: Word;
|
||||||
begin
|
begin
|
||||||
current_byte := _load_byte(source_code_position);
|
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;
|
source_code_position := source_code_position + 1;
|
||||||
_skip_spaces();
|
_skip_spaces();
|
||||||
end;
|
end;
|
||||||
@@ -1194,9 +1200,14 @@ begin
|
|||||||
_read_procedure_temporaries();
|
_read_procedure_temporaries();
|
||||||
|
|
||||||
(* Skip semicolon, "begin" and newline. *)
|
(* Skip semicolon, "begin" and newline. *)
|
||||||
source_code_position := source_code_position + 6;
|
_lexer_read_token(@token_kind);
|
||||||
|
if token_kind = _lexer_token_kind_begin() then
|
||||||
|
_lexer_skip_token();
|
||||||
_compile_procedure_body();
|
_compile_procedure_body();
|
||||||
|
end;
|
||||||
|
if token_kind = _lexer_token_kind_return() then
|
||||||
|
_compile_return_statement();
|
||||||
|
end;
|
||||||
|
|
||||||
(* Write the epilogue. *)
|
(* Write the epilogue. *)
|
||||||
_write_z("\tlw ra, 124(sp)\n\tlw s0, 120(sp)\n\taddi sp, sp, 128\n\tret\n\0");
|
_write_z("\tlw ra, 124(sp)\n\tlw s0, 120(sp)\n\taddi sp, sp, 128\n\tret\n\0");
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user