mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 20:30:28 +02:00
Add instrinsics to runtime
* libguile/intrinsics.c: * libguile/intrinsics.h: New files. * libguile/Makefile.am: * libguile/init.c: Add new files to build.
This commit is contained in:
parent
98fc9c0380
commit
4d530a94bb
4 changed files with 174 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
## Process this file with Automake to create Makefile.in
|
## Process this file with Automake to create Makefile.in
|
||||||
##
|
##
|
||||||
## Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007,
|
## Copyright (C) 1998-2004, 2006-2014, 2016-2018
|
||||||
## 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016, 2017 Free Software Foundation, Inc.
|
## Free Software Foundation, Inc.
|
||||||
##
|
##
|
||||||
## This file is part of GUILE.
|
## This file is part of GUILE.
|
||||||
##
|
##
|
||||||
|
@ -167,6 +167,7 @@ libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES = \
|
||||||
init.c \
|
init.c \
|
||||||
inline.c \
|
inline.c \
|
||||||
instructions.c \
|
instructions.c \
|
||||||
|
intrinsics.c \
|
||||||
ioext.c \
|
ioext.c \
|
||||||
keywords.c \
|
keywords.c \
|
||||||
list.c \
|
list.c \
|
||||||
|
@ -274,6 +275,7 @@ DOT_X_FILES = \
|
||||||
i18n.x \
|
i18n.x \
|
||||||
init.x \
|
init.x \
|
||||||
instructions.x \
|
instructions.x \
|
||||||
|
intrinsics.x \
|
||||||
ioext.x \
|
ioext.x \
|
||||||
keywords.x \
|
keywords.x \
|
||||||
list.x \
|
list.x \
|
||||||
|
@ -626,6 +628,7 @@ modinclude_HEADERS = \
|
||||||
init.h \
|
init.h \
|
||||||
inline.h \
|
inline.h \
|
||||||
instructions.h \
|
instructions.h \
|
||||||
|
intrinsics.h \
|
||||||
ioext.h \
|
ioext.h \
|
||||||
iselect.h \
|
iselect.h \
|
||||||
keywords.h \
|
keywords.h \
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 1995-2004, 2006, 2009-2014 Free Software Foundation, Inc.
|
/* Copyright (C) 1995-2004, 2006, 2009-2014, 2018 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public License
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
@ -74,6 +74,7 @@
|
||||||
#include "libguile/gettext.h"
|
#include "libguile/gettext.h"
|
||||||
#include "libguile/i18n.h"
|
#include "libguile/i18n.h"
|
||||||
#include "libguile/instructions.h"
|
#include "libguile/instructions.h"
|
||||||
|
#include "libguile/intrinsics.h"
|
||||||
#include "libguile/ioext.h"
|
#include "libguile/ioext.h"
|
||||||
#include "libguile/keywords.h"
|
#include "libguile/keywords.h"
|
||||||
#include "libguile/list.h"
|
#include "libguile/list.h"
|
||||||
|
@ -396,6 +397,7 @@ scm_i_init_guile (void *base)
|
||||||
scm_init_array_handle ();
|
scm_init_array_handle ();
|
||||||
scm_bootstrap_bytevectors (); /* Requires array-handle */
|
scm_bootstrap_bytevectors (); /* Requires array-handle */
|
||||||
scm_bootstrap_instructions ();
|
scm_bootstrap_instructions ();
|
||||||
|
scm_bootstrap_intrinsics ();
|
||||||
scm_bootstrap_loader ();
|
scm_bootstrap_loader ();
|
||||||
scm_bootstrap_programs ();
|
scm_bootstrap_programs ();
|
||||||
scm_bootstrap_vm ();
|
scm_bootstrap_vm ();
|
||||||
|
|
94
libguile/intrinsics.c
Normal file
94
libguile/intrinsics.c
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
/* Copyright (C) 2018 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "_scm.h"
|
||||||
|
#include "intrinsics.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct scm_vm_intrinsics scm_vm_intrinsics;
|
||||||
|
|
||||||
|
SCM_DEFINE (scm_intrinsic_list, "intrinsic-list", 0, 0, 0,
|
||||||
|
(void),
|
||||||
|
"")
|
||||||
|
#define FUNC_NAME s_scm_intrinsic_list
|
||||||
|
{
|
||||||
|
SCM list = SCM_EOL;
|
||||||
|
|
||||||
|
#define ADD_INTRINSIC(type, id, name, ID) \
|
||||||
|
if (name) \
|
||||||
|
list = scm_acons (scm_from_latin1_symbol (name), \
|
||||||
|
scm_from_int (SCM_VM_INTRINSIC_##ID), \
|
||||||
|
list);
|
||||||
|
SCM_FOR_ALL_VM_INTRINSICS (ADD_INTRINSIC);
|
||||||
|
#undef ADD_INTRINSIC
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
static SCM
|
||||||
|
add_immediate (SCM a, scm_t_uint8 b)
|
||||||
|
{
|
||||||
|
return scm_sum (a, scm_from_uint8 (b));
|
||||||
|
}
|
||||||
|
|
||||||
|
static SCM
|
||||||
|
sub_immediate (SCM a, scm_t_uint8 b)
|
||||||
|
{
|
||||||
|
return scm_difference (a, scm_from_uint8 (b));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
scm_bootstrap_intrinsics (void)
|
||||||
|
{
|
||||||
|
scm_vm_intrinsics.add = scm_sum;
|
||||||
|
scm_vm_intrinsics.add_immediate = add_immediate;
|
||||||
|
scm_vm_intrinsics.sub = scm_difference;
|
||||||
|
scm_vm_intrinsics.sub_immediate = sub_immediate;
|
||||||
|
scm_vm_intrinsics.mul = scm_product;
|
||||||
|
scm_vm_intrinsics.div = scm_divide;
|
||||||
|
scm_vm_intrinsics.quo = scm_quotient;
|
||||||
|
scm_vm_intrinsics.rem = scm_remainder;
|
||||||
|
scm_vm_intrinsics.mod = scm_modulo;
|
||||||
|
scm_vm_intrinsics.logand = scm_logand;
|
||||||
|
scm_vm_intrinsics.logior = scm_logior;
|
||||||
|
scm_vm_intrinsics.logxor = scm_logxor;
|
||||||
|
|
||||||
|
scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
|
||||||
|
"scm_init_intrinsics",
|
||||||
|
(scm_t_extension_init_func)scm_init_intrinsics,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
scm_init_intrinsics (void)
|
||||||
|
{
|
||||||
|
#ifndef SCM_MAGIC_SNARFER
|
||||||
|
#include "libguile/intrinsics.x"
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Local Variables:
|
||||||
|
c-file-style: "gnu"
|
||||||
|
End:
|
||||||
|
*/
|
72
libguile/intrinsics.h
Normal file
72
libguile/intrinsics.h
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/* Copyright (C) 2018 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SCM_VM_INTRINSICS_H_
|
||||||
|
#define _SCM_VM_INTRINSICS_H_
|
||||||
|
|
||||||
|
#include <libguile.h>
|
||||||
|
|
||||||
|
#ifdef BUILDING_LIBGUILE
|
||||||
|
|
||||||
|
typedef SCM (*scm_t_binary_scm_intrinsic) (SCM, SCM);
|
||||||
|
typedef SCM (*scm_t_binary_uimm_intrinsic) (SCM, scm_t_uint8);
|
||||||
|
|
||||||
|
#define SCM_FOR_ALL_VM_INTRINSICS(M) \
|
||||||
|
M(binary_scm, add, "add", ADD) \
|
||||||
|
M(binary_uimm, add_immediate, "add/immediate", ADD_IMMEDIATE) \
|
||||||
|
M(binary_scm, sub, "sub", SUB) \
|
||||||
|
M(binary_uimm, sub_immediate, "sub/immediate", SUB_IMMEDIATE) \
|
||||||
|
M(binary_scm, mul, "mul", MUL) \
|
||||||
|
M(binary_scm, div, "div", DIV) \
|
||||||
|
M(binary_scm, quo, "quo", QUO) \
|
||||||
|
M(binary_scm, rem, "rem", REM) \
|
||||||
|
M(binary_scm, mod, "mod", MOD) \
|
||||||
|
M(binary_scm, logand, "logand", LOGAND) \
|
||||||
|
M(binary_scm, logior, "logior", LOGIOR) \
|
||||||
|
M(binary_scm, logxor, "logxor", LOGXOR) \
|
||||||
|
/* Add new intrinsics here; also update scm_bootstrap_intrinsics. */
|
||||||
|
|
||||||
|
enum scm_vm_intrinsic
|
||||||
|
{
|
||||||
|
#define DEFINE_ENUM(type, id, name, ID) SCM_VM_INTRINSIC_##ID,
|
||||||
|
SCM_FOR_ALL_VM_INTRINSICS(DEFINE_ENUM)
|
||||||
|
#undef DEFINE_ENUM
|
||||||
|
SCM_VM_INTRINSIC_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
SCM_INTERNAL struct scm_vm_intrinsics
|
||||||
|
{
|
||||||
|
#define DEFINE_MEMBER(type, id, name, ID) scm_t_##type##_intrinsic id;
|
||||||
|
SCM_FOR_ALL_VM_INTRINSICS(DEFINE_MEMBER)
|
||||||
|
#undef DEFINE_MEMBER
|
||||||
|
} scm_vm_intrinsics;
|
||||||
|
|
||||||
|
#endif /* BUILDING_LIBGUILE */
|
||||||
|
|
||||||
|
SCM_INTERNAL SCM scm_intrinsic_list (void);
|
||||||
|
|
||||||
|
SCM_INTERNAL void scm_bootstrap_intrinsics (void);
|
||||||
|
SCM_INTERNAL void scm_init_intrinsics (void);
|
||||||
|
|
||||||
|
#endif /* _SCM_INSTRUCTIONS_H_ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
Local Variables:
|
||||||
|
c-file-style: "gnu"
|
||||||
|
End:
|
||||||
|
*/
|
Loading…
Add table
Add a link
Reference in a new issue