don't use rsp in indirection

This commit is contained in:
sfja 2025-04-02 16:32:51 +02:00
parent c32251b5a0
commit bdff748461
2 changed files with 33 additions and 16 deletions

View File

@ -492,10 +492,32 @@ typedef enum {
PStmtTy_Line, PStmtTy_Line,
PStmtTy_Global, PStmtTy_Global,
PStmtTy_Extern, PStmtTy_Extern,
PStmtTy_Include,
PStmtTy_Define, PStmtTy_Define,
} PStmtTy; } PStmtTy;
typedef struct {
PStmtTy ty;
union {
PLine* line;
char* ident;
};
} PStmt;
void pstmt_free(PStmt* stmt)
{
switch (stmt->ty) {
case PStmtTy_Line:
pline_free(stmt->line);
break;
case PStmtTy_Global:
case PStmtTy_Extern:
case PStmtTy_Define:
free(stmt->ident);
break;
}
free(stmt);
}
typedef struct { typedef struct {
Lexer lexer; Lexer lexer;
Tok tok; Tok tok;
@ -1063,7 +1085,7 @@ typedef struct {
typedef struct { typedef struct {
IdentResolver* re; IdentResolver* re;
Reporter* rep; Reporter* rep;
bool unresolve_is_error; bool second_pass;
} OperandEvaluator; } OperandEvaluator;
static inline uint16_t eval_poperandty_unary(POperandTy ty, uint16_t operand) static inline uint16_t eval_poperandty_unary(POperandTy ty, uint16_t operand)
@ -1131,7 +1153,7 @@ EvaledOperand eval_operand_to_imm(
const IdentResol* re const IdentResol* re
= ident_resolver_resolve(evaluator->re, operand->str); = ident_resolver_resolve(evaluator->re, operand->str);
if (re == NULL) { if (re == NULL) {
if (!evaluator->unresolve_is_error) { if (!evaluator->second_pass) {
return (EvaledOperand) { .ty = EoTy_Imm, .imm = 0 }; return (EvaledOperand) { .ty = EoTy_Imm, .imm = 0 };
} }
REPORTF_ERROR("undefined identifier '%s'", operand->str); REPORTF_ERROR("undefined identifier '%s'", operand->str);
@ -2109,7 +2131,7 @@ int main(int argc, char** argv)
OperandEvaluator evaluator = { OperandEvaluator evaluator = {
.re = &resolver, .re = &resolver,
.rep = &rep, .rep = &rep,
.unresolve_is_error = false, .second_pass = false,
}; };
size_t chunk_capacity = 64; size_t chunk_capacity = 64;
@ -2120,9 +2142,10 @@ int main(int argc, char** argv)
int res = define_labels(&resolver, lines[i]->labels, ip, &rep); int res = define_labels(&resolver, lines[i]->labels, ip, &rep);
if (res != 0) if (res != 0)
errors_occured = true; errors_occured = true;
ip += pline_assemble(&evaluator, chunk, lines[i], &rep); uint16_t size = pline_assemble(&evaluator, chunk, lines[i], &rep);
if (ip == 0) if (size == 0)
errors_occured = true; errors_occured = true;
ip += size;
} }
if (errors_occured) { if (errors_occured) {
@ -2131,7 +2154,7 @@ int main(int argc, char** argv)
goto leave_free_chunk; goto leave_free_chunk;
} }
evaluator.unresolve_is_error = true; evaluator.second_pass = true;
FILE* output_fp = fopen(args.output_file, "wb"); FILE* output_fp = fopen(args.output_file, "wb");
if (!output_fp) { if (!output_fp) {

View File

@ -96,16 +96,10 @@ keyboard_interrupt:
iret iret
put_char: put_char:
; push rbp push rbp
add rsp, rsp, 2
mov u16 [rsp], rbp
mov rbp, rsp mov rbp, rsp
; push r1 push r1
add rsp, rsp, 2 push r2
mov u16 [rsp], r1
; push r2
add rsp, rsp, 2
mov u16 [rsp], r2
mov r2, u16 [screen_y] mov r2, u16 [screen_y]
mul r2, r2, 40 ; vcd_width_in_ch mul r2, r2, 40 ; vcd_width_in_ch