Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - tremor-script VM #2650

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions tremor-script/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
/// Binary semiliteral
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct Bytes<'script> {
mid: Box<NodeMeta>,
pub(crate) mid: Box<NodeMeta>,
/// Bytes
pub value: Vec<BytesPart<'script>>,
}
Expand Down Expand Up @@ -1673,8 +1673,6 @@
pub enum PredicatePattern<'script> {
/// Structural application
TildeEq {
/// Assignment bind point
assign: Cow<'script, str>,
/// Lhs
lhs: Cow<'script, str>,
/// Key
Expand Down Expand Up @@ -1974,6 +1972,11 @@
}

impl<'script> Path<'script> {
/// Get the length of the path
#[must_use]
pub(crate) fn len(&self) -> usize {
self.segments().len()
}

Check warning on line 1979 in tremor-script/src/ast.rs

View check run for this annotation

Codecov / codecov/patch

tremor-script/src/ast.rs#L1977-L1979

Added lines #L1977 - L1979 were not covered by tests
/// Get segments as slice
#[must_use]
pub(crate) fn segments(&self) -> &Segments<'script> {
Expand Down
2 changes: 1 addition & 1 deletion tremor-script/src/ast/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn write_bits_le(
}
}

fn write_bits(
pub(crate) fn write_bits(
bytes: &mut Vec<u8>,
bits: u8,
endianess: Endian,
Expand Down
10 changes: 2 additions & 8 deletions tremor-script/src/ast/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,19 +437,13 @@
use PredicatePattern::{ArrayPatternEq, Bin, RecordPatternEq, TildeEq};
match (self, other) {
(
TildeEq { lhs, key, test },

Check warning on line 440 in tremor-script/src/ast/eq.rs

View check run for this annotation

Codecov / codecov/patch

tremor-script/src/ast/eq.rs#L440

Added line #L440 was not covered by tests
TildeEq {
assign,
lhs,
key,
test,
},
TildeEq {
assign: a2,
lhs: l2,
key: k2,
test: t2,
},
) => assign == a2 && lhs == l2 && key == k2 && test.ast_eq(t2.as_ref()),
) => lhs == l2 && key == k2 && test.ast_eq(t2.as_ref()),

Check warning on line 446 in tremor-script/src/ast/eq.rs

View check run for this annotation

Codecov / codecov/patch

tremor-script/src/ast/eq.rs#L446

Added line #L446 was not covered by tests
(
Bin {
lhs,
Expand Down
2 changes: 0 additions & 2 deletions tremor-script/src/ast/eq/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ fn imut_expr() -> ImutExpr<'static> {
#[test]
fn predicate_pattern() {
assert!(PredicatePattern::TildeEq {
assign: "assign".into(),
lhs: "lhs".into(),
key: "key".into(),
test: Box::new(TestExpr {
Expand All @@ -479,7 +478,6 @@ fn predicate_pattern() {
}),
}
.ast_eq(&PredicatePattern::TildeEq {
assign: "assign".into(),
lhs: "lhs".into(),
key: "key".into(),
test: Box::new(TestExpr {
Expand Down
5 changes: 1 addition & 4 deletions tremor-script/src/ast/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,8 +1396,6 @@ impl<'script> Upable<'script> for PatternRaw<'script> {
pub enum PredicatePatternRaw<'script> {
/// we're forced to make this pub because of lalrpop
TildeEq {
/// we're forced to make this pub because of lalrpop
assign: Cow<'script, str>,
/// we're forced to make this pub because of lalrpop
lhs: Cow<'script, str>,
/// we're forced to make this pub because of lalrpop
Expand Down Expand Up @@ -1453,8 +1451,7 @@ impl<'script> Upable<'script> for PredicatePatternRaw<'script> {
TuplePatternEq,
};
Ok(match self {
TildeEq { assign, lhs, test } => PredicatePattern::TildeEq {
assign,
TildeEq { lhs, test } => PredicatePattern::TildeEq {
key: KnownKey::from(lhs.clone()),
lhs,
test: Box::new(test.up(helper)?),
Expand Down
3 changes: 0 additions & 3 deletions tremor-script/src/ast/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ fn pp_is_exclusive() {
);
let teq = PredicatePattern::TildeEq {
lhs: "k1".into(),
assign: "k".into(),
key: "k1".into(),
test: Box::new(TestExpr {
mid: NodeMeta::dummy(),
Expand All @@ -365,7 +364,6 @@ fn pp_is_exclusive() {
};
let test_eq2 = PredicatePattern::TildeEq {
lhs: "k2".into(),
assign: "k".into(),
key: "k2".into(),
test: Box::new(TestExpr {
mid: NodeMeta::dummy(),
Expand All @@ -376,7 +374,6 @@ fn pp_is_exclusive() {
};
let teq3 = PredicatePattern::TildeEq {
lhs: "k1".into(),
assign: "k".into(),
key: "k1".into(),
test: Box::new(TestExpr {
mid: NodeMeta::dummy(),
Expand Down
12 changes: 3 additions & 9 deletions tremor-script/src/ast/visitors/impls/const_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::ast::{BooleanBinExpr, BooleanBinOpKind};
use crate::{
ast::{base_expr::Ranged, binary::extend_bytes_from_value, NodeMeta},
errors::{
err_generic, err_invalid_unary, err_need_int, error_array_out_of_bound, error_bad_key,
error_decreasing_range, error_need_arr, error_need_obj,
err_generic, err_need_int, error_array_out_of_bound, error_bad_key, error_decreasing_range,
error_need_arr, error_need_obj,
},
interpreter::{exec_binary, exec_unary, Env},
lexer::Span,
Expand Down Expand Up @@ -160,13 +160,7 @@ impl<'run, 'script: 'run> ImutExprVisitor<'script> for ConstFolder<'run, 'script
mid,
} = b.as_ref()
{
let value = exec_unary(*kind, value)
.ok_or_else(|| {
let inner = b.extent();
let outer = b.extent();
err_invalid_unary(&outer, &inner, *kind, value)
})?
.into_owned();
let value = exec_unary(b.as_ref(), b.as_ref(), *kind, value)?.into_owned();
Lit(Literal {
mid: mid.clone(),
value,
Expand Down
22 changes: 8 additions & 14 deletions tremor-script/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#![allow(clippy::large_enum_variant)]
#![allow(deprecated)]
#![allow(missing_docs)]
#![allow(non_snake_case)]

use crate::errors::ErrorKind::InvalidBinaryBoolean;
pub use crate::prelude::ValueType;
Expand Down Expand Up @@ -247,11 +248,11 @@ impl ErrorKind {
Msg, NoClauseHit, NoConstsAllowed, NoEventReferencesAllowed, NoLocalsAllowed,
NoObjectError, NotConstant, NotFound, Oops, Overflow, ParseIntError, ParserError,
PatchKeyExists, PipelineUnknownPort, QueryNodeDuplicateName, QueryNodeReservedName,
QueryStreamNotDefined, RecursionLimit, RuntimeError, TailingHereDoc, TypeConflict,
TypeError, UnexpectedCharacter, UnexpectedEndOfStream, UnexpectedEscapeCode,
UnknownLocal, UnrecognizedToken, UnterminatedExtractor, UnterminatedHereDoc,
UnterminatedIdentLiteral, UnterminatedInterpolation, UnterminatedStringLiteral,
UpdateKeyMissing, Utf8Error, ValueError, WithParamNoArg,
QueryStreamNotDefined, RecursionLimit, RuntimeError, TailingHereDoc, TryFromInt,
TypeConflict, TypeError, UnexpectedCharacter, UnexpectedEndOfStream,
UnexpectedEscapeCode, UnknownLocal, UnrecognizedToken, UnterminatedExtractor,
UnterminatedHereDoc, UnterminatedIdentLiteral, UnterminatedInterpolation,
UnterminatedStringLiteral, UpdateKeyMissing, Utf8Error, ValueError, WithParamNoArg,
};
match self {
NoClauseHit(outer)
Expand Down Expand Up @@ -350,6 +351,7 @@ impl ErrorKind {
| Self::__Nonexhaustive { .. }
| Utf8Error(_)
| FromUtf8Error(_)
| TryFromInt(_)
| ValueError(_) => (Some(Span::yolo()), None),
}
}
Expand Down Expand Up @@ -567,6 +569,7 @@ error_chain! {
AccessError(value_trait::AccessError);
CodecError(tremor_codec::Error);
Common(tremor_common::Error);
TryFromInt(std::num::TryFromIntError);
}
errors {
/*
Expand Down Expand Up @@ -1211,15 +1214,6 @@ pub(crate) fn error_guard_not_bool<T, O: Ranged, I: Ranged>(
error_type_conflict(outer, inner, got.value_type(), ValueType::Bool)
}

pub(crate) fn error_invalid_unary<T, O: Ranged, I: Ranged>(
outer: &O,
inner: &I,
op: ast::UnaryOpKind,
val: &Value,
) -> Result<T> {
Err(err_invalid_unary(outer, inner, op, val))
}

pub(crate) fn err_invalid_unary<O: Ranged, I: Ranged>(
outer: &O,
inner: &I,
Expand Down
3 changes: 2 additions & 1 deletion tremor-script/src/extractor/re.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@
use value_trait::prelude::*;

pub(crate) fn execute(s: &str, result_needed: bool, compiled: &Regex) -> Result<'static> {
compiled.captures(s).map_or(Result::NoMatch, |caps| {
let res = compiled.captures(s);
res.map_or(Result::NoMatch, |caps| {

Check warning on line 142 in tremor-script/src/extractor/re.rs

View check run for this annotation

Codecov / codecov/patch

tremor-script/src/extractor/re.rs#L141-L142

Added lines #L141 - L142 were not covered by tests
if result_needed {
let matches: HashMap<Cow<str>, Value, _> = compiled
.capture_names()
Expand Down
5 changes: 3 additions & 2 deletions tremor-script/src/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -1425,8 +1425,9 @@ WhenClause: Option<ImutExprRaw<'input>> = {

/// Predicate Patterns (aka tests) for record pattrens
PredicateFieldPattern: PredicatePatternRaw<'input> = {
<lhs:Ident> "~=" <expr:TestExpr> => PredicatePatternRaw::TildeEq { assign: lhs.id.clone(), lhs: lhs.id, test: expr},
<assign:Ident> "=" <lhs:Ident> "~=" <expr:TestExpr> => PredicatePatternRaw::TildeEq { assign: assign.id, lhs: lhs.id, test: expr} ,
<lhs:Ident> "~=" <expr:TestExpr> => PredicatePatternRaw::TildeEq { lhs: lhs.id, test: expr},
// FIXME: why was assign never used in here?
<_assign:Ident> "=" <lhs:Ident> "~=" <expr:TestExpr> => PredicatePatternRaw::TildeEq { lhs: lhs.id, test: expr} ,
<lhs:Ident> "~=" <rp:RecordPattern> => PredicatePatternRaw::RecordPatternEq { lhs: lhs.id, pattern: rp },
<lhs:Ident> "~=" <ap:ArrayPattern> => PredicatePatternRaw::ArrayPatternEq { lhs: lhs.id, pattern: ap },
<lhs:Ident> "~=" <ap:TuplePattern> => PredicatePatternRaw::TuplePatternEq { lhs: lhs.id, pattern: ap },
Expand Down
Loading
Loading