aboutsummaryrefslogtreecommitdiff
path: root/guile/pdp_guile.c
blob: 34ca8da13fc11ea46bd493ac58edda0f783c78d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
/*
 *   Pure Data Packet module: Guile Interpreter for pd/pdp
 *   Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
 *
 *   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 of the License, 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 program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */


#include <pthread.h>
#include <libguile.h>
#include <stdio.h>
#include "pdp.h"
#include "pdp_forth.h"

#define D if(0)



/* communication stuff */

static t_class *guile_class;

pthread_mutex_t guile_mux;

t_pdp_list *guile_inlist;
t_pdp_list *guile_outlist;
t_clock *guile_clock;
t_float guile_clock_deltime;


/* GUILE GLUE CODE */

static scm_t_bits pdp_tag;

typedef struct _pdp_scm_wrapper
{
    int packet;
    SCM update_func;
    //char dummy[1000000];
} t_pdp_scm_wrapper;


/* list (comm queue) utility stuff */

static void guile_list_send(t_pdp_list *list, t_pdp_symbol *tag, t_pdp_word_type type, t_pdp_word word)
{
	pthread_mutex_lock(&guile_mux);
	pdp_list_add_back(list, a_symbol, (t_pdp_word)tag);
	pdp_list_add_back(list, type, word);
	pthread_mutex_unlock(&guile_mux);
}

static int guile_list_receive(t_pdp_list *list, t_pdp_symbol **tag, t_pdp_word_type *type, t_pdp_word *word)
{
    int success = 0;
    if (pdp_list_size(list)){
	pthread_mutex_lock(&guile_mux);
	*tag = pdp_list_pop(list).w_symbol;
	*type = list->first->t;
	*word = pdp_list_pop(list);
	pthread_mutex_unlock(&guile_mux);
	success = 1;
    }
    return success;

}

/* pdp list <-> scm list conversion */

/* any packets contained in the pdp list are copied ro */

static SCM pdp_to_scm (t_pdp_list *l) 
{
  SCM pair = SCM_EOL; //temporary pair
  SCM thing; //thing to add to the list
  t_pdp_list *cl = pdp_list_copy_reverse(l); //make a reverse copy of the list
  t_pdp_atom *a;
  t_pdp_scm_wrapper *pg;

  for(a=cl->first;a;a=a->next){

    // convert the atom to a lisp scalar
    switch (a->t){
    case a_list:
      thing = pdp_to_scm(a->w.w_list); break;
    case a_int:
      thing = SCM_MAKINUM(a->w.w_int); break;
    case a_symbol:
      thing = scm_str2symbol(a->w.w_symbol->s_name); break;
    case a_float:
      thing = scm_make_real (a->w.w_float); break;
    case a_packet:
      //post("ATTENTION: pdp_to_scm copies packets");
	pg = (t_pdp_scm_wrapper *) scm_must_malloc (sizeof (t_pdp_scm_wrapper), "pdp");
	pg->packet = pdp_packet_copy_ro(a->w.w_packet);
	pg->update_func = SCM_BOOL_F;
	SCM_NEWSMOB (thing, pdp_tag, pg);
	break;
    default:
      thing = scm_str2symbol("undef"); break;
    }

    // add the atom to the list
    pair = scm_cons(thing, pair); // add thing
    
  }

  // 

  // return the list
  return pair;
}

/* any packets contained in the list are copied ro */
static t_pdp_list *scm_to_pdp (SCM pair) 
{
  t_pdp_list *l = pdp_list_new(0);
  SCM rest = pair;
  SCM head;
  while (1){
    if (!SCM_CONSP(rest)){
      head = rest;
      rest = SCM_EOL;
    }
    else {
      head = SCM_CAR(rest);
      rest = SCM_CDR(rest);
    }
    if (SCM_NULLP(head)) break;
   
    else if (SCM_CONSP(head)){
      pdp_list_add_back(l, a_list, (t_pdp_word)scm_to_pdp(head));
    }
    else if (SCM_SMOB_PREDICATE(pdp_tag, head)){
	t_pdp_scm_wrapper *pg = (t_pdp_scm_wrapper *) SCM_SMOB_DATA (head);
	//post("ATTENTION: scm_to_pdp copies packets");
	pdp_list_add_back(l, a_packet, 
			  (t_pdp_word)(pdp_packet_copy_ro(pg->packet)));
    }
    else if (SCM_INUMP(head)){
	int i = SCM_INUM(head);
	pdp_list_add_back(l, a_int, (t_pdp_word)i);
    }
    else if (SCM_REALP(head)){
	float f = (float)SCM_REAL_VALUE(head);
	pdp_list_add_back(l, a_float, (t_pdp_word)f);
    }
    else if (SCM_SYMBOLP(head)){
      pdp_list_add_back(l, a_symbol, 
			(t_pdp_word)pdp_gensym(SCM_SYMBOL_CHARS(head)));
    }
    else {
      pdp_list_add_back(l, a_undef, (t_pdp_word)0);
    }
  }
  return l;
}




