Handle string as data pointer and length in TAC
This commit is contained in:
@@ -48,18 +48,9 @@ task :convert do
|
|||||||
current_stage << line
|
current_stage << line
|
||||||
elsif !seen_proc && line.start_with?('begin')
|
elsif !seen_proc && line.start_with?('begin')
|
||||||
current_stage << <<~CODE
|
current_stage << <<~CODE
|
||||||
proc g(location: ElnaLocation)
|
|
||||||
begin
|
|
||||||
\tprintf("# %i %i\\n\\0", location.line, location.column)
|
|
||||||
end
|
|
||||||
|
|
||||||
proc f()
|
proc f()
|
||||||
var
|
|
||||||
\tlocation: ElnaLocation
|
|
||||||
begin
|
begin
|
||||||
\tlocation.line := 2;
|
\tprintf("# %.*s %p %i\\n\\0".ptr, "location".length, "location".ptr, "location".ptr, "location".length)
|
||||||
\tlocation.column := 3;
|
|
||||||
\tg(location)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
CODE
|
CODE
|
||||||
|
|||||||
+19
-4
@@ -2510,22 +2510,37 @@ proc elna_tac_string_literal(instructions: ^ElnaList, string_literal_node: ^Elna
|
|||||||
var
|
var
|
||||||
offset: Word
|
offset: Word
|
||||||
instruction: ^ElnaTacInstruction
|
instruction: ^ElnaTacInstruction
|
||||||
|
address: ElnaTacOperand
|
||||||
begin
|
begin
|
||||||
offset := elna_tac_add_string(string_literal_node^.value, string_literal_node^.length);
|
offset := elna_tac_add_string(string_literal_node^.value, string_literal_node^.length);
|
||||||
|
|
||||||
elna_tac_make_variable(operand, symbol_table, word_type);
|
elna_tac_make_variable(operand, symbol_table, string_type);
|
||||||
|
elna_tac_make_variable(@address, symbol_table, word_type);
|
||||||
|
|
||||||
instruction := elna_tac_instruction_create(ElnaTacOperator.get_address);
|
instruction := elna_tac_instruction_create(ElnaTacOperator.get_address);
|
||||||
elna_tac_instruction_set_operand(instruction, 1, ElnaTacKind.variable, "strings".ptr, 7);
|
elna_tac_instruction_set_operand(instruction, 1, ElnaTacKind.variable, "strings".ptr, 7);
|
||||||
elna_tac_instruction_set_operand(instruction, 2, operand^.kind, operand^.value, operand^.length);
|
elna_tac_instruction_set_operand(instruction, 2, address.kind, address.value, address.length);
|
||||||
elna_list_append(instructions, instruction);
|
elna_list_append(instructions, instruction);
|
||||||
|
|
||||||
(* Add offset to the string block pointer. *)
|
(* Add offset to the string block pointer. *)
|
||||||
instruction := elna_tac_instruction_create(ElnaTacOperator.add);
|
instruction := elna_tac_instruction_create(ElnaTacOperator.add);
|
||||||
elna_tac_instruction_set_operand(instruction, 1, operand^.kind, operand^.value, operand^.length);
|
elna_tac_instruction_set_operand(instruction, 1, address.kind, address.value, address.length);
|
||||||
elna_tac_instruction_set_operand(instruction, 2, ElnaTacKind.constant, offset, 4);
|
elna_tac_instruction_set_operand(instruction, 2, ElnaTacKind.constant, offset, 4);
|
||||||
elna_tac_instruction_set_operand(instruction, 3, operand^.kind, operand^.value, operand^.length);
|
elna_tac_instruction_set_operand(instruction, 3, address.kind, address.value, address.length);
|
||||||
|
elna_list_append(instructions, instruction);
|
||||||
|
|
||||||
|
instruction := elna_tac_instruction_create(ElnaTacOperator.copy_to_offset);
|
||||||
|
elna_tac_instruction_set_operand(instruction, 1, address.kind, address.value, address.length);
|
||||||
|
elna_tac_instruction_set_operand(instruction, 2, operand^.kind, operand^.value, operand^.length);
|
||||||
|
elna_tac_instruction_set_operand(instruction, 3, ElnaTacKind.constant, 0, 4);
|
||||||
|
elna_list_append(instructions, instruction);
|
||||||
|
|
||||||
|
instruction := elna_tac_instruction_create(ElnaTacOperator.copy_to_offset);
|
||||||
|
elna_tac_instruction_set_operand(instruction, 1, ElnaTacKind.constant, string_literal_node^.length, 4);
|
||||||
|
elna_tac_instruction_set_operand(instruction, 2, operand^.kind, operand^.value, operand^.length);
|
||||||
|
elna_tac_instruction_set_operand(instruction, 3, ElnaTacKind.constant, 4, 4);
|
||||||
elna_list_append(instructions, instruction)
|
elna_list_append(instructions, instruction)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
proc elna_parser_trait_expression(cursor: ^ElnaLexerCursor) -> ^ElnaTreeTraitExpression
|
proc elna_parser_trait_expression(cursor: ^ElnaLexerCursor) -> ^ElnaTreeTraitExpression
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user