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

Add more functionality for rule-set creation. #6

Open
Tracked by #3
nylvon opened this issue Jan 2, 2024 · 0 comments
Open
Tracked by #3

Add more functionality for rule-set creation. #6

nylvon opened this issue Jan 2, 2024 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request new core feature Adds a new core feature.

Comments

@nylvon
Copy link
Owner

nylvon commented Jan 2, 2024

The basic notion of a rule-set is complete.

However, in order to do more complex rule-sets, right now you have to make intermediary rule-sets, then merge them, like this:

const IsVec3Simple =
    Blank()
        .And(IsInType(FindField("x")))
        .And(IsInType(FindField("y")))
        .And(IsInType(FindField("z")));

const IsVec3Alternative =
    Blank()
        .And(IsInType(FindField("buffer")));

const IsVec3Full =
    Blank()
        .Or(IsVec3Simple)
        .Or(IsVec3Alternative);

However, it would be nice if we could represent these operations in one go like this:

const IsNumeric = 
    Blank()
        .And(IsInType(FindField("x")))
            .Then()
            .Or(IsArchetype(FindField("x"), .Int))
                .Then()
                .And(IsBitCount(FindField("x"), .GreaterOrEqual, 32))
                .And(IsBitCount(FindField("x"), .LessOrEqual, 64))
                .Back()
            .Or(IsArchetype(FindField("x"), .Float))
                .Then()
                .Or(IsBitCount(FindField("x"), .Equal, 32))
                .Or(IsBitCount(FindField("x"), .Equal, 64))
                .Back()
            .Back();

The Then and Back keywords could control the current rule-set scope.

Then grabs the last child of the current rule-set in scope and sets it as the new scope.
Back grabs the parent of the current rule-set and switches the scope back to it.

If one notices the code above, one would realize that we're calling FindField("x") many times. Wouldn't it be nice if we cached it?

We would need an instruction for it to do so, so we may think of something that looks sort of like this:

const IsNumeric = 
    Blank()
        .NewCache(1)
        .Cache(0, FindField("x"))
        .And(IsInType(@This().GetCache(0)))
            .Then()
            .Or(IsArchetype(@This().GetParent(0).GetCache(0), .Int))
                .Then()
                .And(IsBitCount(@This().GetParent(1).GetCache(0), .GreaterOrEqual, 32))
                .Back()
            .Or(IsArchetype(@This().GetParent(0).GetCache(0), .Float))
                .Then()
                .Or(IsBitCount(@This().GetParent(1).GetCache(0), .Equal, 32))
                .Or(IsBitCount(@This().GetParent(1).GetCache(0), .Equal, 64))
                .Back()
            .Back();

We would then introduce the following:

Every rule-set would have a reference to its parent node, through the parent field.
However, interacting with it directly would be error-prone, as a node could lack a parent (i.e. the root node), so we could have a GetParent(x) function, where x would determine the amount of jumps it needs to do.

i.e.: GetParent(0) would return the parent of the rule-set that is in scope right now, and GetParent(1) would return the parent of the parent of that rule-set.

NewCache(x) would create a cache for the scoped rule-set of size x.
Cache(i, x) would cache some result x at position i of the rule-set in scope.
GetCache(i) would return the cache's contents at index i of the rule-set in scope.

Now, this entire rule-set would be difficult to write for a Vec3 made with IsNumeric on each sub-element, so it would be nice if we could have some way of repeating rule-sets in-line, maybe something like this:

const IsNumericVec3 = 
    Blank()
        .NewCache(3),
        .Cache(0, "x"),
        .Cache(1, "y"),
        .Cache(2, "z"),
        .CachePattern(
            .And(
                Blank()
                    .NewCache(1)
                    .Cache(0, FindField(@This().GetCache(1)))
                    .And(IsInType(@This().GetCache(0)))
                        .Then()
                        .Or(IsArchetype(@This().GetParent(0).GetCache(0), .Int))
                            .Then()
                            .And(IsBitCount(@This().GetParent(1).GetCache(0), .GreaterOrEqual, 32))
                            .Back()
                        .Or(IsArchetype(@This().GetParent(0).GetCache(0), .Float))
                            .Then()
                            .Or(IsBitCount(@This().GetParent(1).GetCache(0), .Equal, 32))
                            .Or(IsBitCount(@This().GetParent(1).GetCache(0), .Equal, 64))
                            .Back()
                        .Back()
            )
        );

We could use the cache as a pattern to generate multiple rule-sets.

CachePattern(x) would create new rule-sets based off of the currently-scoped rule-set's cached contents.
In this case, this would create 3 rule-sets with different FindField calls, one for FindField("x"), one for FindField("y"), and one for FindField("z").

This would create a rule-set that would create a IsNumeric for a Vec3-like structure, a IsNumericVec3 rule-set.

The beauty of this is that it could scale massively, and it would require very little re-writing.

This functionality would prove very useful for writing interfaces in one single-line, in a fluent way.

These are all just illustrative, the syntax is bound to be different post implementation, these are just some ideas of desired behavior.

@nylvon nylvon added documentation Improvements or additions to documentation enhancement New feature or request new core feature Adds a new core feature. labels Jan 2, 2024
@nylvon nylvon self-assigned this Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request new core feature Adds a new core feature.
Projects
None yet
Development

No branches or pull requests

1 participant