Permalink
Browse files

Finish implementing Mixed everywhere. Enums are first class.

Previously, exec(s) accepted an array of Constructs. While this worked
most of the time, it has serious limitations, because object types that
cannot extend Construct (i.e. enums, exceptions, dynamically defined
classes) cannot be passed around. Now, we use Mixed everywhere, instead
of Construct (at least in the interfaces), and so now things like enums
and other classes can implement Mixed, and be added into the ecosystem.
As part of this change, enums are now proper ClassTypes.

An interesting learning here is that we violated the Liskov Substitution
Pricipal early on. Had we not done that, and used an interface up front,
(depend on abstractions, not concretions) we would not have had to deal
with any of this.

Since this changes the interface of Function, this breaks ALL
extensions, thus the version has been bumped to 3.3.4. I have decided to
not add binary compatibility either, since that would introduce a
runtime penalty for every single function call, in every single script.
  • Loading branch information...
LadyCailin committed Nov 16, 2018
1 parent ffa8160 commit 0923fef84a5cc4607aa5544ed610e1f9c1e52358
Showing with 2,560 additions and 1,947 deletions.
  1. +13 −2 src/main/java/com/laytonsmith/PureUtilities/Common/StringUtils.java
  2. +11 −11 src/main/java/com/laytonsmith/PureUtilities/MSP/Burst.java
  3. +112 −0 src/main/java/com/laytonsmith/core/FullyQualifiedClassName.java
  4. +1 −1 src/main/java/com/laytonsmith/core/LifeCycle.java
  5. +7 −6 src/main/java/com/laytonsmith/core/{CHVersion.java → MSVersion.java}
  6. +1 −1 src/main/java/com/laytonsmith/core/Main.java
  7. +3 −3 src/main/java/com/laytonsmith/core/MethodScriptCompiler.java
  8. +12 −12 src/main/java/com/laytonsmith/core/Optimizable.java
  9. +1 −1 src/main/java/com/laytonsmith/core/Static.java
  10. +2 −2 src/main/java/com/laytonsmith/core/compiler/FileOptions.java
  11. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/AsKeyword.java
  12. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/AutoKeyword.java
  13. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/BindKeyword.java
  14. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/CaseKeyword.java
  15. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/CatchKeyword.java
  16. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/ClosureKeyword.java
  17. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/DefaultKeyword.java
  18. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/DoKeyword.java
  19. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/ElseKeyword.java
  20. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/FalseKeyword.java
  21. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/FinallyKeyword.java
  22. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/ForKeyword.java
  23. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/ForeachKeyword.java
  24. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/IClosureKeyword.java
  25. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/IfKeyword.java
  26. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/InKeyword.java
  27. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/InstanceofKeyword.java
  28. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/NotInstanceofKeyword.java
  29. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/NullKeyword.java
  30. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/ProcKeyword.java
  31. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/SwitchKeyword.java
  32. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/SynchronizedKeyword.java
  33. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/TrueKeyword.java
  34. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/TryKeyword.java
  35. +2 −2 src/main/java/com/laytonsmith/core/compiler/keywords/WhileKeyword.java
  36. +2 −2 src/main/java/com/laytonsmith/core/constructs/CArray.java
  37. +2 −2 src/main/java/com/laytonsmith/core/constructs/CBoolean.java
  38. +4 −4 src/main/java/com/laytonsmith/core/constructs/CByteArray.java
  39. +60 −55 src/main/java/com/laytonsmith/core/constructs/CClassType.java
  40. +2 −2 src/main/java/com/laytonsmith/core/constructs/CClosure.java
  41. +2 −2 src/main/java/com/laytonsmith/core/constructs/CDecimal.java
  42. +2 −2 src/main/java/com/laytonsmith/core/constructs/CDouble.java
  43. +2 −2 src/main/java/com/laytonsmith/core/constructs/CIClosure.java
  44. +2 −2 src/main/java/com/laytonsmith/core/constructs/CInt.java
  45. +2 −2 src/main/java/com/laytonsmith/core/constructs/CMutablePrimitive.java
  46. +2 −2 src/main/java/com/laytonsmith/core/constructs/CNull.java
  47. +2 −2 src/main/java/com/laytonsmith/core/constructs/CNumber.java
  48. +2 −2 src/main/java/com/laytonsmith/core/constructs/CNumberRunner.java
  49. +2 −2 src/main/java/com/laytonsmith/core/constructs/CPackage.java
  50. +2 −2 src/main/java/com/laytonsmith/core/constructs/CPrimitive.java
  51. +2 −2 src/main/java/com/laytonsmith/core/constructs/CPrimitiveRunner.java
  52. +2 −2 src/main/java/com/laytonsmith/core/constructs/CResource.java
  53. +2 −2 src/main/java/com/laytonsmith/core/constructs/CSecureString.java
  54. +2 −2 src/main/java/com/laytonsmith/core/constructs/CSlice.java
  55. +2 −2 src/main/java/com/laytonsmith/core/constructs/CString.java
  56. +2 −2 src/main/java/com/laytonsmith/core/constructs/CVoid.java
  57. +121 −42 src/main/java/com/laytonsmith/core/constructs/NativeTypeList.java
  58. +0 −1 src/main/java/com/laytonsmith/core/events/BoundEvent.java
  59. +21 −21 src/main/java/com/laytonsmith/core/events/drivers/BlockEvents.java
  60. +4 −4 src/main/java/com/laytonsmith/core/events/drivers/CmdlineEvents.java
  61. +38 −38 src/main/java/com/laytonsmith/core/events/drivers/EntityEvents.java
  62. +14 −14 src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java
  63. +49 −49 src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java
  64. +3 −3 src/main/java/com/laytonsmith/core/events/drivers/PluginEvents.java
  65. +7 −7 src/main/java/com/laytonsmith/core/events/drivers/ServerEvents.java
  66. +7 −7 src/main/java/com/laytonsmith/core/events/drivers/VehicleEvents.java
  67. +4 −4 src/main/java/com/laytonsmith/core/events/drivers/WeatherEvents.java
  68. +5 −5 src/main/java/com/laytonsmith/core/events/drivers/WorldEvents.java
  69. +2 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/AbstractCREException.java
  70. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityException.java
  71. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREBadEntityTypeException.java
  72. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREBindException.java
  73. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CRECastException.java
  74. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREEnchantmentException.java
  75. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREError.java
  76. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREEventException.java
  77. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREException.java
  78. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREFormatException.java
  79. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREIOException.java
  80. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREIllegalArgumentException.java
  81. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREIncludeException.java
  82. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREIndexOverflowException.java
  83. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientArgumentsException.java
  84. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREInsufficientPermissionException.java
  85. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidPluginException.java
  86. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidProcedureException.java
  87. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREInvalidWorldException.java
  88. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CRELengthException.java
  89. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CRENotFoundException.java
  90. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CRENullPointerException.java
  91. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREOAuthException.java
  92. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREPlayerOfflineException.java
  93. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginChannelException.java
  94. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREPluginInternalException.java
  95. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CRERangeException.java
  96. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREReadOnlyException.java
  97. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CRESQLException.java
  98. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREScoreboardException.java
  99. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CRESecurityException.java
  100. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREShellException.java
  101. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREStackOverflowError.java
  102. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREThrowable.java
  103. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREUnageableMobException.java
  104. +2 −2 src/main/java/com/laytonsmith/core/exceptions/CRE/CREUntameableMobException.java
  105. +2 −2 src/main/java/com/laytonsmith/core/extensions/ExtensionTracker.java
  106. +64 −64 src/main/java/com/laytonsmith/core/functions/ArrayHandling.java
  107. +62 −62 src/main/java/com/laytonsmith/core/functions/BasicLogic.java
  108. +2 −2 src/main/java/com/laytonsmith/core/functions/BossBar.java
  109. +5 −5 src/main/java/com/laytonsmith/core/functions/BukkitMetadata.java
  110. +45 −45 src/main/java/com/laytonsmith/core/functions/ByteArrays.java
  111. +3 −3 src/main/java/com/laytonsmith/core/functions/Clipboard.java
  112. +33 −33 src/main/java/com/laytonsmith/core/functions/Cmdline.java
  113. +7 −7 src/main/java/com/laytonsmith/core/functions/Commands.java
  114. +2 −2 src/main/java/com/laytonsmith/core/functions/Compiler.java
  115. +23 −23 src/main/java/com/laytonsmith/core/functions/Crypto.java
  116. +90 −90 src/main/java/com/laytonsmith/core/functions/DataHandling.java
  117. +12 −12 src/main/java/com/laytonsmith/core/functions/DataTransformations.java
  118. +17 −17 src/main/java/com/laytonsmith/core/functions/Debug.java
  119. +3 −3 src/main/java/com/laytonsmith/core/functions/DummyFunction.java
  120. +23 −23 src/main/java/com/laytonsmith/core/functions/Echoes.java
  121. +25 −25 src/main/java/com/laytonsmith/core/functions/Enchantments.java
  122. +92 −92 src/main/java/com/laytonsmith/core/functions/EntityManagement.java
  123. +47 −47 src/main/java/com/laytonsmith/core/functions/Environment.java
  124. +26 −26 src/main/java/com/laytonsmith/core/functions/EventBinding.java
  125. +15 −14 src/main/java/com/laytonsmith/core/functions/Exceptions.java
  126. +17 −17 src/main/java/com/laytonsmith/core/functions/ExecutionQueue.java
  127. +5 −5 src/main/java/com/laytonsmith/core/functions/ExtensionMeta.java
  128. +12 −12 src/main/java/com/laytonsmith/core/functions/FileHandling.java
  129. +0 −1 src/main/java/com/laytonsmith/core/functions/FunctionList.java
  130. +67 −67 src/main/java/com/laytonsmith/core/functions/InventoryManagement.java
  131. +11 −11 src/main/java/com/laytonsmith/core/functions/ItemMeta.java
  132. +5 −5 src/main/java/com/laytonsmith/core/functions/Marquee.java
  133. +99 −68 src/main/java/com/laytonsmith/core/functions/Math.java
  134. +28 −28 src/main/java/com/laytonsmith/core/functions/Meta.java
  135. +30 −30 src/main/java/com/laytonsmith/core/functions/Minecraft.java
  136. +73 −73 src/main/java/com/laytonsmith/core/functions/MobManagement.java
  137. +3 −3 src/main/java/com/laytonsmith/core/functions/OAuth.java
  138. +3 −3 src/main/java/com/laytonsmith/core/functions/Performance.java
  139. +3 −3 src/main/java/com/laytonsmith/core/functions/Permissions.java
  140. +11 −11 src/main/java/com/laytonsmith/core/functions/Persistence.java
  141. +160 −160 src/main/java/com/laytonsmith/core/functions/PlayerManagement.java
  142. +13 −13 src/main/java/com/laytonsmith/core/functions/PluginMeta.java
  143. +6 −6 src/main/java/com/laytonsmith/core/functions/Recipes.java
  144. +16 −17 src/main/java/com/laytonsmith/core/functions/Reflection.java
  145. +13 −13 src/main/java/com/laytonsmith/core/functions/Regex.java
  146. +3 −3 src/main/java/com/laytonsmith/core/functions/ResourceManager.java
  147. +4 −4 src/main/java/com/laytonsmith/core/functions/SQL.java
  148. +11 −11 src/main/java/com/laytonsmith/core/functions/Sandbox.java
  149. +19 −19 src/main/java/com/laytonsmith/core/functions/Scheduling.java
  150. +41 −41 src/main/java/com/laytonsmith/core/functions/Scoreboards.java
  151. +50 −50 src/main/java/com/laytonsmith/core/functions/StringHandling.java
  152. +3 −3 src/main/java/com/laytonsmith/core/functions/TaskHandling.java
  153. +6 −6 src/main/java/com/laytonsmith/core/functions/Threading.java
  154. +8 −8 src/main/java/com/laytonsmith/core/functions/Trades.java
  155. +11 −11 src/main/java/com/laytonsmith/core/functions/Weather.java
  156. +6 −6 src/main/java/com/laytonsmith/core/functions/Web.java
  157. +45 −45 src/main/java/com/laytonsmith/core/functions/World.java
  158. +5 −5 src/main/java/com/laytonsmith/core/functions/XGUI.java
  159. +7 −7 src/main/java/com/laytonsmith/core/functions/bash/BasicLogic.java
  160. +3 −3 src/main/java/com/laytonsmith/core/functions/bash/Compiler.java
  161. +2 −2 src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccessRunner.java
  162. +252 −24 src/main/java/com/laytonsmith/core/natives/interfaces/MEnumType.java
  163. +24 −0 src/main/java/com/laytonsmith/core/natives/interfaces/MEnumTypeValue.java
  164. +1 −1 src/main/java/com/laytonsmith/core/natives/interfaces/Mixed.java
  165. +2 −2 src/main/java/com/laytonsmith/core/natives/interfaces/MixedRunner.java
  166. +6 −0 src/main/java/com/laytonsmith/core/natives/interfaces/ObjectModifier.java
  167. +2 −2 src/main/java/com/laytonsmith/core/natives/interfaces/SizableRunner.java
  168. +11 −11 src/main/java/com/laytonsmith/core/snapins/CorePermissions.java
  169. +14 −14 src/main/java/com/laytonsmith/core/snapins/PackagePermission.java
  170. +7 −7 src/main/java/com/laytonsmith/core/taskmanager/CoreTaskType.java
  171. +3 −3 src/main/java/com/laytonsmith/persistence/CSVDataSource.java
  172. +11 −11 src/main/java/com/laytonsmith/persistence/DataSource.java
  173. +3 −3 src/main/java/com/laytonsmith/persistence/INIDataSource.java
  174. +3 −3 src/main/java/com/laytonsmith/persistence/JSONDataSource.java
  175. +3 −3 src/main/java/com/laytonsmith/persistence/MemoryDataSource.java
  176. +3 −3 src/main/java/com/laytonsmith/persistence/MySQLDataSource.java
  177. +3 −3 src/main/java/com/laytonsmith/persistence/RedisDataSource.java
  178. +3 −3 src/main/java/com/laytonsmith/persistence/SQLiteDataSource.java
  179. +3 −3 src/main/java/com/laytonsmith/persistence/SerializedPersistence.java
  180. +3 −3 src/main/java/com/laytonsmith/persistence/XMLDataSource.java
  181. +3 −3 src/main/java/com/laytonsmith/persistence/YMLDataSource.java
  182. +0 −1 src/main/java/com/laytonsmith/tools/ShellEventMixin.java
  183. +4 −1 src/main/java/com/laytonsmith/tools/SyntaxHighlighters.java
  184. +3 −2 src/main/java/com/laytonsmith/tools/docgen/sitedeploy/APIBuilder.java
  185. +8 −8 src/main/java/com/laytonsmith/tools/docgen/sitedeploy/SiteDeploy.java
  186. +2 −2 src/main/java/com/laytonsmith/tools/pnviewer/PNViewer.java
  187. +8 −7 src/test/java/com/laytonsmith/core/constructs/ClassInfoTest.java
  188. +111 −0 src/test/java/com/laytonsmith/core/constructs/EnumTest.java
  189. +7 −3 src/test/java/com/laytonsmith/core/constructs/TestCClassType.java
  190. +0 −1 src/test/java/com/laytonsmith/core/events/PrefiltersTest.java
  191. +0 −1 src/test/java/com/laytonsmith/core/functions/ArrayHandlingTest.java
