guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 01/24: Add instrinsics to runtime


From: Andy Wingo
Subject: [Guile-commits] 01/24: Add instrinsics to runtime
Date: Tue, 10 Apr 2018 13:24:12 -0400 (EDT)

wingo pushed a commit to branch master
in repository guile.

commit 4d530a94bbe9be2d54216d07b002e700368d4b28
Author: Andy Wingo <address@hidden>
Date:   Fri Mar 30 20:30:42 2018 +0200

    Add instrinsics to runtime
    
    * libguile/intrinsics.c:
    * libguile/intrinsics.h: New files.
    * libguile/Makefile.am:
    * libguile/init.c: Add new files to build.
---
 libguile/Makefile.am  |  7 ++--
 libguile/init.c       |  4 ++-
 libguile/intrinsics.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++
 libguile/intrinsics.h | 72 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 174 insertions(+), 3 deletions(-)

diff --git a/libguile/Makefile.am b/libguile/Makefile.am
index a9646d8..b27e183 100644
--- a/libguile/Makefile.am
+++ b/libguile/Makefile.am
@@ -1,7 +1,7 @@
 ## Process this file with Automake to create Makefile.in
 ##
-##   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007,
-##     2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016, 2017 Free Software 
Foundation, Inc.
+##   Copyright (C) 1998-2004, 2006-2014, 2016-2018
+##     Free Software Foundation, Inc.
 ##
 ##   This file is part of GUILE.
 ##
@@ -167,6 +167,7 @@ address@hidden@_la_SOURCES =                                
\
        init.c                                  \
        inline.c                                \
        instructions.c                          \
+       intrinsics.c                            \
        ioext.c                                 \
        keywords.c                              \
        list.c                                  \
@@ -274,6 +275,7 @@ DOT_X_FILES =                                       \
        i18n.x                                  \
        init.x                                  \
        instructions.x                          \
+       intrinsics.x                            \
        ioext.x                                 \
        keywords.x                              \
        list.x                                  \
@@ -626,6 +628,7 @@ modinclude_HEADERS =                                \
        init.h                                  \
        inline.h                                \
        instructions.h                          \
+       intrinsics.h                            \
        ioext.h                                 \
        iselect.h                               \
        keywords.h                              \
diff --git a/libguile/init.c b/libguile/init.c
index b046685..9b3accb 100644
--- a/libguile/init.c
+++ b/libguile/init.c
@@ -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
  * modify it under the terms of the GNU Lesser General Public License
@@ -74,6 +74,7 @@
 #include "libguile/gettext.h"
 #include "libguile/i18n.h"
 #include "libguile/instructions.h"
+#include "libguile/intrinsics.h"
 #include "libguile/ioext.h"
 #include "libguile/keywords.h"
 #include "libguile/list.h"
@@ -396,6 +397,7 @@ scm_i_init_guile (void *base)
   scm_init_array_handle ();
   scm_bootstrap_bytevectors ();   /* Requires array-handle */
   scm_bootstrap_instructions ();
+  scm_bootstrap_intrinsics ();
   scm_bootstrap_loader ();
   scm_bootstrap_programs ();
   scm_bootstrap_vm ();
diff --git a/libguile/intrinsics.c b/libguile/intrinsics.c
new file mode 100644
index 0000000..1778ea9
--- /dev/null
+++ b/libguile/intrinsics.c
@@ -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:
+*/
diff --git a/libguile/intrinsics.h b/libguile/intrinsics.h
new file mode 100644
index 0000000..c2805de
--- /dev/null
+++ b/libguile/intrinsics.h
@@ -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:
+*/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]