diff options
| author | Andrea Corallo | 2019-05-24 12:24:44 +0200 |
|---|---|---|
| committer | Andrea Corallo | 2020-01-01 11:33:37 +0100 |
| commit | b21539f6083bb7be6ce3b7d7701b270bc0bf384b (patch) | |
| tree | c5cdf7b2b68bd1df85d089a541aed599f3014307 /src/comp.c | |
| parent | 1f2529df7d4663597d6ac72ac001def4cd049c1b (diff) | |
| download | emacs-b21539f6083bb7be6ce3b7d7701b270bc0bf384b.tar.gz emacs-b21539f6083bb7be6ce3b7d7701b270bc0bf384b.zip | |
generalize lisp call ret type
Diffstat (limited to 'src/comp.c')
| -rw-r--r-- | src/comp.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/src/comp.c b/src/comp.c index e7a8b9b0e9f..53cb54cba86 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -115,7 +115,9 @@ typedef struct { | |||
| 115 | INLINE static void pop (unsigned n, gcc_jit_rvalue ***stack_ref, | 115 | INLINE static void pop (unsigned n, gcc_jit_rvalue ***stack_ref, |
| 116 | gcc_jit_rvalue *args[]); | 116 | gcc_jit_rvalue *args[]); |
| 117 | 117 | ||
| 118 | static gcc_jit_function *jit_func_declare (const char *f_name, unsigned nargs, | 118 | static gcc_jit_function *jit_func_declare (const char *f_name, |
| 119 | gcc_jit_type *ret_type, | ||
| 120 | unsigned nargs, | ||
| 119 | gcc_jit_rvalue **args, | 121 | gcc_jit_rvalue **args, |
| 120 | enum gcc_jit_function_kind kind, | 122 | enum gcc_jit_function_kind kind, |
| 121 | bool reusable); | 123 | bool reusable); |
| @@ -141,7 +143,8 @@ pop (unsigned n, gcc_jit_rvalue ***stack_ref, gcc_jit_rvalue *args[]) | |||
| 141 | } | 143 | } |
| 142 | 144 | ||
| 143 | static gcc_jit_function * | 145 | static gcc_jit_function * |
| 144 | jit_func_declare (const char *f_name, unsigned nargs, gcc_jit_rvalue **args, | 146 | jit_func_declare (const char *f_name, gcc_jit_type *ret_type, |
| 147 | unsigned nargs, gcc_jit_rvalue **args, | ||
| 145 | enum gcc_jit_function_kind kind, bool reusable) | 148 | enum gcc_jit_function_kind kind, bool reusable) |
| 146 | { | 149 | { |
| 147 | gcc_jit_param *param[4]; | 150 | gcc_jit_param *param[4]; |
| @@ -219,7 +222,8 @@ jit_func_declare (const char *f_name, unsigned nargs, gcc_jit_rvalue **args, | |||
| 219 | } | 222 | } |
| 220 | 223 | ||
| 221 | static gcc_jit_lvalue * | 224 | static gcc_jit_lvalue * |
| 222 | jit_emit_call (const char *f_name, unsigned nargs, gcc_jit_rvalue **args) | 225 | jit_emit_call (const char *f_name, gcc_jit_type *ret_type, unsigned nargs, |
| 226 | gcc_jit_rvalue **args) | ||
| 223 | { | 227 | { |
| 224 | Lisp_Object key = make_string (f_name, strlen (f_name)); | 228 | Lisp_Object key = make_string (f_name, strlen (f_name)); |
| 225 | EMACS_UINT hash = 0; | 229 | EMACS_UINT hash = 0; |
| @@ -228,7 +232,7 @@ jit_emit_call (const char *f_name, unsigned nargs, gcc_jit_rvalue **args) | |||
| 228 | 232 | ||
| 229 | if (i == -1) | 233 | if (i == -1) |
| 230 | { | 234 | { |
| 231 | jit_func_declare(f_name, nargs, args, GCC_JIT_FUNCTION_IMPORTED, | 235 | jit_func_declare(f_name, ret_type, nargs, args, GCC_JIT_FUNCTION_IMPORTED, |
| 232 | true); | 236 | true); |
| 233 | i = hash_lookup (ht, key, &hash); | 237 | i = hash_lookup (ht, key, &hash); |
| 234 | eassert (i != -1); | 238 | eassert (i != -1); |
| @@ -239,7 +243,7 @@ jit_emit_call (const char *f_name, unsigned nargs, gcc_jit_rvalue **args) | |||
| 239 | 243 | ||
| 240 | gcc_jit_lvalue *res = gcc_jit_function_new_local(comp.func, | 244 | gcc_jit_lvalue *res = gcc_jit_function_new_local(comp.func, |
| 241 | NULL, | 245 | NULL, |
| 242 | comp.lisp_obj_type, | 246 | ret_type, |
| 243 | "res"); | 247 | "res"); |
| 244 | gcc_jit_block_add_assignment(comp.block, NULL, | 248 | gcc_jit_block_add_assignment(comp.block, NULL, |
| 245 | res, | 249 | res, |
| @@ -351,8 +355,8 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 351 | 355 | ||
| 352 | 356 | ||
| 353 | /* Current function being compiled. Return a lips obj. */ | 357 | /* Current function being compiled. Return a lips obj. */ |
| 354 | comp.func = jit_func_declare (f_name, comp_res.max_args, NULL, | 358 | comp.func = jit_func_declare (f_name, comp.lisp_obj_type, comp_res.max_args, |
| 355 | GCC_JIT_FUNCTION_EXPORTED, false); | 359 | NULL, GCC_JIT_FUNCTION_EXPORTED, false); |
| 356 | 360 | ||
| 357 | for (ptrdiff_t i = 0; i < comp_res.max_args; ++i) | 361 | for (ptrdiff_t i = 0; i < comp_res.max_args; ++i) |
| 358 | PUSH (gcc_jit_param_as_rvalue (gcc_jit_function_get_param (comp.func, i))); | 362 | PUSH (gcc_jit_param_as_rvalue (gcc_jit_function_get_param (comp.func, i))); |
| @@ -405,7 +409,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 405 | args[0] = gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, | 409 | args[0] = gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, |
| 406 | comp.lisp_obj_type, | 410 | comp.lisp_obj_type, |
| 407 | vectorp[op]); | 411 | vectorp[op]); |
| 408 | res = jit_emit_call ("Fsymbol_value", 1, args); | 412 | res = jit_emit_call ("Fsymbol_value", comp.lisp_obj_type, 1, args); |
| 409 | PUSH (gcc_jit_lvalue_as_rvalue (res)); | 413 | PUSH (gcc_jit_lvalue_as_rvalue (res)); |
| 410 | break; | 414 | break; |
| 411 | } | 415 | } |
| @@ -438,7 +442,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 438 | args[3] = gcc_jit_context_new_rvalue_from_int (comp.ctxt, | 442 | args[3] = gcc_jit_context_new_rvalue_from_int (comp.ctxt, |
| 439 | comp.int_type, | 443 | comp.int_type, |
| 440 | SET_INTERNAL_SET); | 444 | SET_INTERNAL_SET); |
| 441 | res = jit_emit_call ("set_internal", 4, args); | 445 | res = jit_emit_call ("set_internal", comp.lisp_obj_type, 4, args); |
| 442 | PUSH (gcc_jit_lvalue_as_rvalue (res)); | 446 | PUSH (gcc_jit_lvalue_as_rvalue (res)); |
| 443 | } | 447 | } |
| 444 | break; | 448 | break; |
| @@ -464,7 +468,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 464 | comp.lisp_obj_type, | 468 | comp.lisp_obj_type, |
| 465 | vectorp[op]); | 469 | vectorp[op]); |
| 466 | pop (1, &stack, &args[1]); | 470 | pop (1, &stack, &args[1]); |
| 467 | res = jit_emit_call ("specbind", 2, args); | 471 | res = jit_emit_call ("specbind", comp.lisp_obj_type, 2, args); |
| 468 | PUSH (gcc_jit_lvalue_as_rvalue (res)); | 472 | PUSH (gcc_jit_lvalue_as_rvalue (res)); |
| 469 | break; | 473 | break; |
| 470 | } | 474 | } |
| @@ -519,7 +523,7 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 519 | comp.ptrdiff_type, | 523 | comp.ptrdiff_type, |
| 520 | op); | 524 | op); |
| 521 | 525 | ||
| 522 | res = jit_emit_call ("unbind_n", 1, args); | 526 | res = jit_emit_call ("unbind_n", comp.lisp_obj_type, 1, args); |
| 523 | } | 527 | } |
| 524 | break; | 528 | break; |
| 525 | case Bpophandler: | 529 | case Bpophandler: |
| @@ -548,12 +552,12 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 548 | break; | 552 | break; |
| 549 | case Beq: | 553 | case Beq: |
| 550 | POP2; | 554 | POP2; |
| 551 | res = jit_emit_call ("Feq", 2, args); | 555 | res = jit_emit_call ("Feq", comp.lisp_obj_type, 2, args); |
| 552 | PUSH (gcc_jit_lvalue_as_rvalue (res)); | 556 | PUSH (gcc_jit_lvalue_as_rvalue (res)); |
| 553 | break; | 557 | break; |
| 554 | case Bmemq: | 558 | case Bmemq: |
| 555 | POP1; | 559 | POP1; |
| 556 | res = jit_emit_call ("Fmemq", 1, args); | 560 | res = jit_emit_call ("Fmemq", comp.lisp_obj_type, 1, args); |
| 557 | PUSH (gcc_jit_lvalue_as_rvalue (res)); | 561 | PUSH (gcc_jit_lvalue_as_rvalue (res)); |
| 558 | break; | 562 | break; |
| 559 | break; | 563 | break; |
| @@ -562,17 +566,17 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 562 | break; | 566 | break; |
| 563 | case Bcar: | 567 | case Bcar: |
| 564 | POP1; | 568 | POP1; |
| 565 | res = jit_emit_call ("Fcar", 1, args); | 569 | res = jit_emit_call ("Fcar", comp.lisp_obj_type, 1, args); |
| 566 | PUSH (gcc_jit_lvalue_as_rvalue (res)); | 570 | PUSH (gcc_jit_lvalue_as_rvalue (res)); |
| 567 | break; | 571 | break; |
| 568 | case Bcdr: | 572 | case Bcdr: |
| 569 | POP1; | 573 | POP1; |
| 570 | res = jit_emit_call ("Fcdr", 1, args); | 574 | res = jit_emit_call ("Fcdr", comp.lisp_obj_type, 1, args); |
| 571 | PUSH (gcc_jit_lvalue_as_rvalue (res)); | 575 | PUSH (gcc_jit_lvalue_as_rvalue (res)); |
| 572 | break; | 576 | break; |
| 573 | case Bcons: | 577 | case Bcons: |
| 574 | POP2; | 578 | POP2; |
| 575 | res = jit_emit_call ("Fcons", 2, args); | 579 | res = jit_emit_call ("Fcons", comp.lisp_obj_type, 2, args); |
| 576 | PUSH (gcc_jit_lvalue_as_rvalue (res)); | 580 | PUSH (gcc_jit_lvalue_as_rvalue (res)); |
| 577 | break; | 581 | break; |
| 578 | 582 | ||
| @@ -591,12 +595,12 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length, | |||
| 591 | args[1] = gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, | 595 | args[1] = gcc_jit_context_new_rvalue_from_ptr(comp.ctxt, |
| 592 | comp.lisp_obj_type, | 596 | comp.lisp_obj_type, |
| 593 | Qnil); | 597 | Qnil); |
| 594 | res = jit_emit_call ("Fcons", 2, args); | 598 | res = jit_emit_call ("Fcons", comp.lisp_obj_type, 2, args); |
| 595 | PUSH (gcc_jit_lvalue_as_rvalue (res)); | 599 | PUSH (gcc_jit_lvalue_as_rvalue (res)); |
| 596 | for (int i = 0; i < op; ++i) | 600 | for (int i = 0; i < op; ++i) |
| 597 | { | 601 | { |
| 598 | POP2; | 602 | POP2; |
| 599 | res = jit_emit_call ("Fcons", 2, args); | 603 | res = jit_emit_call ("Fcons", comp.lisp_obj_type, 2, args); |
| 600 | PUSH (gcc_jit_lvalue_as_rvalue (res)); | 604 | PUSH (gcc_jit_lvalue_as_rvalue (res)); |
| 601 | } | 605 | } |
| 602 | break; | 606 | break; |