Skip to content

Commit

Permalink
i missed one file sorry
Browse files Browse the repository at this point in the history
  • Loading branch information
Romualdo666 committed Jul 28, 2023
1 parent 6205db7 commit f512f2b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
20 changes: 11 additions & 9 deletions UndertaleModLib/Compiler/AssemblyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using UndertaleModLib.Decompiler;
using UndertaleModLib.Models;
using static UndertaleModLib.Models.UndertaleInstruction;
Expand All @@ -27,7 +28,7 @@ public class CodeWriter
public List<VariablePatch> varPatches = new List<VariablePatch>();
public List<FunctionPatch> funcPatches = new List<FunctionPatch>();
public List<StringPatch> stringPatches = new List<StringPatch>();

public Parser.Statement currentFunctionContext = null;
public CodeWriter(CompileContext context)
{
compileContext = context;
Expand Down Expand Up @@ -279,7 +280,6 @@ bool hasLocal(string name)
NameStringID = childNameIndex,
Autogenerated = true
};
compileContext.Data.Functions.Add(childFunction);
compileContext.Data.KnownSubFunctions.Add(patch.Name, childFunction);
Expand Down Expand Up @@ -1300,9 +1300,11 @@ private static void AssembleExpression(CodeWriter cw, Parser.Statement e, Parser
isNewFunc = true
});
}

cw.loopContexts.Push(new LoopContext(endPatch, startPatch));
var oldFuncContext = cw.currentFunctionContext;
cw.currentFunctionContext = e;
AssembleStatement(cw, e.Children[1]); // body
cw.currentFunctionContext = oldFuncContext;
AssembleExit(cw);
cw.loopContexts.Pop();
endPatch.Finish(cw);
Expand Down Expand Up @@ -1778,14 +1780,14 @@ private static void AssembleVariablePush(CodeWriter cw, Parser.Statement e, out
switch (id)
{
case -1:
if (cw.compileContext.BuiltInList.GlobalArray.ContainsKey(name) || cw.compileContext.BuiltInList.GlobalNotArray.ContainsKey(name))
if (cw.compileContext.BuiltInList.GlobalArray.ContainsKey(name) || cw.compileContext.BuiltInList.GlobalNotArray.ContainsKey(name) || (cw.currentFunctionContext != null && cw.compileContext.LocalArgs[cw.currentFunctionContext].ContainsKey(name)))
{
if (CompileContext.GMS2_3 &&
name.In(
(name.In(
"argument0", "argument1", "argument2", "argument3",
"argument4", "argument5", "argument6", "argument7",
"argument8", "argument9", "argument10", "argument11",
"argument12", "argument13", "argument14", "argument15"))
"argument12", "argument13", "argument14", "argument15", "a")))
{
// 2.3 argument (excuse the condition... the ID seems to be lost, so this is the easiest way to check)
cw.varPatches.Add(new VariablePatch()
Expand Down Expand Up @@ -2076,13 +2078,13 @@ private static void AssembleStoreVariable(CodeWriter cw, Parser.Statement s, Dat
int id = s.Children[0].ID;
if (id >= 100000)
id -= 100000;
if (CompileContext.GMS2_3 && (cw.compileContext.BuiltInList.GlobalArray.ContainsKey(s.Children[0].Text) || cw.compileContext.BuiltInList.GlobalNotArray.ContainsKey(s.Children[0].Text)))
if (CompileContext.GMS2_3 && (cw.compileContext.BuiltInList.GlobalArray.ContainsKey(s.Children[0].Text) || cw.compileContext.BuiltInList.GlobalNotArray.ContainsKey(s.Children[0].Text)) || (cw.currentFunctionContext != null && cw.compileContext.LocalArgs[cw.currentFunctionContext].ContainsKey(s.Children[0].Text)))
{
if (s.Children[0].Text.In(
if ((s.Children[0].Text.In(
"argument0", "argument1", "argument2", "argument3",
"argument4", "argument5", "argument6", "argument7",
"argument8", "argument9", "argument10", "argument11",
"argument12", "argument13", "argument14", "argument15"))
"argument12", "argument13", "argument14", "argument15")))
{
cw.varPatches.Add(new VariablePatch()
{
Expand Down
1 change: 1 addition & 0 deletions UndertaleModLib/Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CompileContext
public int LastCompiledArgumentCount = 0;
public Dictionary<string, string> LocalVars = new Dictionary<string, string>();
public Dictionary<string, string> GlobalVars = new Dictionary<string, string>();
public Dictionary<Compiler.Parser.Statement, Dictionary<string, int>> LocalArgs = new();
public Dictionary<string, Dictionary<string, int>> Enums = new Dictionary<string, Dictionary<string, int>>();
public UndertaleCode OriginalCode;
public IList<UndertaleVariable> OriginalReferencedLocalVars;
Expand Down
17 changes: 12 additions & 5 deletions UndertaleModLib/Compiler/Parser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -438,6 +439,7 @@ public static Statement ParseTokens(CompileContext context, List<Lexer.Token> to
context.LocalVars["arguments"] = "arguments";
context.GlobalVars.Clear();
context.Enums.Clear();
context.LocalArgs.Clear();
hasError = false;

// Ensuring an EOF exists
Expand Down Expand Up @@ -671,12 +673,15 @@ private static Statement ParseFunction(CompileContext context)
}

EnsureTokenKind(TokenKind.OpenParen);

var i = 0;
Dictionary<string, int> argsDict = new();
while (remainingStageOne.Count > 0 && !hasError && !IsNextToken(TokenKind.EOF, TokenKind.CloseParen))
{
Statement expr = ParseExpression(context);
if (expr != null)
args.Children.Add(expr);
var token = EnsureTokenKind(TokenKind.ProcVariable);
if (token == null)
return null;
argsDict.Add(token.Text, i);
i++;
if (!IsNextTokenDiscard(TokenKind.Comma))
{
if (!IsNextToken(TokenKind.CloseParen))
Expand All @@ -690,7 +695,9 @@ private static Statement ParseFunction(CompileContext context)

if (EnsureTokenKind(TokenKind.CloseParen) == null) return null;

result.Children.Add(ParseStatement(context));
result.Children.Add(ParseStatement(context)); // most likely parses the body.
context.LocalArgs.Add(result, argsDict);

if (expressionMode)
return result;
else // Whatever you call non-anonymous definitions
Expand Down

0 comments on commit f512f2b

Please sign in to comment.