summaryrefslogtreecommitdiff
path: root/boot/stage2.elna
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-05-06 23:58:46 +0200
committerEugen Wissner <belka@caraus.de>2025-05-06 23:58:46 +0200
commit40701008f04f2242ab69bfb4bc4f376e6b75429a (patch)
tree4304c2a75004e35e9f198500a484cbfdedab4c5c /boot/stage2.elna
parent3bd86e6e1cf9634af0f45ed526181351328b350d (diff)
downloadelna-40701008f04f2242ab69bfb4bc4f376e6b75429a.tar.gz
Replace _read_token with the lexer
Diffstat (limited to 'boot/stage2.elna')
-rw-r--r--boot/stage2.elna89
1 files changed, 1 insertions, 88 deletions
diff --git a/boot/stage2.elna b/boot/stage2.elna
index 50f1303..62bd307 100644
--- a/boot/stage2.elna
+++ b/boot/stage2.elna
@@ -183,7 +183,6 @@ begin
goto .Lcompile_identifier_expression_end
end
- (* Global identifier. *);
loca8 := 0x6120616c;
_write_out(@loca8, 4);
loca8 := 0x00202c00 or loca80;
@@ -208,11 +207,6 @@ begin
.Lcompile_identifier_expression_end
end
-(*
-Evalutes an expression and saves the result in a0.
-
-a0 - X in aX, the register number to save the result.
-*)
proc _build_expression()
var
loca0, loca20, loca28, loca8: Word
@@ -305,13 +299,6 @@ begin
.Lbuild_expression_end
end
-(*
-Compiles an lvalue.
-
-Parameters:
-a0 - Pointer to the identifier.
-a1 - Identifier length.
-*)
proc _compile_designator_expression(loca84: ^Byte, loca80: Word)
var
loca0: Word
@@ -352,12 +339,6 @@ begin
.Lcompile_designator_expression_end
end
-(*
-Compiles a statement beginning with an identifier.
-
-Left values should be variables named "loca n", where n is the offset
-of the variable on the stack, like loca8 or loca4.
-*)
proc _compile_identifier()
var
loca0, loca16, loca8: Word
@@ -393,13 +374,6 @@ begin
.Lcompile_identifier_end
end
-(*
-Compiles a procedure call. Expects s1 to point to the first argument.
-a0 - Pointer to the procedure name.
-a1 - Length of the procedure name.
-
-Returns the procedure result in a0.
-*)
proc _compile_call(loca84: ^Byte, loca80: Word)
var
loca0, loca4, loca12: Word
@@ -422,10 +396,6 @@ begin
loca0 := 0x202c30;
_write_out(@loca0, 3);
- (*
- Only 6 arguments are supported with a0-a5.
- Save all arguments on the stack so they aren't overriden afterwards.
- *)
loca0 := -4 * loca12;
loca0 := loca0 + 60;
_printi(loca0);
@@ -450,10 +420,7 @@ begin
loca12 := 0;
.Lcompile_call_restore;
- (*
- Just go through all a0-a5 registers and read them from stack.
- If this stack value contains garbage, the procedure just shouldn't use it.
- *)
+
loca0 := 0x6120776c;
_write_out(@loca0, 4);
loca4 := 0x36202c30;
@@ -514,10 +481,6 @@ begin
_advance(1)
end
-(*
-Reads a token and returns its length in a0.
-_read_token doesn't change s1, it finds the length of the token s1 is pointing to.
-*)
proc _read_token()
var
loca0, loca4: Word
@@ -612,7 +575,6 @@ begin
return loca4
end
-(* Skips the spaces till the next non space character. *)
proc _skip_spaces()
var
loca0: Byte
@@ -643,10 +605,6 @@ begin
.Lspace_loop_end
end
-(*
-Parameters:
- a0 - Line length.
-*)
proc _skip_comment(loca84: Word)
var
loca0: ^Byte
@@ -684,10 +642,6 @@ begin
.Lskip_comment_end
end
-(*
-Parameters:
- a0 - Line length.
-*)
proc _compile_assembly(loca84: Word)
var loca0: ^Byte
begin
@@ -846,7 +800,6 @@ begin
loca0 := 0x0a74;
_write_out(@loca0, 2);
- (* .size identifier, size *);
loca0 := 0x7a69732e;
_write_out(@loca0, 4);
loca0 := 0x2065;
@@ -882,7 +835,6 @@ begin
loca20 := _current();
_advance(loca16);
- (* .type identifier, @function *);
loca0 := 0x7079742e;
_write_out(@loca0, 4);
loca0 := 0x2065;
@@ -910,10 +862,6 @@ begin
loca12 := 0x6e;
loca8 := 0x69676562;
- (*
- Skip all declarations until we find the "begin" keyword, denoting the
- beginning of the procedure body.
- *)
.Lcompile_procedure_begin;
_skip_spaces();
loca0 := _read_token();
@@ -1056,15 +1004,6 @@ begin
_write_out(@loca0, 4)
end
-(*
-Compares two string, which of one has a length, the other one is null-terminated.
-
- a0 - The address of the token string.
- a1 - The length of the string in a0.
- a2 - The address of the null-terminated string.
-
-If the strings match sets a0 to 0, otherwise sets it to 1.
-*)
proc _token_compare(loca84: ^Byte, loca80: Word, loca76: ^Byte)
var
loca0: Bool
@@ -1074,10 +1013,6 @@ begin
.Ltoken_compare_loop;
loca4 := _front(loca76);
- (*
- Will only be 0 if the current character in the null terminated string is \0 and the remaining length of the
- another string is 0.
- *)
loca8 := loca4 or loca80;
if loca8 = 0 then
goto .Ltoken_compare_equal
@@ -1135,7 +1070,6 @@ begin
_put_char(0x0a)
end
-(* a0 - Line length. *)
proc _compile_label(loca84: Word)
var
loca0: Word
@@ -1187,7 +1121,6 @@ begin
_write_out(@loca12, 4);
_put_char(0x20);
- (* Write the label *);
_write_out(@loca16, 4);
_printi(s2);
@@ -1213,20 +1146,10 @@ begin
loca12 := 0x0a3a0a3a;
_write_out(@loca12, 2);
- (* Increment the label counter. *);
s2 := s2 + 1;
_advance(4)
end
-(*
-Parameters:
- a0 - Line length.
- a1 - Whether the section header was already emitted. If not it should be
- emitted before any code is written.
-
-Returns 1 in a0 if the parsed line contained a text section element such a
-procedure or the program entry point. Otherwise sets a0 to 0.
-*)
proc _compile_line(loca84: Word, loca80: Bool)
var
loca0: Char
@@ -1407,7 +1330,6 @@ begin
return loca8
end
-(* Prints ".section .text" and exits. *)
proc _compile_text_section()
var loca0: Word
begin
@@ -1466,7 +1388,6 @@ begin
_skip_spaces()
end
-(* Finds the end of the line and returns its length in a0. *)
proc _read_line()
var
loca0: ^Byte
@@ -1520,23 +1441,16 @@ begin
.Lcompile_end
end
-(* Returns the pointer to the current position in the source text in a0. *)
proc _current()
begin
return s1
end
-(* a0 is the number of bytes to advance in the source text. *)
proc _advance(loca84: Word)
begin
s1 := s1 + loca84
end
-(*
-a0 - Pointer to an array to get the first element.
-
-Returns the first character in the remaining source text.
-*)
proc _front(loca84: ^Word)
begin
return _get(loca84) & 0xff
@@ -1549,7 +1463,6 @@ begin
s2 := 1
end
-(* Entry point. *)
begin
_main();
_compile()