unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* fyi, a reading of guile source
@ 2002-05-16  0:01 Thien-Thi Nguyen
  0 siblings, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2002-05-16  0:01 UTC (permalink / raw)


this has been checked into $workbook/journal/owinebar.notes, btw.
i learned a lot reading it.

thi


------- Start of forwarded message -------
From: Lynn Winebarger <owinebar@free-expression.org>
Subject: Some questions 
Date: Thu, 9 May 2002 00:59:22 -0500
To: guile-devel@gnu.org


So, I've been reading guile some more.  I have some questions that
I'm slowly answering myself by reading the source, but might be answered
faster by people already in the know.

   I don't understand the last 3 lines of scm_ilookup:
  if (SCM_ICDRP (iloc))
    return SCM_CDRLOC (er);
  return SCM_CARLOC (SCM_CDR (er));

      I mean, I understand the operations, I just don't understand what the
storage scheme behind the operations is. (What is it?)

     Memoized objects:  what's the deal?  The manual mentions them several
times but never defines them.  The evaluator (in particular lookupcar) seems
to memoize everything for evaluation purposes but memoized objects are 
defined in debug.c which should mean they are for debugging purposes.

    I'm catting on a "roadmap" file I've jotted down that might be useful to 
others who haven't looked at the source or are scared off by it.  Please
correct anything I've got wrong.  Yes, they're absolutely 
implementation-specific and would require keeping in sync with the sources.
Maybe some others have something to add they might have found useful
when starting to read the code.

Lynn

- ----------------------------------
You are on long and twisty path through the forest.
Some useful files:
guile.c   main and inner_main
init.c    scm_{boot,init}_guile1? and scm_load_startup_files
script.c  scm_shell
tags.h    Possible the most important documentation-wise, 
          partially explains the
          convoluted typing scheme and how some immediates
          are actually considered "instructions" for the 
          evaluator, and some notes on how the contents of
          cells are tagged and set up for garbage collection.
gc_os_dep.c   All kinds of hairy details, including the clever
              methods for finding the stack base when scm_boot_guile
              isn't used.
eval.h     home of the iloc macros.  Supposing the i somehow stands
           for immediate, but not clear why it should be named that
           way.  When closures are memoized (translated into the 
           tree code using the goodies from tags.h), the variable
           references get changed into pairs of numbers denoting how
           many "stack" frames up to go, and the offset in the frame
           of the variable (this is set up on the first evaluation
           of the closure).  Actually pair is not right, the frame
           and offset #'s are encoded into one immediate, with the
           lowest 8 bits being a type tag, then (currently)
           11 bits for the frame and some bits for the offset.
eval.c     of course
modules.c  eval really depends on this, as everything depends on
           the (dynamically scoped) module to provide a top-level
           environment.
dynamic-root.c   Adds an odd spicy flavor to guile.  For fluids,
           call/cc tricks, and threads.
debug.[ch]  home of the memoized type.

Booting up a command line guile follows roughly
this sequence (for our purposes there's no returning from the
unindented functions).
main (duh)
scm_boot_guile   (sets up local variable for stack base) 
scm_boot_guile1  
  => scm_init_guile1  inits all the smobs - this is where all
                      those #include "something.x" statements
                      will actually come into play.  Does other
                      initializations as well.
                      Last act is to load startup files, particularly
                      ice-9/boot-9.scm.  boot-9 defines top-repl
                      (using scm-style-repl and error-catching-repl)
                      last act of boot-9 is to set the "current module"
                      to (guile-user)
inner_main  
scm_shell
   => scm_compile_shell_switches  notable in that it constructs the
                           code guile executes.  In particular, it
                           inserts a call to top-repl if guile's invoked
                           for interactive use. returns the expression
   => scm_current_module   (this was set when loading startup files, 
                            remember?). returns the module
scm_eval_x   scm_compile_shell_switches provides the expression, 
             scm_current_module provides the current module (a smob!)
scm_inner_eval_x   this is wrapped by a dynamic wind that sets the
               current module to be the module handed to scm_eval_x 
               on entrance and restores it on exit (redundant in this
               usage).
scm_primitive_eval_x  applies the module transformer (if any) on the 
                      expression, produces a top-level environment
                      consisting of a list with the current module's
                      "eval-closure" (a smob type created in module.c),
                      and then passes the expression and environment off
                      to the real eval (well, scm_i_eval_x, but that just
                      calls the real eval)

- ---------

eval.c and probably some other files include themselves in
order to produce separate debugging versions of functions
in the object code without having separate versions in the
source.  

*.x files included in init functions are generated by guile-snarf
based on SCM_DEFINE and other macros (which appear all over the code).

lexical environments are just lists of lists of cons cells, but there's
some slight weirdness with the value (may be the cdr or the cadr of the
cons cell).

ilocs: see above at eval.h  some related functions are actually in
       debug.c

memoized smobs:  defined in debug.c  Not clear what is going on here.
     All expressions should get "memoized" as part of expansion/evaluation,
     but the memoized objects appear geared toward preserving the source
     for debugging purposes ??? (otherwise, why is it in debug.c?)


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
------- End of forwarded message -------

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: fyi, a reading of guile source
       [not found] <02051521435901.26010@locke.free-expression.org>
@ 2002-05-16  7:49 ` Martin Grabmueller
  2002-05-17  4:23   ` Thien-Thi Nguyen
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Martin Grabmueller @ 2002-05-16  7:49 UTC (permalink / raw)
  Cc: guile-devel, guile-user

> From: Lynn Winebarger <owinebar@free-expression.org>
> Date: Wed, 15 May 2002 21:43:59 -0500
> 
> On Wednesday 15 May 2002 19:01, Thien-Thi Nguyen wrote:
> > this has been checked into $workbook/journal/owinebar.notes, btw.
> > i learned a lot reading it.
> > 
>    Thanks.  With no response, I had thought everyone else thought
> it was too basic and obvious to mention - or that prospective guile
> modifiers _should_ have to explore these things themselves.  Or 
> both.

For those interested in this: some time ago (when I was trying to
understand this code myself), I wrote down some notes on the data
representation in Guile.  I have appended them, but can't guarantee
whether they are still correct, but I guarantee that they are
incomplete.

'martin

===File ~/data-layout.text==================================
							-*-outline-*-
* Guile's internal representation

** Introduction

