Skip to content

Commit f107d06

Browse files
committed
feat: improved std keyword and functions
1 parent f5727c4 commit f107d06

File tree

2 files changed

+165
-81
lines changed

2 files changed

+165
-81
lines changed

components/ts-to-clar/src/clarity_std.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use clarity::vm::{functions::NativeFunctions, types::TypeSignature};
1+
use clarity::vm::{
2+
functions::NativeFunctions,
3+
types::{StacksBlockInfoProperty, TypeSignature},
4+
};
25
use std::{collections::HashMap, sync::LazyLock};
36

47
pub static STD_PKG_NAME: &str = "clarity";
@@ -74,6 +77,7 @@ std: [
7477
// done
7578
"to-int",
7679
"to-uint",
80+
"print",
7781
7882
// todo
7983
"get-stacks-block-info?",
@@ -93,7 +97,6 @@ std: [
9397
"keccak256",
9498
"secp256k1-recover?",
9599
"secp256k1-verify",
96-
"print",
97100
98101
// not todo
99102
"map",
@@ -150,12 +153,12 @@ std: [
150153
pub enum Parameter {
151154
Any,
152155
Value(TypeSignature),
153-
Identifiers(Vec<String>),
156+
Identifiers(&'static [&'static str]),
154157
}
155158

156159
pub struct StdFunction {
157160
pub name: &'static str,
158-
pub _parameters: Vec<Parameter>,
161+
pub parameters: Vec<(&'static str, Parameter)>,
159162
// return type might not be needed at all in transpiler at some point
160163
// because the type might just be avaible in the ts ast
161164
// making it Optional instead of overengineering it for now
@@ -171,23 +174,37 @@ pub static FUNCTIONS: LazyLock<HashMap<&str, StdFunction>> = LazyLock::new(|| {
171174
"toInt",
172175
StdFunction {
173176
name: ToInt.get_name_str(),
174-
_parameters: vec![Parameter::Value(UIntType)],
177+
parameters: vec![("u", Parameter::Value(UIntType))],
175178
_return_type: Some(IntType),
176179
},
177180
),
178181
(
179182
"toUint",
180183
StdFunction {
181184
name: ToUInt.get_name_str(),
182-
_parameters: vec![Parameter::Value(IntType)],
185+
parameters: vec![("i", Parameter::Value(IntType))],
183186
_return_type: Some(UIntType),
184187
},
185188
),
186189
(
187190
"print",
188191
StdFunction {
189192
name: Print.get_name_str(),
190-
_parameters: vec![Parameter::Any],
193+
parameters: vec![("expr", Parameter::Any)],
194+
_return_type: None,
195+
},
196+
),
197+
(
198+
"getStacksBlockInfo",
199+
StdFunction {
200+
name: GetStacksBlockInfo.get_name_str(),
201+
parameters: vec![
202+
(
203+
"prop-name",
204+
Parameter::Identifiers(StacksBlockInfoProperty::ALL_NAMES),
205+
),
206+
("stacks-block-height", Parameter::Value(UIntType)),
207+
],
191208
_return_type: None,
192209
},
193210
),
@@ -200,7 +217,7 @@ mod tests {
200217

201218
#[test]
202219
fn test_functions() {
203-
// let functions = FUNCTIONS;
220+
assert!(FUNCTIONS.len() == 3)
204221

205222
// println!("Functions: {:?}", FUNCTIONS.keys().collect::<Vec<_>>());
206223
}

0 commit comments

Comments
 (0)