Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nenkai committed Apr 19, 2023
1 parent cca4c3c commit 3e99b2c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion GTAdhocToolchain.CodeGen/AdhocCodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public void Generate()

MainBlock.Write(stream);

Logger.Debug($"Code generated (Size: {stream.Length} bytes, {MainBlock.Instructions.Count} main instructions)");
Logger.Info($"Code generated (Size: {stream.Length} bytes, {MainBlock.Instructions.Count} main instructions)");
Logger.Debug($"[Stack] Stack Size: {MainBlock.Stack.GetStackSize()} - Locals: {MainBlock.Stack.GetLocalVariableStorageSize()}");
}

public void SaveTo(string path)
Expand Down
6 changes: 5 additions & 1 deletion GTAdhocToolchain.Compiler/AdhocScriptCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,11 @@ public void CompileSubroutine(AdhocCodeFrame frame, Node parentNode, Node body,
if (frame.Version >= 10)
frame.AddAttributeOrStaticMemberVariable(subroutine.Name);
else
{
// In older versions the subroutines don't count towards the local storage
// Just keep track of it instead
frame.CurrentScope.StaticScopeVariables.Add(subroutine.Name.Name, subroutine.Name);
}

frame.AddInstruction(subroutine, parentNode.Location.Start.Line);

Expand Down Expand Up @@ -1935,7 +1939,7 @@ private void CompileAssignmentExpression(AdhocCodeFrame frame, AssignmentExpress
// Assigning to a variable or literal directly?
if (assignExpression.Operator == AssignmentOperator.Assign)
{
if (frame.Version > 10)
if (frame.Version >= 11)
{
// a = b = c?
if (assignExpression.Right.Type == Nodes.AssignmentExpression)
Expand Down
6 changes: 5 additions & 1 deletion GTAdhocToolchain.Core/AdhocCodeFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ public void AddInstruction(InstructionBase ins, int lineNumber)
case AdhocInstructionType.JUMP:
case AdhocInstructionType.LOCAL_DEFINE:
case AdhocInstructionType.MODULE_DEFINE:
break;

case AdhocInstructionType.STATIC_DEFINE:
break;

case AdhocInstructionType.NOP:
case AdhocInstructionType.SET_STATE_OLD:
case AdhocInstructionType.TRY_CATCH:
Expand Down Expand Up @@ -367,7 +371,7 @@ public void FreeStaticVariable(AdhocSymbol symbol)
{
bool added = Stack.TryAddStaticVariable(symbol, out newVariable);
if (added)
lastScope.StaticScopeVariables.Add(symbol.Name, symbol);
lastScope.StaticScopeVariables.TryAdd(symbol.Name, symbol);
}
else
{
Expand Down
14 changes: 13 additions & 1 deletion GTAdhocToolchain.Preprocessor/AdhocScriptPreprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class AdhocScriptPreprocessor

private string _baseDirectory;
private string _currentFileName;
public string _currentIncludePath;

private DateTime _fileTimeStamp;

/// <summary>
Expand Down Expand Up @@ -349,7 +351,13 @@ private void DoInclude()
string dir = Path.GetDirectoryName(Path.Combine(_baseDirectory, _currentFileName));
string potentialFile = Path.Combine(dir, file);
if (!File.Exists(potentialFile))
ThrowPreprocessorError(_lookahead, "#include: No such file or directory");
{
// Try alternative based on current (include) file
potentialFile = Path.Combine(Path.GetDirectoryName(_currentIncludePath), file);
if (!File.Exists(potentialFile))
ThrowPreprocessorError(_lookahead, $"#include '{file}': No such file or directory");
}


pathToInclude = potentialFile;
}
Expand All @@ -363,8 +371,11 @@ private void DoInclude()
var oldScanner = _scanner;
var oldFileName = _currentFileName;
var oldTimestamp = _fileTimeStamp;
var oldIncludePath = _currentIncludePath;

SetCurrentFileName(file);
_currentIncludePath = pathToInclude;

_fileTimeStamp = new FileInfo(pathToInclude).LastWriteTime;

_writer.WriteLine($"# 1 \"{file}\"");
Expand All @@ -378,6 +389,7 @@ private void DoInclude()
// Restore state
_lookahead = oldToken;
_scanner = oldScanner;
_currentIncludePath = oldIncludePath;
SetCurrentFileName(oldFileName);
_fileTimeStamp = oldTimestamp;

Expand Down

0 comments on commit 3e99b2c

Please sign in to comment.