@@ -100,10 +100,21 @@ public static String Join(Map map, String entryGlue, String elementGlue, String
* @param glue The glue to use
* @return The concatenated string
*/
public static String Join(Set set, String glue) {
public static <T> String Join(Set<T> set, String glue) {
return Join(set, glue, null, null, null);
}
/**
* Joins a set together, rendering each item with the custom renderer.
* @param set
* @param glue
* @param r
* @return
*/
public static <T> String Join(Set<T> set, String glue, Renderer<T> r) {
return Join(set, glue, null, null, null, r);
}
/**
* Joins a set together (using StringBuilder's {
*
@@ -150,7 +161,7 @@ public static String Join(Set set, String glue, String lastGlue, String glueForT
* @param empty If the set is completely empty, this string is simply returned. If null, an empty string is used.
* @return The concatenated string
*/
public static String Join(Set set, String glue, String lastGlue, String glueForTwoItems, String empty) {
public static <T> String Join(Set<T> set, String glue, String lastGlue, String glueForTwoItems, String empty) {
return Join(set, glue, lastGlue, glueForTwoItems, empty, null);
}
@@ -1,6 +1,6 @@
package com.laytonsmith.PureUtilities.MSP;
import com.laytonsmith.core.CHVersion;
import com.laytonsmith.core.MSVersion;
import com.laytonsmith.core.SimpleDocumentation;
/**
@@ -20,32 +20,32 @@
public static enum BurstType implements SimpleDocumentation {
@RemoteCapability()
META("Provides meta information to the client/server. The payload will be a json with further information", CHVersion.V3_3_1),
META("Provides meta information to the client/server. The payload will be a json with further information", MSVersion.V3_3_1),
@RemoteCapability()
FUNCTION("This is a static function/procedure call. No rider information is provided, but the payload will"
+ " be a json array, with [0] being the fully qualified function name, and [1..] being the json"
+ " encoded arguments.", CHVersion.V3_3_1),
+ " encoded arguments.", MSVersion.V3_3_1),
@RemoteCapability()
METHOD("This is an instance based method call. The rider will be the json encoded object that this method"
+ " is being called on, and the payload will be the same as " + FUNCTION.name() + "'s payload.", CHVersion.V3_3_1),
+ " is being called on, and the payload will be the same as " + FUNCTION.name() + "'s payload.", MSVersion.V3_3_1),
@RemoteCapability()
RESPONSE("This is a response from a previous call. The payload will be the json encoded response.", CHVersion.V3_3_1),
RESPONSE("This is a response from a previous call. The payload will be the json encoded response.", MSVersion.V3_3_1),
@RemoteCapability()
VOID("This is a response from a previous call, but the function/procedure/method returned void. This"
+ " response is simply to inform the client/server that the response succeeded, while minimizing"
+ " the data transmitted", CHVersion.V3_3_1),
+ " the data transmitted", MSVersion.V3_3_1),
@RemoteCapability()
EXCEPTION("This is a response from a previous call, but the function/procedure/method returned with an exception."
+ " The payload will be the exception type, and the rider will be the exception message", CHVersion.V3_3_1),
+ " The payload will be the exception type, and the rider will be the exception message", MSVersion.V3_3_1),
@RemoteCapability()
ERROR("While handling the request, the remote failed unexpectedly. The payload will simply contain error information"
+ " in an unspecified format, which is intended to be helpful, but should not typically be shown to the"
+ " end user.", CHVersion.V3_3_1);
+ " end user.", MSVersion.V3_3_1);
String doc;
CHVersion version;
MSVersion version;
private BurstType(String doc, CHVersion version) {
private BurstType(String doc, MSVersion version) {
this.doc = doc;
this.version = version;
}
@@ -61,7 +61,7 @@ public String docs() {
}
@Override
public CHVersion since() {
public MSVersion since() {
return version;
}
@@ -0,0 +1,112 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.laytonsmith.core;
import com.laytonsmith.PureUtilities.Common.StringUtils;
import com.laytonsmith.core.constructs.NativeTypeList;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
/**
* This class represents a fully qualified class name. It is better to fully qualify the type once, and then pass that
* around, rather than passing around a string.
*/
public final class FullyQualifiedClassName implements Comparable<FullyQualifiedClassName> {
public static final String PATH_SEPARATOR = ".";
private final String fullyQualifiedName;
private FullyQualifiedClassName(String name) {
Objects.requireNonNull(name, "The name passed in may not be null");
this.fullyQualifiedName = name;
}
/**
* Returns the fully qualified class name for the given reference. This is resolved vs the using statements in the
* file.
*
* <p>NOTE: This function currently doesn't request the using statement list, and until that mechanism is designed,
* this method works exactly the same as forDefaultClass. When accepting non-user input, it is currently and will
* always be ok to use forDefaultClasses. Currently, this also holds true for user input as well, because only
* system classes are defined, but once this feature is implemented, this will have to change, and so this method
* will change, unlike forDefaultClass. So, when given user input, this method should always be used, and eventually
* when this method is changed, it will be a compile error, but if you know for sure it's a system class, you can
* use forDefaultClass instead, and there will be no code changes required in the future.
* @param unqualified
* @return
*/
public static FullyQualifiedClassName forName(String unqualified) {
return forDefaultClasses(unqualified);
}
/**
* If the class is known for sure to be within the default import list, this method can be used.
* @param unqualified
* @return
*/
public static FullyQualifiedClassName forDefaultClasses(String unqualified) {
return new FullyQualifiedClassName(NativeTypeList.resolveNativeType(unqualified));
}
/**
* If you know for a fact that the name is already fully qualified, this step skips qualification. If you aren't
* sure whether or not the name is fully qualified, don't use the method, the other methods will accept a fully
* qualified class name, but not change it, but if it isn't fully qualified, then it will do so.
* @param qualified
* @return
*/
public static FullyQualifiedClassName forFullyQualifiedClass(String qualified) {
return new FullyQualifiedClassName(qualified);
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof FullyQualifiedClassName)) {
return false;
}
return fullyQualifiedName.equals(((FullyQualifiedClassName) obj).fullyQualifiedName);
}
@Override
public int hashCode() {
return fullyQualifiedName.hashCode();
}
/**
* Returns the string representation of the fully qualified class name.
* @return
*/
public String getFQCN() {
return fullyQualifiedName;
}
@Override
public String toString() {
return fullyQualifiedName;
}
@Override
public int compareTo(FullyQualifiedClassName o) {
return this.fullyQualifiedName.compareTo(o.fullyQualifiedName);
}
public boolean isTypeUnion() {
return this.fullyQualifiedName.contains("|");
}
public String getSimpleName() {
List<String> parts = new ArrayList<>();
for(String t : fullyQualifiedName.split("|")) {
String[] sparts = t.split(Pattern.quote(PATH_SEPARATOR));
parts.add(sparts[sparts.length - 1]);
}
return StringUtils.Join(parts, "|");
}
}
@@ -13,6 +13,6 @@
@Override
public Version getVersion() {
return CHVersion.LATEST;
return MSVersion.LATEST;
}
}
@@ -7,7 +7,7 @@
*
*
*/
public enum CHVersion implements Version {
public enum MSVersion implements Version {
V0_0_0("0.0.0"), //Unreleased version
V3_0_1("3.0.1"),
V3_0_2("3.0.2"),
@@ -18,28 +18,29 @@
V3_3_0("3.3.0"),
V3_3_1("3.3.1"),
V3_3_2("3.3.2"),
V3_3_3("3.3.3");
V3_3_3("3.3.3"),
V3_3_4("3.3.4");
final SimpleVersion version;
/**
* This points to the latest version in the series. This should normally only be used for things that report the
* <i>current</i> version, not things that are versioned. This is not an actual enum within the class, this is a
* static member of the class which points to the an actual enum.
*/
public static final CHVersion LATEST;
public static final MSVersion LATEST;
static {
//Dynamically determine the latest value.
CHVersion latest = null;
for(CHVersion v : CHVersion.values()) {
MSVersion latest = null;
for(MSVersion v : MSVersion.values()) {
if(latest == null || v.gt(latest)) {
latest = v;
}
}
LATEST = latest;
}
CHVersion(String version) {
MSVersion(String version) {
this.version = new SimpleVersion(version);
}
@@ -467,7 +467,7 @@ public static void main(String[] args) throws Exception {
}
if(parsedArgs.isFlagSet("online")) {
String url = String.format("https://methodscript.com/docs/%s/API/functions/%s",
CHVersion.LATEST.toString(), f.getName());
MSVersion.LATEST.toString(), f.getName());
System.out.println("Launching browser to " + url);
if(!UIUtils.openWebpage(new URL(url))) {
System.err.println("Could not launch browser");
@@ -1979,7 +1979,7 @@ private static void optimize(ParseTree tree, Stack<List<Procedure>> procs, Set<C
}
}
}
boolean fullyStatic = false;
boolean fullyStatic = true;
boolean hasIVars = false;
for(ParseTree node : children) {
if(node.getData() instanceof CFunction) {
@@ -1988,8 +1988,8 @@ private static void optimize(ParseTree tree, Stack<List<Procedure>> procs, Set<C
if(node.getData() instanceof Construct) {
Construct d = (Construct) node.getData();
if(!d.isDynamic() && !(d instanceof IVariable)) {
fullyStatic = true;
if(d.isDynamic() || (d instanceof IVariable)) {
fullyStatic = false;
}
}
if(node.getData() instanceof IVariable) {
@@ -39,29 +39,29 @@
CONSTANT_OFFLINE("If all the parameters of a function are constant, a function with this optimization"
+ " will be run at compile time, and that value stored, instead of it being run each time. For"
+ " instance, the add function is like this, which means that if you were to do add(2, 2), it would"
+ " simply replace that call with 4, at compile time, which makes it more efficient during runtime.", CHVersion.V3_3_1),
+ " simply replace that call with 4, at compile time, which makes it more efficient during runtime.", MSVersion.V3_3_1),
/**
* If the function will return void, and the effects of the function do not need to be ordered, this can be
* selected, and the function will be run on another thread. Note that this will only be valid if a function
* also can be run async. This is a runtime optimization.
*/
INSTANT_RETURN("Some functions can be run async, and there is no benefit for it to wait around for the operation to finish."
+ " For instance, using sys_out() does not need to wait for the IO to flush before returning control to the script.", CHVersion.V3_3_1),
+ " For instance, using sys_out() does not need to wait for the IO to flush before returning control to the script.", MSVersion.V3_3_1),
/**
* If a function can do some amount of optimization at compile time, but can't simply run the exec() function
* directly, this can be selected, which will cause the function's optimize() method to be called. This is a
* compile time optimization.
*/
OPTIMIZE_CONSTANT("A function may be able to do some optimization if the parameters are constant, but it may be"
+ " a bit more complicated than simply running the function. Otherwise, this is exactly like " + CONSTANT_OFFLINE.getName(), CHVersion.V3_3_1),
+ " a bit more complicated than simply running the function. Otherwise, this is exactly like " + CONSTANT_OFFLINE.getName(), MSVersion.V3_3_1),
/**
* If a function can do some amount of optimization at compile time, even if some of the parameters are dynamic,
* this can be selected, which will cause the function's optimizeDynamic() method to be called. This is a
* compile time optimization.
*/
OPTIMIZE_DYNAMIC("Some functions can do some amount of optimization or compilation checks, even if the function is sent dynamic"
+ " parameters. For instance, if(true, rand(), '1') can be changed simply to rand(), because the condition is hard coded"
+ " to be true. In this case, the compile tree is smaller, which makes it more efficient.", CHVersion.V3_3_1),
+ " to be true. In this case, the compile tree is smaller, which makes it more efficient.", MSVersion.V3_3_1),
/**
* If, given the same parameters, the return of this function could be cached (that is, it is a const function)
* this can be selected. This does not guarantee that the results will be cached, since there is a memory trade
@@ -73,15 +73,15 @@
+ " If the engine determines that it is faster to cache the returned values vs re-running the function,"
+ " it may choose to do so. This is a runtime optimization, and is calculated by the engine itself to determine"
+ " which method is faster, so there is no guarantee that any optimization will occur, however, unless this"
+ " option is specified, it will certainly not.", CHVersion.V3_3_1),
+ " option is specified, it will certainly not.", MSVersion.V3_3_1),
/**
* If this function is terminal, that is, it will ALWAYS interrupt program flow, this can be selected. For
* instance, return() is an example. This is used during optimization, and to give compiler warnings.
*/
TERMINAL("If a function is \"terminal\", that is, it is guaranteed to have abnormal code flow (for instance,"
+ " return() or throw()) it is marked terminal, which is used by the compiler to issue warnings, in the"
+ " event you make some code unreachable by putting it under a terminal statement, and to optimize"
+ " by removing the unreachable code from the code tree.", CHVersion.V3_3_1),
+ " by removing the unreachable code from the code tree.", MSVersion.V3_3_1),
/**
* If a function is "side effect free", that is, if the return value is unused, the function itself does
* nothing, then this optimization can be specified. This is mostly useful for cases where the value returns a
@@ -91,15 +91,15 @@
NO_SIDE_EFFECTS("If a function is \"side effect free\", that is, if the return value is unused, the function"
+ " itself does nothing, then this optimization can be specified. This is mostly useful for cases"
+ " where the value returns a check, but the check has been determined by the compiler to be unused,"
+ " making the entire call itself unneeded, allowing the call itself to be removed from the tree.", CHVersion.V3_3_1),
+ " making the entire call itself unneeded, allowing the call itself to be removed from the tree.", MSVersion.V3_3_1),
/**
* Some functions do want to do linking, but in a special, custom way. If this is specified, then the function
* will have the link() method called on it, in place of the default linking mechanism that the compiler
* provides.
*/
CUSTOM_LINK("Some functions do want to do linking, but in a special, custom way. If this is specified, then"
+ " the function will have the link() method called on it, in place of the default linking mechanism that"
+ " the compiler provides.", CHVersion.V3_3_1),
+ " the compiler provides.", MSVersion.V3_3_1),
/**
* This is a priority optimization function, meaning it needs to be optimized before its children are. This is
* required when optimization of the children could cause different internal behavior, for instance if this
@@ -109,12 +109,12 @@
PRIORITY_OPTIMIZATION("This is a priority optimization function, meaning it needs to be optimized before its children are."
+ " This is required when optimization of the children could cause different internal behavior, for instance"
+ " if this function is expecting the presence of some code element, but the child gets optimized out, this"
+ " would cause an error, even though the user did in fact provide code in that section.", CHVersion.V3_3_1);
+ " would cause an error, even though the user did in fact provide code in that section.", MSVersion.V3_3_1);
private final CHVersion since;
private final MSVersion since;
private final String docs;
private OptimizationOption(String docs, CHVersion since) {
private OptimizationOption(String docs, MSVersion since) {
this.docs = docs;
this.since = since;
}
@@ -130,7 +130,7 @@ public String docs() {
}
@Override
public CHVersion since() {
public MSVersion since() {
return since;
}
@@ -525,7 +525,7 @@ public static Construct resolveConstruct(String val, Target t) throws ConfigRunt
}
// TODO: Once compiler environments are added, we would need to check to see if the value here is a custom
// type. However, as it stands, since we only support the native types, we will just hardcode the check here.
String fqType = NativeTypeList.resolveType(val);
String fqType = NativeTypeList.resolveNativeType(val);
if(fqType != null) {
return CClassType.get(fqType);
} else {
Oops, something went wrong.

0 comments on commit 0923fef

Please sign in to comment.