Do not support assembly inline statements

This commit is contained in:
2025-09-14 16:55:51 +02:00
parent ee3b733a81
commit c5f2986120
4 changed files with 3561 additions and 22 deletions

View File

@@ -4,6 +4,10 @@
(* Stage 10 compiler. *) (* Stage 10 compiler. *)
(* - Integer division (/). *)
(* - Remainder operation (%). *)
(* - Label declaration statement. A label starts with a dot and *)
(* the statement ends with a semicolon like any other statement. *)
const const
symbol_builtin_name_int := "Int"; symbol_builtin_name_int := "Int";
symbol_builtin_name_word := "Word"; symbol_builtin_name_word := "Word";
@@ -566,6 +570,24 @@ begin
goto .compile_expression_end; goto .compile_expression_end;
end; end;
if v0 = '%' then
_advance_token(1);
_compile_binary_rhs();
(* Execute the operation. *)
_write_z("rem t0, t1, t0\n\0");
goto .compile_expression_end;
end;
if v0 = '/' then
_advance_token(1);
_compile_binary_rhs();
(* Execute the operation. *)
_write_z("div t0, t1, t0\n\0");
goto .compile_expression_end;
end;
if v0 = '<' then if v0 = '<' then
_advance_token(1); _advance_token(1);
v0 := _load_byte(source_code_position); v0 := _load_byte(source_code_position);
@@ -591,7 +613,7 @@ begin
_compile_binary_rhs(); _compile_binary_rhs();
(* Execute the operation. *) (* Execute the operation. *)
_write_z("slt t0, t0, t1\n\0"); _write_z("slt t0, t1, t0\n\0");
goto .compile_expression_end; goto .compile_expression_end;
end; end;
@@ -599,7 +621,6 @@ begin
_advance_token(1); _advance_token(1);
v0 := _load_byte(source_code_position); v0 := _load_byte(source_code_position);
if v0 = '=' then if v0 = '=' then
li t1, '='
_advance_token(1); _advance_token(1);
_compile_binary_rhs(); _compile_binary_rhs();
@@ -739,7 +760,7 @@ begin
_compile_designator(); _compile_designator();
(* Save the assignee address on the stack. *) (* Save the assignee address on the stack. *)
_write_z("\tsw t0, 20(sp)\n\0"); _write_z("\tsw t0, 60(sp)\n\0");
(* Skip the assignment sign (:=) with surrounding whitespaces. *) (* Skip the assignment sign (:=) with surrounding whitespaces. *)
_advance_token(4); _advance_token(4);
@@ -747,7 +768,7 @@ begin
(* Compile the assignment. *) (* Compile the assignment. *)
_compile_expression(); _compile_expression();
_write_z("\tlw t1, 20(sp)\nsw t0, (t1)\n\0"); _write_z("\tlw t1, 60(sp)\nsw t0, (t1)\n\0");
end; end;
proc _compile_return_statement(); proc _compile_return_statement();
@@ -798,12 +819,12 @@ begin
_write_label(v4); _write_label(v4);
_write_z(":\n\0"); _write_z(":\n\0");
_memcmp(source_code_position, "end", 3); if _memcmp(source_code_position, "end", 3) = 0 then
beqz a0, .compile_if_end goto .compile_if_end;
end;
_memcmp(source_code_position, "else", 3); if _memcmp(source_code_position, "else", 3) = 0 then
beqz a0, .compile_if_else goto .compile_if_else
end;
.compile_if_else: .compile_if_else:
(* Skip "else" and newline. *) (* Skip "else" and newline. *)
_advance_token(5); _advance_token(5);
@@ -817,6 +838,17 @@ begin
_write_z(":\n\0"); _write_z(":\n\0");
end; end;
proc _compile_label_declaration();
begin
(* Skip the dot. *)
_advance_token(1);
v0 := _read_token();
_write_c('.');
_write_s(source_code_position, v0);
_write_z(":\n\0");
_advance_token(v0);
end;
proc _compile_statement(); proc _compile_statement();
begin begin
_skip_spaces(); _skip_spaces();
@@ -845,6 +877,11 @@ begin
goto .compile_statement_end; goto .compile_statement_end;
end; end;
if v0 = '.' then
_compile_label_declaration();
goto .compile_statement_semicolon;
end;
_compile_line(); _compile_line();
goto .compile_statement_end; goto .compile_statement_end;
@@ -1047,7 +1084,6 @@ begin
goto .compile_global_initializer_end; goto .compile_global_initializer_end;
end; end;
unimp
.compile_global_initializer_loop: .compile_global_initializer_loop:
_compile_global_initializer(); _compile_global_initializer();
@@ -1206,17 +1242,13 @@ begin
v4 := compiler_strings_position; v4 := compiler_strings_position;
.compile_loop: .compile_loop:
lw t0, 0(sp) if v0 < v4 then
lw t1, 4(sp)
bge t0, t1, .compile_end
v8 := _load_byte(v0); v8 := _load_byte(v0);
v0 := v0 + 1; v0 := v0 + 1;
_write_c(v8); _write_c(v8);
j .compile_loop goto .compile_loop;
end;
.compile_end:
_write_c('"'); _write_c('"');
_write_c('\n'); _write_c('\n');
end; end;

1738
boot/stage11.elna Normal file

File diff suppressed because it is too large Load Diff

1769
boot/stage12.elna Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -696,7 +696,7 @@ begin
_compile_binary_rhs(); _compile_binary_rhs();
(* Execute the operation. *) (* Execute the operation. *)
_write_z("slt t0, t0, t1\n\0"); _write_z("slt t0, t1, t0\n\0");
goto .compile_expression_end; goto .compile_expression_end;