/* smob callbacks */

static SCM mark_pdp (SCM pdp_smob)
{
    /* Mark the image's name and update function.  */
    t_pdp_scm_wrapper *pg = (t_pdp_scm_wrapper *) SCM_SMOB_DATA (pdp_smob);
    scm_gc_mark (pg->update_func);
    D post("mark_pdp called");
    return SCM_BOOL_F;
}

static size_t free_pdp (SCM pdp_smob)
{
    t_pdp_scm_wrapper *pg = (t_pdp_scm_wrapper *) SCM_SMOB_DATA (pdp_smob);
    pdp_packet_mark_unused(pg->packet);
    scm_must_free(pg);
    D post("free_pdp called");
    return sizeof(t_pdp_scm_wrapper);
}


static int
print_pdp (SCM pdp_smob, SCM port, scm_print_state *pstate)
{
    t_pdp_scm_wrapper *pg = (t_pdp_scm_wrapper *) SCM_SMOB_DATA (pdp_smob);
    char tmp[1000];
    t_pdp *h = pdp_packet_header(pg->packet);
    tmp[999] = 0;
    snprintf(tmp, 999, "#<pdp %d %s>", pg->packet, 
	    h && h->desc ? h->desc->s_name : "unknown");
    scm_puts(tmp, port);
    D post ("print_pdp called");
    return 1;
}


/* extension functions */


static SCM
forth_pdp (SCM stack, SCM program)
{
    t_pdp_word_error e;
    t_pdp_list *s = scm_to_pdp (stack);
    t_pdp_list *p = scm_to_pdp (program);
    e = pdp_forth_execute_def(s, p);
    stack = pdp_to_scm(s);

    if (e){
	post("ERROR: program evaluation aborted with error %d.", e);
    }
    pdp_tree_strip_packets(s);
    pdp_tree_strip_packets(p);
    
    return stack;
    
}

static SCM
define_forth_word_pdp (SCM word, SCM in, SCM out, SCM program)
{
    t_pdp_word_error e;
    t_pdp_list *p;
    t_pdp_symbol *s;
    SCM_ASSERT (SCM_SYMBOLP(word), word, SCM_ARG1, "define-forth-word");
    SCM_ASSERT (SCM_INUMP(in), word, SCM_ARG2, "define-forth-word");
    SCM_ASSERT (SCM_INUMP(out), word, SCM_ARG3, "define-forth-word");
    p = scm_to_pdp (program);
    s = pdp_gensym(SCM_SYMBOL_CHARS(word));
    pdp_forthdict_add_word(s, p, SCM_INUM(in), SCM_INUM(out), -1, 0); 
    
    return SCM_UNSPECIFIED;
    
}


static SCM
unmark_pdp (SCM pdp_smob)
{
    t_pdp_scm_wrapper *pg;
    SCM_ASSERT (SCM_SMOB_PREDICATE (pdp_tag, pdp_smob),
		pdp_smob, SCM_ARG1, "mark-unused");
    pg = (t_pdp_scm_wrapper *) SCM_SMOB_DATA (pdp_smob);
    pdp_packet_mark_unused(pg->packet);
    pg->packet = -1;
    return SCM_UNSPECIFIED;
}




static SCM
is_writable_pdp (SCM pdp_smob)
{
    t_pdp_scm_wrapper *pg;
    SCM_ASSERT (SCM_SMOB_PREDICATE (pdp_tag, pdp_smob),
		pdp_smob, SCM_ARG1, "writable?");
    pg = (t_pdp_scm_wrapper *) SCM_SMOB_DATA (pdp_smob);
    if (pdp_packet_writable(pg->packet)) return SCM_BOOL_T;
    else return SCM_BOOL_F;
    return SCM_UNSPECIFIED;
}

