Skip to content

Commit

Permalink
Merge pull request #61 from dfinance/main-arguments
Browse files Browse the repository at this point in the history
add support for main() arguments
  • Loading branch information
mkurnikov authored May 21, 2020
2 parents 193ac06 + c87931b commit ac8a526
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 107 deletions.
62 changes: 24 additions & 38 deletions crates/dialects/lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,31 @@ serde_derive = "1.0.106"
serde_json = "1.0.52"
codespan = "0.8.0"

#move-vm-runtime = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
#move-vm-state = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
#move-vm-types = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
#libra-state-view = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
#language-e2e-tests = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
#move-core-types = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
#vm = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
#libra-types = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
#move-lang = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
#libra-canonical-serialization = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
#libra-crypto = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
#move-ir-types = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-move-vm-runtime = { package = "move-vm-runtime", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-move-vm-state = { package = "move-vm-state", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-move-vm-types = { package = "move-vm-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-libra-state-view = { package = "libra-state-view", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-language-e2e-tests = { package = "language-e2e-tests", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-move-core-types = { package = "move-core-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-vm = { package = "vm", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-libra-types = { package = "libra-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-move-lang = { package = "move-lang", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-libra-canonical-serialization = { package = "libra-canonical-serialization", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-libra-crypto = { package = "libra-crypto", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfin-move-ir-types = { package = "move-ir-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }

