From 3d1f1c4496ba19b36414012414837ff71f40fe32 Mon Sep 17 00:00:00 2001 From: dzikoysk Date: Wed, 8 Jul 2020 00:46:48 +0200 Subject: [PATCH] GH-532 Rename public visibility to open (Resolve #532) --- examples/package_manager/panda.hjson | 2 +- examples/tests/current_test.panda | 6 +- examples/tests/test-local-module/app.panda | 4 +- .../design/architecture/type/Visibility.java | 2 +- .../type/AbstractExecutableProperty.java | 2 +- .../architecture/type/PandaTypeMetadata.java | 2 +- .../architecture/type/PandaTypeUtils.java | 2 +- .../architecture/type/array/ArrayType.java | 2 +- .../type/generator/TypeGenerator.java | 2 +- .../type/utils/VisibilityComparator.java | 2 +- .../resource/syntax/keyword/Keywords.java | 2 + .../functional/FunctionalPatternTest.java | 4 +- .../resource/syntax/type/FieldParser.java | 2 +- .../resource/syntax/type/MethodParser.java | 2 +- .../resource/syntax/type/TypeParser.java | 2 +- .../panda/examples/ExamplesLauncher.java | 9 ++- .../performance/CurrentTestBenchmark.java | 57 +++++++++++++++++++ 17 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 panda/src/test/java/org/panda_lang/panda/examples/performance/CurrentTestBenchmark.java diff --git a/examples/package_manager/panda.hjson b/examples/package_manager/panda.hjson index de9ee254f..58f4eb145 100644 --- a/examples/package_manager/panda.hjson +++ b/examples/package_manager/panda.hjson @@ -7,6 +7,6 @@ scripts: { } dependencies: [ - github:dzikoysk/panda-dependency@1.0.3 + github:dzikoysk/panda-dependency@1.0.4 ] diff --git a/examples/tests/current_test.panda b/examples/tests/current_test.panda index b1606b885..fac7b064e 100644 --- a/examples/tests/current_test.panda +++ b/examples/tests/current_test.panda @@ -227,8 +227,8 @@ internal class Entity { // random Test class internal class Test { - // public static field INDEX with assigned value - public static Int INDEX = 1 + // open static field INDEX with assigned value + open static Int INDEX = 1 // shared between submodules field shared Test testField @@ -245,7 +245,7 @@ internal class Test { } // static field that creates instance of the current class - public static Test TEST = new Test('Static initialization of class instance') + open static Test TEST = new Test('Static initialization of class instance') shared echo (Object message3) { log message3 diff --git a/examples/tests/test-local-module/app.panda b/examples/tests/test-local-module/app.panda index 8dc9a67b5..11bd58ad8 100644 --- a/examples/tests/test-local-module/app.panda +++ b/examples/tests/test-local-module/app.panda @@ -1,8 +1,8 @@ module test-local-module -public class LocalModuleClass { +open type LocalModuleClass { - public static hello() { + open static hello() { log 'Local Module Class' } diff --git a/panda-framework/src/main/java/org/panda_lang/framework/design/architecture/type/Visibility.java b/panda-framework/src/main/java/org/panda_lang/framework/design/architecture/type/Visibility.java index 8a0b5ce4f..3d6c48e9c 100644 --- a/panda-framework/src/main/java/org/panda_lang/framework/design/architecture/type/Visibility.java +++ b/panda-framework/src/main/java/org/panda_lang/framework/design/architecture/type/Visibility.java @@ -24,7 +24,7 @@ public enum Visibility { /** * May be accessed anywhere */ - PUBLIC(0), + OPEN(0), /** * May be accessed from the associated module and its submodules */ diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/AbstractExecutableProperty.java b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/AbstractExecutableProperty.java index 28254b8db..bcd2450cf 100644 --- a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/AbstractExecutableProperty.java +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/AbstractExecutableProperty.java @@ -83,7 +83,7 @@ public abstract static class PandaParametrizedExecutableBuilder callback; - protected Visibility visibility = Visibility.PUBLIC; + protected Visibility visibility = Visibility.OPEN; protected PropertyParameter[] parameters = ParameterUtils.PARAMETERLESS; protected boolean isNative; diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/PandaTypeMetadata.java b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/PandaTypeMetadata.java index e1b53a325..936960ce3 100644 --- a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/PandaTypeMetadata.java +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/PandaTypeMetadata.java @@ -31,7 +31,7 @@ public class PandaTypeMetadata, TY protected Class javaType; protected String model = TypeModels.CLASS; protected State state = State.DEFAULT; - protected Visibility visibility = Visibility.PUBLIC; + protected Visibility visibility = Visibility.OPEN; protected boolean isNative; protected PandaTypeMetadata() { } diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/PandaTypeUtils.java b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/PandaTypeUtils.java index 2ad163647..7d307d450 100644 --- a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/PandaTypeUtils.java +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/PandaTypeUtils.java @@ -37,7 +37,7 @@ public static Type of(Module module, String name, Class javaType) { .name(name) .module(module) .javaType(javaType) - .visibility(Visibility.PUBLIC) + .visibility(Visibility.OPEN) .state(State.DEFAULT) .model(javaType.isInterface() ? TypeModels.INTERFACE : TypeModels.CLASS) .location(new PandaClassSource(javaType).toLocation()) diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/array/ArrayType.java b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/array/ArrayType.java index 272a0bed8..78ab0f834 100644 --- a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/array/ArrayType.java +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/array/ArrayType.java @@ -37,7 +37,7 @@ public ArrayType(Module module, String name, Class associated, Type type) { .javaType(associated) .model(type.getModel()) .state(type.getState()) - .visibility(Visibility.PUBLIC) + .visibility(Visibility.OPEN) ); this.type = type; diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/generator/TypeGenerator.java b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/generator/TypeGenerator.java index bcc9362c2..42fbb5ccc 100644 --- a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/generator/TypeGenerator.java +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/generator/TypeGenerator.java @@ -52,7 +52,7 @@ protected Type generate(Module module, String name, Class javaType) { .location(new PandaClassSource(javaType).toLocation()) .model(TypeModels.of(javaType)) .state(State.of(javaType)) - .visibility(Visibility.PUBLIC) + .visibility(Visibility.OPEN) .build(); type.addInitializer((typeLoader, initializedType) -> { diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/utils/VisibilityComparator.java b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/utils/VisibilityComparator.java index debb9e90d..9b054b381 100644 --- a/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/utils/VisibilityComparator.java +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/architecture/type/utils/VisibilityComparator.java @@ -44,7 +44,7 @@ public static Option canAccess(Property requested, Context context) { } public static Option canAccess(Property requested, Module currentModule, @Nullable Source currentSource) { - if (requested.getVisibility() == Visibility.PUBLIC) { + if (requested.getVisibility() == Visibility.OPEN) { return Option.none(); } diff --git a/panda-framework/src/main/java/org/panda_lang/framework/language/resource/syntax/keyword/Keywords.java b/panda-framework/src/main/java/org/panda_lang/framework/language/resource/syntax/keyword/Keywords.java index b75b4c383..62664fe03 100644 --- a/panda-framework/src/main/java/org/panda_lang/framework/language/resource/syntax/keyword/Keywords.java +++ b/panda-framework/src/main/java/org/panda_lang/framework/language/resource/syntax/keyword/Keywords.java @@ -82,6 +82,8 @@ public final class Keywords { public static final Keyword NIL = add(VALUES, new Keyword("nil")); + public static final Keyword OPEN = add(VALUES, new Keyword("open")); + public static final Keyword OVERRIDE = add(VALUES, new Keyword("override")); public static final Keyword PUBLIC = add(VALUES, new Keyword("public")); diff --git a/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/pattern/functional/FunctionalPatternTest.java b/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/pattern/functional/FunctionalPatternTest.java index 4f3554b83..d35cf2242 100644 --- a/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/pattern/functional/FunctionalPatternTest.java +++ b/panda-framework/src/test/java/org/panda_lang/framework/language/interpreter/pattern/functional/FunctionalPatternTest.java @@ -46,7 +46,7 @@ class FunctionalPatternTest { @Test void method() { FunctionalPattern functionalPattern = FunctionalPattern.of( - VariantElement.create("visibility").content("public", "shared", "internal"), + VariantElement.create("visibility").content("open", "shared", "internal"), UnitElement.create("isStatic").content("static").optional(), TypeElement.create("type").optional().verify(new NextTokenTypeVerifier(TokenTypes.UNKNOWN, TokenTypes.SEQUENCE)), WildcardElement.create("name").verify(new TokenTypeVerifier(TokenTypes.UNKNOWN, TokenTypes.SEQUENCE)), @@ -76,7 +76,7 @@ void field() { fakeContext.withComponent(Components.EXPRESSION, new PandaExpressionParser(Collections::emptyList)); FunctionalPattern pattern = FunctionalPattern.of( - VariantElement.create("visibility").content(Keywords.PUBLIC.getValue(), Keywords.SHARED.getValue(), Keywords.INTERNAL.getValue()), + VariantElement.create("visibility").content(Keywords.OPEN.getValue(), Keywords.SHARED.getValue(), Keywords.INTERNAL.getValue()), KeywordElement.create(Keywords.STATIC).optional(), KeywordElement.create(Keywords.MUT).optional(), KeywordElement.create(Keywords.NIL).optional(), diff --git a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/FieldParser.java b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/FieldParser.java index 2c7684ff5..264f89905 100644 --- a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/FieldParser.java +++ b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/FieldParser.java @@ -51,7 +51,7 @@ public final class FieldParser extends ParserBootstrap { @Override protected BootstrapInitializer initialize(Context context, BootstrapInitializer initializer) { return initializer.functional(builder -> builder - .variant("visibility").consume(variant -> variant.content(Keywords.PUBLIC, Keywords.SHARED, Keywords.INTERNAL)) + .variant("visibility").consume(variant -> variant.content(Keywords.OPEN, Keywords.SHARED, Keywords.INTERNAL)) .keyword(Keywords.STATIC).optional() .keyword(Keywords.MUT).optional() .keyword(Keywords.NIL).optional() diff --git a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/MethodParser.java b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/MethodParser.java index cd2b88498..9fddbda32 100644 --- a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/MethodParser.java +++ b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/MethodParser.java @@ -66,7 +66,7 @@ public final class MethodParser extends ParserBootstrap { protected BootstrapInitializer initialize(Context context, BootstrapInitializer initializer) { return initializer.functional(pattern -> pattern .keyword(Keywords.OVERRIDE).optional() - .variant("visibility").optional().consume(variant -> variant.content("public", "shared", "internal").map(value -> Visibility.valueOf(value.toString().toUpperCase()))) + .variant("visibility").optional().consume(variant -> variant.content("open", "shared", "internal").map(value -> Visibility.valueOf(value.toString().toUpperCase()))) .keyword(Keywords.STATIC).optional() .wildcard("name").verifyType(TokenTypes.UNKNOWN, TokenTypes.SEQUENCE) .section("parameters", Separators.PARENTHESIS_LEFT) diff --git a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/TypeParser.java b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/TypeParser.java index 24390663e..f58c2dac6 100644 --- a/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/TypeParser.java +++ b/panda/src/main/java/org/panda_lang/panda/language/resource/syntax/type/TypeParser.java @@ -76,7 +76,7 @@ protected BootstrapInitializer initialize(Context context, BootstrapInitia .handler(new FunctionalPatternHandler()) .initializer(new FunctionalPatternInitializer()) .pattern(FunctionalPattern.of( - VariantElement.create("visibility").content(Keywords.PUBLIC, Keywords.SHARED, Keywords.INTERNAL).optional(), + VariantElement.create("visibility").content(Keywords.OPEN, Keywords.SHARED, Keywords.INTERNAL).optional(), VariantElement.create("model").content(Keywords.CLASS, Keywords.TYPE, Keywords.INTERFACE), WildcardElement.create("name").verify(new TokenTypeVerifier(TokenTypes.UNKNOWN)), SubPatternElement.create("extended").optional().of( diff --git a/panda/src/test/java/org/panda_lang/panda/examples/ExamplesLauncher.java b/panda/src/test/java/org/panda_lang/panda/examples/ExamplesLauncher.java index c1fd59481..e1c51e64a 100644 --- a/panda/src/test/java/org/panda_lang/panda/examples/ExamplesLauncher.java +++ b/panda/src/test/java/org/panda_lang/panda/examples/ExamplesLauncher.java @@ -23,11 +23,10 @@ import org.panda_lang.panda.bootstrap.PandaApplicationBootstrap; import org.panda_lang.panda.util.PandaUtils; import org.panda_lang.utilities.commons.TimeUtils; +import org.panda_lang.utilities.commons.function.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.panda_lang.utilities.commons.function.Option; - public final class ExamplesLauncher { public static void launch(String directory, String file) { @@ -57,6 +56,10 @@ public static void launch(Application application) { } public static Application interpret(String directory, String file) { + return interpret("../examples/", directory, file); + } + + public static Application interpret(String prefix, String directory, String file) { Logger logger = LoggerFactory.getLogger(ExamplesLauncher.class); PandaUtils.printJVMUptime(() -> logger); @@ -64,7 +67,7 @@ public static Application interpret(String directory, String file) { Panda panda = factory.createPanda(logger); Option application = PandaApplicationBootstrap.create(panda) - .workingDirectory("../examples/" + directory) + .workingDirectory(prefix + directory) .script(file) .createApplication(); diff --git a/panda/src/test/java/org/panda_lang/panda/examples/performance/CurrentTestBenchmark.java b/panda/src/test/java/org/panda_lang/panda/examples/performance/CurrentTestBenchmark.java new file mode 100644 index 000000000..7199c70f1 --- /dev/null +++ b/panda/src/test/java/org/panda_lang/panda/examples/performance/CurrentTestBenchmark.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2020 Dzikoysk + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.panda_lang.panda.examples.performance; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.runner.RunnerException; +import org.panda_lang.framework.design.architecture.Application; +import org.panda_lang.panda.examples.ExamplesLauncher; +import org.panda_lang.panda.util.BenchmarkUtils; + +import java.util.concurrent.TimeUnit; + +/** + * Just a preview of approximate performance to check some basic behaviours + * + * Bootstrap :: Reflection based injector + * CurrentTestBenchmark.currentTest thrpt 2 0,019 ops/ms + * + * Bootstrap :: Generated method injector + * CurrentTestBenchmark.currentTest thrpt 2 0,025 ops/ms + * + */ +@Fork(value = 1) +@Warmup(iterations = 1) +@Measurement(iterations = 2) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +public class CurrentTestBenchmark { + + @Benchmark + public Object currentTest() { + Application application = ExamplesLauncher.interpret("examples/", "tests", "current_test.panda"); + return application.launch(); + } + + public static void main(String[] args) throws RunnerException { + BenchmarkUtils.run(CurrentTestBenchmark.class); + } + +}