Go to file
rvcas 1b8805825b feat: impl if/is
This commit introduces a new feature into
the parser, typechecker, and formatter.
The work for code gen will be in the next commit.

I was able to leverage some existing infrastructure
by making using of `AssignmentPattern`. A new field
`is` was introduced into `IfBranch`. This field holds
a generic `Option<Is>` meaning a new generic has to be
introduced into `IfBranch`. When used in `UntypedExpr`,
`IfBranch` must use `AssignmentPattern`. When used in
`TypedExpr`, `IfBranch` must use `TypedPattern`.

The parser was updated such that we can support this
kind of psuedo grammar:

`if <expr:condition> [is [<pattern>: ]<annotation>]`

This can be read as, when parsing an `if` expression,
always expect an expression after the keyword `if`. And then
optionally there may be this `is` stuff, and within that you
may optionally expect a pattern followed by a colon. We will
always expect an annotation.

This first expression is still saved as the field
`condition` in `IfBranch`. If `pattern` is not there
AND `expr:condition` is `UntypedExpr::Var` we can set
the pattern to be `Pattern::Var` with the same name. From
there shadowing should allow this syntax sugar to feel
kinda magical within the `IfBranch` block that follow.

The typechecker doesn't need to be aware of the sugar
described above. The typechecker looks at `branch.is`
and if it's `Some(is)` then it'll use `infer_assignment`
for some help. Because of the way that `is` can inject
variables into the scope of the branch's block and since
it's basically just like how `expect` works minus the error
we get to re-use that helper method.

It's important to note that in the typechecker, if `is`
is `Some(_)` then we do not enforce that `condition` is
of type `Bool`. This is because the bool itself will be
whether or not the `is` itself holds true given a PlutusData
payload.

When `is` is None, we do exactly what was being done
previously so that plain `if` expressions remain unaffected
with no semantic changes.

The formatter had to be made aware of the new changes with
some simple changes that need no further explanation.
2024-06-25 18:50:00 -04:00
.github chore(ci): Bump actions/checkout from 3 to 4 2024-06-25 17:49:36 -04:00
crates feat: impl if/is 2024-06-25 18:50:00 -04:00
examples Authorize complete patterns as function args. 2024-06-07 15:42:25 +02:00
.editorconfig rename examples/tests/{a,b,c,d,e,f} into examples/acceptance_tests/00{1,2,3,4,5,6} 2022-12-14 09:45:24 +01:00
.gitattributes Add support for Nix flakes. 2023-02-07 13:16:17 +01:00
.gitignore chore: commit an ignore we can all use without accidentally commiting test files/folders 2024-03-12 08:10:33 -04:00
CHANGELOG.md Authorize complete patterns as function args. 2024-06-07 15:42:25 +02:00
CONTRIBUTING.md chore: add release instructions in contributing.md 2023-08-24 15:43:26 -06:00
Cargo.lock chore: Release 2024-06-06 11:19:34 +02:00
Cargo.toml chore: some dist settings 2024-05-23 21:38:47 -04:00
LICENSE chore: update license 2024-05-01 22:10:47 -04:00
README.md refresh README. 2024-05-31 09:48:14 +02:00
flake.lock bump flake ... but in a way that works for external builds?! 2024-03-04 14:32:27 +00:00
flake.nix bump flake ... but in a way that works for external builds?! 2024-03-04 14:32:27 +00:00

README.md

Aiken

A modern smart contract platform for Cardano

Licence Tests Twitter/X

Crates.io NPM


Getting Started

Hello, World!

Wanna get started right-away? Complete the Hello, World! tutorial!

Contributing

Want to contribute? See CONTRIBUTING.md to know how.

Changelog

Be on top of any updates using the CHANGELOG and the Project Tracking.

Stats

Alt

[!NOTE]

The name comes from Howard Aiken, an American physicist and a pioneer in computing.