diff options
| author | Yuuki Harano | 2021-03-08 21:20:54 +0900 |
|---|---|---|
| committer | Yuuki Harano | 2021-03-08 21:20:54 +0900 |
| commit | 4dda6db3abf4a67455a007d28e14d62a9909f665 (patch) | |
| tree | 88d4e316e81f5bdd8b6801ff89ea68cd164e4055 /src/alloc.c | |
| parent | 565995d408ca65ec9f981f175cca29d2164a5fd0 (diff) | |
| parent | 432c1aaa80ce109250a93f50858a03ce3d01ca34 (diff) | |
| download | emacs-4dda6db3abf4a67455a007d28e14d62a9909f665.tar.gz emacs-4dda6db3abf4a67455a007d28e14d62a9909f665.zip | |
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs into feature/pgtk
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c index 1763a795ab8..ab1e96e0bc6 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -3498,6 +3498,38 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT | |||
| 3498 | return val; | 3498 | return val; |
| 3499 | } | 3499 | } |
| 3500 | 3500 | ||
| 3501 | DEFUN ("make-closure", Fmake_closure, Smake_closure, 1, MANY, 0, | ||
| 3502 | doc: /* Create a byte-code closure from PROTOTYPE and CLOSURE-VARS. | ||
| 3503 | Return a copy of PROTOTYPE, a byte-code object, with CLOSURE-VARS | ||
| 3504 | replacing the elements in the beginning of the constant-vector. | ||
| 3505 | usage: (make-closure PROTOTYPE &rest CLOSURE-VARS) */) | ||
| 3506 | (ptrdiff_t nargs, Lisp_Object *args) | ||
| 3507 | { | ||
| 3508 | Lisp_Object protofun = args[0]; | ||
| 3509 | CHECK_TYPE (COMPILEDP (protofun), Qbyte_code_function_p, protofun); | ||
| 3510 | |||
| 3511 | /* Create a copy of the constant vector, filling it with the closure | ||
| 3512 | variables in the beginning. (The overwritten part should just | ||
| 3513 | contain placeholder values.) */ | ||
| 3514 | Lisp_Object proto_constvec = AREF (protofun, COMPILED_CONSTANTS); | ||
| 3515 | ptrdiff_t constsize = ASIZE (proto_constvec); | ||
| 3516 | ptrdiff_t nvars = nargs - 1; | ||
| 3517 | if (nvars > constsize) | ||
| 3518 | error ("Closure vars do not fit in constvec"); | ||
| 3519 | Lisp_Object constvec = make_uninit_vector (constsize); | ||
| 3520 | memcpy (XVECTOR (constvec)->contents, args + 1, nvars * word_size); | ||
| 3521 | memcpy (XVECTOR (constvec)->contents + nvars, | ||
| 3522 | XVECTOR (proto_constvec)->contents + nvars, | ||
| 3523 | (constsize - nvars) * word_size); | ||
| 3524 | |||
| 3525 | /* Return a copy of the prototype function with the new constant vector. */ | ||
| 3526 | ptrdiff_t protosize = PVSIZE (protofun); | ||
| 3527 | struct Lisp_Vector *v = allocate_vectorlike (protosize, false); | ||
| 3528 | v->header = XVECTOR (protofun)->header; | ||
| 3529 | memcpy (v->contents, XVECTOR (protofun)->contents, protosize * word_size); | ||
| 3530 | v->contents[COMPILED_CONSTANTS] = constvec; | ||
| 3531 | return make_lisp_ptr (v, Lisp_Vectorlike); | ||
| 3532 | } | ||
| 3501 | 3533 | ||
| 3502 | 3534 | ||
| 3503 | /*********************************************************************** | 3535 | /*********************************************************************** |
| @@ -7576,6 +7608,7 @@ N should be nonnegative. */); | |||
| 7576 | defsubr (&Srecord); | 7608 | defsubr (&Srecord); |
| 7577 | defsubr (&Sbool_vector); | 7609 | defsubr (&Sbool_vector); |
| 7578 | defsubr (&Smake_byte_code); | 7610 | defsubr (&Smake_byte_code); |
| 7611 | defsubr (&Smake_closure); | ||
| 7579 | defsubr (&Smake_list); | 7612 | defsubr (&Smake_list); |
| 7580 | defsubr (&Smake_vector); | 7613 | defsubr (&Smake_vector); |
| 7581 | defsubr (&Smake_record); | 7614 | defsubr (&Smake_record); |