From 31adcc5d6c86a9d68270867d6c22c1cf335018ca Mon Sep 17 00:00:00 2001 From: arookas <arookas@outlook.com> Date: Thu, 31 Dec 2015 05:49:29 -0500 Subject: [PATCH] Made system builtins properties instead of an enum. --- ssc/ast/nodes.functions.cs | 10 +++++----- ssc/ast/nodes.system.cs | 22 ++++++++++---------- ssc/context.cs | 41 +++++++++++++++++++------------------- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/ssc/ast/nodes.functions.cs b/ssc/ast/nodes.functions.cs index 806667a..d063d2e 100644 --- a/ssc/ast/nodes.functions.cs +++ b/ssc/ast/nodes.functions.cs @@ -37,12 +37,12 @@ namespace arookas { : base(location) { } public override void Compile(sunContext context) { - var callableInfo = context.MustResolveCallable(this); - if (!callableInfo.Parameters.ValidateArgumentCount(Arguments.Count)) { - throw new sunArgumentCountException(this, callableInfo); + var symbol = context.MustResolveCallable(this); + if (!symbol.Parameters.ValidateArgumentCount(Arguments.Count)) { + throw new sunArgumentCountException(this, symbol); } Arguments.Compile(context); - callableInfo.OpenCallSite(context, Arguments.Count); + symbol.OpenCallSite(context, Arguments.Count); if (IsStatement) { context.Text.WritePOP(); } @@ -60,7 +60,7 @@ namespace arookas { public sunParameterList(sunSourceLocation location) : base(location) { - int count = this.Count(i => i is sunEllipsis); + var count = this.Count(i => i is sunEllipsis); if (count > 1 || (count > 0 && !(this[Count - 1] is sunEllipsis))) { throw new sunVariadicParameterListException(this); } diff --git a/ssc/ast/nodes.system.cs b/ssc/ast/nodes.system.cs index 2d73887..7b32e5b 100644 --- a/ssc/ast/nodes.system.cs +++ b/ssc/ast/nodes.system.cs @@ -4,7 +4,7 @@ : base(location) { } public override void Compile(sunContext context) { - context.Text.WriteFUNC((int)sunSystemBuiltins.Yield, 0); + context.Yield.OpenCallSite(context, 0); context.Text.WritePOP(); } } @@ -14,7 +14,7 @@ : base(location) { } public override void Compile(sunContext context) { - context.Text.WriteFUNC((int)sunSystemBuiltins.Exit, 0); + context.Exit.OpenCallSite(context, 0); context.Text.WritePOP(); } } @@ -24,7 +24,7 @@ : base(location) { } public override void Compile(sunContext context) { - context.Text.WriteFUNC((int)sunSystemBuiltins.Lock, 0); + context.Lock.OpenCallSite(context, 0); context.Text.WritePOP(); } } @@ -34,7 +34,7 @@ : base(location) { } public override void Compile(sunContext context) { - context.Text.WriteFUNC((int)sunSystemBuiltins.Unlock, 0); + context.Unlock.OpenCallSite(context, 0); context.Text.WritePOP(); } } @@ -45,11 +45,6 @@ protected sunCast(sunSourceLocation location) : base(location) { } - protected void Compile(sunContext context, int index) { - Argument.Compile(context); - context.Text.WriteFUNC(index, 1); - } - sunExpressionFlags sunTerm.GetExpressionFlags(sunContext context) { return sunExpressionFlags.Casts | Argument.Analyze(context); } @@ -60,7 +55,8 @@ : base(location) { } public override void Compile(sunContext context) { - Compile(context, (int)sunSystemBuiltins.Int); + Argument.Compile(context); + context.Int.OpenCallSite(context, 1); } } @@ -69,7 +65,8 @@ : base(location) { } public override void Compile(sunContext context) { - Compile(context, (int)sunSystemBuiltins.Float); + Argument.Compile(context); + context.Float.OpenCallSite(context, 1); } } @@ -78,7 +75,8 @@ : base(location) { } public override void Compile(sunContext context) { - Compile(context, (int)sunSystemBuiltins.Typeof); + Argument.Compile(context); + context.Typeof.OpenCallSite(context, 1); } } } diff --git a/ssc/context.cs b/ssc/context.cs index a3fbedf..b76deb7 100644 --- a/ssc/context.cs +++ b/ssc/context.cs @@ -19,6 +19,15 @@ namespace arookas { public sunLoopStack Loops { get; private set; } public sunImportResolver ImportResolver { get; private set; } + // system builtins + public sunCallableSymbol Yield { get; private set; } + public sunCallableSymbol Exit { get; private set; } + public sunCallableSymbol Lock { get; private set; } + public sunCallableSymbol Unlock { get; private set; } + public sunCallableSymbol Int { get; private set; } + public sunCallableSymbol Float { get; private set; } + public sunCallableSymbol Typeof { get; private set; } + public sunContext() { DataTable = new sunDataTable(); SymbolTable = new sunSymbolTable(); @@ -56,14 +65,14 @@ namespace arookas { mTextOffset = (uint)mWriter.Position; mWriter.PushAnchor(); // match code offsets and writer offsets - // add system builtins (must be same order as constants) - AddSystemBuiltin("yield"); - AddSystemBuiltin("exit"); - AddSystemBuiltin("lock"); - AddSystemBuiltin("unlock"); - AddSystemBuiltin("int"); - AddSystemBuiltin("float"); - AddSystemBuiltin("typeof"); + // add system builtins + Yield = AddSystemBuiltin("yield"); + Exit = AddSystemBuiltin("exit"); + Lock = AddSystemBuiltin("lock"); + Unlock = AddSystemBuiltin("unlock"); + Int = AddSystemBuiltin("int"); + Float = AddSystemBuiltin("float"); + Typeof = AddSystemBuiltin("typeof"); } public void Close() { @@ -219,8 +228,10 @@ namespace arookas { return null; } - void AddSystemBuiltin(string name) { - SymbolTable.Add(new sunBuiltinSymbol(name, SymbolTable.Count)); + sunCallableSymbol AddSystemBuiltin(string name) { + var symbol = new sunBuiltinSymbol(name, SymbolTable.Count); + SymbolTable.Add(symbol); + return symbol; } void WriteHeader() { mWriter.WriteString("SPCB"); @@ -232,14 +243,4 @@ namespace arookas { mWriter.WriteS32(SymbolTable.VariableCount); } } - - enum sunSystemBuiltins { - Yield, - Exit, - Lock, - Unlock, - Int, - Float, - Typeof, - } }