Skip to content

Commit e4459c5

Browse files
committed
FEAT: replaced mezzanine with with a lightweight and faster native version
1 parent aa77b3f commit e4459c5

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/core/n-data.c

+22
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,28 @@ static int Check_Char_Range(REBVAL *val, REBINT limit)
515515
}
516516

517517

518+
/***********************************************************************
519+
**
520+
*/ REBNATIVE(with)
521+
/*
522+
// with: native [
523+
// "Evaluates a block binded to the specified context"
524+
// context [object! module! port!] "A reference to the target context"
525+
// body [block!] "A code to be evaluated"
526+
// ]
527+
***********************************************************************/
528+
{
529+
REBSER *frame = VAL_OBJ_FRAME(D_ARG(1));
530+
REBSER *body = VAL_SERIES (D_ARG(2));
531+
532+
Bind_Block(frame, BLK_HEAD(body), BIND_DEEP);
533+
534+
// Evaluate the body:
535+
DO_BLK(D_ARG(2));
536+
return R_TOS1;
537+
}
538+
539+
518540
/***********************************************************************
519541
**
520542
*/ REBNATIVE(not)

src/mezz/mezz-control.reb

-8
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ wrap: func [
3434
do bind/copy/set body make object! 0
3535
]
3636

37-
with: func[
38-
"Evaluates a block binded to the specified context."
39-
context [object! module!]
40-
body [block!]
41-
][
42-
do bind body context
43-
]
44-
4537
any-of: func [
4638
"Returns the first value(s) for which the test is not FALSE or NONE."
4739
'word [word! block!] "Word or block of words to set each time (local)"

src/tests/units/evaluation-test.r3

+11
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,17 @@ Rebol [
211211

212212
===end-group===
213213

214+
215+
===start-group=== "with"
216+
--test-- "with"
217+
o: object [a: 1]
218+
--assert 2 = with o [2 * a]
219+
; test that return is not catched by `with`
220+
f: does [with o [return a] 2]
221+
--assert 1 = f
222+
===end-group===
223+
224+
214225
===start-group=== "attempt"
215226
--test-- "issue-41"
216227
--assert none? attempt [2 / 0] ;@@ https://github.com/Oldes/Rebol-issues/issues/41

0 commit comments

Comments
 (0)