From 820b98b4a919d3e353e3cdd5f3e8d18ee62ea33c Mon Sep 17 00:00:00 2001 From: JoshuaMK Date: Wed, 26 Jan 2022 01:03:02 -0600 Subject: [PATCH] Attempt to correct INC/DEC access --- ssc/ast/nodes.expressions.cs | 4 ++-- ssc/binary.cs | 2 ++ ssc/relocation.cs | 14 ++++++++++++++ ssc/symbol.cs | 4 ++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ssc/ast/nodes.expressions.cs b/ssc/ast/nodes.expressions.cs index 820a78d..cba7462 100644 --- a/ssc/ast/nodes.expressions.cs +++ b/ssc/ast/nodes.expressions.cs @@ -189,7 +189,7 @@ namespace arookas { public override void Compile(sunCompiler compiler, sunStorableSymbol symbol) { symbol.CompileInc(compiler); - symbol.CompileSet(compiler); + symbol.CompilePop(compiler); } } @@ -199,7 +199,7 @@ namespace arookas { public override void Compile(sunCompiler compiler, sunStorableSymbol symbol) { symbol.CompileDec(compiler); - symbol.CompileSet(compiler); + symbol.CompilePop(compiler); } } } diff --git a/ssc/binary.cs b/ssc/binary.cs index c1a5536..98eed39 100644 --- a/ssc/binary.cs +++ b/ssc/binary.cs @@ -184,6 +184,7 @@ namespace arookas { TraceInstruction("inc {0} {1}", display, index); #endif mText.Writer.Write8(0x06); + mText.Writer.Write8(0x04); mText.Writer.WriteS32(display); mText.Writer.WriteS32(index); } @@ -192,6 +193,7 @@ namespace arookas { TraceInstruction("dec {0} {1}", display, index); #endif mText.Writer.Write8(0x07); + mText.Writer.Write8(0x04); mText.Writer.WriteS32(display); mText.Writer.WriteS32(index); } diff --git a/ssc/relocation.cs b/ssc/relocation.cs index b6de903..64a8028 100644 --- a/ssc/relocation.cs +++ b/ssc/relocation.cs @@ -90,6 +90,20 @@ namespace arookas { } } + class sunVariablePopSite : sunSymbolRelocation { + public sunVariablePopSite(sunBinary binary, sunVariableSymbol symbol) + : base(binary, symbol) { + mBinary.WritePOP(); + } + + public override void Relocate() { + mBinary.Keep(); + mBinary.Goto(mPoint); + mBinary.WritePOP(); + mBinary.Back(); + } + } + class sunVariableIncSite : sunSymbolRelocation { public sunVariableIncSite(sunBinary binary, sunVariableSymbol symbol) : base(binary, symbol) { diff --git a/ssc/symbol.cs b/ssc/symbol.cs index 9f1071e..0de4e71 100644 --- a/ssc/symbol.cs +++ b/ssc/symbol.cs @@ -255,6 +255,7 @@ namespace arookas { } public abstract void CompileGet(sunCompiler compiler); public abstract void CompileSet(sunCompiler compiler); + public abstract void CompilePop(sunCompiler compiler); public virtual void CompileInc(sunCompiler compiler) { CompileGet(compiler); compiler.Binary.WriteINT(1); @@ -305,6 +306,9 @@ namespace arookas { public override void CompileDec(sunCompiler compiler) { OpenRelocation(new sunVariableDecSite(compiler.Binary, this)); } + public override void CompilePop(sunCompiler compiler) { + OpenRelocation(new sunVariablePopSite(compiler.Binary, this)); + } } class sunConstantSymbol : sunStorableSymbol {