Skip to content

Commit 027592e

Browse files
committed
code cleanup
1 parent e350d14 commit 027592e

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/UnityScript.Tests/UnityScriptCompilerTestFixture.boo

+13-15
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ class BaseClass:
1010

1111
[Boo.Lang.Extensions.Property(ComputedValue)]
1212
_value as object
13-
14-
abstract def Foo():
15-
pass
1613

1714
[TestFixture]
1815
class UnityScriptCompilerTestFixture:
@@ -22,28 +19,29 @@ class UnityScriptCompilerTestFixture:
2219
[SetUp]
2320
def SetUpCompiler():
2421
compiler = UnityScriptCompiler()
25-
22+
compiler.Parameters.Pipeline = UnityScriptCompiler.Pipelines.CompileToMemory()
23+
compiler.Parameters.ScriptBaseType = BaseClass
24+
compiler.Parameters.ScriptMainMethod = "Awake"
25+
2626
[Test]
2727
def DefaultCompilerParameters():
2828
assert compiler.Parameters.Ducky
2929
assert CompilerOutputType.Library == compiler.Parameters.OutputType
3030

3131
[Test]
3232
def ScriptBaseTypeAndMainMethod():
33-
result = CompileScript("ComputedValue = 42;")
34-
type = result.GeneratedAssembly.GetType("Script")
33+
type = CompileScriptType("ComputedValue = 42;")
3534
assert BaseClass is type.BaseType
3635

37-
b as BaseClass = type()
38-
b.Foo()
36+
b as duck = type()
37+
b.Awake()
3938
assert 42 == b.ComputedValue
4039

4140
[Test]
4241
def ExeEntryPoint():
4342
compiler.Parameters.OutputType = CompilerOutputType.ConsoleApplication
44-
result = CompileScript("public static function Main(argv: String[]): void {}")
45-
generatedAssembly = result.GeneratedAssembly
46-
Assert.AreSame(generatedAssembly.GetType("Script").GetMethod("Main"), generatedAssembly.EntryPoint)
43+
type = CompileScriptType("public static function Main(argv: String[]): void {}")
44+
Assert.AreSame(type.GetMethod("Main"), type.Assembly.EntryPoint)
4745

4846
[Test]
4947
def ModulesAreAnnotatedWithRawArrayIndexing():
@@ -68,11 +66,11 @@ class Bar {}
6866
Assert.IsNull(result.GeneratedAssembly.GetType("Foo"))
6967
Assert.IsNotNull(result.GeneratedAssembly.GetType("Bar"))
7068

71-
def CompileScript(script as string, *defines as (string)):
72-
compiler.Parameters.Pipeline = UnityScriptCompiler.Pipelines.CompileToMemory()
73-
compiler.Parameters.ScriptBaseType = BaseClass
74-
compiler.Parameters.ScriptMainMethod = "Foo"
69+
def CompileScriptType(script as string):
70+
result = CompileScript(script)
71+
return result.GeneratedAssembly.GetType("Script")
7572

73+
def CompileScript(script as string, *defines as (string)):
7674
compiler.Parameters.Input.Clear()
7775
compiler.Parameters.Input.Add(StringInput("Script", script))
7876

src/UnityScript/Steps/ApplySemantics.boo

+8-4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class ApplySemantics(AbstractVisitorCompilerStep):
4949
SetScriptClass(Context, script)
5050

5151
def SetUpMainMethod(module as Module, script as TypeDefinition):
52+
53+
TransformGlobalVariablesIntoFields(module, script)
54+
5255
main = FindExistingMainMethodOn(script)
5356
if main is null:
5457
main = CreateMainMethod(module)
@@ -57,12 +60,13 @@ class ApplySemantics(AbstractVisitorCompilerStep):
5760
Warnings.Add(UnityScriptWarnings.ScriptMainMethodIsImplicitlyDefined(main.LexicalInfo, main.Name))
5861

5962
main.Body.Statements.Extend(module.Globals.Statements)
60-
61-
if UnityScriptParameters.GlobalVariablesBecomeFields:
62-
main.Accept(DeclareGlobalVariables(script))
63-
6463
module.Globals.Statements.Clear()
6564

65+
def TransformGlobalVariablesIntoFields(module as Module, script as TypeDefinition):
66+
if not UnityScriptParameters.GlobalVariablesBecomeFields:
67+
return
68+
module.Globals.Accept(DeclareGlobalVariables(script))
69+
6670
def FindExistingMainMethodOn(typeDef as TypeDefinition):
6771
for member in typeDef.Members:
6872
method = member as Method

0 commit comments

Comments
 (0)