Commit ede0377 1 parent be76d76 commit ede0377 Copy full SHA for ede0377
File tree 3 files changed +30
-1
lines changed
3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 6
6
use crate :: builtin:: Builtin ;
7
7
8
8
/*GENERATE cargo run -- _builtins.tok -- `find . -name "*.rs"` */
9
- pub static BUILTINS : [ Builtin ; 68 ] = [
9
+ pub static BUILTINS : [ Builtin ; 69 ] = [
10
10
Builtin {
11
11
name : "Float" ,
12
12
func : crate :: value:: token:: tokay_token_float,
@@ -163,6 +163,10 @@ pub static BUILTINS: [Builtin; 68] = [
163
163
name : "list_add" ,
164
164
func : crate :: value:: list:: List :: tokay_method_list_add,
165
165
} ,
166
+ Builtin {
167
+ name : "list_clone" ,
168
+ func : crate :: value:: list:: List :: tokay_method_list_clone,
169
+ } ,
166
170
Builtin {
167
171
name : "list_flatten" ,
168
172
func : crate :: value:: list:: List :: tokay_method_list_flatten,
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ impl Object for List {
50
50
}
51
51
}
52
52
53
+ #[ allow( unused_doc_comments) ]
53
54
impl List {
54
55
pub fn new ( ) -> Self {
55
56
Self {
@@ -84,6 +85,17 @@ impl List {
84
85
Ok ( RefValue :: from( list) )
85
86
} ) ;
86
87
88
+ /// Clone `list` into a standalone copy.
89
+ tokay_method ! ( "list_clone : @list" , {
90
+ let borrowed = list. borrow( ) ;
91
+
92
+ if let Some ( list) = borrowed. object:: <List >( ) {
93
+ Ok ( RefValue :: from( list. clone( ) ) )
94
+ } else {
95
+ Ok ( RefValue :: from( List { list: vec![ list. clone( ) ] } ) )
96
+ }
97
+ } ) ;
98
+
87
99
tokay_method ! ( "list_len : @list" , {
88
100
let list = list. borrow( ) ;
89
101
Original file line number Diff line number Diff line change
1
+ #testmode:repl
2
+
3
+ l = 1,2,3
4
+ m = l.clone()
5
+ l += 4
6
+ m += 5, 6, 7
7
+
8
+ l
9
+ m
10
+
11
+ #---
12
+ #(1, 2, 3, 4)
13
+ #(1, 2, 3, 5, 6, 7)
You can’t perform that action at this time.
0 commit comments