Allow assigning variables refering to aggregates
This commit is contained in:
@@ -38,6 +38,7 @@ desc 'Convert previous stage language into the current stage language'
|
|||||||
task :convert do
|
task :convert do
|
||||||
File.open('boot/stage22/cl.elna', 'w') do |current_stage|
|
File.open('boot/stage22/cl.elna', 'w') do |current_stage|
|
||||||
seen_proc = false
|
seen_proc = false
|
||||||
|
seen_global_var = false
|
||||||
File.readlines('boot/stage21/cl.elna').each do |line|
|
File.readlines('boot/stage21/cl.elna').each do |line|
|
||||||
seen_proc = true if line.start_with? 'proc'
|
seen_proc = true if line.start_with? 'proc'
|
||||||
seen_proc = false if line.start_with? 'end'
|
seen_proc = false if line.start_with? 'end'
|
||||||
@@ -46,7 +47,6 @@ task :convert do
|
|||||||
|
|
||||||
proc f();
|
proc f();
|
||||||
var
|
var
|
||||||
x: ElnaLocation;
|
|
||||||
y: ElnaLocation;
|
y: ElnaLocation;
|
||||||
begin
|
begin
|
||||||
y.line := 1;
|
y.line := 1;
|
||||||
@@ -58,6 +58,11 @@ task :convert do
|
|||||||
begin
|
begin
|
||||||
f();
|
f();
|
||||||
FUN
|
FUN
|
||||||
|
elsif line.start_with?('var') && !seen_global_var
|
||||||
|
current_stage << <<~FUN
|
||||||
|
var
|
||||||
|
x: ElnaLocation;
|
||||||
|
FUN
|
||||||
else
|
else
|
||||||
current_stage << line
|
current_stage << line
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ program;
|
|||||||
|
|
||||||
(* Stage 21 compiler. *)
|
(* Stage 21 compiler. *)
|
||||||
|
|
||||||
|
(* - Allow assigning variables refering to aggregates. *)
|
||||||
|
|
||||||
type
|
type
|
||||||
ElnaListNode = record
|
ElnaListNode = record
|
||||||
next: Word
|
next: Word
|
||||||
@@ -1284,7 +1286,7 @@ begin
|
|||||||
elna_rtl_instruction_set_operand(instruction, 2, source_operand.kind, source_operand.value, source_operand.length, 0);
|
elna_rtl_instruction_set_operand(instruction, 2, source_operand.kind, source_operand.value, source_operand.length, 0);
|
||||||
elna_list_append(instructions, instruction);
|
elna_list_append(instructions, instruction);
|
||||||
else
|
else
|
||||||
elna_rtl_memcpy(instructions, @source_operand, pseudo_symbol^.rtl_type, ElnaRtlKind.pseudo,
|
elna_rtl_memcpy(instructions, @source_operand, pseudo_symbol^.rtl_type, source_operand.kind,
|
||||||
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length)
|
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length)
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
@@ -1548,12 +1550,16 @@ var
|
|||||||
begin
|
begin
|
||||||
(* pseudo or pseudo_mem. *)
|
(* pseudo or pseudo_mem. *)
|
||||||
if instruction^.operands[2].kind <> ElnaRtlKind.data then
|
if instruction^.operands[2].kind <> ElnaRtlKind.data then
|
||||||
|
pseudo_symbol := elna_symbol_table_lookup(variable_map, instruction^.operands[2].value, instruction^.operands[2].length);
|
||||||
|
|
||||||
|
if pseudo_symbol^.kind = ElnaRtlInfoKind.object_info then
|
||||||
pseudo_symbol := elna_alloc_variable(instruction^.operands[2].value, instruction^.operands[2].length,
|
pseudo_symbol := elna_alloc_variable(instruction^.operands[2].value, instruction^.operands[2].length,
|
||||||
variable_map);
|
variable_map);
|
||||||
instruction^.operator := ElnaRtlOperator.addi;
|
instruction^.operator := ElnaRtlOperator.addi;
|
||||||
|
|
||||||
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.register, ElnaRtlRegister.sp, 0, 0);
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.register, ElnaRtlRegister.sp, 0, 0);
|
||||||
elna_rtl_instruction_set_operand(instruction, 3, ElnaRtlKind.immediate, pseudo_symbol^.counter, 0, 0)
|
elna_rtl_instruction_set_operand(instruction, 3, ElnaRtlKind.immediate, pseudo_symbol^.counter, 0, 0)
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
if instruction^.operands[1].kind = ElnaRtlKind.pseudo then
|
if instruction^.operands[1].kind = ElnaRtlKind.pseudo then
|
||||||
elna_alloc_operation_target(instructions, instruction, variable_map)
|
elna_alloc_operation_target(instructions, instruction, variable_map)
|
||||||
|
|||||||
Reference in New Issue
Block a user