Skip to content

Commit

Permalink
Improved intermediate emitting for structures.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktMagnus committed Mar 9, 2024
1 parent 682d20c commit 0eb207f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/transpiler/common/instructions/structureInstruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export class StructureInstruction extends Instruction
{
constructor (keyword: string, name: string, parameters: string[])
{
const parameterString = '(' + parameters.join(', ') + ')';
// TODO: The formatting "string" here is a mess. This should instead be solved similar to how functions are formatted.
const parameterString = '\n(\n ' + parameters.join(',\n ') + '\n)';

super(keyword, name, parameterString);

Expand All @@ -14,6 +15,5 @@ export class StructureInstruction extends Instruction
prefix: '',
postfix: '',
};

}
}
8 changes: 4 additions & 4 deletions src/transpiler/intermediate/transpilerIntermediate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Instructions from '../common/instructions';
import * as Intermediates from '../../intermediateLowerer/intermediates';
import { IntermediateKind } from '../../intermediateLowerer/intermediateKind';
import { IntermediateSize } from '../../intermediateLowerer/intermediateSize';
import { IntermediateSymbol } from '../../intermediateLowerer/intermediateSymbols';
import { IntermediateSymbolKind } from '../../intermediateLowerer/intermediateSymbolKind';

Expand Down Expand Up @@ -234,16 +233,17 @@ export class TranspilerIntermediate

private transpileStructure (structureIntermediate: Intermediates.Structure): void
{
const fieldSizes: IntermediateSize[] = [];
const fieldStrings: string[] = [];
for (const field of structureIntermediate.symbol.fields)
{
fieldSizes.push(field.size);
const fieldString = `${field.name}: ${field.size}`;
fieldStrings.push(fieldString);
}

const instruction = new Instructions.Structure(
this.getIntermediateInstructionString(structureIntermediate),
structureIntermediate.symbol.name,
fieldSizes,
fieldStrings,
);

this.instructions.push(instruction);
Expand Down

0 comments on commit 0eb207f

Please sign in to comment.