From f2f013ecb94c5e5781952c67496fec09aff7da2c Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Sun, 31 Oct 2010 20:51:24 -0700 Subject: Rename coerce.scm to runtime-shim.scm. Modify core.scm to use runtime-shim. --- gnuradio-core/src/lib/swig/Makefile.am | 3 +- gnuradio-core/src/lib/swig/gnuradio/coerce.scm | 84 -------------------- gnuradio-core/src/lib/swig/gnuradio/core.scm | 1 + .../src/lib/swig/gnuradio/runtime-shim.scm | 89 ++++++++++++++++++++++ 4 files changed, 92 insertions(+), 85 deletions(-) delete mode 100644 gnuradio-core/src/lib/swig/gnuradio/coerce.scm create mode 100644 gnuradio-core/src/lib/swig/gnuradio/runtime-shim.scm (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/swig/Makefile.am b/gnuradio-core/src/lib/swig/Makefile.am index 2b763d94c..01a5318ec 100644 --- a/gnuradio-core/src/lib/swig/Makefile.am +++ b/gnuradio-core/src/lib/swig/Makefile.am @@ -60,8 +60,9 @@ if GUILE # for gnuradio. This has to be installed top level to be found in the # default search path. nobase_guile_DATA = \ - gnuradio/export-safely.scm \ gnuradio/core.scm \ + gnuradio/export-safely.scm \ + gnuradio/runtime-shim.scm \ Swig/common.scm endif diff --git a/gnuradio-core/src/lib/swig/gnuradio/coerce.scm b/gnuradio-core/src/lib/swig/gnuradio/coerce.scm deleted file mode 100644 index 4654ad6f8..000000000 --- a/gnuradio-core/src/lib/swig/gnuradio/coerce.scm +++ /dev/null @@ -1,84 +0,0 @@ -;;; -;;; Copyright 2010 Free Software Foundation, Inc. -;;; -;;; This file is part of GNU Radio -;;; -;;; GNU Radio is free software; you can redistribute it and/or modify -;;; it under the terms of the GNU General Public License as published by -;;; the Free Software Foundation; either version 3, or (at your option) -;;; any later version. -;;; -;;; GNU Radio 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 General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with this program. If not, see . -;;; - -(define-class () - (block #:accessor block #:init-keyword #:block) - (port #:init-value 0 #:accessor port #:init-keyword #:port)) - -(define (gr:ep block port) - (make - #:block (coerce-to-basic-block block) #:port port)) - -(define (coerce-to-endpoint ep) - (cond ((is-a? ep ) ep) - ((false-if-exception (gr:to-basic-block ep)) - => (lambda (x) (gr:ep x 0))) - ((and (pair? ep) (= 2 (length ep)) - (false-if-exception (gr:to-basic-block (car ep)))) - => (lambda (x) (gr:ep x (cadr ep)))) - (else (error "Cannot coerce to an endpoint: " ep)))) - -(define (coerce-to-basic-block block) - (cond ((is-a? block ) block) - ((false-if-exception (gr:to-basic-block block)) => (lambda (x) x)) - (else (error "Cannot coerce to a gr_basic_block: " block)))) - -(define (coerce-to-top-block block) - (cond ((is-a? block ) block) - ((false-if-exception (gr:to-top-block block)) => (lambda (x) x)) - (else (error "Cannot coerce to a gr_top_block: " block)))) - -(define (coerce-to-hier-block2 block) - (cond ((is-a? block ) block) - ((false-if-exception (gr:to-hier-block2 block)) => (lambda (x) x)) - (else (error "Cannot coerce to a gr_hier_block2: " block)))) - - -;;; Connect one or more block endpoints. An endpoint is either a , -;;; a 2-list (block port), or a block instance. In the latter case, the port number -;;; is assumed to be zero. -;;; -;;; If multiple arguments are provided, connect will attempt to wire them in series, -;;; interpreting the endpoints as inputs or outputs as appropriate. -(define-method (gr:connect hb . points) - (dis/connect "connect" gr:primitive-connect hb points)) - -;;; Disconnect one or more block endpoints... -(define-method (gr:disconnect hb . points) - (dis/connect "disconnect" gr:primitive-disconnect hb points)) - -(define (dis/connect name gf hb points) - (let ((hb (coerce-to-hier-block2 hb)) - (points (list->vector (map coerce-to-endpoint points)))) - - (define (op2 p0 p1) - (gf hb (block p0) (port p0) (block p1) (port p1))) - - (let ((len (vector-length points))) - (case len - ((0) (error (string-append name " requires at least 1 endpoint; None provided."))) - ((1) (gf hb (vector-ref points 0))) - (else - (let loop ((n 1)) - (cond ((< n len) - (op2 (vector-ref points (1- n)) (vector-ref points n)) - (loop (1+ n)))))))))) - - -(export-safely gr:ep gr:connect gr:disconnect) diff --git a/gnuradio-core/src/lib/swig/gnuradio/core.scm b/gnuradio-core/src/lib/swig/gnuradio/core.scm index 294881146..08daeeb34 100644 --- a/gnuradio-core/src/lib/swig/gnuradio/core.scm +++ b/gnuradio-core/src/lib/swig/gnuradio/core.scm @@ -2,6 +2,7 @@ (define-module (gnuradio core) #:use-module (gnuradio gnuradio_core_runtime) + #:use-module (gnuradio runtime-shim) #:use-module (gnuradio gnuradio_core_filter) #:use-module (gnuradio gnuradio_core_io) #:use-module (gnuradio gnuradio_core_general) diff --git a/gnuradio-core/src/lib/swig/gnuradio/runtime-shim.scm b/gnuradio-core/src/lib/swig/gnuradio/runtime-shim.scm new file mode 100644 index 000000000..c08d3947c --- /dev/null +++ b/gnuradio-core/src/lib/swig/gnuradio/runtime-shim.scm @@ -0,0 +1,89 @@ +;;; +;;; Copyright 2010 Free Software Foundation, Inc. +;;; +;;; This file is part of GNU Radio +;;; +;;; GNU Radio is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3, or (at your option) +;;; any later version. +;;; +;;; GNU Radio 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 General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see . +;;; + +(define-module (gnuradio runtime-shim) + #:use-module (oop goops) + #:use-module (gnuradio gnuradio_core_runtime) + #:duplicates (merge-generics replace check)) + +(define-class () + (block #:accessor block #:init-keyword #:block) + (port #:init-value 0 #:accessor port #:init-keyword #:port)) + +(define (gr:ep block port) + (make + #:block (coerce-to-basic-block block) #:port port)) + +(define (coerce-to-endpoint ep) + (cond ((is-a? ep ) ep) + ((false-if-exception (gr:to-basic-block ep)) + => (lambda (x) (gr:ep x 0))) + ((and (pair? ep) (= 2 (length ep)) + (false-if-exception (gr:to-basic-block (car ep)))) + => (lambda (x) (gr:ep x (cadr ep)))) + (else (error "Cannot coerce to an endpoint: " ep)))) + +(define (coerce-to-basic-block block) + (cond ((is-a? block ) block) + ((false-if-exception (gr:to-basic-block block)) => (lambda (x) x)) + (else (error "Cannot coerce to a gr_basic_block: " block)))) + +(define (coerce-to-top-block block) + (cond ((is-a? block ) block) + ((false-if-exception (gr:to-top-block block)) => (lambda (x) x)) + (else (error "Cannot coerce to a gr_top_block: " block)))) + +(define (coerce-to-hier-block2 block) + (cond ((is-a? block ) block) + ((false-if-exception (gr:to-hier-block2 block)) => (lambda (x) x)) + (else (error "Cannot coerce to a gr_hier_block2: " block)))) + + +;;; Connect one or more block endpoints. An endpoint is either a , +;;; a 2-list (block port), or a block instance. In the latter case, the port number +;;; is assumed to be zero. +;;; +;;; If multiple arguments are provided, connect will attempt to wire them in series, +;;; interpreting the endpoints as inputs or outputs as appropriate. +(define-method (gr:connect hb . points) + (dis/connect "connect" gr:primitive-connect hb points)) + +;;; Disconnect one or more block endpoints... +(define-method (gr:disconnect hb . points) + (dis/connect "disconnect" gr:primitive-disconnect hb points)) + +(define (dis/connect name gf hb points) + (let ((hb (coerce-to-hier-block2 hb)) + (points (list->vector (map coerce-to-endpoint points)))) + + (define (op2 p0 p1) + (gf hb (block p0) (port p0) (block p1) (port p1))) + + (let ((len (vector-length points))) + (case len + ((0) (error (string-append name " requires at least 1 endpoint; None provided."))) + ((1) (gf hb (vector-ref points 0))) + (else + (let loop ((n 1)) + (cond ((< n len) + (op2 (vector-ref points (1- n)) (vector-ref points n)) + (loop (1+ n)))))))))) + + +(export-safely gr:ep gr:connect gr:disconnect) -- cgit