-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement instruction sequences; let; var expressions
- Loading branch information
1 parent
b501c71
commit 0a156d2
Showing
10 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
```k | ||
module RUST-LET | ||
imports COMMON-K-CELL | ||
imports RUST-CASTS | ||
imports RUST-EXECUTION-CONFIGURATION | ||
imports RUST-VALUE-SYNTAX | ||
imports RUST-SHARED-SYNTAX | ||
// Not all cases are implemented | ||
rule | ||
<k> | ||
let Variable:Identifier : T:Type = V:Value ; => .K | ||
... | ||
</k> | ||
<next-value-id> NextId:Int => NextId +Int 1 </next-value-id> | ||
<locals> Locals:Map => Locals[Variable <- NextId] </locals> | ||
<values> Values:Map => Values[NextId <- implicitCast(V, T)] </values> | ||
rule | ||
<k> | ||
let Variable:Identifier = V:Value ; => .K | ||
... | ||
</k> | ||
<next-value-id> NextId:Int => NextId +Int 1 </next-value-id> | ||
<locals> Locals:Map => Locals[Variable <- NextId] </locals> | ||
<values> Values:Map => Values[NextId <- V] </values> | ||
requires notBool mayBeDefaultTypedInt(V) | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
```k | ||
module RUST-STATEMENTS | ||
imports RUST-SHARED-SYNTAX | ||
rule Nes:NonEmptyStatements E:Expression => Nes ~> E | ||
rule S:Statement Ss:NonEmptyStatements => S ~> Ss | ||
rule .NonEmptyStatements => .K | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
```k | ||
requires "expression/casts.md" | ||
requires "expression/literals.md" | ||
requires "expression/variables.md" | ||
module RUST-EXPRESSION | ||
imports private RUST-CASTS | ||
imports private RUST-EXPRESSION-LITERALS | ||
imports private RUST-EXPRESSION-VARIABLES | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
```k | ||
module RUST-EXPRESSION-VARIABLES | ||
imports COMMON-K-CELL | ||
imports RUST-EXECUTION-CONFIGURATION | ||
imports RUST-VALUE-SYNTAX | ||
imports RUST-SHARED-SYNTAX | ||
rule | ||
<k> | ||
Variable:Identifier :: .PathExprSegments => V | ||
... | ||
</k> | ||
<locals> Variable |-> VarId:Int ... </locals> | ||
<values> VarId |-> V:Value ... </values> | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
new LetFinal; | ||
call LetFinal.let_final; | ||
return_value; | ||
check_eq 100_u64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![no_std] | ||
|
||
#[allow(unused_imports)] | ||
use multiversx_sc::imports::*; | ||
|
||
#[multiversx_sc::contract] | ||
pub trait LetFinal { | ||
#[init] | ||
fn init(&self) { | ||
} | ||
|
||
#[upgrade] | ||
fn upgrade(&self) {} | ||
|
||
fn let_final(&self) -> u64 { | ||
let x = 100_u64; | ||
x | ||
} | ||
} |