Skip to content

Commit

Permalink
- Adicionado recurso de zoom ao editor de código fonte.
Browse files Browse the repository at this point in the history
- Atualizado a versão do componente AvalonEdit para a mais recente.
- Realizada algumas refatorações automáticas de código.
  • Loading branch information
sharivan committed Apr 24, 2024
1 parent 27f3d11 commit 71c8946
Show file tree
Hide file tree
Showing 32 changed files with 595 additions and 555 deletions.
20 changes: 10 additions & 10 deletions Asm/Assembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public Assembler()
writer = new BinaryWriter(output);
constantOut = new MemoryStream();
constantWritter = new BinaryWriter(constantOut);
issuedLabels = new List<Label>();
bindedLabels = new List<Label>();
externalFunctions = new List<(string, int)>();
sourceCodeLines = new List<(string, int, int)>();
sourceCodeLineMap = new Dictionary<(string, int), int>();
globalVariables = new List<GlobalVariable>();
localVariables = new List<LocalVariable>();
functions = new List<Function>();
issuedLabels = [];
bindedLabels = [];
externalFunctions = [];
sourceCodeLines = [];
sourceCodeLineMap = [];
globalVariables = [];
localVariables = [];
functions = [];
}

public void AddExternalFunctionNames((string, int)[] entries)
Expand Down Expand Up @@ -348,7 +348,7 @@ public void Emit(Assembler other)

