Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
b984dd1
move Instruction(s) and Elem to own module (execution no longer depen…
michaeljklein Jan 27, 2022
8a22e13
implement restacking primitive (backend)
michaeljklein Feb 1, 2022
7d96a34
add restack append, executor, and instruction
michaeljklein Feb 1, 2022
7d3b847
add serde json (de)serializer
michaeljklein Feb 1, 2022
6c284b9
add first restack test (failing)
michaeljklein Feb 7, 2022
d1465eb
add granular stack manipulations, add tests, fix tests (passing)
michaeljklein Feb 7, 2022
e64ac66
fix unused import, document stack primitives, add tests for each (pas…
michaeljklein Feb 8, 2022
9c27595
remove Bytes32: combine with Bytes(N)
michaeljklein Feb 8, 2022
3b93180
add le/lt primitives, use arbitrary_precision numbers for manually de…
michaeljklein Feb 8, 2022
970f65d
prototype (concat, slice, index, lookup) and implement concat
michaeljklein Feb 8, 2022
6a7c49d
implement concat for bytes, string, array, object; prototype slice an…
michaeljklein Feb 9, 2022
ac770e9
add to/from json for object/string/array, add instruction symbols, fi…
michaeljklein Feb 11, 2022
eea7876
add debug method for stack, verbose execution, fix push/pop, extend demo
michaeljklein Feb 11, 2022
eff41f9
fixed eq bug, kick out restack, cleanup example
michaeljklein Feb 11, 2022
7fd559b
tests now passing: deriving clone, eq, ord on instruction
michaeljklein Feb 11, 2022
92e27bc
rename s/Fn//
michaeljklein Feb 14, 2022
32aab54
add string_to_bytes primitive
michaeljklein Feb 14, 2022
988a056
extend example with concat/hash of two fields
michaeljklein Feb 14, 2022
ea9c3ea
replace *FromJson with UnpackJson, use ElemSymbol to replace simple_type
michaeljklein Feb 14, 2022
f089faa
use pop_pushN to simplify executor
michaeljklein Feb 14, 2022
83ab03d
WIP preparing to type instructions
michaeljklein Feb 16, 2022
8e88d03
implement arbitrary for ElemSymbol, Number
michaeljklein Feb 16, 2022
26638dd
add arbitrary instances for Value, Map, Number, ElemSymbol
michaeljklein Feb 17, 2022
c7543ed
migrate Arbitrary instances and Elem to own files, cleanup
michaeljklein Feb 17, 2022
f5fc69b
add typing for each instruction besides Restack
michaeljklein Feb 17, 2022
3af5eab
added zip_then to compare typed stacks and got tests passing
michaeljklein Feb 18, 2022
3ee0763
unification up and running for stack types
michaeljklein Feb 18, 2022
186edc3
typing Instructions, made Instructions a struct, make type errors mor…
michaeljklein Feb 21, 2022
a2dbfbb
types work for three instruction example with new unification algorithm
michaeljklein Feb 22, 2022
a2293f8
now typing [push(json), unpack_to(object), dup] with silent eq error
michaeljklein Feb 22, 2022
35505c5
type-level lists prototype
michaeljklein Feb 23, 2022
f825b0d
add dyn-clone, use type equality
michaeljklein Feb 24, 2022
48d6d19
use Arc
michaeljklein Feb 24, 2022
ade811b
WIP: debugging IsInstruction for concat
michaeljklein Mar 1, 2022
4ccf649
cleanup and get working with return types
michaeljklein Mar 1, 2022
fd6822d
implemented IsInstructionT for concat
michaeljklein Mar 1, 2022
b980727
add type-level sets
michaeljklein Mar 1, 2022
575909e
merge IsElem and AnElem
michaeljklein Mar 2, 2022
b14af3c
debugging and applying AnElem
michaeljklein Mar 2, 2022
d112edc
iterator impls, debugging return type API
michaeljklein Mar 3, 2022
bdb83b1
fix returning too many values
michaeljklein Mar 3, 2022
0e645c2
WIP: checkpoint broken mutable references
michaeljklein Mar 7, 2022
d5981bf
fixed mutex and got concat IsInstructionT up to parity w/ IsInstruction
michaeljklein Mar 7, 2022
f44126b
IsInstructionT up to parity with InstructionT
michaeljklein Mar 7, 2022
3e9c174
add alias/handler for untyped inputs, use for le/lt/eq
michaeljklein Mar 8, 2022
1869268
added InstructionT impl for all but Restack
michaeljklein Mar 8, 2022
39af1ac
WIP: cleanup
michaeljklein Mar 10, 2022
4a41781
implement typed popping from stack for instructions
michaeljklein Mar 10, 2022
fd63fcb
make Elems and IsList Iterable, dynamic instruction dispatch
michaeljklein Mar 14, 2022
e59508b
example program working with new instruction types
michaeljklein Mar 14, 2022
7b018e9
cleanup unused versions of instructions/executor
michaeljklein Mar 14, 2022
18e2513
debugging type errors: added AJsonElem for rest of types, recreating …
michaeljklein Mar 16, 2022
244ecef
added debug info to stack type and popping from stack
michaeljklein Mar 16, 2022
c155477
WIP: replacing EnumSet's with ElemType's
michaeljklein Mar 16, 2022
cccbb1b
WIP: include debug info w/ elem sets and propagate
michaeljklein Mar 17, 2022
757902d
calculate type at each instruction evaluation and include w/ debug info
michaeljklein Mar 18, 2022
9a7cb9e
prettier-printed errors -> found and fixed off-by-one error
michaeljklein Mar 18, 2022
0eaae81
use clap for cli parsing, pretty print elem/stack, get running and pa…
michaeljklein Mar 21, 2022
9fe5fb8
cleanup and get largest example working again
michaeljklein Mar 21, 2022
cd65240
add basic template for schema w/ test
michaeljklein Mar 23, 2022
6c4729b
debugging tokio version error, add query/template handling to cli, de…
michaeljklein Mar 23, 2022
aa4140b
adding test server: post expected (to, from) get or get as posted
michaeljklein Mar 23, 2022
f1c58c4
support rate limiting, extra debug info, for test api and begin imple…
michaeljklein Mar 25, 2022
f1a9f1d
wrapping up test server: post and get api works
michaeljklein Mar 28, 2022
947f420
support multiple queries and debug/fail-fast for queries
michaeljklein Mar 28, 2022
d72070d
json to template, support put in schemas, caching works, token gating…
michaeljklein Mar 28, 2022
b162cbd
add support for monomorphic typing, split out Query into own module
michaeljklein Mar 28, 2022
72bb43c
split out into more modules, remove executor, fix query caching, cleanup
michaeljklein Mar 29, 2022
3fa18d4
adding missing docs
michaeljklein Apr 13, 2022
e5b6721
implement Error for IsInstruction errors
michaeljklein Apr 13, 2022
fbfab00
continuing to add docs, replace empty enums with Empty
michaeljklein Apr 13, 2022
4ff47a8
document queries and json_template, cleanup queries
michaeljklein Apr 13, 2022
0b5f2a6
add docs for an_elem, arbitrary, elem[_type], json_template, [re]stac…
michaeljklein Apr 13, 2022
b4dbdf8
linting and adding docs
michaeljklein Apr 14, 2022
5c3fca6
splitting out Elems into more modules
michaeljklein Apr 20, 2022
edcb391
split out modules per major type and add missing docs
michaeljklein Apr 29, 2022
8b82259
add nom line-oriented parser: first pass
michaeljklein May 11, 2022
c8b29ca
add documentation and unit tests for new parser
michaeljklein May 12, 2022
ed1dbc0
add type_annotation slot for unpack_json, fix tailing whitespace at e…
michaeljklein May 12, 2022
d92648e
WIP conversion to stack-based Instructions
michaeljklein May 17, 2022
7670c1f
WIP: conversion to stack instructions implemented up to assignments u…
michaeljklein May 18, 2022
ad94e40
cleanup and finish implementation of InstructionWriter
michaeljklein May 24, 2022
b55cfde
add InstructionsWriter docstrings, clippy first pass
michaeljklein May 26, 2022
c21a78f
WIP: clippy linting
michaeljklein May 26, 2022
61f31d9
merge with main branch
michaeljklein May 26, 2022
c848a63
clippy linting pass
michaeljklein Jun 3, 2022
c8b4c02
support basic parsing of literal Elem's in assignments, WIP test case…
michaeljklein Jun 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rustflags = ["-Cinstrument-coverage"]
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ hex = "0.4"
hex-literal = "0.3"
indexmap = "1.5"
k256 = { version = "0.10.2", features = ["std", "ecdsa", "serde"] }
nom = "7.1.1"
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
reqwest = { version = "0.11.10", features = ["json"] }
Expand Down
2 changes: 1 addition & 1 deletion src/an_elem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl AnElem for Value {


/// AnElem::from_elem errors
#[derive(Clone, Debug, Error)]
#[derive(Clone, Debug, Error, PartialEq)]
pub enum AnElemError {
/// AnElem::from_elem: element popped from the Stack wasn't the expected type
#[error("AnElem::from_elem: element popped from the stack\n\n{found}\n\nwasn't the expected type:\n{expected:?}")]
Expand Down
6 changes: 6 additions & 0 deletions src/an_elem_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ pub struct Return<T: AnElem> {
return_value: Arc<Mutex<Option<T>>>,
}

impl<T: AnElem> Default for Return<T> {
fn default() -> Self {
Self::new()
}
}

impl<T: AnElem> Return<T> {
/// New Return slot with nothing in it
pub fn new() -> Self {
Expand Down
6 changes: 4 additions & 2 deletions src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ impl Arbitrary for ArbitraryNumber {
} else {
let x: f64 = Arbitrary::arbitrary(g);
ArbitraryNumber { number:
Number::from_f64(x).unwrap_or(From::from(0u8))
Number::from_f64(x)
.unwrap_or_else(|| From::from(0u8))
}
}
}
Expand All @@ -51,7 +52,8 @@ impl Arbitrary for ArbitraryNumber {
Some(self_f64) => Box::new(
self_f64.shrink()
.map(|x| ArbitraryNumber {
number: Number::from_f64(x).unwrap_or(From::from(0u8)),
number: Number::from_f64(x)
.unwrap_or_else(|| From::from(0u8)),
})),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ impl Cli {
}

/// Run Cli::parse_and_run_result and print its result
pub async fn parse_and_run(&self) -> () {
pub async fn parse_and_run(&self) {
match self.parse_and_run_result().await {
Ok(()) => println!("successful!"),
Err(e) => println!("failed:\n{}\n", e),
}
}

/// Run a set of Cli arguments
pub async fn run(&self) -> () {
pub async fn run(&self) {
match self.command {
None => self.parse_and_run().await,
Some(Commands::Parse) => {
Expand Down
4 changes: 2 additions & 2 deletions src/elem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ pub enum ElemSymbol {
impl Arbitrary for ElemSymbol {
fn arbitrary(g: &mut Gen) -> Self {
let choices: Vec<ElemSymbol> = EnumSet::all().iter().collect();
*g.choose(&choices).unwrap_or_else(|| &Self::Unit)
*g.choose(&choices).unwrap_or(&Self::Unit)
}

fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
let self_copy = self.clone();
let self_copy = *self;
Box::new(EnumSet::all().iter().filter(move |&x| x < self_copy))
}
}
Expand Down
27 changes: 16 additions & 11 deletions src/elem_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ impl Display for ElemType {
.fold(String::new(),
|memo, x| {
let x_str: &'static str = From::from(x);
if memo == "" {
if memo.is_empty() {
x_str.to_string()
} else {
memo + ", " + &x_str.to_string()
memo + ", " + x_str
}
}
))
Expand Down Expand Up @@ -101,7 +101,7 @@ impl ElemSymbol {
info: locations.iter()
.map(|&location|
ElemTypeInfo {
location: location,
location,
}).collect(),
}
}
Expand All @@ -119,11 +119,11 @@ impl ElemType {
pub fn from_locations(type_set: EnumSet<ElemSymbol>,
locations: Vec<Location>) -> Self {
ElemType {
type_set: type_set,
type_set,
info: locations.iter()
.map(|&location|
ElemTypeInfo {
location: location,
location,
}).collect(),
}
}
Expand All @@ -136,10 +136,10 @@ impl ElemType {
}

/// Calculate the union of two ElemType's and append their metadata
pub fn union(&self, other: Self) -> Self {
pub fn union(&self, other: &mut Self) -> Self {
let both = self.type_set.union(other.type_set);
let mut both_info = self.info.clone();
both_info.append(&mut other.info.clone());
both_info.append(&mut other.info);
ElemType {
type_set: both,
info: both_info,
Expand All @@ -149,7 +149,7 @@ impl ElemType {
/// Unify two ElemType's by returning their intersection and combining their metadata
///
/// Fails if their intersection is empty (i.e. if it results in an empty type)
pub fn unify(&self, other: Self) -> Result<Self, ElemTypeError> {
pub fn unify(&self, other: &mut Self) -> Result<Self, ElemTypeError> {
let both = self.type_set.intersection(other.type_set);
if both.is_empty() {
Err(ElemTypeError::UnifyEmpty {
Expand All @@ -158,7 +158,7 @@ impl ElemType {
})
} else {
let mut both_info = self.info.clone();
both_info.append(&mut other.info.clone());
both_info.append(&mut other.info);
Ok(ElemType {
type_set: both,
info: both_info,
Expand Down Expand Up @@ -239,13 +239,18 @@ impl StackType {
self.types.len()
}

/// Is length of the StackType empty?
pub fn is_empty(&self) -> bool {
self.types.is_empty()
}

/// Push the given ElemType to the StackType
pub fn push(&mut self, elem_type: ElemType) -> () {
pub fn push(&mut self, elem_type: ElemType) {
self.types.insert(0, elem_type)
}

/// Push (count) copies of the given ElemType to the StackType
pub fn push_n(&mut self, elem_type: ElemType, count: usize) -> () {
pub fn push_n(&mut self, elem_type: ElemType, count: usize) {
for _index in 0..count {
self.push(elem_type.clone())
}
Expand Down
2 changes: 1 addition & 1 deletion src/elems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use thiserror::Error;
// - random typed program?

/// Errors thrown by Elems::pop
#[derive(Clone, Debug, Error)]
#[derive(Clone, Debug, Error, PartialEq)]
pub enum ElemsPopError {
/// "Elems::pop singleton: tried to pop an Elem that was not found:\nelem_symbol:\n{elem_symbol:?}\n\n{error}"
#[error("Elems::pop singleton: tried to pop an Elem that was not found:\nelem_symbol:\n{elem_symbol:?}\n\n{error}")]
Expand Down
6 changes: 3 additions & 3 deletions src/elems_input_output_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ where
.map(|x| {
match x {
Or::Left(array) => Self::Left {
array: array,
array,
returning: Return::new(),
},
Or::Right(y) => Self::Right(y),
Expand Down Expand Up @@ -125,13 +125,13 @@ where
let mut type_tl = IOElems::type_of(PhantomData::<U>)
.map_err(|e| ElemsPopError::ReturnOrTl(Arc::new(e)))?;
let last_type_id = type_tl.context.max_type_id()
.map_err(|e| ElemsPopError::ReturnOrContextError(e))?;
.map_err(ElemsPopError::ReturnOrContextError)?;
let next_type_id = type_tl.context.push(ElemType {
type_set: AnElem::elem_symbol(PhantomData::<T>),
info: vec![],
});
type_tl.context.unify(last_type_id, next_type_id)
.map_err(|e| ElemsPopError::ReturnOrContextError(e))?;
.map_err(ElemsPopError::ReturnOrContextError)?;
Ok(type_tl)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/elems_input_output_singleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ where
info: vec![],
});
Ok(Type {
context: context,
context,
i_type: (1..num_inputs).into_iter().map(|_| type_id).collect(),
o_type: vec![type_id],
})
Expand Down
8 changes: 3 additions & 5 deletions src/elems_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ where
match self {
Self::Left(array) => IterOr::Left(
Singleton {
array: array,
array,
}.into_iter()
),
Self::Right(xs) => IterOr::Right(xs.into_iter()),
Expand All @@ -98,8 +98,6 @@ where
type N = N;
type Tl = U;

// fn left(_s: PhantomData<Self>, x: GenericArray<Self::Hd, Self::N>) -> Self { Self::Left(x) }
// fn right(_s: PhantomData<Self>, x: Self::Tl) -> Self { Self::Right(x) }
fn or<V, F: Fn(&GenericArray<Self::Hd, Self::N>) -> V, G: Fn(&Self::Tl) -> V>(&self, f: F, g: G) -> V {
match self {
Self::Left(x) => f(x),
Expand Down Expand Up @@ -132,8 +130,8 @@ where
type_set: AnElem::elem_symbol(PhantomData::<T>),
info: vec![],
};
let elem_type_tl = Elems::elem_type(PhantomData::<U>)?;
Ok(elem_type_hd.union(elem_type_tl))
let mut elem_type_tl = Elems::elem_type(PhantomData::<U>)?;
Ok(elem_type_hd.union(&mut elem_type_tl))
}
}

2 changes: 1 addition & 1 deletion src/elems_singleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where
}
})?;
Ok(Singleton {
array: array,
array,
})
}

Expand Down
25 changes: 16 additions & 9 deletions src/json_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ use indexmap::IndexMap;
use serde_json::{Map, Number, Value};
use thiserror::Error;

// TODO: relocate
/// Map<String, T> defined to be convenient to Serialize and Deserialize
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TMap<T> {
map: IndexMap<String, T>,
}

impl<T> Default for TMap<T> {
fn default() -> Self {
Self::new()
}
}

impl<T> TMap<T> {
/// IndexMap::new
pub fn new() -> Self {
Expand Down Expand Up @@ -78,7 +85,7 @@ where
}

Ok(TMap {
map: map,
map,
})
}
}
Expand Down Expand Up @@ -138,7 +145,7 @@ impl TValue {
Value::Bool(x) => Self::Bool(x),
Value::Number(x) => Self::Number(x),
Value::String(x) => Self::String(x),
Value::Array(x) => Self::Array(x.into_iter().map(|x| TValue::from_json(x)).collect()),
Value::Array(x) => Self::Array(x.into_iter().map(TValue::from_json).collect()),
Value::Object(x) => Self::Object(TMap {
map: x.into_iter().map(|(x, y)| (x, TValue::from_json(y))).collect()
}),
Expand All @@ -164,13 +171,13 @@ impl TValue {
Self::String(x) => Ok(Value::String(x)),
Self::Array(x) => Ok(Value::Array(x.into_iter().map(|y| y.run(variables.clone())).collect::<Result<Vec<Value>, TValueRunError>>()?)),
Self::Object(x) => Ok(Value::Object(x.map.into_iter().map(|(y, z)| Ok((y, z.run(variables.clone())?))).collect::<Result<Map<String, Value>, TValueRunError>>()?)),
Self::Var(x) => {
variables.get(&x)
.map(|y| y.clone())
Self::Var(variable) => {
variables.get(&variable)
.cloned()
.ok_or_else(|| TValueRunError {
variable: x,
variable,
value: vec![self_copy],
variables: variables,
variables,
})
},
}
Expand Down Expand Up @@ -198,12 +205,12 @@ impl Template {
pub fn new(template: TValue) -> Self {
Self {
variables: Map::new(),
template: template,
template,
}
}

/// Set the given variable name to the given Value
pub fn set(&mut self, name: String, value: Value) -> () {
pub fn set(&mut self, name: String, value: Value) {
self.variables.insert(name, value);
}

Expand Down
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
//! Cryptoscript Rust Library
//! See cli for the command line interface

#![warn(missing_docs, elided_lifetimes_in_paths, explicit_outlives_requirements, keyword_idents, missing_copy_implementations, missing_debug_implementations, non_ascii_idents, noop_method_call, single_use_lifetimes, trivial_casts, trivial_numeric_casts, unreachable_pub, unused_extern_crates, unused_import_braces, unused_lifetimes, unused_qualifications)]
#![warn(missing_docs, elided_lifetimes_in_paths, explicit_outlives_requirements, keyword_idents, missing_copy_implementations, missing_debug_implementations, non_ascii_idents, noop_method_call, trivial_casts, trivial_numeric_casts, unreachable_pub, unused_extern_crates, unused_import_braces, unused_lifetimes, unused_qualifications)]

// single_use_lifetimes,
// #![warn(unused_crate_dependencies)]
// #![warn(unused_results)]

Expand Down Expand Up @@ -80,6 +81,11 @@ pub use typed_instrs::Instrs;
mod parse;
pub use parse::{parse, parse_json};

mod parse_utils;
pub use parse_utils::{parse_string, whitespace_delimited};
mod parse_nom;
pub use parse_nom::{parse_nom, SourceCode, SourceBlock, Comment, Var, Assignment, App, Expr, TypeAnnotation, InstructionsWriter};

mod rest_api;
pub use rest_api::Api;
mod cli;
Expand Down Expand Up @@ -142,7 +148,7 @@ fn sha256(input: &Vec<u8>) -> Vec<u8> {

// read hash digest and consume hasher
let result = hasher.finalize();
return result.to_vec();
result.to_vec()
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct LineNo {
impl From<usize> for LineNo {
fn from(line_no: usize) -> Self {
LineNo {
line_no: line_no,
line_no,
}
}
}
Expand All @@ -35,7 +35,7 @@ impl LineNo {
pub fn in_at(&self, argument_index: usize) -> Location {
Location {
line_no: *self,
argument_index: argument_index,
argument_index,
is_input: true,
}
}
Expand All @@ -47,7 +47,7 @@ impl LineNo {
pub fn out_at(&self, argument_index: usize) -> Location {
Location {
line_no: *self,
argument_index: argument_index,
argument_index,
is_input: false,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ async fn main() {



println!("");
println!("");
println!();
println!();
// println!("Template test:");

// ERC-20 token balance (currently)
Expand Down
Loading