clarity to SmartWeave translator
VERY EXPERIMENTAL. Can compile only hello world for now. WIP
# install nvm https://github.com/nvm-sh/nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
source ~/.bashrc
# node install
nvm i 12
npm i -g iced-coffee-script
# we need clang-8 and git
# For ubuntu 20.04
apt-get update
apt-get install clang-8 lld-8 git
# fix missing wasm-ld binary
ln -s /usr/bin/wasm-ld-8 /usr/bin/wasm-ld
git clone https://github.com/vird/clarity2smartweave_wasm
cd clarity2smartweave_wasm
npm i
./cli.coffee test.clar
# see ./build/compiled.js for results
# for some reason node@12 does't like `export async function handle`, so I use `this.handle = async function`
# enable this behaviour with --fix-export
./cli.coffee test.clar --fix-export
./manual3.coffee
# expected output
# { state: {}, result: 1 }
# run tests
npm test
Note some points are duplicated. Reason: ast4gen has lot of stuff and it's a reasonable checklist for turing-complete stuff (clarity is not, but whatever)
Also I plan make superset of clarity for 2 purposes:
- put all smartweave stuff in non-standard endpoints (so you can write in clarity whatever you want for arweave, because patching generated C or WASM is much more painful)
- turing-complete (why not?)
Feature | Implemented | Tested |
---|---|---|
Clarity API | ||
operations | ||
un - | ||
bin + - * / | ||
mod pow | ||
to-int to-uint | ||
< > <= >= | ||
and or xor not | ||
is-eq | ||
define | ||
define-constant | ||
define-private | ||
define-public |
|
|
define-read-only | ||
define-data-var | ||
define-fungible-token | ||
define-non-fungible-token | ||
stmt/control flow | ||
let | ||
begin | ||
if | ||
match | ||
asserts! | ||
type-related | ||
ok | ||
try! | ||
default-to | ||
is-ok is-none is-err is-some | ||
true/false | ||
none | ||
response | ||
err | ||
list/buffer | ||
len | ||
as-max-len? | ||
concat | ||
map | ||
fold | ||
filter | ||
append | ||
map | ||
define-map | ||
map-get | ||
map-set! | ||
map-insert! | ||
map-delete! | ||
trait | ||
define-trait | ||
use-trait | ||
impl-trait | ||
unwrap | ||
unwrap | ||
unwrap-err | ||
unwrap-panic | ||
unwrap-err-panic | ||
crypto | ||
hash160 | ||
sha256 | ||
sha512 | ||
sha256 | ||
keccak256 | ||
block/tx related | ||
ft-get-balance | ||
nft-get-owner? | ||
ft-transfer? | ||
nft-transfer? | ||
nft-mint? | ||
ft-mint? | ||
stx-get-balance | ||
stx-transfer? | ||
stx-burn? | ||
at-block | ||
get-block-info? | ||
IO state | ||
var-get | ||
var-set | ||
IO contract | ||
contract-call? | ||
tx-sender | ||
contract-caller | ||
block-height | ||
as-contract | ||
contract-of | ||
IO misc | ||
unknown | ||
transfer-to-recipient! | ||
transfer-from? | ||
append-item | ||
SmartWeave API sync | ||
SmartWeave.transaction | ||
SmartWeave.block | ||
SmartWeave API async? | ||
SmartWeave.arweave.crypto | ||
SmartWeave.arweave.utils | ||
SmartWeave.arweave.ar | ||
SmartWeave.arweave.wallets | ||
SmartWeave.contracts |
ast4gen perspective checklist
Feature | Implemented | Tested |
---|---|---|
expr AST | ||
ast.Un_op | ||
ast.Bin_op | ||
+ - * / | ||
mod pow | ||
< > <= >= | ||
and or xor not | ||
== != | ||
ast.Const |
|
|
ast.Var |
|
|
stmt AST | ||
ast.Fn_decl | ||
ast.Ret | ||
ast.Fn_call | ||
ast.Var_decl (global, define-read-only) | ||
ast.Var_decl (local, let) | ||
stmt AST control flow | ||
ast.If | ||
Types | ||
bool | ||
string (arg+ret) |
|
|
principal | ||
list | ||
tuple | ||
int as i32 | ||
uint as u32 | ||
int/uint as i64 | ||
int/uint as i128/u128 | ||
buffer | ||
optional | ||
response ok-type err-type | ||