Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,9 @@ frontend/source patterns may still reach a `Bridge/Exit` path even when an SSA i
| `len(map)` | Bridge/Exit | Inline |
| `get(map)` | Bridge/Exit | Helper |
| `has(map)` | Bridge/Exit | Helper |
| `string_contains`, `string_replace_literal`, `string_lower_ascii`, `string_split_literal` | Bridge/Exit | Helper |
| `re::match`, `re::replace` | Bridge/Exit | Helper |
| Dynamic `type`, `to_string`, equality, and `len` | Bridge/Exit | Helper (known `type` / string `to_string` cases are folded) |
| All other builtins | Bridge/Exit | Bridge/Exit or NYI, depending on trace shape |
| Host imports | Bridge/Exit | Bridge/Exit or branch-exit trace, never inline |

Expand Down
2 changes: 1 addition & 1 deletion src/builtins/runtime/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ pub(super) fn builtin_type_of_impl(value: VmValueRef<'_>) -> String {

/// Convert a value into a display string.
#[pd_host_function(name = "__to_string")]
pub(super) fn builtin_to_string_impl(value: VmValueRef<'_>) -> String {
pub(crate) fn builtin_to_string_impl(value: VmValueRef<'_>) -> String {
render_value_for_display(value)
}

Expand Down
13 changes: 13 additions & 0 deletions src/builtins/runtime/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ pub(super) fn builtin_re_match(vm: &mut Vm, pattern: &str, text: &str) -> VmResu
Ok(regex.is_match(text))
}

pub(crate) fn native_re_match(vm: &mut Vm, pattern: &str, text: &str) -> VmResult<bool> {
builtin_re_match_impl(vm, pattern, text)
}

/// Returns the first substring matched by a regular expression.
#[pd_host_function(name = "re::find")]
pub(super) fn builtin_re_find(vm: &mut Vm, pattern: &str, text: &str) -> VmResult<Option<String>> {
Expand All @@ -126,6 +130,15 @@ pub(super) fn builtin_re_replace(
Ok(regex.replace_all(text, replacement).into_owned())
}

pub(crate) fn native_re_replace(
vm: &mut Vm,
pattern: &str,
text: &str,
replacement: &str,
) -> VmResult<String> {
builtin_re_replace_impl(vm, pattern, text, replacement)
}

/// Splits a string on regular-expression matches.
#[pd_host_function(name = "re::split")]
pub(super) fn builtin_re_split(vm: &mut Vm, pattern: &str, text: &str) -> VmResult<VmArray> {
Expand Down
47 changes: 46 additions & 1 deletion src/vm/jit/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ pub(crate) enum SsaInstKind {
input: SsaValueId,
tag: ValueType,
},
ValueLen {
value: SsaValueId,
},
StringLen {
text: SsaValueId,
},
Expand Down Expand Up @@ -139,6 +142,15 @@ pub(crate) enum SsaInstKind {
text: SsaValueId,
needle: SsaValueId,
},
RegexMatch {
pattern: SsaValueId,
text: SsaValueId,
},
RegexReplace {
pattern: SsaValueId,
text: SsaValueId,
replacement: SsaValueId,
},
StringReplaceLiteral {
text: SsaValueId,
needle: SsaValueId,
Expand All @@ -147,6 +159,12 @@ pub(crate) enum SsaInstKind {
StringLowerAscii {
text: SsaValueId,
},
TypeOf {
value: SsaValueId,
},
ToString {
value: SsaValueId,
},
StringSplitLiteral {
text: SsaValueId,
delimiter: SsaValueId,
Expand Down Expand Up @@ -331,6 +349,10 @@ pub(crate) enum SsaInstKind {
lhs: SsaValueId,
rhs: SsaValueId,
},
ValueCmpEq {
lhs: SsaValueId,
rhs: SsaValueId,
},
IntCmpLt {
lhs: SsaValueId,
rhs: SsaValueId,
Expand Down Expand Up @@ -358,6 +380,7 @@ impl SsaInstKind {
| Self::UnboxFloat { input }
| Self::UnboxBool { input }
| Self::UnboxHeapPtr { input, .. }
| Self::ValueLen { value: input }
| Self::StringLen { text: input }
| Self::BytesLen { bytes: input }
| Self::ArrayLen { array: input }
Expand All @@ -379,12 +402,19 @@ impl SsaInstKind {
Self::BytesGet { bytes, index } => vec![*bytes, *index],
Self::BytesHas { bytes, index } => vec![*bytes, *index],
Self::StringContains { text, needle } => vec![*text, *needle],
Self::RegexMatch { pattern, text } => vec![*pattern, *text],
Self::RegexReplace {
pattern,
text,
replacement,
} => vec![*pattern, *text, *replacement],
Self::StringReplaceLiteral {
text,
needle,
replacement,
} => vec![*text, *needle, *replacement],
Self::StringLowerAscii { text } => vec![*text],
Self::TypeOf { value } | Self::ToString { value } => vec![*value],
Self::StringSplitLiteral { text, delimiter } => vec![*text, *delimiter],
Self::StringConcat { lhs, rhs } | Self::BytesConcat { lhs, rhs } => vec![*lhs, *rhs],
Self::BytesFromArrayU8 { array } => vec![*array],
Expand Down Expand Up @@ -422,6 +452,7 @@ impl SsaInstKind {
| Self::FloatCmpLt { lhs, rhs }
| Self::FloatCmpGt { lhs, rhs }
| Self::IntCmpEq { lhs, rhs }
| Self::ValueCmpEq { lhs, rhs }
| Self::IntCmpLt { lhs, rhs }
| Self::IntCmpGt { lhs, rhs } => vec![*lhs, *rhs],
Self::IntAddImm { lhs, .. }
Expand Down Expand Up @@ -975,6 +1006,7 @@ fn render_inst_kind(kind: &SsaInstKind) -> String {
SsaInstKind::UnboxFloat { input } => format!("unbox_float {input}"),
SsaInstKind::UnboxBool { input } => format!("unbox_bool {input}"),
SsaInstKind::UnboxHeapPtr { input, tag } => format!("unbox_ptr {input}, {tag:?}"),
SsaInstKind::ValueLen { value } => format!("value_len {value}"),
SsaInstKind::StringLen { text } => format!("string_len {text}"),
SsaInstKind::BytesLen { bytes } => format!("bytes_len {bytes}"),
SsaInstKind::StringSlice {
Expand All @@ -993,12 +1025,24 @@ fn render_inst_kind(kind: &SsaInstKind) -> String {
SsaInstKind::StringContains { text, needle } => {
format!("string_contains {text}, {needle}")
}
SsaInstKind::RegexMatch { pattern, text } => {
format!("regex_match {pattern}, {text}")
}
SsaInstKind::RegexReplace {
pattern,
text,
replacement,
} => format!("regex_replace {pattern}, {text}, {replacement}"),
SsaInstKind::StringReplaceLiteral {
text,
needle,
replacement,
} => format!("string_replace_literal {text}, {needle}, {replacement}"),
} => {
format!("string_replace_literal {text}, {needle}, {replacement}")
}
SsaInstKind::StringLowerAscii { text } => format!("string_lower_ascii {text}"),
SsaInstKind::TypeOf { value } => format!("type_of {value}"),
SsaInstKind::ToString { value } => format!("to_string {value}"),
SsaInstKind::StringSplitLiteral { text, delimiter } => {
format!("string_split_literal {text}, {delimiter}")
}
Expand Down Expand Up @@ -1057,6 +1101,7 @@ fn render_inst_kind(kind: &SsaInstKind) -> String {
SsaInstKind::FloatCmpLt { lhs, rhs } => format!("fcmp_lt {lhs}, {rhs}"),
SsaInstKind::FloatCmpGt { lhs, rhs } => format!("fcmp_gt {lhs}, {rhs}"),
SsaInstKind::IntCmpEq { lhs, rhs } => format!("icmp_eq {lhs}, {rhs}"),
SsaInstKind::ValueCmpEq { lhs, rhs } => format!("value_eq {lhs}, {rhs}"),
SsaInstKind::IntCmpLt { lhs, rhs } => format!("icmp_lt {lhs}, {rhs}"),
SsaInstKind::IntCmpLtImm { lhs, imm } => format!("icmp_lt_imm {lhs}, {imm}"),
SsaInstKind::IntCmpGt { lhs, rhs } => format!("icmp_gt {lhs}, {rhs}"),
Expand Down
Loading
Loading