dfinance-move-vm-runtime = { package = "move-vm-runtime", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfinance-move-vm-state = { package = "move-vm-state", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfinance-move-vm-types = { package = "move-vm-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfinance-libra-state-view = { package = "libra-state-view", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfinance-language-e2e-tests = { package = "language-e2e-tests", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfinance-move-core-types = { package = "move-core-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfinance-vm = { package = "vm", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfinance-libra-types = { package = "libra-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfinance-move-lang = { package = "move-lang", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfinance-libra-canonical-serialization = { package = "libra-canonical-serialization", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfinance-libra-crypto = { package = "libra-crypto", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }
dfinance-move-ir-types = { package = "move-ir-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020" }

#
move-vm-runtime = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
move-vm-state = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
move-vm-types = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
libra-state-view = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
language-e2e-tests = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
move-core-types = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
vm = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
libra-types = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
move-lang = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
libra-canonical-serialization = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
libra-crypto = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
move-ir-types = { git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-move-vm-runtime = { package = "move-vm-runtime", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-move-vm-state = { package = "move-vm-state", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-move-vm-types = { package = "move-vm-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-libra-state-view = { package = "libra-state-view", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-language-e2e-tests = { package = "language-e2e-tests", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-move-core-types = { package = "move-core-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-vm = { package = "vm", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-libra-types = { package = "libra-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-move-lang = { package = "move-lang", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-libra-canonical-serialization = { package = "libra-canonical-serialization", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-libra-crypto = { package = "libra-crypto", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }
orig-move-ir-types = { package = "move-ir-types", git = "https://github.com/dfinance/libra.git", branch = "12.05.2020.original" }

#move-vm-runtime = { path = "../../../dvm-libra/language/move-vm/runtime" }
#move-vm-state = { path = "../../../dvm-libra/language/move-vm/state" }
Expand Down
26 changes: 13 additions & 13 deletions crates/dialects/lang/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ use std::fs;

fn build_replacement_table() -> HashMap<&'static str, &'static str> {
let mut table = HashMap::new();
table.insert("move_core_types::", "dfinance_move_core_types::");
table.insert("move_lang::", "dfinance_move_lang::");
table.insert("move_ir_types::", "dfinance_move_ir_types::");
table.insert("orig_move_core_types::", "dfin_move_core_types::");
table.insert("orig_move_lang::", "dfin_move_lang::");
table.insert("orig_move_ir_types::", "dfin_move_ir_types::");

table.insert("move_vm_runtime::", "dfinance_move_vm_runtime::");
table.insert("move_vm_state::", "dfinance_move_vm_state::");
table.insert("move_vm_types::", "dfinance_move_vm_types::");
table.insert("vm::", "dfinance_vm::");
table.insert("orig_move_vm_runtime::", "dfin_move_vm_runtime::");
table.insert("orig_move_vm_state::", "dfin_move_vm_state::");
table.insert("orig_move_vm_types::", "dfin_move_vm_types::");
table.insert("orig_vm::", "dfin_vm::");

table.insert("libra_state_view::", "dfinance_libra_state_view::");
table.insert("libra_types::", "dfinance_libra_types::");
table.insert("orig_libra_state_view::", "dfin_libra_state_view::");
table.insert("orig_libra_types::", "dfin_libra_types::");
table.insert(
"libra_canonical_serialization::",
"dfinance_libra_canonical_serialization::",
"orig_libra_canonical_serialization::",
"dfin_libra_canonical_serialization::",
);
table.insert("libra_crypto::", "dfinance_libra_crypto::");
table.insert("language_e2e_tests::", "dfinance_language_e2e_tests::");
table.insert("orig_libra_crypto::", "dfin_libra_crypto::");
table.insert("orig_language_e2e_tests::", "dfin_language_e2e_tests::");

table.insert("crate::libra", "crate::dfina");
table
Expand Down
30 changes: 25 additions & 5 deletions crates/dialects/lang/src/dfina/executor.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use anyhow::Result;
use dfinance_libra_types::{
use dfin_libra_types::{
transaction::{parse_as_transaction_argument, TransactionArgument},
vm_error::StatusCode,
write_set::{WriteOp, WriteSet},
};
use dfinance_move_core_types::account_address::AccountAddress;
use dfinance_move_vm_types::{loaded_data::types::FatStructType, values::GlobalValue};
use dfinance_vm::errors::{vm_error, Location, VMResult};
use dfin_move_core_types::account_address::AccountAddress;
use dfin_move_vm_types::loaded_data::types::FatStructType;
use dfin_move_vm_types::{values::GlobalValue, values::Value};
use dfin_vm::errors::{vm_error, Location, VMResult};

use shared::results::ResourceChange;
use utils::FilePath;
Expand All @@ -30,11 +32,22 @@ fn convert_set_value(struct_type: FatStructType, val: GlobalValue) -> VMResult<R
Ok(change)
}

/// Convert the transaction arguments into move values.
fn convert_txn_arg(arg: TransactionArgument) -> Value {
match arg {
TransactionArgument::U64(i) => Value::u64(i),
TransactionArgument::Address(a) => Value::address(a),
TransactionArgument::Bool(b) => Value::bool(b),
TransactionArgument::U8Vector(v) => Value::vector_u8(v),
}
}

pub fn compile_and_run(
script: (FilePath, String),
deps: &[(FilePath, String)],
sender: String,
genesis_write_set: WriteSet,
args: Vec<String>,
) -> Result<Vec<ResourceChange>> {
let sender =
AccountAddress::from_hex_literal(&sender).expect("Should be validated in the caller");
Expand All @@ -47,8 +60,15 @@ pub fn compile_and_run(
crate::dfina::prepare_fake_network_state(compiled_modules, genesis_write_set);

let serialized_script = crate::dfina::serialize_script(compiled_script)?;

let mut script_args = Vec::with_capacity(args.len());
for passed_arg in args {
let transaction_argument = parse_as_transaction_argument(&passed_arg)?;
let script_arg = convert_txn_arg(transaction_argument);
script_args.push(script_arg);
}
let changed_resources =
crate::dfina::execute_script(sender, &network_state, serialized_script, vec![])?;
crate::dfina::execute_script(sender, &network_state, serialized_script, script_args)?;

let mut changes = vec![];
for (_, global_val) in changed_resources {
Expand Down
24 changes: 12 additions & 12 deletions crates/dialects/lang/src/dfina/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use std::collections::BTreeMap;

use anyhow::Result;
use codespan::ByteIndex;
use dfinance_language_e2e_tests::data_store::FakeDataStore;
use dfinance_libra_types::{
use dfin_language_e2e_tests::data_store::FakeDataStore;
use dfin_libra_types::{
access_path::AccessPath, account_address::AccountAddress, vm_error::VMStatus,
write_set::WriteSet,
};
use dfinance_move_core_types::gas_schedule::{GasAlgebra, GasUnits};
use dfinance_move_ir_types::location::Loc;
use dfinance_move_lang::{
use dfin_move_core_types::gas_schedule::{GasAlgebra, GasUnits};
use dfin_move_ir_types::location::Loc;
use dfin_move_lang::{
cfgir,
compiled_unit::CompiledUnit,
errors::{Error, FilesSourceText},
Expand All @@ -19,16 +19,16 @@ use dfinance_move_lang::{
shared::Address,
strip_comments_and_verify, to_bytecode,
};
use dfinance_move_vm_runtime::MoveVM;
use dfinance_move_vm_state::execution_context::SystemExecutionContext;
use dfinance_move_vm_types::{
use dfin_move_vm_runtime::MoveVM;
use dfin_move_vm_state::execution_context::SystemExecutionContext;
use dfin_move_vm_types::{
gas_schedule::zero_cost_schedule,
loaded_data::types::FatStructType,
transaction_metadata::TransactionMetadata,
values::{GlobalValue, Value},
};
use dfinance_vm::file_format::CompiledScript;
use dfinance_vm::CompiledModule;
use dfin_vm::file_format::CompiledScript;
use dfin_vm::CompiledModule;

use shared::bech32;
use shared::errors::{
Expand Down Expand Up @@ -63,7 +63,7 @@ fn from_compiler_error(comp_error: CompilerError) -> Error {

pub fn report_errors(files: FilesSourceText, errors: Vec<CompilerError>) -> ! {
let errors = errors.into_iter().map(from_compiler_error).collect();
dfinance_move_lang::errors::report_errors(files, errors)
dfin_move_lang::errors::report_errors(files, errors)
}

fn into_compiler_error(error: Error) -> CompilerError {
Expand Down Expand Up @@ -248,7 +248,7 @@ pub fn check_defs(
source_definitions,
lib_definitions,
};
dfinance_move_lang::check_program(Ok(ast_program), Some(sender))
dfin_move_lang::check_program(Ok(ast_program), Some(sender))
}

pub fn generate_bytecode(
Expand Down
6 changes: 3 additions & 3 deletions crates/dialects/lang/src/dfina/resources.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use anyhow::Result;
use dfinance_libra_types::{
use dfin_libra_types::{
access_path::AccessPath,
language_storage::ResourceKey,
write_set::{WriteOp, WriteSet, WriteSetMut},
};
use dfinance_move_core_types::{account_address::AccountAddress, identifier::Identifier};
use dfinance_move_vm_types::loaded_data::types::{FatStructType, FatType};
use dfin_move_core_types::{account_address::AccountAddress, identifier::Identifier};
use dfin_move_vm_types::loaded_data::types::{FatStructType, FatType};

use shared::results::{ResourceChange, ResourceChangeOp, ResourceType};

Expand Down
30 changes: 25 additions & 5 deletions crates/dialects/lang/src/libra/executor.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use anyhow::Result;
use libra_types::{
use orig_libra_types::{
transaction::{parse_as_transaction_argument, TransactionArgument},
vm_error::StatusCode,
write_set::{WriteOp, WriteSet},
};
use move_core_types::account_address::AccountAddress;
use move_vm_types::{loaded_data::types::FatStructType, values::GlobalValue};
use vm::errors::{vm_error, Location, VMResult};
use orig_move_core_types::account_address::AccountAddress;
use orig_move_vm_types::loaded_data::types::FatStructType;
use orig_move_vm_types::{values::GlobalValue, values::Value};
use orig_vm::errors::{vm_error, Location, VMResult};

use shared::results::ResourceChange;
use utils::FilePath;
Expand All @@ -30,11 +32,22 @@ fn convert_set_value(struct_type: FatStructType, val: GlobalValue) -> VMResult<R
Ok(change)
}

/// Convert the transaction arguments into move values.
fn convert_txn_arg(arg: TransactionArgument) -> Value {
match arg {
TransactionArgument::U64(i) => Value::u64(i),
TransactionArgument::Address(a) => Value::address(a),
TransactionArgument::Bool(b) => Value::bool(b),
TransactionArgument::U8Vector(v) => Value::vector_u8(v),
}
}

pub fn compile_and_run(
script: (FilePath, String),
deps: &[(FilePath, String)],
sender: String,
genesis_write_set: WriteSet,
args: Vec<String>,
) -> Result<Vec<ResourceChange>> {
let sender =
AccountAddress::from_hex_literal(&sender).expect("Should be validated in the caller");
Expand All @@ -47,8 +60,15 @@ pub fn compile_and_run(
crate::libra::prepare_fake_network_state(compiled_modules, genesis_write_set);

let serialized_script = crate::libra::serialize_script(compiled_script)?;

let mut script_args = Vec::with_capacity(args.len());
for passed_arg in args {
let transaction_argument = parse_as_transaction_argument(&passed_arg)?;
let script_arg = convert_txn_arg(transaction_argument);
script_args.push(script_arg);
}
let changed_resources =
crate::libra::execute_script(sender, &network_state, serialized_script, vec![])?;
crate::libra::execute_script(sender, &network_state, serialized_script, script_args)?;

let mut changes = vec![];
for (_, global_val) in changed_resources {
Expand Down
24 changes: 12 additions & 12 deletions crates/dialects/lang/src/libra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use std::collections::BTreeMap;

use anyhow::Result;
use codespan::ByteIndex;
use language_e2e_tests::data_store::FakeDataStore;
use libra_types::{
use orig_language_e2e_tests::data_store::FakeDataStore;
use orig_libra_types::{
access_path::AccessPath, account_address::AccountAddress, vm_error::VMStatus,
write_set::WriteSet,
};
use move_core_types::gas_schedule::{GasAlgebra, GasUnits};
use move_ir_types::location::Loc;
use move_lang::{
use orig_move_core_types::gas_schedule::{GasAlgebra, GasUnits};
use orig_move_ir_types::location::Loc;
use orig_move_lang::{
cfgir,
compiled_unit::CompiledUnit,
errors::{Error, FilesSourceText},
Expand All @@ -19,16 +19,16 @@ use move_lang::{
shared::Address,
strip_comments_and_verify, to_bytecode,
};
use move_vm_runtime::MoveVM;
use move_vm_state::execution_context::SystemExecutionContext;
use move_vm_types::{
use orig_move_vm_runtime::MoveVM;
use orig_move_vm_state::execution_context::SystemExecutionContext;
use orig_move_vm_types::{
gas_schedule::zero_cost_schedule,
loaded_data::types::FatStructType,
transaction_metadata::TransactionMetadata,
values::{GlobalValue, Value},
};
use vm::file_format::CompiledScript;
use vm::CompiledModule;
use orig_vm::file_format::CompiledScript;
use orig_vm::CompiledModule;

use shared::bech32;
use shared::errors::{
Expand Down Expand Up @@ -63,7 +63,7 @@ fn from_compiler_error(comp_error: CompilerError) -> Error {

pub fn report_errors(files: FilesSourceText, errors: Vec<CompilerError>) -> ! {
let errors = errors.into_iter().map(from_compiler_error).collect();
move_lang::errors::report_errors(files, errors)
orig_move_lang::errors::report_errors(files, errors)
}

fn into_compiler_error(error: Error) -> CompilerError {
Expand Down Expand Up @@ -248,7 +248,7 @@ pub fn check_defs(
source_definitions,
lib_definitions,
};
move_lang::check_program(Ok(ast_program), Some(sender))
orig_move_lang::check_program(Ok(ast_program), Some(sender))
}

pub fn generate_bytecode(
Expand Down
6 changes: 3 additions & 3 deletions crates/dialects/lang/src/libra/resources.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use anyhow::Result;
use libra_types::{
use orig_libra_types::{
access_path::AccessPath,
language_storage::ResourceKey,
write_set::{WriteOp, WriteSet, WriteSetMut},
};
use move_core_types::{account_address::AccountAddress, identifier::Identifier};
use move_vm_types::loaded_data::types::{FatStructType, FatType};
use orig_move_core_types::{account_address::AccountAddress, identifier::Identifier};
use orig_move_vm_types::loaded_data::types::{FatStructType, FatType};

use shared::results::{ResourceChange, ResourceChangeOp, ResourceType};

Expand Down
Loading

0 comments on commit ac8a526

Please sign in to comment.