static SCM
make_pdp (SCM type)
{
    int p;
    t_pdp_scm_wrapper *pg;
    char *t;

    /* construct with type */
    if (SCM_SYMBOLP(type)){
      t = SCM_SYMBOL_CHARS(type);
      p =  pdp_factory_newpacket(pdp_gensym(t));
    }
    /* copy construct from packet id */
    else if (SCM_INUMP(type)){
      int i = SCM_INUM(type);
      p = pdp_packet_copy_ro(i);
    }
    else {
      SCM_ASSERT (0,  type,  SCM_ARG1, "make-pdp");
    }

    /* check if valid packet */
    SCM_ASSERT (p != -1,  type,  SCM_ARG1, "make-pdp");

    /* build smob */
    pg = (t_pdp_scm_wrapper *) scm_must_malloc (sizeof (t_pdp_scm_wrapper), "pdp");
    pg->packet = p;
    pg->update_func = SCM_BOOL_F;
    SCM_RETURN_NEWSMOB (pdp_tag, pg);
}

static SCM
_in (void)
{
    
    t_pdp_scm_wrapper *pg;
    t_pdp_word w;
    t_pdp_symbol *stag;
    t_pdp_word_type type = a_undef;
    int skip = 1;

    SCM tag;
    SCM thing;
    SCM pair;

    D post("receiving pdp packet");

    if (!guile_list_receive(guile_inlist, &stag, &type, &w)) goto exit;
    tag = scm_str2symbol(stag->s_name);

    switch(type){
    case a_packet:
	pg = (t_pdp_scm_wrapper *) scm_must_malloc (sizeof (t_pdp_scm_wrapper), "pdp");
	pg->packet = w.w_packet;
	pg->update_func = SCM_BOOL_F;
	SCM_NEWSMOB (thing, pdp_tag, pg);
	break;
    case a_symbol:
	thing = scm_str2symbol(w.w_symbol->s_name);
	break;
    case a_float:
	thing = scm_make_real (w.w_float);
	break;

    default:
	goto exit;
	
    }
    pair = scm_cons2(tag, thing, SCM_EOL);
    return pair;

	
 exit:
    return SCM_BOOL_F;
}

static SCM
_out (SCM tag, SCM thing)
{
    t_pdp_symbol *stag;
    SCM_ASSERT (SCM_SYMBOLP (tag),  tag,  SCM_ARG1, "out");
    stag = pdp_gensym(SCM_SYMBOL_CHARS(tag));

    if (SCM_SMOB_PREDICATE(pdp_tag, thing)){
	t_pdp_scm_wrapper *pg = (t_pdp_scm_wrapper *) SCM_SMOB_DATA (thing);
	guile_list_send(guile_outlist, stag, a_packet, 
			(t_pdp_word)(pdp_packet_copy_ro(pg->packet)));
    }
    else if (SCM_INUMP(thing)){
	int i = SCM_INUM(thing);
	guile_list_send(guile_outlist, stag, a_int, (t_pdp_word)i);
    }
    else if (SCM_REALP(thing)){
	float f = (float)SCM_REAL_VALUE(thing);
	guile_list_send(guile_outlist, stag, a_float, (t_pdp_word)f);
    }
    else if (SCM_SYMBOLP(thing)){
	char *s = SCM_SYMBOL_CHARS(thing);
	guile_list_send(guile_outlist, stag, a_symbol, (t_pdp_word)(pdp_gensym(s)));
    }
    else if (SCM_CONSP(thing)){
      t_pdp_list *l = scm_to_pdp(thing);
      guile_list_send(guile_outlist, stag, a_list, (t_pdp_word)l);
    }
    else{
	SCM_ASSERT (0,  thing,  SCM_ARG2, "out");
    }

    return SCM_BOOL_T;

}


static SCM
test_pdp (SCM thing)
{
    if (SCM_SMOB_PREDICATE(pdp_tag, thing)) return SCM_BOOL_T;
    else return SCM_BOOL_F;
}
static SCM
printdebugforthword_pdp (SCM thing)
{
    t_pdp_symbol *s;
    t_pdp_atom *a;
    SCM_ASSERT (SCM_SYMBOLP(thing), thing, SCM_ARG1, "pdp-debug-forth-word");
    s = pdp_gensym(SCM_SYMBOL_CHARS(thing));

    pdp_forth_word_print_debug(s);

    return SCM_UNSPECIFIED;
    
}

static SCM
printdebug_pdp (SCM thing)
{
  if (SCM_INUMP(thing)){
    int p = SCM_INUM(thing);
    pdp_packet_print_debug(p);
    return SCM_UNSPECIFIED;
  }

    SCM_ASSERT (SCM_SMOB_PREDICATE(pdp_tag, thing), thing, SCM_ARG1, "pdp-debug-packet");
    pdp_packet_print_debug(((t_pdp_scm_wrapper *) SCM_SMOB_DATA (thing))->packet);
    return SCM_UNSPECIFIED;
    
}
/* the inner main function. when this is called, guile
   is initialized. when this function returns, exit(0)
   is called. */
