From 11da70a971235261b1f862282d67b1e80c35c258 Mon Sep 17 00:00:00 2001 From: Ivan Kalinin Date: Wed, 25 Oct 2023 19:30:56 +0200 Subject: [PATCH] Fix strange opcodes --- Cargo.lock | 20 ++++++------- Cargo.toml | 2 +- README.md | 41 +++++++++++++++++++++++++- cli/Cargo.toml | 4 +-- extension/package.json | 3 +- extension/syntaxes/tvm.tmLanguage.json | 2 +- src/asm/opcodes.rs | 18 +++++------ src/ast.rs | 8 +++++ 8 files changed, 73 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a252f43..a30c91e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7d5a2cecb58716e47d67d5703a249964b14c7be1ec3cad3affc295b2d1c35d" +checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" dependencies = [ "cfg-if", "getrandom", @@ -307,7 +307,7 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "everscale-asm" -version = "0.0.3" +version = "0.0.4" dependencies = [ "ahash", "anyhow", @@ -1191,9 +1191,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.9" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", @@ -1326,7 +1326,7 @@ dependencies = [ [[package]] name = "tvmasm" -version = "0.0.4" +version = "0.0.5" dependencies = [ "ahash", "anyhow", @@ -1561,18 +1561,18 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "zerocopy" -version = "0.7.11" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c19fae0c8a9efc6a8281f2e623db8af1db9e57852e04cde3e754dd2dc29340f" +checksum = "81ba595b9f2772fbee2312de30eeb80ec773b4cb2f1e8098db024afadda6c06f" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.11" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc56589e9ddd1f1c28d4b4b5c773ce232910a6bb67a70133d61c9e347585efe9" +checksum = "772666c41fb6dceaf520b564b962d738a8e1a83b41bd48945f50837aed78bb1d" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index b06d9de..1f6361a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "everscale-asm" description = "Rust implementation of TVM Assembler" repository = "https://github.com/broxus/everscale-asm" -version = "0.0.3" +version = "0.0.4" edition = "2021" rust-version = "1.70" include = ["src/**/*.rs", "src/**/*.tvm", "./LICENSE-*", "./README.md"] diff --git a/README.md b/README.md index 31a2d1b..71ca6de 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ [rust-version-link]: https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html -[workflow-badge]: https://img.shields.io/github/actions/workflow/status/broxus/everscale-asm/master.yml?branch=master +[workflow-badge]: https://img.shields.io/github/actions/workflow/status/broxus/everscale-asm/master.yaml?branch=master [workflow-link]: https://github.com/broxus/everscale-asm/actions?query=workflow%3Amaster @@ -63,6 +63,45 @@ let code: Cell = Code::assemble(r#" "#)?; ``` +## Syntax + +``` +// Single-line comments + +// Opcodes must be in uppercase, can start with a digit or minus, +// and can contain '#' or '_' +NOP +2DROP +-ROT +STREF_L + +// Opcodes with number as an argument +PUSHINT 12 +PUSHINT -0xded +PUSHINT 0b10110101 + +// Opcodes with stack register as an argument +PUSH s1 +XCHG s10, s100 +PU2XC s1, s(-1), s(-2) + +// Opcodes with control registers (c0, .., c5, c7) +PUSH c3 +PUSHCTR c7 + +// Opcodes with slice or continuation +PUSHSLICE x{123123_} +PUSHSLICE b{10001001} +IFREFELSEREF { + PUSHINT 1 +}, { + PUSHINT 2 +} + +``` + +[Full opcodes list](https://test.ton.org/tvm.pdf) + ## Contributing We welcome contributions to the project! If you notice any issues or errors, feel free to open an issue or submit a pull request. diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c6bc477..36f3f7a 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -2,7 +2,7 @@ name = "tvmasm" description = "CLI for TVM Assembler" repository = "https://github.com/broxus/everscale-asm" -version = "0.0.4" +version = "0.0.5" edition = "2021" rust-version = "1.70" include = ["src/**/*.rs", "src/**/*.tvm", "./LICENSE-*", "./README.md"] @@ -24,4 +24,4 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } unicode-width = "0.1" everscale-types = { version = "0.1.0-rc.6", default-features = false } -everscale-asm = { path = "../", version = "0.0.3" } +everscale-asm = { path = "../", version = "0.0.4" } diff --git a/extension/package.json b/extension/package.json index 17ce4c8..388a84c 100644 --- a/extension/package.json +++ b/extension/package.json @@ -4,7 +4,8 @@ "description": "Language client extension for TVM Assembler", "publisher": "Rexagon", "license": "MIT", - "version": "0.0.2", + "homepage": "https://github.com/broxus/everscale-asm/blob/master/README.md", + "version": "0.0.3", "engines": { "vscode": "^1.65.0" }, diff --git a/extension/syntaxes/tvm.tmLanguage.json b/extension/syntaxes/tvm.tmLanguage.json index 075751d..45fe683 100644 --- a/extension/syntaxes/tvm.tmLanguage.json +++ b/extension/syntaxes/tvm.tmLanguage.json @@ -32,7 +32,7 @@ "patterns": [ { "name": "entity.name.function", - "match": "([0-9]?[A-Z#_][a-zA-Z0-9#_]*)" + "match": "(-?[0-9]?[A-Z#_][a-zA-Z0-9#_]*)" } ] }, diff --git a/src/asm/opcodes.rs b/src/asm/opcodes.rs index d5de251..3e14f06 100644 --- a/src/asm/opcodes.rs +++ b/src/asm/opcodes.rs @@ -205,7 +205,7 @@ fn register_stackops(t: &mut Opcodes) { "XCPU" => 0x51(s, s), "PUXC" => 0x52(s, s, adj = 0x01), "PUSH2" => 0x53(s, s), - "XCHG3_l" => 0x540(s, s, s), + "XCHG3_L" => 0x540(s, s, s), "XC2PU" => 0x541(s, s, s), "XCPUXC" => 0x542(s, s, s, adj = 0x001), "XCPU2" => 0x543(s, s, s), @@ -525,20 +525,20 @@ fn register_stackops(t: &mut Opcodes) { "STUXQ" => 0xcf05, "STIXRQ" => 0xcf06, "STUXRQ" => 0xcf07, - "STI_l" => 0xcf08(u8 - 1), - "STU_l" => 0xcf09(u8 - 1), + "STI_L" => 0xcf08(u8 - 1), + "STU_L" => 0xcf09(u8 - 1), "STIR" => 0xcf0a(u8 - 1), "STUR" => 0xcf0b(u8 - 1), "STIQ" => 0xcf0c(u8 - 1), "STUQ" => 0xcf0d(u8 - 1), "STIRQ" => 0xcf0e(u8 - 1), "STURQ" => 0xcf0f(u8 - 1), - "STREF_l" => 0xcf10, + "STREF_L" => 0xcf10, "STBREF" => 0xcf11, - "STSLICE_l" => 0xcf12, + "STSLICE_L" => 0xcf12, "STB" => 0xcf13, "STREFR" => 0xcf14, - "STBREFR_l" => 0xcf15, + "STBREFR_L" => 0xcf15, "STSLICER" => 0xcf16, "STBR" | "BCONCAT" => 0xcf17, "STREFQ" => 0xcf18, @@ -594,8 +594,8 @@ fn register_stackops(t: &mut Opcodes) { "LDUXQ" => 0xd705, "PLDIXQ" => 0xd706, "PLDUXQ" => 0xd707, - "LDI_l" => 0xd708(u8 - 1), - "LDU_l" => 0xd709(u8 - 1), + "LDI_L" => 0xd708(u8 - 1), + "LDU_L" => 0xd709(u8 - 1), "PLDI" => 0xd70a(u8 - 1), "PLDU" => 0xd70b(u8 - 1), "LDIQ" => 0xd70c(u8 - 1), @@ -607,7 +607,7 @@ fn register_stackops(t: &mut Opcodes) { "PLDSLICEX" => 0xd719, "LDSLICEXQ" => 0xd71a, "PLDSLICEXQ" => 0xd71b, - "LDSLICE_l" => 0xd71c(u8 - 1), + "LDSLICE_L" => 0xd71c(u8 - 1), "PLDSLICE" => 0xd71d(u8 - 1), "LDSLICEQ" => 0xd71e(u8 - 1), "PLDSLICEQ" => 0xd71f(u8 - 1), diff --git a/src/ast.rs b/src/ast.rs index a42a605..cef91d4 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -127,6 +127,14 @@ fn instr_ident<'a>() -> impl Parser<'a, &'a str, &'a str, extra::Err