-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
167 changed files
with
1,584 additions
and
320 deletions.
There are no files selected for viewing
244 changes: 132 additions & 112 deletions
244
crates/analyzer/tests/snapshots/analysis__data_copying_stress.snap
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
122 changes: 122 additions & 0 deletions
122
crates/parser/tests/cases/snapshots/cases__print_ast__erc20.snap.new
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,122 @@ | ||
--- | ||
source: crates/parser/tests/cases/print_ast.rs | ||
expression: "parse_and_print(\"demos/erc20_token.fe\", src)" | ||
|
||
--- | ||
contract ERC20 { | ||
_balances: Map<address, u256> | ||
_allowances: Map<address, Map<address, u256>> | ||
_total_supply: u256 | ||
_name: String<100> | ||
_symbol: String<100> | ||
_decimals: u8 | ||
|
||
event Approval { | ||
idx owner: address | ||
idx spender: address | ||
value: u256 | ||
} | ||
|
||
event Transfer { | ||
idx from: address | ||
idx to: address | ||
value: u256 | ||
} | ||
|
||
pub fn __init__(mut self, mut ctx: Context, name: String<100>, symbol: String<100>) { | ||
self._name = name | ||
self._symbol = symbol | ||
self._decimals = u8(18) | ||
self._mint(ctx, account: ctx.msg_sender(), value: 1000_000_000_000_000_000_000_000) | ||
} | ||
|
||
pub fn name(self) -> String<100> { | ||
return self._name.to_mem() | ||
} | ||
|
||
pub fn symbol(self) -> String<100> { | ||
return self._symbol.to_mem() | ||
} | ||
|
||
pub fn decimals(self) -> u8 { | ||
return self._decimals | ||
} | ||
|
||
pub fn totalSupply(self) -> u256 { | ||
return self._total_supply | ||
} | ||
|
||
pub fn balanceOf(self, _ account: address) -> u256 { | ||
return self._balances[account] | ||
} | ||
|
||
pub fn transfer(mut self, mut ctx: Context, recipient: address, value: u256) -> bool { | ||
self._transfer(ctx, sender: ctx.msg_sender(), recipient, value) | ||
return true | ||
} | ||
|
||
pub fn allowance(self, owner: address, spender: address) -> u256 { | ||
return self._allowances[owner][spender] | ||
} | ||
|
||
pub fn approve(mut self, mut ctx: Context, spender: address, value: u256) -> bool { | ||
self._approve(ctx, owner: ctx.msg_sender(), spender, value) | ||
return true | ||
} | ||
|
||
pub fn transferFrom(mut self, mut ctx: Context, sender: address, recipient: address, value: u256) -> bool { | ||
assert self._allowances[sender][ctx.msg_sender()] >= value | ||
self._transfer(ctx, sender, recipient, value) | ||
self._approve(ctx, owner: sender, spender: ctx.msg_sender(), value: self._allowances[sender][ctx.msg_sender()] - value) | ||
return true | ||
} | ||
|
||
pub fn increaseAllowance(mut self, mut ctx: Context, spender: address, addedValue: u256) -> bool { | ||
self._approve(ctx, owner: ctx.msg_sender(), spender, value: self._allowances[ctx.msg_sender()][spender] + addedValue) | ||
return true | ||
} | ||
|
||
pub fn decreaseAllowance(mut self, mut ctx: Context, spender: address, subtractedValue: u256) -> bool { | ||
self._approve(ctx, owner: ctx.msg_sender(), spender, value: self._allowances[ctx.msg_sender()][spender] - subtractedValue) | ||
return true | ||
} | ||
|
||
fn _transfer(mut self, mut ctx: Context, sender: address, recipient: address, value: u256) { | ||
assert sender != address(0) | ||
assert recipient != address(0) | ||
_before_token_transfer(from: sender, to: recipient, value) | ||
self._balances[sender] = self._balances[sender] - value | ||
self._balances[recipient] = self._balances[recipient] + value | ||
emit Transfer(ctx, from: sender, to: recipient, value) | ||
} | ||
|
||
fn _mint(mut self, mut ctx: Context, account: address, value: u256) { | ||
assert account != address(0) | ||
_before_token_transfer(from: address(0), to: account, value) | ||
self._total_supply = self._total_supply + value | ||
self._balances[account] = self._balances[account] + value | ||
emit Transfer(ctx, from: address(0), to: account, value) | ||
} | ||
|
||
fn _burn(mut self, mut ctx: Context, account: address, value: u256) { | ||
assert account != address(0) | ||
_before_token_transfer(from: account, to: address(0), value) | ||
self._balances[account] = self._balances[account] - value | ||
self._total_supply = self._total_supply - value | ||
emit Transfer(ctx, from: account, to: address(0), value) | ||
} | ||
|
||
fn _approve(mut self, mut ctx: Context, owner: address, spender: address, value: u256) { | ||
assert owner != address(0) | ||
assert spender != address(0) | ||
self._allowances[owner][spender] = value | ||
emit Approval(ctx, owner, spender, value) | ||
} | ||
|
||
fn _setup_decimals(mut self, _ decimals_: u8) { | ||
self._decimals = decimals_ | ||
} | ||
|
||
fn _before_token_transfer(from: address, to: address, _ value: u256) {} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
crates/parser/tests/cases/snapshots/cases__print_ast__guest_book.snap.new
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,22 @@ | ||
--- | ||
source: crates/parser/tests/cases/print_ast.rs | ||
expression: "parse_and_print(\"demos/guest_book.fe\", src)" | ||
|
||
--- | ||
contract GuestBook { | ||
messages: Map<address, String<100>> | ||
|
||
event Signed { | ||
book_msg: String<100> | ||
} | ||
|
||
pub fn sign(mut self, ctx: Context, book_msg: String<100>) { | ||
self.messages[ctx.msg_sender()] = book_msg | ||
emit Signed(ctx, book_msg) | ||
} | ||
|
||
pub fn get_msg(self, addr: address) -> String<100> { | ||
return self.messages[addr].to_mem() | ||
} | ||
} | ||
|
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
Oops, something went wrong.