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

Feature - CLEO Containers #204

Open
MiranDMC opened this issue Sep 21, 2024 · 7 comments
Open

Feature - CLEO Containers #204

MiranDMC opened this issue Sep 21, 2024 · 7 comments

Comments

@MiranDMC
Copy link
Collaborator

MiranDMC commented Sep 21, 2024

Introduce data container feature and opcodes to support it.

Container instance is meant to store single kind of data type.
Available types: int, float, text
As far as it is technically possible types validation is performed in opcode commands at runtime. In case of mismatch error is thrown.

Class name: container

Opcodes:

create_container - container type
remove_container

container_size
container_clear

container_insert - one or multiple values
container_insert_front - one or multiple values
container_insert_at - index and one or multiple values

container_remove - optional count
container_remove_front - optional count
container_remove_at -  index and optional count

container_get - one or multiple return values
container_get_front - one or multiple return values
container_get_at - index and one or multiple return values
container_get_random - one or multiple return values

container_contains - one or more search values
container_count - one search value
container_find - search value
container_find_back - search value

container_sort - sorting order and zero or more synchronized container handles

container_write_to_file
container_read_from_file
@x87
Copy link

x87 commented Sep 21, 2024

I think type should be set in the constructor.

int_container = create_container type 0
string_container = create_container type 1
container_add int_container 1 2 3
container_add int_container "runtime error"
container_add string_container "ok"

@MiranDMC
Copy link
Collaborator Author

MiranDMC commented Sep 21, 2024

I think type should be set in the constructor.

int_container = create_container type 0
string_container = create_container type 1
container_add int_container 1 2 3
container_add int_container "runtime error"
container_add string_container "ok"

How getters will look then?

@x87
Copy link

x87 commented Sep 21, 2024

int_container = create_container type 0
container_add int_container 1 2 3
int x = get_by_index int_container 0 // x= 1
int y = get_by_index int_container 1 // y= 2
int z = get_by_index int_container 2 // z= 3

string_container = create_container type 1
container_add string_container "ok"
longstring s = get_by_index string_container 0 // s= "ok"

names are temporary to illustrate the idea

@MiranDMC
Copy link
Collaborator Author

MiranDMC commented Sep 21, 2024

Will the getter opcode be able in every case to distinguish return parameter type and validate it? Especially float and int types.

@x87
Copy link

x87 commented Sep 21, 2024

addition

int_container = create_container type 0
container_add int_container 1 2 3
int x = get_by_index int_container 0 // x= 1
int y = get_by_index int_container 1 // y= 2
int z = get_by_index int_container 2 // z= 3

string_container = create_container type 1
container_add string_container "this is a very long string that couldn't live in a variable"
int s = get_by_index string_container 0 // s= pointer to "this is a very long string that couldn't live in a variable"
print_help_formatted s // prints "this is a very long string that couldn't live in a variable"

string containers return a pointer.

@x87
Copy link

x87 commented Sep 21, 2024

Will the getter opcode be able in every case to distinguish return parameter type and validate it? Especially float and int types.

I wouldn't care in runtime. you provide a 32-bit variable and runtime either copies the value (if it's int or float) or returns a pointer if it's a string, or other object.

validation can be done in compiler or linter

@x87
Copy link

x87 commented Sep 23, 2024

runtime should keep track of created containers and delete them / free memory when the script ends (on game reload)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants