summaryrefslogtreecommitdiff
path: root/gruel/src/scheme
diff options
context:
space:
mode:
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>2009-07-20 03:47:14 +0000
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>2009-07-20 03:47:14 +0000
commit6f50256f958ac60d5fc9212b24d86777c1b2ec0d (patch)
treeafdde009cf81d93bcb84027937c62ef71194d9fd /gruel/src/scheme
parentaff2d8ad842994b1f58e0dc56b7d2fd6229377a9 (diff)
Merged r11452:11459 from jcorgan/pmt-gruel into trunk. Trunk passes distcheck.
* Merges libpmt into libgruel * Modifies libmblock to use libgruel gruel::pmt_t will be the fundamental msg content for the new message passing implemention for 3.3. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11460 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gruel/src/scheme')
-rw-r--r--gruel/src/scheme/Makefile.am21
-rw-r--r--gruel/src/scheme/gnuradio/Makefile.am31
-rwxr-xr-xgruel/src/scheme/gnuradio/gen-serial-tags.scm118
-rw-r--r--gruel/src/scheme/gnuradio/macros-etc.scm50
-rw-r--r--gruel/src/scheme/gnuradio/pmt-serial-tags.scm75
-rw-r--r--gruel/src/scheme/gnuradio/pmt-serialize.scm48
6 files changed, 343 insertions, 0 deletions
diff --git a/gruel/src/scheme/Makefile.am b/gruel/src/scheme/Makefile.am
new file mode 100644
index 0000000000..4980063d70
--- /dev/null
+++ b/gruel/src/scheme/Makefile.am
@@ -0,0 +1,21 @@
+#
+# Copyright 2007 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+SUBDIRS = gnuradio
diff --git a/gruel/src/scheme/gnuradio/Makefile.am b/gruel/src/scheme/gnuradio/Makefile.am
new file mode 100644
index 0000000000..0ce01f6f85
--- /dev/null
+++ b/gruel/src/scheme/gnuradio/Makefile.am
@@ -0,0 +1,31 @@
+#
+# Copyright 2007,2009 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+#pkgdatadir = $(datadir)/gnuradio
+
+EXTRA_DIST = \
+ gen-serial-tags.scm
+
+# really scheme source files
+dist_pkgdata_DATA = \
+ pmt-serial-tags.scm \
+ pmt-serialize.scm \
+ macros-etc.scm
+
diff --git a/gruel/src/scheme/gnuradio/gen-serial-tags.scm b/gruel/src/scheme/gnuradio/gen-serial-tags.scm
new file mode 100755
index 0000000000..7b90872288
--- /dev/null
+++ b/gruel/src/scheme/gnuradio/gen-serial-tags.scm
@@ -0,0 +1,118 @@
+#!/usr/bin/guile \
+-e main -s
+!#
+;;; -*-scheme-*-
+;;;
+;;; Copyright 2007 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, write to the Free Software Foundation, Inc.,
+;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+;;;
+
+(use-modules (ice-9 format))
+
+(defmacro when (pred . body)
+ `(if ,pred (begin ,@body) #f))
+
+;; ----------------------------------------------------------------
+
+(define (main args)
+
+ (define (usage)
+ (format 0
+ "usage: ~a <pmt-serial-tags.scm> <pmt_serial_tags.h>~%"
+ (car args)))
+
+ (when (not (= (length args) 3))
+ (usage)
+ (format 0 "args: ~s~%" args)
+ (exit 1))
+
+ (let ((i-file (open-input-file (cadr args)))
+ (h-file (open-output-file (caddr args))))
+
+ (write-header-comment h-file "// ")
+ (display "#ifndef INCLUDED_PMT_SERIAL_TAGS_H\n" h-file)
+ (display "#define INCLUDED_PMT_SERIAL_TAGS_H\n" h-file)
+ (newline h-file)
+ (display "enum pst_tags {\n" h-file)
+
+ (for-each-in-file i-file
+ (lambda (form)
+ (let* ((name (cadr form))
+ (c-name (string-upcase (c-ify name)))
+ (value (caddr form)))
+ ;;(format h-file "static const int ~a\t= 0x~x;~%" c-name value)
+ (format h-file " ~a\t= 0x~x,~%" c-name value))))
+
+ (display "};\n" h-file)
+ (display "#endif\n" h-file)))
+
+(define (c-ify name)
+ (list->string (map (lambda (c)
+ (if (eqv? c #\-) #\_ c))
+ (string->list (symbol->string name)))))
+
+
+(define (write-header-comment o-port prefix)
+ (for-each (lambda (comment)
+ (format o-port "~a~a~%" prefix comment))
+ header-comment))
+
+(define header-comment
+ '(
+ ""
+ "Copyright 2007 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, write to the Free Software Foundation, Inc.,"
+ "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA."
+ ""
+ ""
+ "THIS FILE IS MACHINE GENERATED FROM pmt-serial-tags.scm. DO NOT EDIT BY HAND."
+ "See pmt-serial-tags.scm for additional commentary."
+ ""))
+
+
+
+(define (for-each-in-file file f)
+ (let ((port (if (port? file)
+ file
+ (open-input-file file))))
+ (letrec
+ ((loop
+ (lambda (port form)
+ (cond ((eof-object? form)
+ (when (not (eq? port file))
+ (close-input-port port))
+ #t)
+ (else
+ (f form)
+ (set! form #f) ; for GC
+ (loop port (read port)))))))
+ (loop port (read port)))))
diff --git a/gruel/src/scheme/gnuradio/macros-etc.scm b/gruel/src/scheme/gnuradio/macros-etc.scm
new file mode 100644
index 0000000000..ac2a4a342a
--- /dev/null
+++ b/gruel/src/scheme/gnuradio/macros-etc.scm
@@ -0,0 +1,50 @@
+;;; -*- scheme -*-
+;;;
+;;; Copyright 2007 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, write to the Free Software Foundation, Inc.,
+;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+;;;
+
+(define-module (gnuradio macros-etc)
+ :export (atom? when unless for-each-in-file))
+
+(define (atom? obj)
+ (not (pair? obj)))
+
+(defmacro when (pred . body)
+ `(if ,pred (begin ,@body) #f))
+
+(defmacro unless (pred . body)
+ `(if (not ,pred) (begin ,@body) #f))
+
+
+(define (for-each-in-file file f)
+ (let ((port (if (port? file)
+ file
+ (open-input-file file))))
+ (letrec
+ ((loop
+ (lambda (port form)
+ (cond ((eof-object? form)
+ (when (not (eq? port file))
+ (close-input-port port))
+ #t)
+ (else
+ (f form)
+ (set! form #f) ; for GC
+ (loop port (read port)))))))
+ (loop port (read port)))))
diff --git a/gruel/src/scheme/gnuradio/pmt-serial-tags.scm b/gruel/src/scheme/gnuradio/pmt-serial-tags.scm
new file mode 100644
index 0000000000..646a751ea4
--- /dev/null
+++ b/gruel/src/scheme/gnuradio/pmt-serial-tags.scm
@@ -0,0 +1,75 @@
+;;; -*-scheme-*-
+;;;
+;;; Copyright 2007 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 (define 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, write to the Free Software Foundation, Inc.,
+;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+;;;
+
+;;; definitions of tag values used for marshalling pmt data
+
+(define pst-true #x00)
+(define pst-false #x01)
+(define pst-symbol #x02) ; untagged-int16 n; followed by n bytes of symbol name
+(define pst-int32 #x03)
+(define pst-double #x04)
+(define pst-complex #x05) ; complex<double>: real, imag
+(define pst-null #x06)
+(define pst-pair #x07) ; followed by two objects
+(define pst-vector #x08) ; untagged-int32 n; followed by n objects
+(define pst-dict #x09) ; untagged-int32 n; followed by n key/value tuples
+
+(define pst-uniform-vector #x0a)
+
+;; u8, s8, u16, s16, u32, s32, u64, s64, f32, f64, c32, c64
+;;
+;; untagged-uint8 tag
+;; untagged-uint8 uvi (define uniform vector info, see below)
+;; untagged-int32 n-items
+;; untagged-uint8 npad
+;; npad bytes of zeros to align binary data
+;; n-items binary numeric items
+;;
+;; uvi:
+;; +-+-+-+-+-+-+-+-+
+;; |B| subtype |
+;; +-+-+-+-+-+-+-+-+
+;;
+;; B == 0, numeric data is little-endian.
+;; B == 1, numeric data is big-endian.
+
+ (define uvi-endian-mask #x80)
+ (define uvi-subtype-mask #x7f)
+
+ (define uvi-little-endian #x00)
+ (define uvi-big-endian #x80)
+
+ (define uvi-u8 #x00)
+ (define uvi-s8 #x01)
+ (define uvi-u16 #x02)
+ (define uvi-s16 #x03)
+ (define uvi-u32 #x04)
+ (define uvi-s32 #x05)
+ (define uvi-u64 #x06)
+ (define uvi-s64 #x07)
+ (define uvi-f32 #x08)
+ (define uvi-f64 #x09)
+ (define uvi-c32 #x0a)
+ (define uvi-c64 #x0b)
+
+
+(define pst-comment #x3b) ; ascii ';'
+(define pst-comment-end #x0a) ; ascii '\n'
diff --git a/gruel/src/scheme/gnuradio/pmt-serialize.scm b/gruel/src/scheme/gnuradio/pmt-serialize.scm
new file mode 100644
index 0000000000..c1d32d75b1
--- /dev/null
+++ b/gruel/src/scheme/gnuradio/pmt-serialize.scm
@@ -0,0 +1,48 @@
+;;;
+;;; Copyright 2007 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, write to the Free Software Foundation, Inc.,
+;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+;;;
+
+;;; An implementation of pmt_serialize in scheme.
+;;; Currently handles only symbols and pairs. They're all we need for now.
+
+(define-module (gnuradio pmt-serialize)
+ :export (pmt-serialize))
+
+(load-from-path "gnuradio/pmt-serial-tags")
+
+(define (pmt-serialize obj put-byte)
+ (define (put-u16 x)
+ (put-byte (logand (ash x -8) #xff))
+ (put-byte (logand x #xff)))
+
+ (cond ((null? obj)
+ (put-byte pst-null))
+ ((symbol? obj)
+ (let* ((sym-as-bytes (map char->integer (string->list (symbol->string obj))))
+ (len (length sym-as-bytes)))
+ (put-byte pst-symbol)
+ (put-u16 len)
+ (for-each put-byte sym-as-bytes)))
+
+ ((pair? obj)
+ (put-byte pst-pair)
+ (pmt-serialize (car obj) put-byte)
+ (pmt-serialize (cdr obj) put-byte))
+ (else
+ (throw 'not-implemented "pmt-serialize" obj))))