static void guile_inner_main(void *closure, int argv, char **argc)
{
    /* initialize data types and functions */
    pdp_tag = scm_make_smob_type ("pdp", sizeof(t_pdp_scm_wrapper)); 
    scm_set_smob_free (pdp_tag, free_pdp);
    scm_set_smob_print (pdp_tag, print_pdp);
    scm_set_smob_mark (pdp_tag, mark_pdp);

    /* pdp stuff */
    scm_c_define_gsubr ("make-pdp", 1, 0, 0, make_pdp);
    scm_c_define_gsubr ("writable?", 1, 0, 0, is_writable_pdp);
    scm_c_define_gsubr ("pdp?", 1, 0, 0, test_pdp);

    /* communication */
    scm_c_define_gsubr ("in", 0, 0, 0, _in);
    scm_c_define_gsubr ("out", 2, 0, 0, _out);

    /* pdp forth link */
    scm_c_define_gsubr ("forth", 2, 0, 0, forth_pdp);
    scm_c_define_gsubr ("define-forth-word", 4, 0, 0, define_forth_word_pdp);

    /* debug methods */
    scm_c_define_gsubr ("mark-unused", 1, 0, 0, unmark_pdp);
    scm_c_define_gsubr ("pdp-debug-packet", 1, 0, 0, printdebug_pdp);
    scm_c_define_gsubr ("pdp-debug-forth-word", 1, 0, 0, printdebugforthword_pdp);

    /* start the shell */
    scm_c_eval_string("(set! scm-repl-prompt \"pdp> \")");

    //scm_c_eval_string("(load \"/home/tom/.guile\")");
    //while(1) {
    //post("read evaluate print loop");
    //scm_c_eval_string("(display scm-repl-prompt)(display (eval (read) (current-module)))(newline)");
    //}
    
    scm_shell(0,0);
}


/* the outer main function for booting the guile system
   this is a separate thread */
static void *guile_main(void *x)
{
    scm_boot_guile(0,0,guile_inner_main,0);
    return 0;
}


/* start the thread that boots the guile system */
static void guile_boot_in_thread(void)
{
    pthread_t thread;
    pthread_attr_t attr;

    pthread_attr_init(&attr);
    pthread_attr_setschedpolicy(&attr, SCHED_OTHER); 
    pthread_create(&thread, &attr, guile_main, 0);

}


/* some restrictions on the pdp -> pd list conversion:

   -  due to the nature of the pdp protocol in pd (3 phase)
      a packet can not appear in a pd list. it will be sent out
      as a pdp packet to the receiver corresponding to the tag.
      the legal way to send a packet from guile is (out 'tag packet)

   -  pd lists cannot be recursive, so pdp trees will need to be 
      flattened first.
*/
     
/* this sends a (flat pdp list) to a pd receiver 
   the list cannot contain pdp packets */
static void pd_pdplist(void *thing, t_symbol *tag, t_pdp_list *l, int elements){
  t_atom pd_atom[elements];
  int i;
  t_pdp_atom *a = l->first;
  for (i=0; i<elements; i++,a=a->next){
    switch(a->t){
    case a_float:
      SETFLOAT(pd_atom+i, a->w.w_float); break;
    case a_int:
      SETFLOAT(pd_atom+i, (float)a->w.w_int); break;
    case a_pointer:
      SETPOINTER(pd_atom+i, a->w.w_pointer); break;
    case a_symbol:
      SETSYMBOL(pd_atom+i, gensym(a->w.w_symbol->s_name)); break;
    case a_packet:
      post("ERROR: can't put packet %d inside a pd list (not a pd atom)", 
	   a->w.w_packet);
      SETSYMBOL(pd_atom+i, gensym("deadpacket")); break;
    case a_list:
      post("ERROR: can't put a list inside a pd list (not a pd atom):");
      pdp_list_print(a->w.w_list);
      SETSYMBOL(pd_atom+i, gensym("deadlist")); break;
    default:
      SETSYMBOL(pd_atom+i, gensym("undef")); break;
      
    }
  }
  typedmess(thing, tag, elements, pd_atom);


  pdp_tree_strip_packets(l);
  pdp_tree_free(l);
}



static void guile_callback(void *dummy)
{
    int skip = 1;
    t_pdp_symbol *s = 0;
    t_pdp_word_type type = a_undef;
    t_pdp_word w;
    t_atom atom[3];
    void *thing;

    t_symbol *tag_sym;

    if (!guile_list_receive(guile_outlist, &s, &type, &w)) goto exit;

    tag_sym = gensym(s->s_name);
    thing = tag_sym->s_thing;

    //post("got something from guile");

    if (!thing) goto exit;



    /* send to outlet */
    switch(type){
    case a_packet:
	SETFLOAT(atom+1, (float)w.w_packet);
	SETSYMBOL(atom+0, pdp_sym_rro());
	typedmess(thing, pdp_sym_pdp(), 2, atom);
	SETSYMBOL(atom+0, pdp_sym_rrw());
	typedmess(thing, pdp_sym_pdp(), 2, atom);
	SETSYMBOL(atom+0, pdp_sym_prc());
	typedmess(thing, pdp_sym_pdp(), 2, atom);
	pdp_packet_mark_unused(w.w_packet);
	break;
   
    case a_float:
	pd_float(thing, w.w_float);
	break;
	
    case a_int:
	pd_float(thing, (float)w.w_int);
	break;

    case a_symbol:
	pd_symbol(thing, gensym(w.w_symbol->s_name));
	break;

    case a_list:{
      int elements = w.w_list->elements;
      t_symbol *tag;
      
      if (elements){
	/* if first element is a symbol, we use it to tag the list */
	if (w.w_list->first->t == a_symbol){
	  tag = gensym(w.w_list->first->w.w_symbol->s_name);
	  elements--;
	  pdp_list_pop(w.w_list);
	  pd_pdplist(thing, tag, w.w_list, elements);
	}
	/* else tag it as "list" */
	else {
	  pd_pdplist(thing, gensym("list"), w.w_list, elements);

	}
      }
      else{ //an empty list is a bang
	pd_bang(thing);
      }
      break;
    }

    default:
	break;
    }

 exit:
    clock_delay(guile_clock, guile_clock_deltime);
}



/* PD INTERFACE OBJECT */

t_class *scheme_send_class;

typedef struct _scheme_send
{
    t_object x_obj;
    t_outlet *x_outlet;
    t_pdp_symbol *x_tag;
} t_scheme_send;


static void *scheme_send_new(t_symbol *s)
{
    t_scheme_send *x = 0;
    x = (t_scheme_send *)pd_new(scheme_send_class);

    x->x_tag = (s == gensym("")) ? 
	x->x_tag = pdp_gensym("dummy") : pdp_gensym(s->s_name);

    return (void*)x;
}

static void scheme_send_anything(t_scheme_send *x, t_symbol *s, int argc, t_atom *argv)
{
    void *thing = 0;

    if (s == &s_float && argc == 1 && argv[0].a_type == A_FLOAT){
	guile_list_send(guile_inlist, x->x_tag, a_float, 
			(t_pdp_word)argv[1].a_w.w_float);
    }

    else if (s == &s_symbol && argc == 1 && argv[0].a_type == A_SYMBOL){
	guile_list_send(guile_inlist, x->x_tag, a_symbol, 
			(t_pdp_word)pdp_gensym(argv[0].a_w.w_symbol->s_name));
    }

    else if (argc == 0){
	guile_list_send(guile_inlist, x->x_tag, a_symbol, 
			(t_pdp_word)pdp_gensym(s->s_name));
    }

    else if (s == gensym("pdp") 
	&& argc == 2 
	&& argv[0].a_type == A_SYMBOL 
	&& argv[0].a_w.w_symbol == gensym("register_ro")
	&& argv[1].a_type == A_FLOAT){
	  
	guile_list_send(guile_inlist, x->x_tag, a_packet, 
			(t_pdp_word)pdp_packet_copy_ro((int)argv[1].a_w.w_float));
    }

}




static void scheme_send_free(t_scheme_send *x)
{
}

void pdp_guile_setup(void)
{

    post("PDP: scheme extension");

    /* setup guile interpreter */
    guile_boot_in_thread();

    /* setup communication stuff */
    guile_inlist = pdp_list_new(0);
    guile_outlist = pdp_list_new(0);

    pthread_mutex_init(&guile_mux, NULL);
    guile_clock_deltime = 1.0f;
    guile_clock = clock_new(0, (t_method)guile_callback);
    clock_delay(guile_clock, guile_clock_deltime);



    /* create interface class */
    scheme_send_class = class_new(gensym("ss"), (t_newmethod)scheme_send_new,
   	(t_method)scheme_send_free, sizeof(t_scheme_send), 0, A_DEFSYMBOL, A_NULL);

    class_addanything(scheme_send_class, scheme_send_anything);
}