Skip to content

Commit

Permalink
GH-556 Enhance implementation of types (#558)
Browse files Browse the repository at this point in the history
* GH-556 Cleanup type domain names

* GH-556 Cleanup type domain names and implement part of the Signature metadata

* GH-556 Support equals/hashCode by Result, transform Signature type to either type or abstract identifier and move tests to the Groovy directory

* GH-556 Add AbstractSignature

* GH-556 Rename pipeline to parser pool and improve stage api by stage service

* GH-556 Simplify modules and loading services, improve relations between signatures and types, refactor type and module parsers

* GH-556 Remove some deprecated classes replaced with a new api

* GH-556 Rewrite throw, return, continue and break parsers

* GH-556 Rewrite log parser

* GH-556 Rewrite while and base call parsers

* GH-556 Rewrite number parser

* GH-556 Add block parser abstraction layer for block-related parsers and support localizable entities

* GH-556 Rewrite for parser

* GH-556 Rewrite for-each parser

* GH-556 Rewrite late declaration parser

* GH-556 Rewrite conditional parser

* GH-556 Add basic type generator

* GH-556 Link type generator with type parser

* GH-556 Rewrite try-catch parser

* GH-556 Rewrite standalone-expression parser

* GH-556 Rewrite self constructor parser

* GH-556 Rewrite field parser

* GH-556 Rewrite method parser

* GH-556 Rewrite assignation parsers

* GH-556 Apply changes from ContextParser in its inheritors

* GH-556 Mark as 0.1.4-alpha

* GH-556 Damn boi it compilesss

* GH-556 Add part of the signature matching logic

* GH-556 Apply changes with various signature types

* GH-556 Fix module and type queries, fix panda qualifier reader and pool parser

* GH-556 Fix several bugs in SourceReader, log/field/method/signature/type parsers, restore generator classes, initialize default modules [...]

* GH-556 Fix several bugs related to lazy loaded types

* GH-556 Respect priorities of registered parsers in the pool

* GH-556 Support negation through the 'not' keyword (Resolve #586)

* GH-556 Remove recursive assignation parser, improve signature merging algorithm, [...]

* GH-556 Support autocasts between primitives (Resolve #587)

* GH-556 Use autocasts as a base resource to determine the result of Type#isAssignableFrom method, fix conditional parser, for-each parser and try-catch parser, [...]

* GH-556 Change synchronized-source instead of root source-stream in  SubparsersUtils#readType utility method

* GH-556 Improve require procedure and replace type based autocasts with reference based

* GH-556 Register primitive types in type generator to avoid duplication of generated wrappers

* GH-556 Support retrying of delegated task, fix conditions and improve class generator, [...]

* GH-556 Fix conditional parser, remove old assignation parser, update deprecated unit tests (Fix #589)

* GH-556 Remove expression transactions (Resolve #594)

* GH-556 Remove functional and linear pattern (Resolve #595)

* GH-556 Simplify method and constructor matching, support simple generic type in type signature

* GH-556 Support generic type content like fields, assignation and constructor

* GH-556 Support methods with generic return type

* GH-556 Support parametrized arguments in method calls

* GH-556 Support reassignation of parametrized types

* GH-556 Fix REPL frame and add part of the generics comparison

* GH-556 Support comparison of generic parameters in signatures
  • Loading branch information
dzikoysk authored Dec 31, 2020
1 parent a99a3b0 commit 37bb134
Show file tree
Hide file tree
Showing 506 changed files with 8,624 additions and 13,792 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The latest indev build
<dependency>
<groupId>org.panda-lang</groupId>
<artifactId>panda</artifactId>
<version>0.1.3-alpha</version>
<version>0.2.0-alpha</version>
</dependency>
```

Expand Down
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

MAVEN_OPTS="-Xverify:none -XX:+TieredCompilation -XX:TieredStopAtLevel=1"
mvn -T 1C install -am -offline
43 changes: 43 additions & 0 deletions examples/lang/generics.panda
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module lang

main {
/* Parametrized instance */
Foo<String> parametrizedType = new Foo<String>('test')

/* Parametrized return type */
String parametrizedValue = parametrizedType.getValue()
// Int invalidValue = genericType.getValue() /* Should not compile */

/* Parametrized arguments */
parametrizedType.setValue(parametrizedValue)
// genericType.setValue(10) /* Should not compile */

/* Parametrized reassignation */
Foo<String> sameParametrizedType = parametrizedType
Foo<Object> lowerParametrizedType = sameParametrizedType
Bar<String> lowerBaseType = sameParametrizedType
Bar<Object> lowerBaseAndParametrizedType = sameParametrizedType
// Foo<Foo> invalidSignature = parametrizedType /* Should not compile */
}

type Foo<V> : Bar<V> {
constructor (V barValue) {
base(barValue)
}
}

type Bar<V> {
internal mut V value

constructor (V value) {
this.value = value
}

shared setValue (V value) {
this.value = value
}

shared getValue () -> V {
return value
}
}
69 changes: 18 additions & 51 deletions examples/tests/current_test.panda
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require java:collections
require 'current_test_required'
// import 'test-local-module' internal module
require 'test-local-module'
require test-local-module

// import java class
import org.panda_lang.panda.PandaConstants
Expand Down Expand Up @@ -54,7 +55,7 @@ main {
log 'Hello Panda', flag, varFoo, s, test, i, math

// verify logic
if !flag {
if not flag {
throw new RuntimeException('Nope If')
}
else if flag {
Expand Down Expand Up @@ -94,12 +95,7 @@ main {
break // or just stop
}

// create TestArray instance and
TestArray testArray = new TestArray(7);
testArray.modify(test)

// print array and some logical expressions
log "Content of " + "array " + testArray.array.asString()
// logical expressions
log "OR v AND: " + (false || false) + ", " + false || true, true && false, true && true
log "Compare: " + 1 > 2, 1 > 2, 1 < 2, 2 < 1
log "Random", (false || false) + ", " + false || true, true && false, true && true, (false || false) + ", " + false || true, true && false, true && true
Expand All @@ -114,6 +110,7 @@ main {
log creaseValue

// create instance of class imported from another file
// should use generated default constructor
Required required = new Required()
required.hello()

Expand Down Expand Up @@ -152,20 +149,21 @@ main {
log 10 + Int.parseInt('5') + list.size()

// map array to iterable in foreach
foreach (String var : new String[10]) { }
// foreach (String var : new Array<String>(10)) { }

// make sure that we can use primitive arrays
PrimitiveChar[] primitiveArray = (')#onlypanda').toCharArray()
Arrays.sort(primitiveArray)
log primitiveArray[0]
log new String(primitiveArray)
// PrimitiveChar[] primitiveArray = (')#onlypanda').toCharArray()
// Arrays.sort(primitiveArray)
//log primitiveArray[0]
// log new String(primitiveArray)

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

// Autocast
Long value = new Int(10)
log value.getClass()
Int intValue = 10
Long longValue = intValue
log longValue.getClass()

// Verify implementation of native equals
Entity a = new Entity("same")
Expand All @@ -191,7 +189,7 @@ shared interface IEcho {
}

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

constructor () {
base('We need to call base constructor if we extend another type with custom constructor')
Expand All @@ -213,7 +211,7 @@ shared class Foo : Test, IEcho {
}

// simple entity to test equality implemented as native method
internal class Entity {
internal type Entity {

internal String name

Expand All @@ -229,7 +227,7 @@ internal class Entity {
}

// random Test class
internal class Test {
internal type Test {

// open static field INDEX with assigned value
open static Int INDEX = 1
Expand All @@ -249,7 +247,7 @@ internal class 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 class instance') }

shared echo (Object message3) {
log message3
Expand All @@ -276,44 +274,13 @@ internal class Test {

}

// array test
internal class TestArray {

// shared array
shared String[] array

// create TestArray and define array size
constructor (Int size) {
this.array = new String[size]
}

// modify some values in array
shared modify (Test test) {
this.getArray()[Test.INDEX] = "Hello Array"
array[6] = String.valueOf(this)

log "Value at array[test.index]: " + this.getArray()[test.INDEX]
varargs(array)
}

shared varargs (nil mut String... varargs) {
log varargs.asString()
}

// get array
internal getArray() -> String[] {
return array
}

}

internal class CustomThread : Thread {
internal type CustomThread : Thread {

constructor () {
base('CustomThread')
}

override run () {
override run () -> PrimitiveVoid {
log 'Called in ' + Thread.currentThread().getName()
}

Expand Down
2 changes: 2 additions & 0 deletions examples/tests/current_test_required.panda
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export org.panda_lang.utilities.commons.StringUtils
// shared class to test visibility access
shared type Required {

// should generate default empty constructor

shared hello() {
log "Required print"

Expand Down
Loading

0 comments on commit 37bb134

Please sign in to comment.