for (int i = 0; i < other.issuedLabels.Count; i++)
{
Label label = other.issuedLabels[i];
var label = other.issuedLabels[i];

for (int j = 0; j < label.references.Count; j++)
{
Expand All @@ -360,7 +360,7 @@ public void Emit(Assembler other)
issuedLabels.Add(label);
}

foreach (Label label in other.bindedLabels)
foreach (var label in other.bindedLabels)
{
label.bindedAssembler = this;
label.bindedIP += (int) startPosition;
Expand Down
6 changes: 3 additions & 3 deletions Asm/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ internal Label()
bindedAssembler = null;
bindedIP = -1;

references = new List<(Assembler, int)>();
references = [];
}

private void UpdateReference(Assembler assembler, int index)
{
(Assembler, int) reference = references[index];
Assembler referenceAssembler = reference.Item1;
var reference = references[index];
var referenceAssembler = reference.Item1;
if (assembler != referenceAssembler)
return;

Expand Down
80 changes: 40 additions & 40 deletions Comp/CompilationUnity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ internal CompilationUnity(Compiler compiler, string name, string fileName, bool
FileName = fileName;
IsUnity = isUnity;

imports = new();
importTable = new();
globals = new();
globalTable = new();
fieldAggregations = new();
fieldAggregationTable = new();
typeSets = new();
typeSetTable = new();
functions = new();
functionTable = new();
stringTable = new();
undeclaredTypes = new();
undeclaredTypeTable = new();
imports = [];
importTable = [];
globals = [];
globalTable = [];
fieldAggregations = [];
fieldAggregationTable = [];
typeSets = [];
typeSetTable = [];
functions = [];
functionTable = [];
stringTable = [];
undeclaredTypes = [];
undeclaredTypeTable = [];

GlobalVariableSize = 0;
EntryPoint = null;
Expand All @@ -117,7 +117,7 @@ internal CompilationUnity(Compiler compiler, string name, string fileName, bool

internal ImportResult AddImport(string unityName, out CompilationUnity result)
{
CompilationUnity unity = Compiler.OpenUnity(unityName);
var unity = Compiler.OpenUnity(unityName);
if (unity == null)
{
result = null;
Expand Down Expand Up @@ -153,7 +153,7 @@ public CompilationUnity GetImport(int index)

public CompilationUnity GetImport(string name)
{
return importTable.TryGetValue(name, out CompilationUnity result) ? result : null;
return importTable.TryGetValue(name, out var result) ? result : null;
}

public int GetStringOffset(string value)
Expand All @@ -170,12 +170,12 @@ public int GetStringOffset(string value)

public GlobalVariable FindGlobalVariable(string name, bool searchInImports = true)
{
if (globalTable.TryGetValue(name, out GlobalVariable result))
if (globalTable.TryGetValue(name, out var result))
return result;

if (searchInImports)
{
foreach (CompilationUnity unity in imports)
foreach (var unity in imports)
{
result = unity.FindGlobalVariable(name, false);
if (result != null)
Expand All @@ -193,7 +193,7 @@ public GlobalVariable GetGlobalVariable(int index)

internal GlobalVariable DeclareGlobalVariable(string name, AbstractType type, SourceInterval interval)
{
GlobalVariable result = FindGlobalVariable(name);
var result = FindGlobalVariable(name);
if (result != null)
return null;

Expand All @@ -205,7 +205,7 @@ internal GlobalVariable DeclareGlobalVariable(string name, AbstractType type, So

internal GlobalVariable DeclareGlobalVariable(string name, AbstractType type, SourceInterval interval, object initialValue)
{
GlobalVariable result = FindGlobalVariable(name);
var result = FindGlobalVariable(name);
if (result != null)
return null;

Expand All @@ -218,12 +218,12 @@ internal GlobalVariable DeclareGlobalVariable(string name, AbstractType type, So

public FieldAggregationType FindFieldAggregation(string name, bool searchInImports = true)
{
if (fieldAggregationTable.TryGetValue(name, out FieldAggregationType result))
if (fieldAggregationTable.TryGetValue(name, out var result))
return result;

if (searchInImports)
{
foreach (CompilationUnity unity in imports)
foreach (var unity in imports)
{
result = unity.FindFieldAggregation(name, false);
if (result != null)
Expand All @@ -241,7 +241,7 @@ public FieldAggregationType GeFieldAggregation(int index)

internal StructType DeclareStruct(string name, SourceInterval interval)
{
NamedType nt = FindNamedType(name);
var nt = FindNamedType(name);
if (nt != null)
return null;

Expand All @@ -253,7 +253,7 @@ internal StructType DeclareStruct(string name, SourceInterval interval)

internal ClassType DeclareClass(string name, SourceInterval interval)
{
NamedType nt = FindNamedType(name);
var nt = FindNamedType(name);
if (nt != null)
return null;

Expand All @@ -265,12 +265,12 @@ internal ClassType DeclareClass(string name, SourceInterval interval)

public TypeSetType FindTypeSet(string name, bool searchInImports = true)
{
if (typeSetTable.TryGetValue(name, out TypeSetType result))
if (typeSetTable.TryGetValue(name, out var result))
return result;

if (searchInImports)
{
foreach (CompilationUnity unity in imports)
foreach (var unity in imports)
{
result = unity.FindTypeSet(name, false);
if (result != null)
Expand All @@ -288,7 +288,7 @@ public TypeSetType GetTypeSet(int index)

internal TypeSetType DeclareTypeSet(string name, AbstractType type, SourceInterval interval)
{
NamedType nt = FindNamedType(name);
var nt = FindNamedType(name);
if (nt != null)
return null;

Expand All @@ -300,18 +300,18 @@ internal TypeSetType DeclareTypeSet(string name, AbstractType type, SourceInterv

public NamedType FindNamedType(string name)
{
FieldAggregationType st = FindFieldAggregation(name);
var st = FindFieldAggregation(name);
return st != null ? st : FindTypeSet(name);
}

public Function FindFunction(string name, bool searchInImports = true)
{
if (functionTable.TryGetValue(name, out Function result))
if (functionTable.TryGetValue(name, out var result))
return result;

if (searchInImports)
{
foreach (CompilationUnity unity in imports)
foreach (var unity in imports)
{
result = unity.FindFunction(name, false);
if (result != null)
Expand All @@ -324,7 +324,7 @@ public Function FindFunction(string name, bool searchInImports = true)

internal Function DeclareFunction(FieldAggregationType declaringType, string name, SourceInterval interval, bool isExtern)
{
Function result = FindFunction(name);
var result = FindFunction(name);
if (result != null)
return null;

Expand All @@ -336,12 +336,12 @@ internal Function DeclareFunction(FieldAggregationType declaringType, string nam

internal UnresolvedType FindUndeclaredType(string name)
{
return undeclaredTypeTable.TryGetValue(name, out UnresolvedType result) ? result : null;
return undeclaredTypeTable.TryGetValue(name, out var result) ? result : null;
}

internal UnresolvedType AddUndeclaredType(string name, SourceInterval interval)
{
UnresolvedType result = FindUndeclaredType(name);
var result = FindUndeclaredType(name);
if (result != null)
return result;

Expand Down Expand Up @@ -384,28 +384,28 @@ internal void WriteConstants(Assembler assembler)

internal void Resolve()
{
foreach (UnresolvedType type in undeclaredTypes)
foreach (var type in undeclaredTypes)
{
FieldAggregationType st = FindFieldAggregation(type.Name);
var st = FindFieldAggregation(type.Name);

type.ReferencedType = st ?? throw new CompilerException(type.Interval, $"Tipo não declarado: '{type.Name}'.");
}

foreach (FieldAggregationType st in fieldAggregations)
foreach (var st in fieldAggregations)
st.Resolve();

foreach (TypeSetType ts in typeSets)
foreach (var ts in typeSets)
ts.Resolve();

GlobalVariableSize = 0;
foreach (GlobalVariable global in globals)
foreach (var global in globals)
{
global.Resolve();
global.Offset = GlobalVariableSize;
GlobalVariableSize += Compiler.GetAlignedSize(global.Type.Size);
}

foreach (Function function in functions)
foreach (var function in functions)
function.Resolve();

undeclaredTypes.Clear();
Expand All @@ -417,8 +417,8 @@ internal void EmitStringRelease(Assembler assembler)
Context context = new(this, Interval);
for (int i = 0; i < globals.Count; i++)
{
GlobalVariable g = globals[i];
AbstractType type = g.Type;
var g = globals[i];
var type = g.Type;
type.EmitStringRelease(context, Compiler, assembler, GlobalStartOffset + g.Offset, AbstractType.ReleaseType.GLOBAL);
}
}
Expand Down
Loading

0 comments on commit 71c8946

Please sign in to comment.