Skip to content

Commit

Permalink
Make self return type the default return type, remove 'class' keyword…
Browse files Browse the repository at this point in the history
… and simplify names of expression parsers
  • Loading branch information
dzikoysk committed Feb 8, 2021
1 parent 8d343c1 commit 5210730
Show file tree
Hide file tree
Showing 35 changed files with 180 additions and 214 deletions.
10 changes: 5 additions & 5 deletions examples/lang/type.panda
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ type Methods {

shared Int count = 5

shared initialize() {
shared initialize () {
staticMethod()
anotherInitialize('Another initialize')

Int count = count(10)
log count
}

shared count(Int count) -> Int {
shared count (Int count) -> Int {
return count
}

shared anotherInitialize(String message) {
shared anotherInitialize (String message) {
log message
}

shared static staticMethod() {
shared static staticMethod () {
anotherStaticMethod('Another static method')
}

shared static anotherStaticMethod(String message) {
shared static anotherStaticMethod (String message) {
log message
}

Expand Down
4 changes: 2 additions & 2 deletions examples/performance/matmul.panda
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Matrix multiplication algorithm

Algorithm for multiplying two 100x100 matrices using the standard cubic-time algorithm.
This benchmark evaluates the performance of nested loops with a simple inner loop, which is frequent in scientific computing.
This benchmark evaluates the performance of nested loops with a simple internal loop, which is frequent in scientific computing.

The algorithm uses the slowest elements like math on non primitive numbers, arrays accessors and initializers.
It's useful to have a view at the overall performance of these mechanics.
Expand All @@ -29,7 +29,7 @@

*/

internal class Matmul {
internal type Matmul {

internal matgen(Int n) -> Double[][] {
Double[][] a = new Double[n][n]
Expand Down
16 changes: 8 additions & 8 deletions examples/summary-example/src/app.panda
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ main {
creaseValue++
log creaseValue

// create instance of class imported from another file
// create instance of type imported from another file
// should use generated default constructor
Required required = new Required()
required.hello()
Expand Down Expand Up @@ -152,8 +152,8 @@ main {
//log primitiveArray[0]
// log new String(primitiveArray)

// Use class from imported internal module
LocalModuleClass.hello()
// Use type from imported internal module
LocalModule.hello()

// Autocast
Int intValue = 10
Expand All @@ -179,25 +179,25 @@ shared interface IEcho {
shared static anotherEcho (String doSth) -> String

// standard method to impl
internal 'self test' () -> self
internal 'self test' ()

}

// simple class that extends class Test and implements interface IEcho
// simple type that extends Test type and implements interface IEcho
shared type Foo : Test, IEcho {

constructor () {
base('We need to call base constructor if we extend another type with custom constructor')
}

// we need to mark overridden methods by the keyword
override static anotherEcho (String message1) -> String {
override static anotherEcho (String message1) -> String {
log message1
return this
}

// we need to impl all methods
override 'self test' () -> self { }
override 'self test' () { }

override toString () -> String {
return 'Foo'
Expand Down Expand Up @@ -242,7 +242,7 @@ internal type Test {
}

// static field that creates instance of the current class
// open static Test TEST = { new Test('Static initialization of class instance') }
// open static Test TEST = { new Test('Static initialization of type instance') }

shared echo (Object message3) {
log message3
Expand Down
6 changes: 3 additions & 3 deletions examples/summary-example/src/local-module/type.panda
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open type LocalModuleClass {
open type LocalModule {

open static hello() {
log 'Local Module Class'
open static hello () {
log 'Local Module'
}

}
6 changes: 3 additions & 3 deletions examples/summary-example/src/required.panda
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// export StringUtils class, this class will be visible in another files
// export StringUtils class, this type will be visible in another files
export org.panda_lang.utilities.commons.StringUtils

// shared class to test visibility access
// shared type to test visibility access
shared type Required {

// should generate default empty constructor

shared hello() {
log "Required print"

// Imported by current_test.panda java class should not be visible
// Imported by current_test.panda java type should not be visible
// Console.print(PandaConstants.VERSION)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static State of(Class<?> clazz) {
* @return the state
*/
public static State of(String state) {
return (state.equals(Keywords.TYPE.getValue()) || state.equals(Keywords.CLASS.getValue())) ? State.DEFAULT : State.ABSTRACT;
return state.equals(Keywords.TYPE.getValue()) ? State.DEFAULT : State.ABSTRACT;
}

public static void requireInstantiation(Context<?> context, Type type, Snippetable source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ public enum Visibility {
* May be accessed from the associated module and its submodules
*/
SHARED(1),
/**
* May be accessed from the associated module and its submodules
*/
INTERNAL(2),
/**
* May be accessed only from the same source file or by inheritance
*/
INTERNAL(2);
CLOSED(3);

private final int modifier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
* limitations under the License.
*/

package org.panda_lang.panda.language.syntax.expressions.subparsers;

import org.panda_lang.framework.interpreter.parser.expression.ExpressionSubparser;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionSubparserWorker;
package org.panda_lang.framework.interpreter.parser.expression;

public abstract class AbstractExpressionSubparserWorker implements ExpressionSubparserWorker {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class Keywords {

public static final Keyword CATCH = add(VALUES, new Keyword("catch"));

public static final Keyword CLASS = add(VALUES, new Keyword("class"));
public static final Keyword CLOSED = add(VALUES, new Keyword("closed"));

public static final Keyword CONSTRUCTOR = add(VALUES, new Keyword("constructor"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.panda_lang.panda.language.syntax;

import org.panda_lang.framework.architecture.expression.Expression;
import org.panda_lang.framework.architecture.type.Visibility;
import org.panda_lang.framework.interpreter.parser.Context;
import org.panda_lang.framework.interpreter.parser.SourceReader;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionParser;
Expand All @@ -26,6 +27,7 @@
import org.panda_lang.framework.interpreter.token.TokenInfo;
import org.panda_lang.framework.resource.syntax.TokenTypes;
import org.panda_lang.framework.resource.syntax.auxiliary.Section;
import org.panda_lang.framework.resource.syntax.keyword.Keywords;
import org.panda_lang.framework.resource.syntax.operator.Operators;
import org.panda_lang.framework.resource.syntax.separator.Separators;
import org.panda_lang.panda.language.syntax.type.SignatureParser;
Expand Down Expand Up @@ -63,6 +65,10 @@ public Option<SignatureSource> readSignature() {
);
}

public Option<Visibility> readVisibility() {
return readVariant(Keywords.OPEN, Keywords.SHARED, Keywords.INTERNAL, Keywords.CLOSED).map(Visibility::of);
}

public Option<Section> readGenerics() {
return readBetween(Operators.ANGLE_LEFT, Operators.ANGLE_RIGHT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@

import org.panda_lang.framework.interpreter.parser.expression.ExpressionSubparser;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionSubparsers;
import org.panda_lang.panda.language.syntax.expressions.subparsers.CastExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.ConstructorExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.CreaseExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.DeclarationExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.IsExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.LiteralExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.MethodExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.NegateExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.number.NegativeExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.number.NotBitwiseExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.number.NumberExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.operation.OperationExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.SectionExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.SequenceExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.StaticExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.VariableExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.AssignationExpressionSubparser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.CastParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.InstanceCreationParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.CreaseParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.DeclarationParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.IsParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.LiteralParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.MethodParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.NegateParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.number.NegativeParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.number.NotBitwiseParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.number.NumberParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.operation.OperationExpressionParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.SectionParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.SequenceParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.StaticParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.VariableParser;
import org.panda_lang.panda.language.syntax.expressions.subparsers.AssignationPrarser;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -43,23 +43,23 @@ public final class PandaExpressions {

public static Collection<ExpressionSubparser> createSubparsers() {
return Arrays.asList(
new AssignationExpressionSubparser(),
new CastExpressionSubparser(),
new ConstructorExpressionSubparser(),
new CreaseExpressionSubparser(),
new DeclarationExpressionSubparser(),
new IsExpressionSubparser(),
new LiteralExpressionSubparser(),
new MethodExpressionSubparser(),
new NegateExpressionSubparser(),
new NegativeExpressionSubparser(),
new NotBitwiseExpressionSubparser(),
new NumberExpressionSubparser(),
new OperationExpressionSubparser(),
new SectionExpressionSubparser(),
new SequenceExpressionSubparser(),
new StaticExpressionSubparser(),
new VariableExpressionSubparser()
new AssignationPrarser(),
new CastParser(),
new InstanceCreationParser(),
new CreaseParser(),
new DeclarationParser(),
new IsParser(),
new LiteralParser(),
new MethodParser(),
new NegateParser(),
new NegativeParser(),
new NotBitwiseParser(),
new NumberParser(),
new OperationExpressionParser(),
new SectionParser(),
new SequenceParser(),
new StaticParser(),
new VariableParser()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.panda_lang.framework.architecture.statement.Variable;
import org.panda_lang.framework.interpreter.parser.Context;
import org.panda_lang.framework.interpreter.parser.PandaParserFailure;
import org.panda_lang.framework.interpreter.parser.expression.AbstractExpressionSubparserWorker;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionCategory;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionContext;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionResult;
Expand All @@ -35,7 +36,7 @@
import org.panda_lang.framework.interpreter.token.TokenInfo;
import org.panda_lang.framework.resource.syntax.operator.Operators;

public final class AssignationExpressionSubparser implements ExpressionSubparser {
public final class AssignationPrarser implements ExpressionSubparser {

@Override
public ExpressionSubparserWorker createWorker(Context<?> context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.panda_lang.framework.architecture.type.signature.Signature;
import org.panda_lang.framework.architecture.type.VisibilityComparator;
import org.panda_lang.framework.interpreter.parser.Context;
import org.panda_lang.framework.interpreter.parser.expression.AbstractExpressionSubparserWorker;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionContext;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionResult;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionSubparser;
Expand All @@ -29,7 +30,7 @@
import org.panda_lang.framework.resource.syntax.keyword.Keywords;
import org.panda_lang.utilities.commons.function.Result;

public final class CastExpressionSubparser implements ExpressionSubparser {
public final class CastParser implements ExpressionSubparser {

@Override
public ExpressionSubparserWorker createWorker(Context<?> context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.panda_lang.framework.architecture.dynamic.accessor.AccessorExpression;
import org.panda_lang.framework.architecture.expression.Expression;
import org.panda_lang.framework.interpreter.parser.Context;
import org.panda_lang.framework.interpreter.parser.expression.AbstractExpressionSubparserWorker;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionCategory;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionContext;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionParserSettings;
Expand All @@ -30,7 +31,7 @@
import org.panda_lang.framework.resource.syntax.operator.CreaseType;
import org.panda_lang.framework.resource.syntax.operator.Operators;

public final class CreaseExpressionSubparser implements ExpressionSubparser {
public final class CreaseParser implements ExpressionSubparser {

@Override
public ExpressionSubparserWorker createWorker(Context<?> context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.panda_lang.framework.architecture.type.signature.Signature;
import org.panda_lang.framework.interpreter.parser.Context;
import org.panda_lang.framework.interpreter.parser.PandaParserFailure;
import org.panda_lang.framework.interpreter.parser.expression.AbstractExpressionSubparserWorker;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionContext;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionResult;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionSubparser;
Expand All @@ -39,7 +40,7 @@
import org.panda_lang.panda.language.syntax.type.SignatureSource;
import org.panda_lang.utilities.commons.function.Option;

public final class DeclarationExpressionSubparser implements ExpressionSubparser {
public final class DeclarationParser implements ExpressionSubparser {

@Override
public ExpressionSubparserWorker createWorker(Context<?> context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.panda_lang.framework.architecture.type.signature.AdjustedExpression;
import org.panda_lang.framework.architecture.type.signature.Signature;
import org.panda_lang.framework.interpreter.parser.Context;
import org.panda_lang.framework.interpreter.parser.expression.AbstractExpressionSubparserWorker;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionCategory;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionContext;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionResult;
Expand All @@ -48,7 +49,7 @@

import java.util.List;

public final class ConstructorExpressionSubparser implements ExpressionSubparser {
public final class InstanceCreationParser implements ExpressionSubparser {

@Override
public ExpressionSubparserWorker createWorker(Context<?> context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.panda_lang.framework.architecture.type.signature.Signature;
import org.panda_lang.framework.architecture.type.Type;
import org.panda_lang.framework.interpreter.parser.Context;
import org.panda_lang.framework.interpreter.parser.expression.AbstractExpressionSubparserWorker;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionContext;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionResult;
import org.panda_lang.framework.interpreter.parser.expression.ExpressionSubparser;
Expand All @@ -30,7 +31,7 @@
import org.panda_lang.framework.resource.syntax.keyword.Keywords;
import org.panda_lang.utilities.commons.function.Result;

public final class IsExpressionSubparser implements ExpressionSubparser {
public final class IsParser implements ExpressionSubparser {

@Override
public ExpressionSubparserWorker createWorker(Context<?> context) {
Expand Down
Loading

0 comments on commit 5210730

Please sign in to comment.