Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement cell semtype in runtime #42847

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
58b3177
Implement scaffolding
heshanpadmasiri May 7, 2024
c5397fd
Port never type
heshanpadmasiri May 9, 2024
78a1953
Port nil type
heshanpadmasiri May 10, 2024
d59e17f
Port Decimal type
heshanpadmasiri May 10, 2024
ed71405
Port float type
heshanpadmasiri May 10, 2024
b5d6326
Refactor caches to use DATs
heshanpadmasiri May 10, 2024
7954de5
Port int type
heshanpadmasiri May 12, 2024
ac31fef
Port Boolean type
heshanpadmasiri May 12, 2024
09c5c94
Port String type
heshanpadmasiri May 12, 2024
1c16f6f
Refactor SemType implementation
heshanpadmasiri May 14, 2024
8d6a251
Add doc comments
heshanpadmasiri May 27, 2024
1f16d81
Fix float equality
heshanpadmasiri May 29, 2024
ee052f9
Refactor type tests
heshanpadmasiri May 28, 2024
0a73764
Add runtime type tests provider
heshanpadmasiri May 28, 2024
42b59ed
Add more basic type tests
heshanpadmasiri May 29, 2024
32f7c98
Fix compile time type bugs
heshanpadmasiri May 29, 2024
505006f
Refactor type resolvers
heshanpadmasiri Jun 3, 2024
be9b5c1
Add runtime type tests provider
heshanpadmasiri May 28, 2024
00e7160
Make it possible to create cell type
heshanpadmasiri May 29, 2024
9abce86
Implement bdd operations
heshanpadmasiri May 30, 2024
d0eaf68
Introduce cell delegate
heshanpadmasiri May 30, 2024
fbbe814
Implement cell subtype
heshanpadmasiri May 30, 2024
a912920
Cache cell type creation
heshanpadmasiri Jun 3, 2024
bfb6132
Use read write locks for atom table
heshanpadmasiri Jun 3, 2024
1cf21f4
Add JDoc comments to new classes
heshanpadmasiri Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
*/
public class PredefinedTypes {

private static final Module EMPTY_MODULE = new Module(null, null, null);
public static final Module EMPTY_MODULE = new Module(null, null, null);

public static final IntegerType TYPE_INT = new BIntegerType(TypeConstants.INT_TNAME, EMPTY_MODULE);
public static final IntegerType TYPE_INT_SIGNED_8 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public class RuntimeConstants {
// Empty value for string
public static final BString STRING_EMPTY_VALUE = StringUtils.fromString("");

public static final Long INT_MAX_VALUE = 9223372036854775807L;
public static final Long INT_MIN_VALUE = -9223372036854775807L - 1L;
public static final Integer BBYTE_MIN_VALUE = 0;
public static final Integer BBYTE_MAX_VALUE = 255;
public static final Integer SIGNED32_MAX_VALUE = 2147483647;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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 io.ballerina.runtime.api.types.semtype;

/**
* Represent the BDD atom.
*
* @since 2201.10.0
*/
public interface Atom {

int index();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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 io.ballerina.runtime.api.types.semtype;

/**
* Marker type representing AtomicType.
*
* @since 2201.10.0
*/
public interface AtomicType {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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 io.ballerina.runtime.api.types.semtype;

// SEMTYPE-TODO: revisit this after fully implementing semtypes. Added this to match nBallerina where this is just a
// type alias to int. Maybe not needed here due to the way we have modeled type hierarchy (need to check if doing
// instancof checks on this is faster than checking if some is 0)

/**
* Represents a union of basic types.
*
* @since 2201.10.0
*/
public interface BasicTypeBitSet {

default int some() {
return 0;
}

default SubType[] subTypeData() {
return new SubType[0];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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 io.ballerina.runtime.api.types.semtype;

/**
* Represent bit field that indicate which basic type a semType belongs to.
*
* @since 2201.10.0
*/
public final class BasicTypeCode {

public static final int CODE_NIL = 0x00;
public static final int CODE_BOOLEAN = 0x01;
public static final int CODE_INT = 0x02;
public static final int CODE_FLOAT = 0x03;
public static final int CODE_DECIMAL = 0x04;
public static final int CODE_STRING = 0x05;
public static final int CODE_ERROR = 0x06;
public static final int CODE_TYPEDESC = 0x07;
public static final int CODE_HANDLE = 0x08;
public static final int CODE_FUNCTION = 0x09;
public static final int CODE_FUTURE = 0x0A;
public static final int CODE_STREAM = 0x0B;
public static final int CODE_LIST = 0x0C;
public static final int CODE_MAPPING = 0x0D;
public static final int CODE_TABLE = 0x0E;
public static final int CODE_XML = 0x0F;
public static final int CODE_OBJECT = 0x10;
public static final int CODE_CELL = 0x11;
public static final int CODE_UNDEF = 0x12;
public static final int CODE_B_TYPE = 0x13;

// Inherently immutable
public static final BasicTypeCode BT_NIL = from(CODE_NIL);
public static final BasicTypeCode BT_BOOLEAN = from(CODE_BOOLEAN);
public static final BasicTypeCode BT_INT = from(CODE_INT);
public static final BasicTypeCode BT_FLOAT = from(CODE_FLOAT);
public static final BasicTypeCode BT_DECIMAL = from(CODE_DECIMAL);
public static final BasicTypeCode BT_STRING = from(CODE_STRING);
public static final BasicTypeCode BT_ERROR = from(CODE_ERROR);
public static final BasicTypeCode BT_TYPEDESC = from(CODE_TYPEDESC);
public static final BasicTypeCode BT_HANDLE = from(CODE_HANDLE);
public static final BasicTypeCode BT_FUNCTION = from(CODE_FUNCTION);

// Inherently mutable
public static final BasicTypeCode BT_FUTURE = from(CODE_FUTURE);
public static final BasicTypeCode BT_STREAM = from(CODE_STREAM);

// Selectively immutable
public static final BasicTypeCode BT_LIST = from(CODE_LIST);
public static final BasicTypeCode BT_MAPPING = from(CODE_MAPPING);
public static final BasicTypeCode BT_TABLE = from(CODE_TABLE);
public static final BasicTypeCode BT_XML = from(CODE_XML);
public static final BasicTypeCode BT_OBJECT = from(CODE_OBJECT);

// Non-val
public static final BasicTypeCode BT_CELL = from(CODE_CELL);
public static final BasicTypeCode BT_UNDEF = from(CODE_UNDEF);
public static final BasicTypeCode BT_B_TYPE = from(CODE_B_TYPE);

// Helper bit fields (does not represent basic type tag)
static final int VT_COUNT = CODE_OBJECT + 1;
static final int VT_MASK = (1 << VT_COUNT) - 1;

static final int VT_COUNT_INHERENTLY_IMMUTABLE = 0x0A;
public static final int VT_INHERENTLY_IMMUTABLE = (1 << VT_COUNT_INHERENTLY_IMMUTABLE) - 1;

private int code;

private BasicTypeCode(int code) {
this.code = code;
}

public static BasicTypeCode from(int code) {
if (BasicTypeCodeCache.isCached(code)) {
return BasicTypeCodeCache.cache[code];
}
return new BasicTypeCode(code);
}

public int code() {
return code;
}

private static final class BasicTypeCodeCache {

private static final BasicTypeCode[] cache;
static {
cache = new BasicTypeCode[CODE_B_TYPE + 2];
for (int i = CODE_NIL; i < CODE_B_TYPE + 1; i++) {
cache[i] = new BasicTypeCode(i);
}
}

private static boolean isCached(int code) {
return 0 < code && code < VT_COUNT;
}

}
}
Loading
Loading