Removed old scope code.

It was flawed to begin with, so it'd need to be redesigned from the
ground up to be put back in.
This commit is contained in:
arookas 2016-03-08 02:25:33 -05:00
parent fbb0430325
commit 23aee05fb4
6 changed files with 0 additions and 131 deletions

View file

@ -66,25 +66,6 @@ namespace arookas {
public int LocalCount {
get {
#if SSC_SCOPES
var locals = 0;
var maxChildLocals = 0;
foreach (var child in this) {
if (child is sunVariableDeclaration || child is sunVariableDefinition) {
++locals;
}
else if (child is sunCompoundStatement) {
locals += child.LocalCount; // HACK: compound statements aren't their own scope
}
else if (!(child is sunFunctionDefinition)) { // don't recurse into function bodies
var childLocals = child.LocalCount;
if (childLocals > maxChildLocals) {
maxChildLocals = childLocals;
}
}
}
return locals + maxChildLocals;
#else
var locals = 0;
foreach (var child in this) {
if (child is sunVariableDeclaration || child is sunVariableDefinition) {
@ -95,7 +76,6 @@ namespace arookas {
}
}
return locals;
#endif
}
}

View file

@ -99,9 +99,6 @@ namespace arookas {
: base(location) { }
public override void Compile(sunCompiler compiler) {
#if SSC_SCOPES
compiler.Context.Scopes.Push();
#endif
var loop = PushLoop(compiler.Context);
TryCompile(Declaration, compiler);
var bodyPrologue = compiler.Binary.Offset;
@ -114,9 +111,6 @@ namespace arookas {
bodyEpilogue.Relocate();
loop.BreakPoint = compiler.Binary.Offset;
compiler.Context.Loops.Pop(compiler);
#if SSC_SCOPES
compiler.Context.Scopes.Pop();
#endif
}
}
class sunForDeclaration : sunNode {

View file

@ -7,16 +7,6 @@
class sunStatementBlock : sunNode {
public sunStatementBlock(sunSourceLocation location)
: base(location) { }
public override void Compile(sunCompiler compiler) {
#if SSC_SCOPES
compiler.Context.Scopes.Push(compiler.Context.Scopes.Top.Type);
#endif
base.Compile(compiler);
#if SSC_SCOPES
compiler.Context.Scopes.Pop();
#endif
}
}
class sunImport : sunNode {

View file

@ -97,11 +97,7 @@ namespace arookas {
}
sunVariableSymbol DeclareVariable(sunIdentifier node, sunSymbolModifiers modifiers) {
var local = (modifiers & sunSymbolModifiers.Local) != 0;
#if SSC_SCOPES
if (local && Scopes.Top.Type == sunScopeType.Function) {
#else
if (local && Scopes.Count > 1) {
#endif
throw new sunLocalFunctionVariableException(node);
}
var name = MangleSymbolName(node.Value, node.Location.ScriptId, false, local);
@ -109,11 +105,7 @@ namespace arookas {
if (symbol == null) {
throw new sunRedeclaredVariableException(node);
}
#if SSC_SCOPES
if (Scopes.Top.Type == sunScopeType.Script) {
#else
if (Scopes.Count == 1) {
#endif
SymbolTable.Add(symbol);
}
return symbol;

View file

@ -5,25 +5,11 @@ using System.Linq;
namespace arookas {
class sunScopeStack : IEnumerable<sunScope> {
List<sunScope> mStack;
#if SSC_SCOPES
int mLocals;
#endif
public int Count {
get { return mStack.Count; }
}
#if SSC_SCOPES
public sunScope Root {
get { return this.FirstOrDefault(i => i.Type == Top.Type); }
}
public sunScope Script {
get { return this.FirstOrDefault(i => i.Type == sunScopeType.Script); }
}
public sunScope Function {
get { return this.FirstOrDefault(i => i.Type == sunScopeType.Function); }
}
#endif
public sunScope Top {
get { return this[Count - 1]; }
}
@ -34,78 +20,32 @@ namespace arookas {
public sunScopeStack() {
mStack = new List<sunScope>(8);
#if SSC_SCOPES
Push(sunScopeType.Script); // push global scope
#else
Push();
#endif
}
public void Push() {
#if SSC_SCOPES
Push(Top.Type);
#else
mStack.Add(new sunScope());
#endif
}
#if SSC_SCOPES
public void Push(sunScopeType type) {
mStack.Add(new sunScope(type));
}
#endif
public void Pop() {
if (Count > 1) {
#if SSC_SCOPES
if (Top.Type == sunScopeType.Script) {
mLocals = 0; // left the function, reset locals
}
#else
// close relocations while we still have references to the symbols
foreach (var variable in Top) {
variable.CloseRelocations();
}
#endif
mStack.RemoveAt(Count - 1);
}
}
public void Clear() {
mStack.Clear();
#if SSC_SCOPES
Push(sunScopeType.Script); // add global scope
mLocals = 0;
#else
Push();
#endif
}
public sunVariableSymbol DeclareVariable(string name) {
#if SSC_SCOPES
switch (Top.Type) {
case sunScopeType.Script: return DeclareGlobal(name);
case sunScopeType.Function: return DeclareLocal(name);
}
return null;
#else
return Top.DeclareVariable(name, Count - 1, Top.VariableCount);
#endif
}
public sunConstantSymbol DeclareConstant(string name, sunExpression expression) {
return Top.DeclareConstant(name, expression);
}
#if SSC_SCOPES
sunVariableSymbol DeclareGlobal(string name) {
// symbol's display/index will be
// filled out by the relocation code
return Top.DeclareVariable(name, 0, 0);
}
sunVariableSymbol DeclareLocal(string name) {
var symbol = Top.DeclareVariable(name, 1, mLocals);
if (symbol != null) {
++mLocals;
}
return symbol;
}
#endif
public IEnumerator<sunScope> GetEnumerator() {
return mStack.GetEnumerator();
@ -117,25 +57,9 @@ namespace arookas {
class sunScope : IEnumerable<sunStorableSymbol> {
List<sunStorableSymbol> mStorables;
#if SSC_SCOPES
sunScopeType mType;
#endif
#if SSC_SCOPES
public sunScopeType Type {
get { return mType; }
}
#endif
#if SSC_SCOPES
public sunScope(sunScopeType type) {
#else
public sunScope() {
#endif
mStorables = new List<sunStorableSymbol>(10);
#if SSC_SCOPES
mType = type;
#endif
}
public int StorableCount {
@ -186,11 +110,4 @@ namespace arookas {
return GetEnumerator();
}
}
#if SSC_SCOPES
enum sunScopeType {
Script,
Function,
}
#endif
}

View file

@ -185,11 +185,7 @@ namespace arookas {
public override void Compile(sunCompiler compiler) {
mOffset = compiler.Binary.Offset;
#if SSC_SCOPES
compiler.Context.Scopes.Push(sunScopeType.Function);
#else
compiler.Context.Scopes.Push();
#endif
foreach (var parameter in Parameters) {
compiler.Context.Scopes.DeclareVariable(parameter); // since there is no AST node for these, they won't affect MaxLocalCount
}