The following code snippet was used for producing the internal
representation dumps in the following sections.

  (use-modules (srfi srfi-13))
  (define (bin o)
    (string-pad (number->string (object-address o) 2) 32 #\0))


** General

All Scheme values are represented by a 32-bit word.  This word encodes
the data type (at least the group of types) a value belongs to.
Additionally, this word may contain information about the value,
either directly in the data word, or in another memory region.  In the
letter case, the 32-bit word includes a pointer to that region.

So for determining an object's type, it is first necessary to check
the contents of this 32-bit word, and then the memory location pointed
to, if it contains a pointer.

This section focuses on this 32-bit word every value must have.  The
following sections will describe how to interpret the referenced
memory regions.


*** A word on Scheme objects.

It is normally not allowed in a variable of type SCM to have a 1 in
bit #0.  There are exceptions for values in the CAR of cells, but more
on that later.

So if examining a value of type SCM, you can check if the lowest bit
is 1.  If it is, you don't have a valid Scheme value.


**** Most objects

31            24|23           16|15            8|7             0
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |0|
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'


**** glocs and structs

Values like this are only valid in the CAR of heap cells.

31            24|23           16|15            8|7             0
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |1|
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'


*** Scheme objects

Immediates can be determined by checking the bits #1 and #2.  If one
of them is 1, it is an immediate, otherwise it is a heap pointer.


**** Immediates integers (fixnums)

Immediate integers are 30-bit two's-complement integers (aka fixnums),
encoded as immediates for performance reasons.  Access to them is very
fast, and creating them does not involve allocation of heap storage.

31            24|23           16|15            8|7             0
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |1|0|
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `---------------------------------------------------------'
                fixnum value in two's-complement


**** Immediates (no heap memory associated)

Characters, immediate codes etc. are represented as immediates with
100 in bit 2-0.

31            24|23           16|15            8|7             0
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |1|0|0|
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `-------------------------------------------------------'
                 type-dependent information


**** Heap pointers

Pointers into the Scheme heap can be determined by checking whether
the three lowest bits are zero.  The complete 32-bit value can then be
dereferenced, and the two (or four for double cells) words pointed to
can be examined to get more detailed type information.  Normally, it
is the first word of the heap region which contains the additional
type information.  The complete word is a valid pointer into heap
storage because heap cells are aligned on 8-byte boundaries.

31            24|23           16|15            8|7             0
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |0|0|0|
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `-------------------------------------------------------------'
                  pointer into the cell heap


** Immediates

*** Fixnums

Fixnums are integers limited to the range -2^{29} to 2^29-1.  Larger
integers are represented as `Bignums', described below.

Fixnums are also known as INUMs (immediate numbers).  They always have
the value 10 in the two lowest bits.  That is why the test for INUMs
is as follows:

#define SCM_INUMP(x)	(2 & SCM_UNPACK (x))

guile> (bin 0)
"00000000000000000000000000000010"
guile> (bin 1)                                                  
"00000000000000000000000000000110"
guile> (bin -1)
"11111111111111111111111111111110"
guile> (bin 343434)
"00000000000101001111011000101010"

31            24|23           16|15            8|7             0
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |1|0|
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `---------------------------------------------------------' `--'
                           fixnum                          fixnum
                           value                          indicator

*** Characters

Characters are immediates with 100 in bits #2-#0, and 11110 in the
bits #7-#3.  The character code is stored in bits #15-#8 and the rest
of the word is unused.  Switching to Unicode representation could
easily be done by simply using the upper 16 bits for the character
code.

The test for checking for characters tests whether the lowest 8 bits
are equal to the 8-bit character type code, which is 0xf4.

#define SCM_CHARP(x) (SCM_ITAG8(x) == scm_tc8_char)

guile> (bin #\a)
"00000000000000000110000111110100"
guile> (bin #\b)
"00000000000000000110001011110100"
guile> (bin #\nul)
"00000000000000000000000011110100"

31            24|23           16|15            8|7             0
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | |1|1|1|1|0|1|0|0|
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `-----------------------------' `-------------' `-------------'
             unused                 character       character
                                      value         indicator

*** Ilocs

Ilocs are used for specifying lexical variables.  They are substituted
for symbols which happen to be such variables by the evaluator.

The test for checking for ilocs tests whether the lowest 8 bits are
equal to the 8-bit iloc type code, which is 0xfc.

31            24|23           16|15            8|7             0
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | |1|1|1|1|1|1|0|0|
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `---------------------------------------------' `-------------'
        FIXME: check out bit numbers                  iloc
                                                    indicator


*** Special symbols

Special symbols are inserted into cons pairs when the evaluator finds
them.

FIXME: Details.

** Heap objects

Heap objects are thos objects which occupy memory on the Scheme heap.
The SCM values are tagged with three zeros in the lowest bits and the
whole SCM value is to be interpreted as a pointer to a heap cell.
There are two types of heap cells.  The normal cells occupy two words
each, and the double cells occupy four words.

Double cells are used for objects which require more than two words,
but for which malloc()ing another heap block is too expensive, for
example real numbers.

Other bigger objects, strings, vectors and bignums for example, store
information in separate memory regions.


*** Strings

guile> (bin "")
"00001000000001001010000000100000"
guile> (bin (string))
"01000000001010010000000000101000"
guile> (bin (string #\a))
"01000000001010001110010001001000"
guile> (bin "foo")
"01000000001010010100101110110000"

The SCM of a string:

31            24|23           16|15            8|7             0
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |0|0|0|
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `-------------------------------------------------------------'
                   pointer into cell heap

The cell layout for strings:

31            24|23           16|15            8|7             0
                 string length                    string type code
 .---------------------------------------------.   .-----------.
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | |0|0|1|0|1|0|1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `-------------------------------------------------------------'
                  pointer to malloc()ed region


*** Symbols

Symbols are represented similarly to strings, but they occupy double
cells.  The third word stores the hash value of the symbol name, and
the fourth word is the head of a property list.  The CAR of this list
holds the symbol's function slot (only used for emulating other Lisp
dialects) and the CDR an association list of the symbol's properties.

The SCM of a symbol:

31            24|23           16|15            8|7             0
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |0|0|0|
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `-------------------------------------------------------------'
                   pointer into cell heap

The double cell layout for symbols:

31            24|23           16|15            8|7             0
                 symbol length                    symbol type code
 .---------------------------------------------.   .-----------.
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | |0|0|0|0|1|0|1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 `-------------------------------------------------------------'
.                 pointer to malloc()ed region                  .
.                                                               .
.             symbol's hash value as a raw integer              .
 .-------------------------------------------------------------.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `-------------------------------------------------------------'
                           property list


*** Vectors

Vectors (normal and weak vectors) are represented similar to strings.
The 7-bit type codes are 13 (normal vectors) and 15 (weak vectors).

The SCM of a vector:

31            24|23           16|15            8|7             0
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |0|0|0|
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `-------------------------------------------------------------'
                   pointer into cell heap

The cell layout for vectors:

31            24|23           16|15            8|7             0
                 vector length                    vector type code
 .---------------------------------------------.   .-----------.
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | |0|0|0|1|1|0|1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `-------------------------------------------------------------'
                  pointer to malloc()ed region


There are several types of weak vectors.  The exact type (weak vector,
weak hash table, value/key/both) is encoded in the malloc()ed memory
block, by allocating the vector one element bigger, and then pointing
to the second element.  The type is then stored one word before the
vector contents (FIXME: how is it represented?)

The cell layout for weak vectors:

31            24|23           16|15            8|7             0
                 vector length                 weak vector type code
 .---------------------------------------------.   .-----------.
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
| | | | | | | | | | | | | | | | | | | | | | | | | |0|0|0|1|1|1|1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `-------------------------------------------------------------'
                  pointer to malloc()ed region

*** Real numbers

Real numbers are stored in double cells.  In the first word of the
cell, the type code for smobs is stored in the 8 lowest bits.  Numbers
(reals, complex numbers and bignums) are special smobs, because they
occupy the first three smob codes.  This makes it efficient to test
whether a pointer into a heap points to a number.

31            24|23           16|15            8|7             0
                                             real smob type code
                                             .-. .-------------.
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|1|1|1|1|1|1|1|1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 `-------------------------------------------------------------'
.                             empty                             .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
`-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-'
 `-------------------------------------------------------------'
                      real number as a C double

*** Bignums

31            24|23           16|15            8|7             0
                                           bignum smob type code
                                             .-. .-------------.
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|1|1|1|1|1|1|1|1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 `-------------------------------------------------------------'
                     pointer to digit memory

*** Complex numbers

31            24|23           16|15            8|7             0
                                          complex smob type code
                                             .-. .-------------.
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|1|1|1|1|1|1|1|1|1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 `-------------------------------------------------------------'
                     pointer to `struct complex'

*** Smobs

Smobs (abbreviation for ``small objects'') are used for adding data
types to Guile dynamically.  An extension library can request a new
smob type code dynamically and can then create smobs of this type,
passing these values around like all builtin types.  The Guile library
can determine all necessary information from the smob number stored in
each smob.  For example the procedures for marking used smobs and
finalizing them can be retrieved from the smob table using this
number.

31            24|23           16|15            8|7             0
                                   smob number    smob type code
                                 .-------------. .-------------.
.-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-.
|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0| | | | | | | | |1|1|1|1|1|1|1|1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 `-------------------------------------------------------------'
                    dependant on the smob type


============================================================

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: fyi, a reading of guile source
  2002-05-16  7:49 ` fyi, a reading of guile source Martin Grabmueller
@ 2002-05-17  4:23   ` Thien-Thi Nguyen
  2002-05-18 13:47   ` Neil Jerram
       [not found]   ` <m3lmahzhxw.fsf@laruns.ossau.uklinux.net>
  2 siblings, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2002-05-17  4:23 UTC (permalink / raw)
  Cc: owinebar, guile-user

   From: Martin Grabmueller <mg@glug.org>
   Date: Thu, 16 May 2002 09:49:48 +0200

   For those interested in this: some time ago (when I was trying to
   understand this code myself), I wrote down some notes on the data
   representation in Guile.  I have appended them, but can't guarantee
   whether they are still correct, but I guarantee that they are
   incomplete.

thanks for the notes -- very fine!  now in $w/journal/mgrabmue.notes.

see below for preliminary bit-field-diagram.  i'm sure a little string
slinging here and there and it could generate those sweet drawings.

in the end we want to embed such bf-descriptions as comments in the
source, and emacs will generate demos on the fly.  see Project ADHOC for
some front-end work.

(ahh, demos...)

thi


____________________________________
#!/bin/sh
# aside from this initial boilerplate, this is actually -*- scheme -*- code
main='(module-ref (resolve-module '\''(scripts bit-field-diagram)) '\'main')'
exec ${GUILE-guile} -l $0 -c "(apply $main (cdr (command-line)))" "$@"
!#
;;; bit-field-diagram --- Display bit-field diagrams in different ways

;; 	Copyright (C) 2002 Free Software Foundation, Inc.
;;
;; This program 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 2, or
;; (at your option) any later version.
;;
;; This program 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 software; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
;; Boston, MA 02111-1307 USA

;;; Author: Thien-Thi Nguyen <ttn@gnu.org>

;;; Commentary:

;; Usage: bit-field-diagram [ARGS]
;;
;; bit-field-diagram does something.
;;
;; TODO: Write it!

;;; Code:

(define-module (scripts bit-field-diagram)
  :use-module (ice-9 format)
  :export (bit-field-diagram))

(define name  car)
(define width cdr)

(define (bf-description<-string s)      ; alist ((NAME . WIDTH) ...)
  (with-input-from-string s
    (lambda () (read))))

(define (bit-field-diagram . args)
  (let ((bf-description (bf-description<-string (car args))))
    (format #t ",,|~:{~V@A|~},,\n"
            (map (lambda (pair)
                   (list (* 2 (width pair)) (name pair)))
                 bf-description))))

(define (zmain . args)
  (bit-field-diagram "((hello . 15) (there . 37))")
  #t)

(define main bit-field-diagram)

;;; bit-field-diagram ends here

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: fyi, a reading of guile source
  2002-05-16  7:49 ` fyi, a reading of guile source Martin Grabmueller
  2002-05-17  4:23   ` Thien-Thi Nguyen
@ 2002-05-18 13:47   ` Neil Jerram
       [not found]   ` <m3lmahzhxw.fsf@laruns.ossau.uklinux.net>
  2 siblings, 0 replies; 5+ messages in thread
From: Neil Jerram @ 2002-05-18 13:47 UTC (permalink / raw)
  Cc: owinebar, guile-devel, guile-user

>>>>> "Martin" == Martin Grabmueller <mg@glug.org> writes:

    Martin> For those interested in this: some time ago (when I was trying to
    Martin> understand this code myself), I wrote down some notes on the data
    Martin> representation in Guile.  I have appended them, but can't guarantee
    Martin> whether they are still correct, but I guarantee that they are
    Martin> incomplete. [...]

Thanks!  I found this very clear and informative.  One correction: in
the bitmap for real numbers, smob number should be 1, not 2.

        Neil


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: fyi, a reading of guile source
       [not found]   ` <m3lmahzhxw.fsf@laruns.ossau.uklinux.net>
@ 2002-05-19  4:00     ` Thien-Thi Nguyen
  0 siblings, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2002-05-19  4:00 UTC (permalink / raw)
  Cc: owinebar, guile-devel, guile-user

   From: Neil Jerram <neil@ossau.uklinux.net>
   Date: 18 May 2002 14:47:23 +0100

   Thanks!  I found this very clear and informative.  One correction: in
   the bitmap for real numbers, smob number should be 1, not 2.

why not munge $w/journal/mgrabmue.notes directly (you both have write
privs)?

thi

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-05-19  4:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <02051521435901.26010@locke.free-expression.org>
2002-05-16  7:49 ` fyi, a reading of guile source Martin Grabmueller
2002-05-17  4:23   ` Thien-Thi Nguyen
2002-05-18 13:47   ` Neil Jerram
     [not found]   ` <m3lmahzhxw.fsf@laruns.ossau.uklinux.net>
2002-05-19  4:00     ` Thien-Thi Nguyen
2002-05-16  0:01 Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).