Skip to content
GitLab
About GitLab
GitLab: the DevOps platform
Explore GitLab
Install GitLab
How GitLab compares
Get started
GitLab docs
GitLab Learn
Pricing
Talk to an expert
/
Help
What's new
2
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Projects
Groups
Snippets
Sign up now
Login
Sign in / Register
Toggle navigation
Menu
Open sidebar
subnetzero
iridium
Commits
eee41a00
Commit
eee41a00
authored
Oct 11, 2018
by
Fletcher Haynes
Browse files
Fixed all cargo check errors
parent
246da94f
Pipeline
#32693561
passed with stages
in 13 minutes and 42 seconds
Changes
12
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.rustfmt.toml
View file @
eee41a00
max_width
=
100
hard_tabs
=
false
tab_spaces
=
4
newline_style
=
"Auto"
use_small_heuristics
=
"Default"
indent_style
=
"Block"
wrap_comments
=
false
comment_width
=
80
normalize_comments
=
false
format_strings
=
false
format_macro_matchers
=
false
format_macro_bodies
=
true
empty_item_single_line
=
true
struct_lit_single_line
=
true
fn_single_line
=
false
where_single_line
=
false
imports_indent
=
"Block"
imports_layout
=
"Mixed"
merge_imports
=
false
reorder_imports
=
true
reorder_modules
=
true
reorder_impl_items
=
false
type_punctuation_density
=
"Wide"
space_before_colon
=
false
space_after_colon
=
true
spaces_around_ranges
=
false
binop_separator
=
"Front"
remove_nested_parens
=
true
combine_control_expr
=
true
struct_field_align_threshold
=
0
match_arm_blocks
=
true
force_multiline_blocks
=
false
fn_args_density
=
"Tall"
brace_style
=
"SameLineWhere"
control_brace_style
=
"AlwaysSameLine"
trailing_semicolon
=
true
trailing_comma
=
"Vertical"
match_block_trailing_comma
=
false
blank_lines_upper_bound
=
1
blank_lines_lower_bound
=
0
edition
=
"2018"
merge_derives
=
true
use_try_shorthand
=
false
use_field_init_shorthand
=
false
force_explicit_abi
=
true
condense_wildcard_suffixes
=
false
color
=
"Auto"
required_version
=
"0.99.5"
unstable_features
=
false
disable_all_formatting
=
false
skip_children
=
false
hide_parse_errors
=
false
error_on_line_overflow
=
false
error_on_unformatted
=
false
report_todo
=
"Never"
report_fixme
=
"Never"
ignore
=
[]
emit_mode
=
"Files"
make_backup
=
false
src/assembler/mod.rs
View file @
eee41a00
...
...
@@ -9,11 +9,8 @@ pub mod program_parsers;
pub
mod
register_parsers
;
pub
mod
symbols
;
use
std
::
fmt
;
use
byteorder
::{
LittleEndian
,
WriteBytesExt
};
use
nom
::
types
::
CompleteStr
;
use
log
;
use
assembler
::
assembler_errors
::
AssemblerError
;
use
assembler
::
instruction_parsers
::
AssemblerInstruction
;
...
...
@@ -87,7 +84,10 @@ impl Assembler {
self
.process_first_phase
(
&
program
);
if
!
self
.errors
.is_empty
()
{
// TODO: Can we avoid a clone here?
error!
(
"Errors were found in the first parsing phase: {:?}"
,
self
.errors
);
error!
(
"Errors were found in the first parsing phase: {:?}"
,
self
.errors
);
return
Err
(
self
.errors
.clone
());
};
debug!
(
"First parsing phase complete"
);
...
...
@@ -132,11 +132,18 @@ impl Assembler {
// TODO: Factor this out into another function? Put it in `process_label_declaration` maybe?
if
self
.current_section
.is_some
()
{
// If we have hit a segment header already (e.g., `.code`) then we are ok
debug!
(
"Parsing label declaration in first phase: {:?} with offset {:?}"
,
i
.get_label_name
(),
self
.current_instruction
*
4
);
debug!
(
"Parsing label declaration in first phase: {:?} with offset {:?}"
,
i
.get_label_name
(),
self
.current_instruction
*
4
);
self
.process_label_declaration
(
&
i
);
}
else
{
// If we have *not* hit a segment header yet, then we have a label outside of a segment, which is not allowed
error!
(
"Label found outside of a section in first phase: {:?}"
,
i
.get_label_name
());
error!
(
"Label found outside of a section in first phase: {:?}"
,
i
.get_label_name
()
);
self
.errors
.push
(
AssemblerError
::
NoSegmentDeclarationFound
{
instruction
:
self
.current_instruction
,
});
...
...
@@ -162,7 +169,10 @@ impl Assembler {
// Same as in first pass, except in the second pass we care about opcodes and directives
for
i
in
&
p
.instructions
{
if
i
.is_directive
()
{
debug!
(
"Found a directive in second phase {:?}, bypassing"
,
i
.directive
);
debug!
(
"Found a directive in second phase {:?}, bypassing"
,
i
.directive
);
continue
;
}
if
i
.is_opcode
()
{
...
...
@@ -200,7 +210,10 @@ impl Assembler {
}
};
debug!
(
"Found label declaration: {} on line {}"
,
name
,
self
.current_instruction
);
debug!
(
"Found label declaration: {} on line {}"
,
name
,
self
.current_instruction
);
// Check if label is already in use (has an entry in the symbol table)
// TODO: Is there a cleaner way to do this?
if
self
.symbols
.has_symbol
(
&
name
)
{
...
...
@@ -209,8 +222,13 @@ impl Assembler {
}
// If we make it here, it isn't a symbol we've seen before, so stick it in the table
let
symbol
=
Symbol
::
new_with_offset
(
name
,
SymbolType
::
Label
,
(
self
.current_instruction
*
4
)
+
60
);
debug!
(
"Added new symbol to table: {:?} with offset {:?}"
,
symbol
,
(
self
.current_instruction
*
4
)
+
60
);
let
symbol
=
Symbol
::
new_with_offset
(
name
,
SymbolType
::
Label
,
(
self
.current_instruction
*
4
)
+
60
);
debug!
(
"Added new symbol to table: {:?} with offset {:?}"
,
symbol
,
(
self
.current_instruction
*
4
)
+
60
);
self
.symbols
.add_symbol
(
symbol
);
}
...
...
@@ -333,11 +351,15 @@ impl Assembler {
}
match
new_section
{
AssemblerSection
::
Code
{
ref
mut
starting_instruction
}
=>
{
AssemblerSection
::
Code
{
ref
mut
starting_instruction
,
}
=>
{
debug!
(
"Code section starts at: {}"
,
self
.current_instruction
);
*
starting_instruction
=
Some
(
self
.current_instruction
.clone
())
}
AssemblerSection
::
Data
{
ref
mut
starting_instruction
}
=>
{
AssemblerSection
::
Data
{
ref
mut
starting_instruction
,
}
=>
{
debug!
(
"Data section starts at: {}"
,
self
.current_instruction
);
*
starting_instruction
=
Some
(
self
.current_instruction
.clone
())
}
...
...
src/bin/iridium.rs
View file @
eee41a00
...
...
@@ -44,7 +44,9 @@ fn main() {
}
let
alias
=
matches
.value_of
(
"NODE_ALIAS"
)
.unwrap_or
(
""
);
let
server_addr
=
matches
.value_of
(
"SERVER_LISTEN_HOST"
)
.unwrap_or
(
"127.0.0.1"
);
let
server_addr
=
matches
.value_of
(
"SERVER_LISTEN_HOST"
)
.unwrap_or
(
"127.0.0.1"
);
let
server_port
=
matches
.value_of
(
"SERVER_LISTEN_PORT"
)
.unwrap_or
(
"2254"
);
let
num_threads
=
match
matches
.value_of
(
"THREADS"
)
{
...
...
@@ -66,13 +68,15 @@ fn main() {
Some
(
filename
)
=>
{
let
program
=
read_file
(
filename
);
let
mut
asm
=
Assembler
::
new
();
let
mut
vm
=
VM
::
new
()
.with_alias
(
alias
.to_string
())
.with_cluster_bind
(
server_addr
.into
(),
server_port
.into
());
let
mut
vm
=
VM
::
new
()
.with_alias
(
alias
.to_string
())
.with_cluster_bind
(
server_addr
.into
(),
server_port
.into
());
vm
.logical_cores
=
num_threads
;
let
program
=
asm
.assemble
(
&
program
);
match
program
{
Ok
(
p
)
=>
{
vm
.add_bytes
(
p
);
let
events
=
vm
.run
();
let
_
events
=
vm
.run
();
println!
(
"{:#?}"
,
vm
.registers
);
std
::
process
::
exit
(
0
);
}
...
...
@@ -80,7 +84,9 @@ fn main() {
}
}
None
=>
{
let
mut
vm
=
VM
::
new
()
.with_alias
(
alias
.to_string
())
.with_cluster_bind
(
server_addr
.into
(),
server_port
.into
());
let
mut
vm
=
VM
::
new
()
.with_alias
(
alias
.to_string
())
.with_cluster_bind
(
server_addr
.into
(),
server_port
.into
());
let
mut
repl
=
REPL
::
new
(
vm
);
let
mut
rx
=
repl
.rx_pipe
.take
();
thread
::
spawn
(
move
||
{
...
...
src/cluster/client.rs
View file @
eee41a00
use
std
::
io
::{
BufRead
,
Write
};
use
std
::
io
::{
BufReader
,
BufWriter
};
use
std
::
net
::
TcpStream
;
use
std
::
thread
;
use
std
::
sync
::{
Arc
,
RwLock
,
Mutex
};
use
std
::
sync
::
mpsc
::
channel
;
use
std
::
sync
::
mpsc
::{
Receiver
,
Sender
};
use
cluster
::
message
::
IridiumMessage
;
use
cluster
::
manager
::
Manager
;
use
std
::
sync
::{
Arc
,
Mutex
};
use
std
::
thread
;
pub
struct
ClusterClient
{
alias
:
Option
<
String
>
,
pub
reader
:
BufReader
<
TcpStream
>
,
pub
writer
:
BufWriter
<
TcpStream
>
,
rx
:
Option
<
Arc
<
Mutex
<
Receiver
<
String
>>>>
,
tx
:
Option
<
Arc
<
Mutex
<
Sender
<
String
>>>>
,
_
tx
:
Option
<
Arc
<
Mutex
<
Sender
<
String
>>>>
,
pub
raw_stream
:
TcpStream
,
}
...
...
@@ -29,18 +26,23 @@ impl ClusterClient {
reader
:
BufReader
::
new
(
reader
),
writer
:
BufWriter
::
new
(
writer
),
raw_stream
:
stream
,
tx
:
Some
(
Arc
::
new
(
Mutex
::
new
(
tx
))),
_
tx
:
Some
(
Arc
::
new
(
Mutex
::
new
(
tx
))),
rx
:
Some
(
Arc
::
new
(
Mutex
::
new
(
rx
))),
alias
:
None
alias
:
None
,
}
}
pub
fn
send_hello
(
&
mut
self
)
{
let
alias
=
self
.alias
.clone
();
let
alias
=
alias
.unwrap
();
self
.raw_stream
.write
(
&
alias
.as_bytes
());
if
let
Ok
(
_
)
=
self
.raw_stream
.write
(
&
alias
.as_bytes
())
{
trace!
(
"Hello sent!"
);
}
else
{
error!
(
"Error sending hello"
);
}
}
#[allow(dead_code)]
fn
w
(
&
mut
self
,
msg
:
&
str
)
->
bool
{
match
self
.writer
.write_all
(
msg
.as_bytes
())
{
Ok
(
_
)
=>
match
self
.writer
.flush
()
{
...
...
@@ -60,22 +62,20 @@ impl ClusterClient {
fn
recv_loop
(
&
mut
self
)
{
let
chan
=
self
.rx
.take
()
.unwrap
();
let
mut
writer
=
self
.raw_stream
.try_clone
()
.unwrap
();
let
_t
=
thread
::
spawn
(
move
||
{
loop
{
if
let
Ok
(
locked_rx
)
=
chan
.lock
()
{
match
locked_rx
.recv
()
{
Ok
(
msg
)
=>
{
match
writer
.write_all
(
msg
.as_bytes
())
{
Ok
(
_
)
=>
{}
Err
(
_e
)
=>
{}
};
match
writer
.flush
()
{
Ok
(
_
)
=>
{}
Err
(
_e
)
=>
{}
};
}
Err
(
_e
)
=>
{}
let
_t
=
thread
::
spawn
(
move
||
loop
{
if
let
Ok
(
locked_rx
)
=
chan
.lock
()
{
match
locked_rx
.recv
()
{
Ok
(
msg
)
=>
{
match
writer
.write_all
(
msg
.as_bytes
())
{
Ok
(
_
)
=>
{}
Err
(
_e
)
=>
{}
};
match
writer
.flush
()
{
Ok
(
_
)
=>
{}
Err
(
_e
)
=>
{}
};
}
Err
(
_e
)
=>
{}
}
}
});
...
...
src/cluster/manager.rs
View file @
eee41a00
use
std
::
collections
::
HashMap
;
use
std
::
sync
::{
Arc
,
RwLock
};
use
cluster
::
client
::
ClusterClient
;
use
cluster
::
{
NodeAlias
,
NodeCollection
}
;
use
cluster
::
NodeAlias
;
#[derive(Default)]
pub
struct
Manager
{
clients
:
NodeCollection
clients
:
HashMap
<
NodeAlias
,
ClusterClient
>
,
}
impl
Manager
{
pub
fn
new
()
->
Manager
{
Manager
{
clients
:
HashMap
::
new
()
clients
:
HashMap
::
new
()
,
}
}
...
...
src/cluster/message.rs
View file @
eee41a00
pub
enum
IridiumMessage
{
Hello
{
alias
:
String
},
HelloAck
{
alias
:
String
,
nodes
:
Vec
<
(
String
,
String
,
String
)
>
}
pub
enum
IridiumMessage
{
Hello
{
alias
:
String
,
},
HelloAck
{
alias
:
String
,
nodes
:
Vec
<
(
String
,
String
,
String
)
>
,
},
}
#[cfg(test)]
mod
test
{
}
mod
test
{}
src/cluster/mod.rs
View file @
eee41a00
pub
mod
server
;
pub
mod
client
;
pub
mod
manager
;
pub
mod
message
;
use
std
::
sync
::{
Arc
,
RwLock
};
use
std
::
collections
::
HashMap
;
use
cluster
::
client
::
ClusterClient
;
pub
mod
server
;
type
NodeAlias
=
String
;
type
NodeCollection
=
HashMap
<
NodeAlias
,
ClusterClient
>
;
src/cluster/server.rs
View file @
eee41a00
use
std
::
io
::
Read
;
use
std
::
net
::{
SocketAddr
,
TcpListener
};
use
std
::
sync
::{
Arc
,
RwLock
};
use
std
::
net
::{
TcpListener
,
SocketAddr
};
use
std
::
thread
;
use
std
::
io
::
Read
;
use
cluster
::
client
::
ClusterClient
;
use
cluster
::
manager
::
Manager
;
pub
fn
listen
(
addr
:
SocketAddr
,
connection_manager
:
Arc
<
RwLock
<
Manager
>>
)
{
pub
fn
listen
(
addr
:
SocketAddr
,
_
connection_manager
:
Arc
<
RwLock
<
Manager
>>
)
{
info!
(
"Initializing Cluster server..."
);
let
listener
=
TcpListener
::
bind
(
addr
)
.unwrap
();
for
stream
in
listener
.incoming
()
{
...
...
@@ -15,7 +15,7 @@ pub fn listen(addr: SocketAddr, connection_manager: Arc<RwLock<Manager>>) {
thread
::
spawn
(
move
||
{
let
mut
buf
=
[
0
;
1024
];
let
mut
client
=
ClusterClient
::
new
(
stream
);
let
bytes_read
=
client
.reader
.read
(
&
mut
buf
);
let
_
bytes_read
=
client
.reader
.read
(
&
mut
buf
);
let
alias
=
String
::
from_utf8_lossy
(
&
buf
);
println!
(
"Alias is: {:?}"
,
alias
);
client
.run
();
...
...
src/lib.rs
View file @
eee41a00
...
...
@@ -7,11 +7,10 @@ extern crate nom;
extern
crate
num_cpus
;
extern
crate
uuid
;
pub
mod
assembler
;
pub
mod
cluster
;
pub
mod
instruction
;
pub
mod
remote
;
pub
mod
repl
;
pub
mod
scheduler
;
pub
mod
vm
;
pub
mod
cluster
;
src/repl/mod.rs
View file @
eee41a00
...
...
@@ -4,18 +4,18 @@ use std;
use
std
::
fs
::
File
;
use
std
::
io
;
use
std
::
io
::{
Read
,
Write
};
use
std
::
net
::
TcpStream
;
use
std
::
num
::
ParseIntError
;
use
std
::
path
::
Path
;
use
std
::
sync
::{
RwLock
,
Arc
,
mpsc
};
use
std
::
sync
::
mpsc
::{
Receiver
,
Sender
};
use
std
::
net
::
TcpStream
;
use
std
::
sync
::{
mpsc
};
use
nom
::
types
::
CompleteStr
;
use
assembler
::
program_parsers
::
program
;
use
assembler
::
Assembler
;
use
cluster
;
use
cluster
::
manager
::
Manager
;
use
repl
::
command_parser
::
CommandParser
;
use
scheduler
::
Scheduler
;
use
vm
::
VM
;
...
...
@@ -339,10 +339,14 @@ impl REPL {
}
}
fn
cluster_members
(
&
mut
self
,
args
:
&
[
&
str
])
{
fn
cluster_members
(
&
mut
self
,
_
args
:
&
[
&
str
])
{
self
.send_message
(
format!
(
"Listing Known Nodes:"
));
let
cluster_members
=
self
.vm.connection_manager
.read
()
.unwrap
()
.get_client_names
();
let
cluster_members
=
self
.vm
.connection_manager
.read
()
.unwrap
()
.get_client_names
();
self
.send_message
(
format!
(
"{:#?}"
,
cluster_members
));
}
}
src/vm.rs
View file @
eee41a00
use
std
;
use
std
::
thread
;
use
std
::
net
::{
SocketAddr
};
use
std
::
io
::
Cursor
;
use
std
::
net
::
SocketAddr
;
use
std
::
sync
::{
Arc
,
RwLock
};
use
std
::
thread
;
use
byteorder
::
*
;
use
chrono
::
prelude
::
*
;
use
num_cpus
;
use
uuid
::
Uuid
;
use
assembler
::{
PIE_HEADER_LENGTH
,
PIE_HEADER_PREFIX
,
Assembler
};
use
assembler
::{
PIE_HEADER_LENGTH
,
PIE_HEADER_PREFIX
};
use
cluster
;
use
cluster
::
manager
::
Manager
;
use
instruction
::
Opcode
;
...
...
@@ -25,9 +25,9 @@ pub enum VMEventType {
impl
VMEventType
{
pub
fn
stop_code
(
&
self
)
->
u32
{
match
&
self
{
&
VMEventType
::
Start
=>
{
0
}
&
VMEventType
::
GracefulStop
{
code
}
=>
{
*
code
}
&
VMEventType
::
Crash
{
code
}
=>
{
*
code
}
&
VMEventType
::
Start
=>
0
,
&
VMEventType
::
GracefulStop
{
code
}
=>
*
code
,
&
VMEventType
::
Crash
{
code
}
=>
*
code
,
}
}
}
...
...
@@ -76,8 +76,7 @@ pub struct VM {
// Server address that the VM will bind to for server-to-server communications
server_addr
:
Option
<
String
>
,
// Port the server will bind to for server-to-server communications
server_port
:
Option
<
String
>
server_port
:
Option
<
String
>
,
}
impl
VM
{
...
...
@@ -179,7 +178,6 @@ impl VM {
let
register
=
self
.next_8_bits
()
as
usize
;
let
number
=
i32
::
from
(
self
.next_16_bits
());
self
.registers
[
register
]
=
number
;
}
Opcode
::
ADD
=>
{
let
register1
=
self
.registers
[
self
.next_8_bits
()
as
usize
];
...
...
@@ -455,17 +453,20 @@ impl VM {
self
.registers
[
self
.next_8_bits
()
as
usize
]
=
data
;
}
Opcode
::
SETM
=>
{
let
offset
=
self
.registers
[
self
.next_8_bits
()
as
usize
]
as
usize
;
let
_
offset
=
self
.registers
[
self
.next_8_bits
()
as
usize
]
as
usize
;
let
data
=
self
.registers
[
self
.next_8_bits
()
as
usize
];
let
mut
buf
:
[
u8
;
4
]
=
[
0
,
0
,
0
,
0
];
buf
.as_mut
()
.write_i32
::
<
LittleEndian
>
(
data
);
let
_
=
buf
.as_mut
()
.write_i32
::
<
LittleEndian
>
(
data
);
}
Opcode
::
PUSH
=>
{
let
data
=
self
.registers
[
self
.next_8_bits
()
as
usize
];
let
mut
buf
:
[
u8
;
4
]
=
[
0
,
0
,
0
,
0
];
buf
.as_mut
()
.write_i32
::
<
LittleEndian
>
(
data
);
for
b
in
&
buf
{
self
.stack
.push
(
*
b
);
if
let
Ok
(
_
)
=
buf
.as_mut
()
.write_i32
::
<
LittleEndian
>
(
data
)
{
for
b
in
&
buf
{
self
.stack
.push
(
*
b
);
}
}
else
{
return
Some
(
1
);
}
}
Opcode
::
POP
=>
{
...
...
@@ -523,7 +524,7 @@ impl VM {
}
// The 4 is added here to allow for the 4 bytes that tell the VM where the executable code starts
while
prepension
.len
()
<
PIE_HEADER_LENGTH
+
4
{
while
prepension
.len
()
<
PIE_HEADER_LENGTH
+
4
{
prepension
.push
(
0
);
}
...
...
@@ -543,7 +544,10 @@ impl VM {
error!
(
"Unable to bind to cluster server address: {}"
,
addr
);
}
}
else
{
error!
(
"Unable to bind to cluster server port: {:?}"
,
self
.server_port
);
error!
(
"Unable to bind to cluster server port: {:?}"
,
self
.server_port
);
}
}
...
...
tests/commons/mod.rs
View file @
eee41a00
pub
fn
setup
()
{
// setup code specific to your library's tests would go here
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment