2013-05-23 14:52:29 +02:00
|
|
|
/* Copyright (C) 2001, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
|
2001-04-01 05:03:41 +00:00
|
|
|
*
|
2009-05-26 22:23:44 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
2009-06-17 00:22:09 +01:00
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 3 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
2001-04-01 05:03:41 +00:00
|
|
|
*
|
2009-06-17 00:22:09 +01:00
|
|
|
* This library is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
2009-05-26 22:23:44 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
2001-04-01 05:03:41 +00:00
|
|
|
*
|
2009-05-26 22:23:44 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-06-17 00:22:09 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
* 02110-1301 USA
|
2009-05-26 22:23:44 +02:00
|
|
|
*/
|
2001-04-01 05:03:41 +00:00
|
|
|
|
2001-04-16 03:43:48 +00:00
|
|
|
#ifndef _SCM_PROGRAMS_H_
|
|
|
|
|
#define _SCM_PROGRAMS_H_
|
2001-04-01 05:03:41 +00:00
|
|
|
|
|
|
|
|
#include <libguile.h>
|
|
|
|
|
|
2013-05-23 14:52:29 +02:00
|
|
|
/*
|
|
|
|
|
* The new RTL programs.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-11-19 18:28:19 +01:00
|
|
|
#define SCM_PROGRAM_P(x) (SCM_HAS_TYP7 (x, scm_tc7_program))
|
|
|
|
|
#define SCM_PROGRAM_CODE(x) ((scm_t_uint32 *) SCM_CELL_WORD_1 (x))
|
|
|
|
|
#define SCM_PROGRAM_FREE_VARIABLES(x) (SCM_CELL_OBJECT_LOC (x, 2))
|
|
|
|
|
#define SCM_PROGRAM_FREE_VARIABLE_REF(x,i) (SCM_PROGRAM_FREE_VARIABLES (x)[i])
|
|
|
|
|
#define SCM_PROGRAM_FREE_VARIABLE_SET(x,i,v) (SCM_PROGRAM_FREE_VARIABLES (x)[i]=(v))
|
|
|
|
|
#define SCM_PROGRAM_NUM_FREE_VARIABLES(x) (SCM_CELL_WORD_0 (x) >> 16)
|
|
|
|
|
#define SCM_VALIDATE_PROGRAM(p,x) SCM_MAKE_VALIDATE (p, x, PROGRAM_P)
|
2013-05-23 14:52:29 +02:00
|
|
|
|
2013-11-19 18:55:03 +01:00
|
|
|
#ifdef BUILDING_LIBGUILE
|
2013-05-23 14:52:29 +02:00
|
|
|
static inline SCM
|
|
|
|
|
scm_i_make_rtl_program (const scm_t_uint32 *code)
|
|
|
|
|
{
|
2013-11-19 18:24:22 +01:00
|
|
|
return scm_cell (scm_tc7_program, (scm_t_bits)code);
|
2013-05-23 14:52:29 +02:00
|
|
|
}
|
2013-11-19 18:55:03 +01:00
|
|
|
#endif
|
2013-05-23 14:52:29 +02:00
|
|
|
|
|
|
|
|
SCM_INTERNAL SCM scm_make_rtl_program (SCM bytevector, SCM byte_offset, SCM free_variables);
|
|
|
|
|
SCM_INTERNAL SCM scm_rtl_program_p (SCM obj);
|
|
|
|
|
SCM_INTERNAL SCM scm_rtl_program_code (SCM program);
|
|
|
|
|
|
Subrs are RTL programs
* libguile/gsubr.c: Define RTL stubs instead of stack VM stubs.
(SUBR_STUB_CODE, get_subr_stub_code): Adapt to return a uint32_t*
pointer instead of a SCM value.
(create_subr): Create RTL procedures instead of stack VM procedures.
For RTL procedures, the function pointer, name, and generic address
pointer go inline to the procedure, as free variables.
(scm_i_primitive_arity, scm_i_primitive_call_ip): New helpers.
(scm_c_make_gsubr, scm_c_define_gsubr, scm_c_make_gsubr_with_generic)
(scm_c_define_gsubr_with_generic): Adapt to create_gsubr being renamed
to create_subr.
Remove gsubr test code.
* libguile/gsubr.h (SCM_PRIMITIVE_P, SCM_PRIMITIVE_GENERIC_P): Only RTL
programs can be primitives now.
(SCM_SUBRF, SCM_SUBR_NAME, SCM_SUBR_GENERIC): These fields are now in
the RTL free variables, not the object table.
* libguile/programs.c (scm_i_rtl_program_name):
(scm_i_rtl_program_documentation):
(scm_i_rtl_program_properties):
(scm_i_rtl_program_minimum_arity): Implement these appropriately for
primitives, which lack debugging information.
(scm_primitive_p, scm_primitive_call_ip): New helpers.
* libguile/snarf.h: Remove static allocation for subrs. Since there is
nothing to allocate besides the program itself, which needs runtime
relocation, static allocation is not a win.
* system/vm/program.scm: Fix up various arity-related things for
primitives, which don't use ELF arity info.
* test-suite/tests/eval.test ("stack involving a primitive"): Add an
XFAIL until we get just one VM.
2013-10-18 10:03:26 +02:00
|
|
|
SCM_INTERNAL SCM scm_primitive_p (SCM obj);
|
|
|
|
|
SCM_INTERNAL SCM scm_primitive_call_ip (SCM prim);
|
|
|
|
|
|
2013-05-05 18:26:53 +02:00
|
|
|
SCM_INTERNAL SCM scm_i_rtl_program_name (SCM program);
|
2013-05-16 23:38:29 +02:00
|
|
|
SCM_INTERNAL SCM scm_i_rtl_program_documentation (SCM program);
|
2013-05-17 22:10:16 +02:00
|
|
|
SCM_INTERNAL SCM scm_i_rtl_program_properties (SCM program);
|
2013-05-23 14:52:29 +02:00
|
|
|
|
2013-11-07 23:03:45 +01:00
|
|
|
SCM_INTERNAL SCM scm_find_source_for_addr (SCM ip);
|
|
|
|
|
|
2001-04-01 05:03:41 +00:00
|
|
|
/*
|
|
|
|
|
* Programs
|
|
|
|
|
*/
|
|
|
|
|
|
2009-09-17 00:14:16 +01:00
|
|
|
#define SCM_F_PROGRAM_IS_BOOT 0x100
|
continuations are vm procedures
* libguile/vm-i-system.c (continuation-call): New op, like subr-call or
foreign-call, but for continuations.
* libguile/continuations.h: Add scm_i_continuation_call internal
declaration.
(SCM_CONTINUATIONP): Reimplement in terms of
SCM_PROGRAM_IS_CONTINUATION.
(scm_tc16_continuation, SCM_CONTREGS, SCM_CONTINUATION_LENGTH)
(SCM_SET_CONTINUATION_LENGTH, SCM_JMPBUF, SCM_DYNENV, SCM_THROW_VALUE)
(SCM_CONTINUATION_ROOT, SCM_DFRAME): Remove these from the exposed
API.
(scm_i_continuation_to_frame): New internal declaration.
* libguile/continuations.c
* libguile/continuations.c: Add trickery like in foreign.c, smob.c, and
gsubr.c, so that we can make procedural trampolines for continuations.
(scm_i_continuation_to_frame): New internal function, from stacks.c.
* libguile/programs.h (SCM_F_PROGRAM_IS_CONTINUATION)
(SCM_PROGRAM_IS_CONTINUATION): Add a flag for programs that are
continuations. Probably should add flags for the other trampoline
types too.
* libguile/programs.c (scm_i_program_print): Print continuations as
before.
* libguile/stacks.c (scm_stack_id, scm_make_stack): Use
scm_i_continuation_to_frame in the continuation case.
2010-02-06 17:00:03 +01:00
|
|
|
#define SCM_F_PROGRAM_IS_PRIMITIVE 0x200
|
|
|
|
|
#define SCM_F_PROGRAM_IS_PRIMITIVE_GENERIC 0x400
|
|
|
|
|
#define SCM_F_PROGRAM_IS_CONTINUATION 0x800
|
2010-03-04 12:02:02 +01:00
|
|
|
#define SCM_F_PROGRAM_IS_PARTIAL_CONTINUATION 0x1000
|
2013-10-18 17:41:33 +02:00
|
|
|
#define SCM_F_PROGRAM_IS_FOREIGN 0x2000
|
2001-04-01 05:03:41 +00:00
|
|
|
|
programs have their own tc7 now
* libguile/tags.h (scm_tc7_program):
* libguile/programs.h: Programs now have their own tc7 code. Fix up the
macros appropriately.
* libguile/programs.c: Remove smobby bits, leaving marking, printing,
and application for other parts of Guile.
* libguile/debug.c (scm_procedure_source):
* libguile/eval.c (scm_trampoline_0, scm_trampoline_1)
(scm_trampoline_2): Add cases for tc7_program.
* libguile/eval.i.c (CEVAL, SCM_APPLY):
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/gc-card.c (scm_i_sweep_card, scm_i_tag_name):
* libguile/gc-mark.c (1):
* libguile/print.c (iprin1):
* libguile/procs.c (scm_procedure_p, scm_thunk_p)
* libguile/vm-i-system.c (make-closure): Adapt to new procedure
representation.
* libguile/procprop.c (scm_i_procedure_arity): Do the right thing for
programs.
* test-suite/tests/procprop.test ("procedure-arity"): Arity test now
succeeds.
* libguile/goops.c (scm_class_of): Programs now belong to the class
<procedure>, not a smob class.
* libguile/vm.h (struct vm, struct vm_cont):
* libguile/vm-engine.c (vm_engine):
* libguile/frames.h (SCM_FRAME_BYTE_CAST, struct vm_frame):
* libguile/frames.c (scm_c_make_vm_frame): Fix usages of scm_byte_t,
changing them to scm_t_uint8.
2009-08-20 14:27:38 +02:00
|
|
|
#define SCM_PROGRAM_IS_BOOT(x) (SCM_CELL_WORD_0 (x) & SCM_F_PROGRAM_IS_BOOT)
|
2010-01-06 22:16:57 +01:00
|
|
|
#define SCM_PROGRAM_IS_PRIMITIVE(x) (SCM_CELL_WORD_0 (x) & SCM_F_PROGRAM_IS_PRIMITIVE)
|
2010-01-05 16:50:58 +01:00
|
|
|
#define SCM_PROGRAM_IS_PRIMITIVE_GENERIC(x) (SCM_CELL_WORD_0 (x) & SCM_F_PROGRAM_IS_PRIMITIVE_GENERIC)
|
continuations are vm procedures
* libguile/vm-i-system.c (continuation-call): New op, like subr-call or
foreign-call, but for continuations.
* libguile/continuations.h: Add scm_i_continuation_call internal
declaration.
(SCM_CONTINUATIONP): Reimplement in terms of
SCM_PROGRAM_IS_CONTINUATION.
(scm_tc16_continuation, SCM_CONTREGS, SCM_CONTINUATION_LENGTH)
(SCM_SET_CONTINUATION_LENGTH, SCM_JMPBUF, SCM_DYNENV, SCM_THROW_VALUE)
(SCM_CONTINUATION_ROOT, SCM_DFRAME): Remove these from the exposed
API.
(scm_i_continuation_to_frame): New internal declaration.
* libguile/continuations.c
* libguile/continuations.c: Add trickery like in foreign.c, smob.c, and
gsubr.c, so that we can make procedural trampolines for continuations.
(scm_i_continuation_to_frame): New internal function, from stacks.c.
* libguile/programs.h (SCM_F_PROGRAM_IS_CONTINUATION)
(SCM_PROGRAM_IS_CONTINUATION): Add a flag for programs that are
continuations. Probably should add flags for the other trampoline
types too.
* libguile/programs.c (scm_i_program_print): Print continuations as
before.
* libguile/stacks.c (scm_stack_id, scm_make_stack): Use
scm_i_continuation_to_frame in the continuation case.
2010-02-06 17:00:03 +01:00
|
|
|
#define SCM_PROGRAM_IS_CONTINUATION(x) (SCM_CELL_WORD_0 (x) & SCM_F_PROGRAM_IS_CONTINUATION)
|
2010-03-04 12:02:02 +01:00
|
|
|
#define SCM_PROGRAM_IS_PARTIAL_CONTINUATION(x) (SCM_CELL_WORD_0 (x) & SCM_F_PROGRAM_IS_PARTIAL_CONTINUATION)
|
2013-10-18 17:41:33 +02:00
|
|
|
#define SCM_PROGRAM_IS_FOREIGN(x) (SCM_CELL_WORD_0 (x) & SCM_F_PROGRAM_IS_FOREIGN)
|
2001-04-01 05:03:41 +00:00
|
|
|
|
2010-10-08 12:21:20 +02:00
|
|
|
SCM_API SCM scm_program_source (SCM program, SCM ip, SCM sources);
|
allocate free variables inline to closures
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/programs.h (SCM_PROGRAM_FREE_VARIABLES)
(SCM_PROGRAM_FREE_VARIABLE_REF, SCM_PROGRAM_FREE_VARIABLE_SET)
(SCM_PROGRAM_NUM_FREE_VARIABLES):
* libguile/programs.c (scm_make_program, scm_program_num_free_variables)
(scm_program_free_variable_ref, scm_program_free_variable_set_x):
Allocate free variables inline with programs, instead of being in a
vect. Should improve locality, and require fewer local variables in
the VM.
* libguile/vm-engine.c (vm_engine): Remove free_vars and free_vars_count
variables.
* libguile/vm-engine.h (CACHE_PROGRAM): No need to muck with free_vars
and free_vars_count.
(CHECK_FREE_VARIABLE): Update for inline free vars.
* libguile/vm-i-system.c (FREE_VARIABLE_REF): Update for inline free
vars.
(make-closure, fix-closure): Take the closure vals as separate stack
args, and copy or fix them inline into the appropriate closure.
* module/language/objcode/spec.scm (program-free-variables): Define a
local version of this removed function.
* module/language/tree-il/compile-glil.scm (flatten): Adjust to not make
a vector when making closures.
* module/system/vm/program.scm: Export program-num-free-variables,
program-free-variable-ref, program-free-variable-set!, and remove
program-free-variables.
* test-suite/tests/tree-il.test ("lambda"): Update to not make vectors
when making closures.
2010-01-09 16:42:27 +01:00
|
|
|
SCM_API SCM scm_program_num_free_variables (SCM program);
|
|
|
|
|
SCM_API SCM scm_program_free_variable_ref (SCM program, SCM i);
|
|
|
|
|
SCM_API SCM scm_program_free_variable_set_x (SCM program, SCM i, SCM x);
|
2008-08-20 14:32:36 -07:00
|
|
|
|
de-nargs struct scm_objcode; procedure-property refactor
* libguile/objcodes.h (struct scm_objcode): Remove nargs, nrest, and
nlocs, as they are no longer needed. Also obviates the need for a
padding word.
* libguile/procs.c (scm_thunk_p): Use scm_i_program_arity for programs.
* libguile/procprop.c (scm_i_procedure_arity): Use scm_i_program_arity
for programs.
(scm_procedure_properties, scm_set_procedure_properties_x)
(scm_procedure_property, scm_set_procedure_property_x): Rework so that
non-closure properties are stored directly in a weak hash, instead of
needing a weak hash of "stand-in" closures to hold the properties. Fix
docstrings also.
* libguile/root.h (scm_stand_in_procs): Remove from the scm_sys_protects
set. Actually with libGC, we should be able to store the elements of
scm_sys_protects directly as global variables.
* libguile/gc.c (scm_init_storage): Remove scm_stand_in_procs
initialization.
* libguile/programs.c (scm_i_program_arity): New private accessor, tries
to determine the "minimum arity" of a program.
* libguile/vm.c (really_make_boot_program): Adapt to changes in
struct scm_objcode.
* module/language/assembly.scm (*program-header-len*, byte-length):
* module/language/assembly/compile-bytecode.scm (write-bytecode):
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
* module/language/assembly/disassemble.scm (disassemble-load-program):
Adapt to changes in objcode.
* module/system/xref.scm (program-callee-rev-vars): Adapt to changes in
assembly.
* module/language/glil.scm: Remove nargs, nrest, and nlocs from
glil-program.
* module/language/glil/compile-assembly.scm (make-meta, glil->assembly):
* module/language/glil/decompile-assembly.scm (decompile-toplevel):
(decompile-load-program): Adapt to changes in GLIL and assembly.
* module/language/tree-il/compile-glil.scm (flatten-lambda): Adapt to
changes in GLIL.
* test-suite/tests/asm-to-bytecode.test: Adapt to assembly and bytecode
changes.
* test-suite/tests/tree-il.test: Adapt to GLIL changes.
2009-10-13 23:45:22 +02:00
|
|
|
SCM_INTERNAL int scm_i_program_arity (SCM program, int *req, int *opt, int *rest);
|
programs have their own tc7 now
* libguile/tags.h (scm_tc7_program):
* libguile/programs.h: Programs now have their own tc7 code. Fix up the
macros appropriately.
* libguile/programs.c: Remove smobby bits, leaving marking, printing,
and application for other parts of Guile.
* libguile/debug.c (scm_procedure_source):
* libguile/eval.c (scm_trampoline_0, scm_trampoline_1)
(scm_trampoline_2): Add cases for tc7_program.
* libguile/eval.i.c (CEVAL, SCM_APPLY):
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/gc-card.c (scm_i_sweep_card, scm_i_tag_name):
* libguile/gc-mark.c (1):
* libguile/print.c (iprin1):
* libguile/procs.c (scm_procedure_p, scm_thunk_p)
* libguile/vm-i-system.c (make-closure): Adapt to new procedure
representation.
* libguile/procprop.c (scm_i_procedure_arity): Do the right thing for
programs.
* test-suite/tests/procprop.test ("procedure-arity"): Arity test now
succeeds.
* libguile/goops.c (scm_class_of): Programs now belong to the class
<procedure>, not a smob class.
* libguile/vm.h (struct vm, struct vm_cont):
* libguile/vm-engine.c (vm_engine):
* libguile/frames.h (SCM_FRAME_BYTE_CAST, struct vm_frame):
* libguile/frames.c (scm_c_make_vm_frame): Fix usages of scm_byte_t,
changing them to scm_t_uint8.
2009-08-20 14:27:38 +02:00
|
|
|
SCM_INTERNAL void scm_i_program_print (SCM program, SCM port,
|
|
|
|
|
scm_print_state *pstate);
|
2009-05-26 22:23:44 +02:00
|
|
|
SCM_INTERNAL void scm_bootstrap_programs (void);
|
|
|
|
|
SCM_INTERNAL void scm_init_programs (void);
|
2001-04-01 05:03:41 +00:00
|
|
|
|
2001-04-16 03:43:48 +00:00
|
|
|
#endif /* _SCM_PROGRAMS_H_ */
|
2001-04-01 05:03:41 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Local Variables:
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
End:
|
|
|
|
|
*/
|