Do not support assembly inline statements
This commit is contained in:
@@ -4,6 +4,10 @@
|
||||
|
||||
(* 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
|
||||
symbol_builtin_name_int := "Int";
|
||||
symbol_builtin_name_word := "Word";
|
||||
@@ -566,6 +570,24 @@ begin
|
||||
|
||||
goto .compile_expression_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
|
||||
_advance_token(1);
|
||||
v0 := _load_byte(source_code_position);
|
||||
@@ -591,7 +613,7 @@ begin
|
||||
_compile_binary_rhs();
|
||||
|
||||
(* Execute the operation. *)
|
||||
_write_z("slt t0, t0, t1\n\0");
|
||||
_write_z("slt t0, t1, t0\n\0");
|
||||
|
||||
goto .compile_expression_end;
|
||||
end;
|
||||
@@ -599,7 +621,6 @@ begin
|
||||
_advance_token(1);
|
||||
v0 := _load_byte(source_code_position);
|
||||
if v0 = '=' then
|
||||
li t1, '='
|
||||
_advance_token(1);
|
||||
_compile_binary_rhs();
|
||||
|
||||
@@ -739,7 +760,7 @@ begin
|
||||
_compile_designator();
|
||||
|
||||
(* 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. *)
|
||||
_advance_token(4);
|
||||
@@ -747,7 +768,7 @@ begin
|
||||
(* Compile the assignment. *)
|
||||
_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;
|
||||
|
||||
proc _compile_return_statement();
|
||||
@@ -798,12 +819,12 @@ begin
|
||||
_write_label(v4);
|
||||
_write_z(":\n\0");
|
||||
|
||||
_memcmp(source_code_position, "end", 3);
|
||||
beqz a0, .compile_if_end
|
||||
|
||||
_memcmp(source_code_position, "else", 3);
|
||||
beqz a0, .compile_if_else
|
||||
|
||||
if _memcmp(source_code_position, "end", 3) = 0 then
|
||||
goto .compile_if_end;
|
||||
end;
|
||||
if _memcmp(source_code_position, "else", 3) = 0 then
|
||||
goto .compile_if_else
|
||||
end;
|
||||
.compile_if_else:
|
||||
(* Skip "else" and newline. *)
|
||||
_advance_token(5);
|
||||
@@ -817,6 +838,17 @@ begin
|
||||
_write_z(":\n\0");
|
||||
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();
|
||||
begin
|
||||
_skip_spaces();
|
||||
@@ -845,6 +877,11 @@ begin
|
||||
|
||||
goto .compile_statement_end;
|
||||
end;
|
||||
if v0 = '.' then
|
||||
_compile_label_declaration();
|
||||
|
||||
goto .compile_statement_semicolon;
|
||||
end;
|
||||
_compile_line();
|
||||
goto .compile_statement_end;
|
||||
|
||||
@@ -1047,7 +1084,6 @@ begin
|
||||
|
||||
goto .compile_global_initializer_end;
|
||||
end;
|
||||
unimp
|
||||
|
||||
.compile_global_initializer_loop:
|
||||
_compile_global_initializer();
|
||||
@@ -1206,17 +1242,13 @@ begin
|
||||
v4 := compiler_strings_position;
|
||||
|
||||
.compile_loop:
|
||||
lw t0, 0(sp)
|
||||
lw t1, 4(sp)
|
||||
bge t0, t1, .compile_end
|
||||
if v0 < v4 then
|
||||
v8 := _load_byte(v0);
|
||||
v0 := v0 + 1;
|
||||
_write_c(v8);
|
||||
|
||||
v8 := _load_byte(v0);
|
||||
v0 := v0 + 1;
|
||||
_write_c(v8);
|
||||
|
||||
j .compile_loop
|
||||
|
||||
.compile_end:
|
||||
goto .compile_loop;
|
||||
end;
|
||||
_write_c('"');
|
||||
_write_c('\n');
|
||||
end;
|
||||
|
1738
boot/stage11.elna
Normal file
1738
boot/stage11.elna
Normal file
File diff suppressed because it is too large
Load Diff
1769
boot/stage12.elna
Normal file
1769
boot/stage12.elna
Normal file
File diff suppressed because it is too large
Load Diff
@@ -696,7 +696,7 @@ begin
|
||||
_compile_binary_rhs();
|
||||
|
||||
(* Execute the operation. *)
|
||||
_write_z("slt t0, t0, t1\n\0");
|
||||
_write_z("slt t0, t1, t0\n\0");
|
||||
|
||||
goto .compile_expression_end;
|
||||
|
||||
|
Reference in New Issue
Block a user