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

Commit

Permalink
Fix some review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 committed Apr 8, 2020
1 parent f5cc9ee commit 833f5f5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 42 deletions.
8 changes: 4 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ export CIRCUIT_DIRECTORY='./zinc-examples/casual/'
export CIRCUIT_BUILD_DIRECTORY="${CIRCUIT_DIRECTORY}/build/"
export CIRCUIT_DATA_DIRECTORY="${CIRCUIT_DIRECTORY}/data/"

export ZARGO_PATH="./target/${TARGET_DIRECTORY}/zargo"

cargo fmt --all
cargo clippy
cargo build ${CARGO_LOG_LEVEL} ${RELEASE_MODE_FLAG}
cargo test
cargo run ${CARGO_LOG_LEVEL} ${RELEASE_MODE_FLAG} --bin 'zinc-tester' -- ${LOG_LEVEL}

rm -rfv "${CIRCUIT_BUILD_DIRECTORY}"
rm -rfv "${CIRCUIT_DATA_DIRECTORY}"

export ZARGO_PATH="./target/${TARGET_DIRECTORY}/zargo"
"${ZARGO_PATH}" clean ${LOG_LEVEL} \
--manifest-path "${CIRCUIT_DIRECTORY}/Zargo.toml"

"${ZARGO_PATH}" proof-check ${LOG_LEVEL} \
--manifest-path "${CIRCUIT_DIRECTORY}/Zargo.toml" \
Expand Down
3 changes: 0 additions & 3 deletions zinc-book/src/05-operators/02-bitwise.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Bitwise operators

Bitwise operators do not perform any kind of overflow checking at
compile time. If an overflow happens, the Zinc VM will fail at runtime.

The `|=`, `^=`, `&=`, `<<=`, `>>=` shortcut operators perform the operation
and assign the result to the first operand. The first operand must be a mutable memory location
like a variable, array element, or structure field.
Expand Down
6 changes: 3 additions & 3 deletions zinc-compiler/src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct File {
}

lazy_static! {
pub static ref INDEX: RwLock<HashMap<usize, PathBuf>> = RwLock::new(HashMap::new());
pub static ref INDEX: RwLock<Vec<PathBuf>> = RwLock::new(Vec::new());
}

impl File {
Expand All @@ -43,7 +43,7 @@ impl File {
INDEX
.write()
.expect(crate::PANIC_MUTEX_SYNC)
.insert(next_file_id, self.path);
.push(self.path);

let syntax_tree = Parser::default()
.parse(&self.code, Some(next_file_id))
Expand All @@ -67,7 +67,7 @@ impl File {
INDEX
.write()
.expect(crate::PANIC_MUTEX_SYNC)
.insert(next_file_id, self.path);
.push(self.path);

let syntax_tree = Parser::default()
.parse(&self.code, Some(next_file_id))
Expand Down
30 changes: 14 additions & 16 deletions zinc-compiler/src/generator/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ impl Bytecode {
}
}

pub fn into_bytes(self) -> Vec<u8> {
for (index, instruction) in self.instructions.iter().enumerate() {
log::debug!("{:03} {:?}", index, instruction)
}

let program = Program::new(
self.input_types_as_struct(),
self.output_type.into(),
self.instructions,
);

program.to_bytes()
}

fn input_types_as_struct(&self) -> DataType {
DataType::Struct(
self.input_fields
Expand All @@ -193,19 +207,3 @@ impl Into<Vec<Instruction>> for Bytecode {
self.instructions
}
}

impl Into<Vec<u8>> for Bytecode {
fn into(self) -> Vec<u8> {
for (index, instruction) in self.instructions.iter().enumerate() {
log::debug!("{:03} {:?}", index, instruction)
}

let program = Program::new(
self.input_types_as_struct(),
self.output_type.into(),
self.instructions,
);

program.to_bytes()
}
}
20 changes: 10 additions & 10 deletions zinc-compiler/src/lexical/token/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt;

#[derive(Debug, Default, Clone, Copy, PartialEq)]
pub struct Location {
pub file: Option<usize>,
pub file_index: Option<usize>,
pub line: usize,
pub column: usize,
}
Expand All @@ -18,7 +18,7 @@ impl Location {
///
pub fn new(line: usize, column: usize) -> Self {
Self {
file: None,
file_index: None,
line,
column,
}
Expand All @@ -28,9 +28,9 @@ impl Location {
/// Creates a location with a file identifier.
/// The file identifier can be used to get its path from the global type index.
///
pub fn new_beginning(file: Option<usize>) -> Self {
pub fn new_beginning(file_index: Option<usize>) -> Self {
Self {
file,
file_index,
line: 1,
column: 1,
}
Expand All @@ -42,7 +42,7 @@ impl Location {
///
pub fn shifted_down(&self, lines: usize, column: usize) -> Self {
Self {
file: self.file,
file_index: self.file_index,
line: self.line + lines,
column,
}
Expand All @@ -53,7 +53,7 @@ impl Location {
///
pub fn shifted_right(&self, columns: usize) -> Self {
Self {
file: self.file,
file_index: self.file_index,
line: self.line,
column: self.column + columns,
}
Expand All @@ -64,18 +64,18 @@ impl fmt::Display for Location {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match (self.line, self.column) {
(0, 0) => write!(f, "<unavailable>"),
(line, column) => match self.file {
Some(file) => write!(
(line, column) => match self.file_index {
Some(file_index) => write!(
f,
"{}:{}:{}",
crate::file::INDEX
.read()
.expect(crate::PANIC_MUTEX_SYNC)
.get(&file)
.get(file_index)
.expect(crate::PANIC_FILE_INDEX)
.to_string_lossy(),
line,
column
column,
),
None => write!(f, "{}:{}", line, column),
},
Expand Down
7 changes: 3 additions & 4 deletions zinc-compiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,14 @@ fn main_inner(args: Arguments) -> Result<(), Error> {
args.public_data_template_path
);

let bytecode: Vec<u8> = Rc::try_unwrap(bytecode)
let bytecode = Rc::try_unwrap(bytecode)
.expect(zinc_compiler::PANIC_LAST_SHARED_REFERENCE)
.into_inner()
.into();
.into_inner();

File::create(&args.bytecode_output_path)
.map_err(OutputError::Creating)
.map_err(Error::BytecodeOutput)?
.write_all(bytecode.as_slice())
.write_all(bytecode.into_bytes().as_slice())
.map_err(OutputError::Writing)
.map_err(Error::BytecodeOutput)?;
log::info!("Compiled to {:?}", args.bytecode_output_path);
Expand Down
4 changes: 2 additions & 2 deletions zinc-tester/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ impl ProgramData {
let bytecode = Rc::try_unwrap(bytecode)
.expect(crate::PANIC_LAST_SHARED_REFERENCE)
.into_inner();
let bytecode: Vec<u8> = bytecode.into();

let program = Program::from_bytes(bytecode.as_slice()).map_err(Error::Program)?;
let program =
Program::from_bytes(bytecode.into_bytes().as_slice()).map_err(Error::Program)?;

Ok(program)
}
Expand Down

0 comments on commit 833f5f5

Please sign in to comment.