Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
made tests and lints passed
Browse files Browse the repository at this point in the history
  • Loading branch information
robin committed Jul 5, 2023
1 parent da26b9a commit 778b236
Show file tree
Hide file tree
Showing 21 changed files with 1,248 additions and 1,214 deletions.
720 changes: 515 additions & 205 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions language/move-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ edition = "2021"
dirs-next = "2.0.0"
once_cell = "1.7.2"
cfg-if = "1.0.0"
lazy_static = "1.4.0"
wait-timeout = "0.2.0"
regex = "1.5.5"
bisection = "0.1.0"
Expand Down Expand Up @@ -50,4 +49,3 @@ pprof = { version = "0.11.0" , features = ["flamegraph" , "protobuf"]}
aptos = []
sui = []
pprof = []

64 changes: 31 additions & 33 deletions language/move-analyzer/doc/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
move-analyzer2 is a novel move-lanugage IDE support.
move-analyzer2 include semantic analyzer of move and MSL.
Here we demonstrate serval core concepts in move-analyzer2 to help you understand how it works.

## Basic

### `Item`
Expand All @@ -21,7 +21,7 @@ For example, module, function are all `Scope`.
0x1::some_module{
// define function, const,...
fun some_fun() {
// function is a `Scope` too, you can create variable and ...
// function is a `Scope` too, you can create variable and ...
}
}
~~~
Expand All @@ -41,14 +41,14 @@ For example, module, function are all `Scope`.
Example:
~~~
fun some_fun() {
{ // When enter, we create a `Scope` to hold declared variables.
// push this `Scope` to `scopes` stack.
// push this `Scope` to `scopes` stack.
let _x = 100;
...
// At end, we pop out this `Scope`.
...
// At end, we pop out this `Scope`.
}
}
Expand All @@ -57,7 +57,7 @@ fun some_fun() {

Example:
~~~
0x1::some_module {
0x1::some_module {
fun some_fun() { // some_fun will saved in `addresses` and can be accessed.
}
Expand All @@ -71,15 +71,15 @@ Example:
pub enum ResolvedType {
// Structure type
Struct(item::ItemStruct),
// Build in type like u8 ...
// Build in type like u8 ...
BuildInType(BuildInType),
/// T : drop typeparameter
TParam(Name, Vec<Ability>),
/// & mut ...
Ref(bool, Box<ResolvedType>),
...
...
}
~~~
`ResolvedType` is the type which have semantic meanings.
Expand All @@ -89,7 +89,7 @@ Example:
struct XXX { ... }
fun some_fun() : XXX // XXX will resovled to ResolvedType::Struct which will contains info of a structure.
{
}
~~~

Expand All @@ -103,14 +103,14 @@ Example:
fun some_fun() {
let x = 1;
some_fun2(x); // When we dealing with access of x
// We have a structure below
some_fun2(x); // When we dealing with access of x
// We have a structure below
Access::ExprAccessChain(
NameAccessChain, // access point.
Option<AddrAndModuleName>, // The item maybe locate at some module,So we can implement goto to definition,... for module.
Box<Item>, // The actual Item.
)
),
)
),
~~~

### `ItemOrAccessHandler`.
Expand All @@ -127,8 +127,8 @@ pub trait ItemOrAccessHandler: std::fmt::Display {
project_context: &ProjectContext,
item_or_access: &ItemOrAccess,
);
...
...
/// Visitor should finished.
fn finished(&self) -> bool;
Expand All @@ -141,7 +141,7 @@ Actualy the `ItemOrAccessHandler` is a consumer and can consume the information

`ItemOrAccess` is either a `Item` or `Access`. Features like `goto to definition` and `auto completion` ,... base On `ScopeVisitor`.

For example
For example

When you want to implement `goto to definition`.
* if the `item_or_access` is `Item` you just return the `def_loc` of the `item_or_access`.
Expand All @@ -154,11 +154,11 @@ So the main purpose of `Project` is to produce `ItemOrAccess`.
`AstProvider` is a trait that have a lot of `with` function.
~~~
fn with_const(&self, mut call_back: impl FnMut(AccountAddress, Symbol, &Constant)) {
...
...
}
fn with_struct(&self, mut call_back: impl FnMut(AccountAddress, Symbol, &StructDefinition)) {
...
...
}
~~~
This is convenient way for someone who interested in gettting all the constants or functions in a module.
Expand All @@ -178,9 +178,9 @@ pub struct Project {
>,
/// All manifests
pub(crate) manifests: Vec<move_package::source_package::parsed_manifest::SourceManifest>,
...
...
/// All manifests related to this project.
pub(crate) manifest_paths: Vec<PathBuf>,
Expand All @@ -207,7 +207,7 @@ pub fn visit(
visitor: &mut dyn ItemOrAccessHandler,
provider: impl AstProvider,
) {
...
...
}
~~~
Expand All @@ -222,7 +222,7 @@ pub fn visit(
visitor: &mut dyn ItemOrAccessHandler,
provider: impl AstProvider,
) {
...
...
provider.with_const(|addr, name, c| {
self.visit_const(Some((addr, name)), c, project_context, visitor);
});
Expand All @@ -236,7 +236,7 @@ pub fn visit(
project_context: &ProjectContext,
visitor: &mut dyn ItemOrAccessHandler,
) {
...
...
// Get const's ty
let ty = project_context.resolve_type(&c.signature, self);
// Create the ItemOrAccess
Expand All @@ -251,7 +251,7 @@ pub fn visit(
let item: Item = item.into();
// enter the `Item` into Scope.
if let Some((address, module)) = enter_top {
project_context.enter_top_item(self, address, module, c.name.value(), item.clone(), false);
} else {
project_context.enter_item(self, c.name.value(), item);
Expand Down Expand Up @@ -293,7 +293,7 @@ Well first We need load it the memory.
pub struct MultiProject {
// projects are all loaded project from filesystem.
pub projects: HashMap<HashSet<PathBuf>, Project>,
...
...
}
~~~
But which project should answer the user call (like `goto to definition`) , the `projects` field is map which the `key`
Expand All @@ -307,9 +307,9 @@ There is another thing I want mention about.
Mutlti project can have the same dependency, So there are somethings can share together Like AST definitions.
~~~
pub struct MultiProject {
...
...
pub asts: HashMap<PathBuf, Rc<RefCell<SourceDefs>>>,
...
...
}
~~~
Share AST definition reduce memory consumption and save us time for loading project.
Expand All @@ -319,5 +319,3 @@ Share AST definition reduce memory consumption and save us time for loading proj
### Build in semantic analyzer
move-analyzer has build in semantic analyzer.It's can infer variable's type.
Know about variables in current scope,etc.


2 changes: 1 addition & 1 deletion language/move-analyzer/editors/code/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This a project modified from https://github.com/move-language/move
# This a project modified from https://github.com/move-language/move

# Sui-Move-Analyzer

Expand Down
22 changes: 11 additions & 11 deletions language/move-analyzer/editors/code/src/reg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,36 +168,36 @@ const Reg = {
const sui_move_toml_template = `[package]
name = "my_first_package"
version = "0.0.1"
[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework", rev = "devnet" }
[addresses]
my_first_package = "0x0"
sui = "0x2"
`;
const sui_module_file_template = `
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
module my_first_package::my_module {
// Part 1: imports
use sui::object::{Self, UID};
use sui::transfer;
use sui::tx_context::{Self, TxContext};
// Part 2: struct definitions
struct Sword has key, store {
id: UID,
magic: u64,
strength: u64,
}
struct Forge has key {
id: UID,
swords_created: u64,
}
// Part 3: module initializer to be executed when this module is published
fun init(ctx: &mut TxContext) {
let admin = Forge {
Expand All @@ -207,22 +207,22 @@ const Reg = {
// transfer the forge object to the module/package publisher
transfer::transfer(admin, tx_context::sender(ctx));
}
// Part 4: accessors required to read the struct attributes
public fun magic(self: &Sword): u64 {
self.magic
}
public fun strength(self: &Sword): u64 {
self.strength
}
public fun swords_created(self: &Forge): u64 {
self.swords_created
}
// Part 5: entry functions to create and transfer swords
public entry fun sword_create(forge: &mut Forge, magic: u64, strength: u64, recipient: address,
public entry fun sword_create(forge: &mut Forge, magic: u64, strength: u64, recipient: address,
ctx: &mut TxContext) {
// create a sword
let sword = Sword {
Expand Down
Loading

0 comments on commit 778b236

Please sign in to comment.