aboutsummaryrefslogtreecommitdiff
path: root/externals/gridflow/base
diff options
context:
space:
mode:
Diffstat (limited to 'externals/gridflow/base')
-rw-r--r--externals/gridflow/base/bitpacking.c44
-rw-r--r--externals/gridflow/base/flow_objects.c32
-rw-r--r--externals/gridflow/base/flow_objects.rb219
-rw-r--r--externals/gridflow/base/flow_objects_for_image.c7
-rw-r--r--externals/gridflow/base/flow_objects_for_matrix.c2
-rw-r--r--externals/gridflow/base/grid.c38
-rw-r--r--externals/gridflow/base/grid.h341
-rw-r--r--externals/gridflow/base/main.c11
-rw-r--r--externals/gridflow/base/main.rb21
-rw-r--r--externals/gridflow/base/number.c201
-rw-r--r--externals/gridflow/base/source_filter.rb24
-rw-r--r--externals/gridflow/base/test.rb554
12 files changed, 775 insertions, 719 deletions
diff --git a/externals/gridflow/base/bitpacking.c b/externals/gridflow/base/bitpacking.c
index 143f6edb..cb09a812 100644
--- a/externals/gridflow/base/bitpacking.c
+++ b/externals/gridflow/base/bitpacking.c
@@ -1,5 +1,5 @@
/*
- $Id: bitpacking.c,v 1.1 2005-10-04 02:02:13 matju Exp $
+ $Id: bitpacking.c,v 1.2 2006-03-15 04:37:06 matju Exp $
GridFlow
Copyright (c) 2001,2002,2003,2004 by Mathieu Bouchard
@@ -26,18 +26,18 @@
#include <stdlib.h>
#include <stdio.h>
+//#define CONVERT0(z) (((in[z] << hb[z]) >> 7) & mask[z])
+#define CONVERT0(z) ((in[z] >> chop[z]) << slide[z])
+
#define CONVERT1 t = \
- (((in[0] << hb[0]) >> 7) & mask[0]) | \
- (((in[1] << hb[1]) >> 7) & mask[1]) | \
- (((in[2] << hb[2]) >> 7) & mask[2])
+ CONVERT0(0) | CONVERT0(1) | CONVERT0(2)
#define CONVERT2 \
- for (t=0,i=0; i<self->size; i++) t |= (((in[i] << hb[i]) >> 7) & mask[i]);
+ for (t=0,i=0; i<self->size; i++) t |= CONVERT0(i);
#define CONVERT3 \
- for (t=0,i=0; i<self->size; i++) { \
- t |= ((in[i]>>(7-hb[i]))|(in[i]<<(hb[i]-7))) & mask[i]; \
- }
+ for (t=0,i=0; i<self->size; i++) \
+ t |= (((unsigned)in[i]>>(7-hb[i]))|(in[i]<<(hb[i]-7))) & mask[i];
#define WRITE_LE \
for (int bytes = self->bytes; bytes; bytes--, t>>=8) *out++ = t;
@@ -74,29 +74,29 @@ template <class T>
static void default_pack(BitPacking *self, int n, Pt<T> in, Pt<uint8> out) {
uint32 t;
int i;
- int hb[4];
- uint32 mask[4];
int sameorder = self->endian==2 || self->endian==::is_le();
int size = self->size;
-
- for (i=0; i<self->size; i++) hb[i] = highest_bit(self->mask[i]);
- memcpy(mask,self->mask,size*sizeof(uint32));
-
+ uint32 mask[4]; memcpy(mask,self->mask,size*sizeof(uint32));
+ uint32 hb[4]; for (i=0; i<size; i++) hb[i] = highest_bit(mask[i]);
+ uint32 span[4]; for (i=0; i<size; i++) span[i] = hb[i] - lowest_bit(mask[i]);
+ uint32 chop[4]; for (i=0; i<size; i++) chop[i] = 7-span[i];
+ uint32 slide[4]; for (i=0; i<size; i++) slide[i] = hb[i]-span[i];
+
if (sameorder && size==3) {
switch(self->bytes) {
- case 2: NTIMES(t=CONVERT1; *((int16 *)out)=t; out+=2; in+=3;) return;
- case 4: NTIMES(t=CONVERT1; *((int32 *)out)=t; out+=4; in+=3;) return;
+ case 2: NTIMES(CONVERT1; *((int16 *)out)=t; out+=2; in+=3;) return;
+ case 4: NTIMES(CONVERT1; *((int32 *)out)=t; out+=4; in+=3;) return;
}
}
if (self->is_le()) {
switch (size) {
case 3: for (; n--; in+=3) {CONVERT1; WRITE_LE;} break;
- case 4: for (; n--; in+=4) {CONVERT3; WRITE_LE;} break;
+ case 4: for (; n--; in+=4) {CONVERT1; WRITE_LE;} break;
default:for (; n--; in+=size) {CONVERT2; WRITE_LE;}}
} else {
switch (size) {
case 3: for (; n--; in+=3) {CONVERT1; WRITE_BE;} break;
- case 4: for (; n--; in+=4) {CONVERT3; WRITE_BE;} break;
+ case 4: for (; n--; in+=4) {CONVERT1; WRITE_BE;} break;
default:for (; n--; in+=size) {CONVERT2; WRITE_BE;}}
}
}
@@ -132,8 +132,11 @@ template <class T>
static void pack2_565(BitPacking *self, int n, Pt<T> in, Pt<uint8> out) {
const int hb[3] = {15,10,4};
const uint32 mask[3] = {0x0000f800,0x000007e0,0x0000001f};
+ uint32 span[3] = {4,5,4};
+ uint32 chop[3] = {3,2,3};
+ uint32 slide[3] = {11,5,0};
uint32 t;
- NTIMES( t=CONVERT1; *((short *)out)=t; out+=2; in+=3; )
+ NTIMES(CONVERT1; *((short *)out)=t; out+=2; in+=3;)
}
template <class T>
@@ -187,7 +190,8 @@ static void pack3_888b(BitPacking *self, int n, Pt<T> in, Pt<uint8> out) {
NTIMES( o32[0] = (in[0]<<16) | (in[1]<<8) | in[2]; o32++; in+=3; )
}
-/* (R,G,B,?) -> B:8,G:8,R:8,0:8 */
+// (R,G,B,?) -> B:8,G:8,R:8,0:8
+// fishy
template <class T>
static void pack3_bgrn8888(BitPacking *self, int n, Pt<T> in, Pt<uint8> out) {
/* NTIMES( out[2]=in[0]; out[1]=in[1]; out[0]=in[2]; out+=4; in+=4; ) */
diff --git a/externals/gridflow/base/flow_objects.c b/externals/gridflow/base/flow_objects.c
index ac3305d6..f971553d 100644
--- a/externals/gridflow/base/flow_objects.c
+++ b/externals/gridflow/base/flow_objects.c
@@ -1,8 +1,8 @@
/*
- $Id: flow_objects.c,v 1.1 2005-10-04 02:02:13 matju Exp $
+ $Id: flow_objects.c,v 1.2 2006-03-15 04:37:08 matju Exp $
GridFlow
- Copyright (c) 2001,2002,2003,2004 by Mathieu Bouchard
+ Copyright (c) 2001,2002,2003,2004,2005 by Mathieu Bouchard
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -158,6 +158,7 @@ static Ruby INTORFLOAT2NUM(T value) {return INT2NUM(value);}
static Ruby INTORFLOAT2NUM(int64 value) {return gf_ll2num(value);}
static Ruby INTORFLOAT2NUM(float32 value) {return rb_float_new(value);}
static Ruby INTORFLOAT2NUM(float64 value) {return rb_float_new(value);}
+static Ruby INTORFLOAT2NUM(ruby value) {return value.r;}
GRID_INLET(GridExport,0) {
} GRID_FLOW {
@@ -213,9 +214,9 @@ struct GridStore : GridObject {
PtrGrid r; // can't be \attr
PtrGrid put_at; // can't be //\attr
\attr Numop *op;
- int32 wdex [Dim::MAX_DIMENSIONS]; // temporary buffer, copy of put_at
- int32 fromb[Dim::MAX_DIMENSIONS];
- int32 to2 [Dim::MAX_DIMENSIONS];
+ int32 wdex [Dim::MAX_DIM]; // temporary buffer, copy of put_at
+ int32 fromb[Dim::MAX_DIM];
+ int32 to2 [Dim::MAX_DIM];
int lsd; // lsd = Last Same Dimension (for put_at)
int d; // goes with wdex
\decl void initialize (Grid *r=0);
@@ -258,7 +259,7 @@ GRID_INLET(GridStore,0) {
int na = in->dim->n;
int nb = r->dim->n;
int nc = in->dim->get(na-1);
- STACK_ARRAY(int32,v,Dim::MAX_DIMENSIONS);
+ STACK_ARRAY(int32,v,Dim::MAX_DIM);
if (na<1) RAISE("must have at least 1 dimension.",na,1,1+nb);
int lastindexable = r->dim->prod()/r->dim->prod(nc) - 1;
int ngreatest = nt_greatest((T *)0);
@@ -413,6 +414,8 @@ GRID_INLET(GridOp,0) {
SAME_TYPE(in,r);
out=new GridOutlet(this,0,in->dim,in->nt);
in->set_mode(6);
+} GRID_ALLOC {
+ //out->ask(in->allocn,(Pt<T> &)in->alloc,in->allocfactor,in->allocmin,in->allocmax);
} GRID_FLOW {
Pt<T> rdata = (Pt<T>)*r;
int loop = r->dim->prod();
@@ -787,7 +790,7 @@ void GridFor::trigger (T bogus) {
if (!from->dim->equal(to->dim) || !to->dim->equal(step->dim))
RAISE("dimension mismatch");
#define FOO(T) trigger((T)0);
- TYPESWITCH_NOFLOAT(from->nt,FOO,);
+ TYPESWITCH_JUSTINT(from->nt,FOO,);
#undef FOO
}
@@ -1048,7 +1051,8 @@ GRID_INLET(GridTranspose,0) {
} GRID_FLOW {
STACK_ARRAY(T,res,na*nb*nc*nd);
if (dim1==dim2) { out->send(n,data); return; }
- for (; n; n-=na*nb*nc*nd, data+=na*nb*nc*nd) {
+ int prod = na*nb*nc*nd;
+ for (; n; n-=prod, data+=prod) {
for (int a=0; a<na; a++)
for (int b=0; b<nb; b++)
for (int c=0; c<nc; c++)
@@ -1107,14 +1111,14 @@ GRID_INLET(GridReverse,0) {
\end class GridReverse
//****************************************************************
-\class GridCentroid2 < GridObject
-struct GridCentroid2 : GridObject {
+\class GridCentroid < GridObject
+struct GridCentroid : GridObject {
\decl void initialize ();
\grin 0 int
int sumx,sumy,sum,y; // temporaries
};
-GRID_INLET(GridCentroid2,0) {
+GRID_INLET(GridCentroid,0) {
if (in->dim->n != 3) RAISE("expecting 3 dims");
if (in->dim->v[2] != 1) RAISE("expecting 1 channel");
in->set_factor(in->dim->prod(1));
@@ -1137,14 +1141,16 @@ GRID_INLET(GridCentroid2,0) {
blah[0] = sum ? sumy/sum : 0;
blah[1] = sum ? sumx/sum : 0;
out->send(2,blah);
+ rb_funcall(rself,SI(send_out),2,INT2NUM(1),INT2NUM(blah[0]));
+ rb_funcall(rself,SI(send_out),2,INT2NUM(2),INT2NUM(blah[1]));
} GRID_END
\def void initialize () {
rb_call_super(argc,argv);
}
-\classinfo { IEVAL(rself,"install '#centroid2',1,1"); }
-\end class GridCentroid2
+\classinfo { IEVAL(rself,"install '#centroid',1,3"); }
+\end class GridCentroid
//****************************************************************
\class GridPerspective < GridObject
diff --git a/externals/gridflow/base/flow_objects.rb b/externals/gridflow/base/flow_objects.rb
index 6ea06c56..8782ae21 100644
--- a/externals/gridflow/base/flow_objects.rb
+++ b/externals/gridflow/base/flow_objects.rb
@@ -1,8 +1,8 @@
=begin
- $Id: flow_objects.rb,v 1.1 2005-10-04 02:02:13 matju Exp $
+ $Id: flow_objects.rb,v 1.2 2006-03-15 04:37:28 matju Exp $
GridFlow
- Copyright (c) 2001,2002,2003,2004 by Mathieu Bouchard
+ Copyright (c) 2001,2002,2003,2004,2005 by Mathieu Bouchard
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -70,7 +70,7 @@ FObject.subclass("gridflow",1,1) {
def _0_formats
post "-"*32
GridFlow.fclasses.each {|k,v|
- next if not /#in:/ =~ k
+ next if not /#io:/ =~ k
modes = case v.flags
when 2; "#out"
when 4; "#in"
@@ -265,7 +265,7 @@ GridPack =
GridObject.subclass("#pack",1,1) {
install_rgrid 0
class<<self;attr_reader :ninlets;end
- def initialize(n=nil,cast=:int32)
+ def initialize(n=2,cast=:int32)
n||=self.class.ninlets
n>=16 and raise "too many inlets"
super
@@ -298,13 +298,13 @@ GridObject.subclass("#pack",1,1) {
# the install_rgrids in the following are hacks so that
# outlets can work. (install_rgrid is supposed to be for receiving)
# maybe GF-0.8 doesn't need that.
-GridPack.subclass("@two", 2,1) { install_rgrid 0 }
-GridPack.subclass("@three",3,1) { install_rgrid 0 }
-GridPack.subclass("@four", 4,1) { install_rgrid 0 }
-GridPack.subclass("@eight",8,1) { install_rgrid 0 }
+GridPack.subclass("@two", 2,1) { install_rgrid 0; def initialize() super 2 end }
+GridPack.subclass("@three",3,1) { install_rgrid 0; def initialize() super 2 end }
+GridPack.subclass("@four", 4,1) { install_rgrid 0; def initialize() super 2 end }
+GridPack.subclass("@eight",8,1) { install_rgrid 0; def initialize() super 2 end }
GridObject.subclass("#unpack",1,0) {
install_rgrid 0, true
- def initialize(n)
+ def initialize(n=2)
@n=n
n>=10 and raise "too many outlets"
super
@@ -338,8 +338,9 @@ GridObject.subclass("unix_time",1,3) {
tt = t.to_s
send_out_grid_begin 0, [tt.length], :uint8
send_out_grid_flow 0, tt, :uint8
- send_out 1, t.to_i
- send_out 2, t.to_f-t.to_f.floor
+ send_out 1, t.to_i/86400, t.to_i%86400,
+ ((t.to_f-t.to_f.floor)*1000000).to_i
+ send_out 2, t.year, t.month, t.day, t.hour, t.min, t.day
end
}
### test with "shell xlogo &" -> [exec]
@@ -352,6 +353,7 @@ FObject.subclass("renamefile",1,0) {
}
FObject.subclass("ls",1,1) {
def _0_symbol(s) send_out 0, :list, *Dir.new(s.to_s).map {|x| x.intern } end
+ def _0_glob (s) send_out 0, :list, *Dir[ s.to_s].map {|x| x.intern } end
}
#-------- fClasses for: math
@@ -420,36 +422,32 @@ FPatcher.subclass("@scale_to",2,1) {
}
#<vektor> told me to:
-# RGBtoYUV : @fobjects = ["#inner ( 3 3 # 66 -38 112 128 -74 -94 25 112 -18 )",
+# RGBtoYUV : @fobjects = ["#inner (3 3 # 66 -38 112 128 -74 -94 25 112 -18)",
# "@ >> 8","@ + {16 128 128}"]
-# YUVtoRGB : @fobjects = ["@ - ( 16 128 128 )",
-# "#inner ( 3 3 # 298 298 298 0 -100 516 409 -208 0 )","@ >> 8"]
+# YUVtoRGB : @fobjects = ["@ - (16 128 128)",
+# "#inner (3 3 # 298 298 298 0 -100 516 409 -208 0)","@ >> 8"]
FPatcher.subclass("#rotate",2,1) {
- @fobjects = ["@inner * + 0","@ >> 8"]
+ @fobjects = ["#inner","# >> 8"]
@wires = [-1,0,0,0, 0,0,1,0, 1,0,-1,0]
def update_rotator
- rotator = (0...@axis[2]).map {|i|
- (0...@axis[2]).map {|j|
- if i==j then 256 else 0 end
- }
- }
+ n = @axis[2]
+ rotator = (0...n).map {|i| (0...n).map {|j| if i==j then 256 else 0 end }}
th = @angle * Math::PI / 18000
scale = 1<<8
- (0...2).each {|i|
- (0...2).each {|j|
- rotator[@axis[i]][@axis[j]] =
- (scale*Math.cos(th+(j-i)*Math::PI/2)).to_i
- }
- }
- @fobjects[0].send_in 2,
- @axis[2], @axis[2], "#".intern, *rotator.flatten
+ (0...2).each {|i| (0...2).each {|j|
+ a = @axis[i].to_i
+ b = @axis[j].to_i
+ #GridFlow.post "(#{a},#{b}) #{rotator[a].inspect}"
+ rotator[a][b] = (scale*Math.cos(th+(j-i)*Math::PI/2)).to_i
+ }}
+ @fobjects[0].send_in 1,n,n,"#".intern,*rotator.flatten
end
def _0_axis(from,to,total)
total>=0 or raise "total-axis number incorrect"
from>=0 and from<total or raise "from-axis number incorrect"
to >=0 and to <total or raise "to-axis number incorrect"
- @axis = [from,to,total]
+ @axis = [from.to_i,to.to_i,total.to_i]
update_rotator
end
def initialize(rot=0,axis=[0,1,2])
@@ -644,7 +642,7 @@ class PDNetSocket < FObject
@socket.bind nil, port
end
when :tcp
- if host=="-" then
+ if host=="-" then
@server = TCPServer.new("localhost",port)
else
@socket = TCPSocket.new(host,port)
@@ -722,7 +720,7 @@ PDNetSocket.subclass("pd_netreceive",0,2) {
# bogus class for representing objects that have no recognized class.
FObject.subclass("broken",0,0) {
- def args; a=@args.dup; a[7,0] = " "+classname; a end
+ def args; a=@args.dup; a[7,0] = " "+classname; a end
}
FObject.subclass("fork",1,2) {
@@ -892,6 +890,21 @@ FObject.subclass("range",1,1) {
post "setting a[#{m[1].to_i-1}] = #{a[0]}"
end
}
+FObject.subclass("listfind",2,1) {
+ def initialize(*a) _1_list(*a) end
+ def _1_list(*a) @a = a end
+ def _0_float(x)
+ i=0
+ while i<@a.length
+ (send_out 0,i; return) if @a[i]==x
+ i+=1
+ end
+ send_out 0,-1
+ end
+ doc:_1_list,"list to search into"
+ doc:_0_float,"float to find in that list"
+ doc_out:_0_float,"position of the incoming float in the stored list"
+}
#-------- fClasses for: GUI
@@ -1257,92 +1270,6 @@ end
#-------- fClasses for: Hardware
-if const_defined? :USB
-
-class<<USB
- attr_reader :busses
-end
-
-class DelcomUSB < GridFlow::FObject
- Vendor,Product=0x0FC5,0x1222
- def self.find
- r=[]
- USB.busses.each {|dir,bus|
- bus.each {|dev|
- r<<dev if dev.idVendor==Vendor and dev.idProduct==Product
- }
- }
- r
- end
- def initialize #(bus=nil,dev=nil)
- r=DelcomUSB.find
- raise "no such device" if r.length<1
- raise "#{r.length} such devices (which one???)" if r.length>1
- @usb=USB.new(r[0])
- if_num=nil
- r[0].config.each {|config|
- config.interface.each {|interface|
- if_num = interface.bInterfaceNumber
- }
- }
- # post "Interface # %i\n", if_num
- @usb.set_configuration 1
- @usb.claim_interface if_num
- @usb.set_altinterface 0 rescue ArgumentError
- end
- # libdelcom had this:
- # uint8 recipient, deviceModel, major, minor, dataL, dataM;
- # uint16 length; uint8[8] extension;
- def _0_send_command(major,minor,dataL,dataM,extension="\0\0\0\0\0\0\0\0")
- raise "closed" if not @usb
- raise "extension.length!=8" if extension.length!=8
- @usb.control_msg(
- 0x000000c8, 0x00000012,
- minor*0x100+major,
- dataM*0x100+dataL,
- extension, 5000)
- end
- def delete; @usb.close; end
- install "delcomusb", 1, 1
-end
-
-# Klippeltronics
-FObject.subclass("multio",1,1) {
- Vendor,Product=0xDEAD,0xBEEF
- def self.find
- r=[]
- USB.busses.each {|dir,bus|
- bus.each {|dev|
- post "dir=%s, vendor=%x, product=%x",
- dir, dev.idVendor, dev.idProduct
- r<<dev if dev.idVendor==Vendor and dev.idProduct==Product
- }
- }
- r
- end
- def initialize
- r=self.class.find
- raise "no such device" if r.length<1
- raise "#{r.length} such devices (which one???)" if r.length>1
- $iobox=@usb=USB.new(r[0])
- if_num=nil
- r[0].config.each {|config|
- config.interface.each {|interface|
- #post "interface=%s", interface.to_s
- if_num = interface.bInterfaceNumber
- }
- }
- # post "Interface # %i\n", if_num
- # @usb.set_configuration 0
- @usb.claim_interface if_num
- @usb.set_altinterface 0 rescue ArgumentError
- end
- #@usb.control_msg(0b10100001,0x01,0,0,"",1000)
- #@usb.control_msg(0b10100001,0x01,0,1," ",0)
- def delete; @usb.close; end
-}
-end # if const_defined? :USB
-
# requires Ruby 1.8.0 because of bug in Ruby 1.6.x
FObject.subclass("joystick_port",0,1) {
def initialize(port)
@@ -1388,6 +1315,21 @@ FObject.subclass("plotter_control",1,1) {
end
}
+# ASCII, useful for controlling pics
+FObject.subclass("ascii",1,1) {
+ def puts(x)
+ x.each_byte {|b| send_out 0, b }
+ end
+ def _0_float x; puts "#{x.to_i}" end
+}
+
+# System, similar to shell
+FObject.subclass("system",1,1) {
+ def _0_system(*a)
+ system(a.join(" "))
+ end
+}
+
(begin require "linux/ParallelPort"; true; rescue LoadError; false end) and
FObject.subclass("parallel_port",1,3) {
def initialize(port,manually=0)
@@ -1419,7 +1361,8 @@ FObject.subclass("parallel_port",1,3) {
}
(begin require "linux/SoundMixer"; true; rescue LoadError; false end) and
-FObject.subclass("SoundMixer",1,1) {
+#FObject.subclass("SoundMixer",1,1) {
+class GFSoundMixer < FObject; install "SoundMixer",1,1
# BUG? i may have the channels (left,right) backwards
def initialize(filename)
super
@@ -1449,7 +1392,7 @@ FObject.subclass("SoundMixer",1,1) {
@@vars.each {|var| _0_get var }
end
end
-}
+end#}
# experimental
FObject.subclass("rubyarray",2,1) {
@@ -1473,4 +1416,42 @@ FObject.subclass("rubyarray",2,1) {
end
}
+FObject.subclass("regsub",3,1) {
+ def initialize(from,to) _1_symbol(from); _2_symbol(to) end
+ def _0_symbol(s) send_out 0, :symbol, s.to_s.gsub(@from, @to).intern end
+ def _1_symbol(from) @from = Regexp.new(from.to_s.gsub(/`/,"\\")) end
+ def _2_symbol(to) @to = to.to_s.gsub(/`/,"\\") end
+ doc:_0_symbol,"a string to transform"
+ doc:_1_symbol,"a regexp pattern to be found inside of the string"
+ doc:_2_symbol,"a replacement for the found pattern"
+ doc_out:_0_symbol,"the transformed string"
+}
+
+FObject.subclass("memstat",1,1) {
+ def _0_bang
+ f = File.open("/proc/#{$$}/stat")
+ send_out 0, Float(f.gets.split(" ")[22]) / 1024.0
+ f.close
+ end
+ doc:_0_bang,"lookup process stats for the currently running pd+ruby "+
+ "and figure out how much RAM it uses."
+ doc_out:_0_float,"virtual size of RAM in kilobytes (includes swapped out and shared memory)"
+}
+
+FObject.subclass("sendgui",1,0) {
+ def _0_list(*x)
+ GridFlow.gui x.join(" ").gsub(/`/,";")+"\n"
+ end
+ install "sys_vgui", 1, 0
+ doc:_0_list,"a Tcl/Tk command to send to the pd client."
+}
+
end # module GridFlow
+
+begin
+ require "gridflow/rblti"
+ GridFlow.post "Ruby-LTI support loaded."
+rescue Exception => e
+ #GridFlow.post "%s", e.inspect
+ #GridFlow.post "(rblti not found)"
+end
diff --git a/externals/gridflow/base/flow_objects_for_image.c b/externals/gridflow/base/flow_objects_for_image.c
index 2041c3e1..f6d6398d 100644
--- a/externals/gridflow/base/flow_objects_for_image.c
+++ b/externals/gridflow/base/flow_objects_for_image.c
@@ -1,8 +1,8 @@
/*
- $Id: flow_objects_for_image.c,v 1.1 2005-10-04 02:02:13 matju Exp $
+ $Id: flow_objects_for_image.c,v 1.2 2006-03-15 04:37:08 matju Exp $
GridFlow
- Copyright (c) 2001,2002,2003 by Mathieu Bouchard
+ Copyright (c) 2001,2002,2003,2004,2005 by Mathieu Bouchard
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -207,7 +207,7 @@ GRID_INLET(GridScaleBy,0) {
int p=0;
#define LOOP(z) \
for (int i=0; i<rowsize; i+=z) \
- for (int k=0; k<scalex; k++, p+=3)
+ for (int k=0; k<scalex; k++, p+=z)
switch (chans) {
case 3: LOOP(3) {Z(0);Z(1);Z(2);} break;
case 4: LOOP(4) {Z(0);Z(1);Z(2);Z(3);} break;
@@ -477,6 +477,7 @@ GRID_INLET(DrawPolygon,0) {
}
} GRID_END
+
GRID_INPUT(DrawPolygon,1,color) {} GRID_END
GRID_INPUT(DrawPolygon,2,polygon) {init_lines();} GRID_END
diff --git a/externals/gridflow/base/flow_objects_for_matrix.c b/externals/gridflow/base/flow_objects_for_matrix.c
index d245a10f..b88accba 100644
--- a/externals/gridflow/base/flow_objects_for_matrix.c
+++ b/externals/gridflow/base/flow_objects_for_matrix.c
@@ -1,5 +1,5 @@
/*
- $Id: flow_objects_for_matrix.c,v 1.1 2005-10-04 02:02:13 matju Exp $
+ $Id: flow_objects_for_matrix.c,v 1.2 2006-03-15 04:37:08 matju Exp $
GridFlow
Copyright (c) 2001,2002,2003 by Mathieu Bouchard
diff --git a/externals/gridflow/base/grid.c b/externals/gridflow/base/grid.c
index 877a460f..c3ec5932 100644
--- a/externals/gridflow/base/grid.c
+++ b/externals/gridflow/base/grid.c
@@ -1,5 +1,5 @@
/*
- $Id: grid.c,v 1.1 2005-10-04 02:02:13 matju Exp $
+ $Id: grid.c,v 1.2 2006-03-15 04:37:08 matju Exp $
GridFlow
Copyright (c) 2001,2002,2003,2004 by Mathieu Bouchard
@@ -32,10 +32,24 @@
#include <ctype.h>
/* copied from bridge/puredata.c (sorry: linkage issue) */
-struct Pointer : CObject { void *p; Pointer(void *_p) : p(_p) {}};
-Ruby Pointer_s_noo (void *ptr) {
- return Data_Wrap_Struct(EVAL("GridFlow::Pointer"), 0, 0, new Pointer(ptr));}
-static void *Pointer_gut (Ruby rself) {DGS(Pointer); return self->p;}
+struct Pointer : CObject {
+ void *p;
+ Pointer(void *_p) : p(_p) {}
+};
+
+#define Pointer_s_new Pointer_s_new_2
+#define Pointer_get Pointer_get_2
+
+static Ruby Pointer_s_new (void *ptr) {
+ Pointer *self = new Pointer(ptr);
+ Ruby rself = Data_Wrap_Struct(EVAL("GridFlow::Pointer"), 0, CObject_free, self);
+ self->rself = rself;
+ return rself;
+}
+static void *Pointer_get (Ruby rself) {
+ DGS(Pointer);
+ return self->p;
+}
//#define TRACE fprintf(stderr,"%s %s [%s:%d]\n",INFO(parent),__PRETTY_FUNCTION__,__FILE__,__LINE__);assert(this);
#define TRACE assert(this);
@@ -43,8 +57,7 @@ static void *Pointer_gut (Ruby rself) {DGS(Pointer); return self->p;}
#define CHECK_TYPE(d) \
if (NumberTypeE_type_of(d)!=this->nt) RAISE("%s(%s): " \
"type mismatch during transmission (got %s expecting %s)", \
- INFO(parent), \
- __PRETTY_FUNCTION__, \
+ INFO(parent), __PRETTY_FUNCTION__, \
number_type_table[NumberTypeE_type_of(d)].name, \
number_type_table[this->nt].name);
@@ -77,6 +90,8 @@ static inline void NUM(Ruby x, S &y) { \
EACH_FLOAT_TYPE(FOO)
#undef FOO
+static inline void NUM(Ruby x, ruby &y) { y.r=x; }
+
void Grid::init_from_ruby_list(int n, Ruby *a, NumberTypeE nt) {
Ruby delim = SYM(#);
for (int i=0; i<n; i++) {
@@ -162,15 +177,12 @@ bool GridInlet::supports_type(NumberTypeE nt) {
Ruby GridInlet::begin(int argc, Ruby *argv) {TRACE;
if (!argc) return PTR2FIX(this);
- GridOutlet *back_out = (GridOutlet *) Pointer_gut(argv[0]);
+ GridOutlet *back_out = (GridOutlet *) Pointer_get(argv[0]);
nt = (NumberTypeE) INT(argv[1]);
argc-=2, argv+=2;
PROF(parent) {
- if (dim) {
- gfpost("%s: grid inlet conflict; aborting %s in favour of %s",
+ if (dim) RAISE("%s: grid inlet conflict; aborting %s in favour of %s",
INFO(parent), INFO(sender), INFO(back_out->parent));
- abort();
- }
sender = back_out->parent;
if ((int)nt<0 || (int)nt>=(int)number_type_table_end)
RAISE("%s: inlet: unknown number type",INFO(parent));
@@ -328,7 +340,7 @@ void GridOutlet::begin(int woutlet, P<Dim> dim, NumberTypeE nt) {TRACE;
Ruby a[n+4];
a[0] = INT2NUM(woutlet);
a[1] = bsym._grid;
- a[2] = Pointer_s_noo(this);
+ a[2] = Pointer_s_new(this);
a[3] = INT2NUM(nt);
for(int i=0; i<n; i++) a[4+i] = INT2NUM(dim->get(i));
parent->send_out(COUNT(a),a);
diff --git a/externals/gridflow/base/grid.h b/externals/gridflow/base/grid.h
index 4aaf2aa3..9e971b99 100644
--- a/externals/gridflow/base/grid.h
+++ b/externals/gridflow/base/grid.h
@@ -1,8 +1,8 @@
/*
- $Id: grid.h,v 1.1 2005-10-04 02:02:13 matju Exp $
+ $Id: grid.h,v 1.2 2006-03-15 04:37:08 matju Exp $
GridFlow
- Copyright (c) 2001,2002,2003,2004 by Mathieu Bouchard
+ Copyright (c) 2001,2002,2003,2004,2005 by Mathieu Bouchard
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -25,7 +25,7 @@
#define __GF_GRID_H
// current version number as string literal
-#define GF_VERSION "0.8.0"
+#define GF_VERSION "0.8.1"
#define GF_COMPILE_TIME __DATE__ ", " __TIME__
#include <new>
@@ -36,6 +36,12 @@
#include <stdio.h>
#include <math.h>
+#ifdef __APPLE__
+static inline void *memalign (size_t a, size_t n) {return malloc(n);}
+#else
+#include <malloc.h>
+#endif
+
extern "C" {
#include <ruby.h>
#include <rubyio.h>
@@ -58,11 +64,7 @@ extern "C" {
#endif
#define BUG(s,args...) {fprintf(stderr,s "\nat: %s\n",args,__PRETTY_FUNCTION__); ::raise(11);}
-
-// !@#$ what am I going to do about this? should this be changed?
-// should I wrap all of the Ruby API for C++-style convenience?
-typedef VALUE Ruby;
-// typedef struct Ruby { VALUE x };
+#define L gfpost("%s:%d in %s",__FILE__,__LINE__,__PRETTY_FUNCTION__);
#ifdef IS_BRIDGE
#define RAISE(args...) rb_raise(rb_eArgError,args)
@@ -76,6 +78,8 @@ typedef VALUE Ruby;
if (RUBY_RELEASE_CODE < 20030716) rb_enable_super(a,b)
#endif
+typedef VALUE Ruby;
+
/* undocumented function from Ruby that is one thing we need to fix a very elusive bug
that manifests itself when embedding ruby inside a plugin of another app. This exists
for all versions of Ruby up to now, and I don't know when it gets fixed. */
@@ -86,7 +90,6 @@ void rb_raise0(
const char *file, int line, const char *func, VALUE exc, const char *fmt, ...)
__attribute__ ((noreturn));
};
-#define L fprintf(stderr,"%s:%d in %s\n",__FILE__,__LINE__,__PRETTY_FUNCTION__);
#define SI(_sym_) (rb_intern(#_sym_))
#define SYM(_sym_) (ID2SYM(SI(_sym_)))
#define DGS(_class_) \
@@ -104,21 +107,16 @@ static inline long rb_ary_len(Ruby s) {return RARRAY(s)->len;}
static inline Ruby *rb_ary_ptr(Ruby s) {return RARRAY(s)->ptr;}
static inline const char *rb_sym_name(Ruby sym) {return rb_id2name(SYM2ID(sym));}
#define rb_str_pt(s,t) Pt<t>((t*)rb_str_ptr(s),rb_str_len(s))
-
-// shorthands
#define IEVAL(_self_,s) rb_funcall(_self_,SI(instance_eval),1,rb_str_new2(s))
#define EVAL(s) rb_eval_string(s)
#define rassert(_p_) if (!(_p_)) RAISE(#_p_);
-
// because of older versions of Ruby (1.6.?)
#define rb_obj_class(o) rb_funcall((o),SI(class),0)
#define WATCH(n,ar) { \
- char foo[16*1024], *p=foo; \
- p += sprintf(p,"%s: ",#ar); \
+ char foo[16*1024], *p=foo; p += sprintf(p,"%s: ",#ar); \
for (int q=0; q<n; q++) p += sprintf(p,"%lld ",(long long)ar[q]); \
- gfpost("%s",foo); \
-}
+ gfpost("%s",foo);}
// we're gonna override assert, so load it first, to avoid conflicts
#include <assert.h>
@@ -148,7 +146,7 @@ static inline const char *rb_sym_name(Ruby sym) {return rb_id2name(SYM2ID(sym));
static inline Ruby PTR2FIX (const void *ptr) {
long p = (long)ptr;
- if ((p&3)!=0) BUG("unaligned pointer: %08x\n",(long)(ptr));
+ if ((p&3)!=0) BUG("unaligned pointer: %p\n",ptr);
return LONG2NUM(p>>2);
}
#define FIX2PTR(type,ruby) ((type *)(TO(long,ruby)<<2))
@@ -184,7 +182,7 @@ static inline float64 gf_abs(float64 a) { return fabs(a); }
// integer powers in log(b) time. T is assumed Integer
template <class T> static inline T ipow(T a, T b) {
for(T r=1;;) {if (b&1) r*=a; b>>=1; if (!b) return r; a*=a;}
-}
+}
// kludge
static inline float32 ipow(float32 a, float32 b) { return pow(a,b); }
@@ -196,7 +194,6 @@ static inline float64 ipow(float64 a, float64 b) { return pow(a,b); }
template <class T> static inline T min(T a, T b) { return a<b?a:b; }
template <class T> static inline T max(T a, T b) { return a>b?a:b; }
//template <class T> inline T min(T a, T b) { T c = (a-b)>>31; return (a&c)|(b&~c); }
-//template <class T> inline T max(T a, T b) { T c = (a-b)>>31; return (a&c)|(b&~c); }
// greatest common divisor, by euclid's algorithm
// this runs in log(a+b) number operations
@@ -221,12 +218,12 @@ template <class T> static T gcd2 (T a, T b) {
template <class T> static inline T lcm (T a, T b) {return a*b/gcd(a,b);}
// returns the position (0..31) of highest bit set in a word, or 0 if none.
-#define FOO(N) if ((x>>N)&(((typeof(x))1<<N)-1)) { x>>=N; i+=N; }
-static int highest_bit(uint8 x) {int i=0; FOO(4)FOO(2)FOO(1)return i;}
-static int highest_bit(uint16 x) {int i=0; FOO(8)FOO(4)FOO(2)FOO(1)return i;}
-static int highest_bit(uint32 x) {int i=0; FOO(16)FOO(8)FOO(4)FOO(2)FOO(1)return i;}
-static int highest_bit(uint64 x) {int i=0;FOO(32)FOO(16)FOO(8)FOO(4)FOO(2)FOO(1)return i;}
-#undef FOO
+#define Z(N) if ((x>>N)&(((typeof(x))1<<N)-1)) { x>>=N; i+=N; }
+static int highest_bit(uint8 x) {int i=0; Z(4)Z(2)Z(1)return i;}
+static int highest_bit(uint16 x) {int i=0; Z(8)Z(4)Z(2)Z(1)return i;}
+static int highest_bit(uint32 x) {int i=0; Z(16)Z(8)Z(4)Z(2)Z(1)return i;}
+static int highest_bit(uint64 x) {int i=0;Z(32)Z(16)Z(8)Z(4)Z(2)Z(1)return i;}
+#undef Z
// returns the position (0..31) of lowest bit set in a word, or 0 if none.
template <class T> static int lowest_bit(T n) { return highest_bit((~n+1)&n); }
@@ -262,7 +259,7 @@ static inline uint64 rdtsc() {return 0;}
#define EACH_INT_TYPE(MACRO) MACRO(uint8) MACRO(int16) MACRO(int32) MACRO(int64)
#define EACH_FLOAT_TYPE(MACRO) MACRO(float32) MACRO(float64)
#endif
-#define EACH_NUMBER_TYPE(MACRO) EACH_INT_TYPE(MACRO) EACH_FLOAT_TYPE(MACRO)
+#define EACH_NUMBER_TYPE(MACRO) EACH_INT_TYPE(MACRO) EACH_FLOAT_TYPE(MACRO) MACRO(ruby)
// note: loop unrolling macros assume N!=0
// btw this may cause alignment problems when 8 does not divide N
@@ -279,6 +276,132 @@ static inline uint64 rdtsc() {return 0;}
PTR+=4; N-=4; ARGS; if (N) goto start; }
//****************************************************************
+// my own little Ruby <-> C++ layer
+
+//struct Arg { Ruby a; };
+//struct ArgList { int n; Pt<Arg> v; };
+static inline bool INTEGER_P(Ruby x) {return FIXNUM_P(x)||TYPE(x)==T_BIGNUM;}
+static inline bool FLOAT_P(Ruby x) {return TYPE(x)==T_FLOAT;}
+#define INT(x) TO(int32,x)
+#define TO(t,x) convert(x,(t*)0)
+
+// not using NUM2INT because Ruby can convert Symbol to int
+// (by compatibility with Ruby 1.4)
+static inline int32 convert(Ruby x, int32 *foo) {
+ if (INTEGER_P(x)) return NUM2INT(x);
+ if (FLOAT_P(x)) return NUM2INT(rb_funcall(x,SI(round),0));
+ RAISE("expected Integer or Float (got %s)",
+ rb_str_ptr(rb_funcall(x,SI(inspect),0)));
+}
+static int16 convert(Ruby x, int16 *foo) {
+ int v = INT(x);
+ if (v<-0x8000 || v>=0x8000) RAISE("value %d is out of range",v);
+ return v;}
+static uint16 convert(Ruby x, uint16 *foo) {
+ int v = INT(x);
+ if (v<0 || v>=0x10000) RAISE("value %d is out of range",v);
+ return v;}
+static bool convert(Ruby x, bool *foo) {
+ if (x==Qtrue) return true;
+ if (x==Qfalse) return false;
+ switch (TYPE(x)) {
+ case T_FIXNUM: case T_BIGNUM: case T_FLOAT: return !!INT(x);
+ default: RAISE("can't convert to bool");
+ }
+}
+
+#ifdef HAVE_GCC64
+static uint64 convert(Ruby val, uint64 *foo) { return NUM2ULONG(val); }
+static int64 convert(Ruby val, int64 *foo) { return NUM2ULONG(val); }
+static Ruby gf_ull2num(uint64 val) { return ULONG2NUM(val); }
+static Ruby gf_ll2num(uint64 val) { return LONG2NUM(val); }
+#else
+static uint64 convert(Ruby val, uint64 *foo) {
+ if (FIXNUM_P(val)) return (uint64)FIX2LONG(val);
+ if (TYPE(val)!=T_BIGNUM) RAISE("type error");
+ uint64 v = (uint64)NUM2UINT(rb_funcall(val,SI(>>),1,INT2FIX(32))) << 32;
+ return v + NUM2UINT(rb_funcall(val,SI(&),1,UINT2NUM(0xffffffff)));}
+static int64 convert(Ruby val, int64 *foo) {
+ if (FIXNUM_P(val)) return (int64)FIX2LONG(val);
+ if (TYPE(val)!=T_BIGNUM) RAISE("type error");
+ int64 v = (int64)NUM2INT(rb_funcall(val,SI(>>),1,INT2FIX(32))) << 32;
+ return v + NUM2UINT(rb_funcall(val,SI(&),1,UINT2NUM(0xffffffff)));}
+static Ruby gf_ull2num(uint64 val) {
+ Ruby x = rb_funcall(UINT2NUM((uint32)(val>>32)),SI(<<),1,INT2FIX(32));
+ return rb_funcall(x,SI(+),1,UINT2NUM((uint32)val));}
+static Ruby gf_ll2num(int64 val) {
+ Ruby x = rb_funcall( INT2NUM(( int32)(val>>32)),SI(<<),1,INT2FIX(32));
+ return rb_funcall(x,SI(+),1,UINT2NUM((uint32)val));}
+#endif
+
+static long convert(Ruby x, long *foo) {
+ return sizeof(long)==sizeof(int32) ?
+ convert(x,(int32 *)0) :
+ convert(x,(int64 *)0);
+}
+
+static float64 convert(Ruby x, float64 *foo) {
+ if (INTEGER_P(x)) return INT(x);
+ if (TYPE(x)!=T_FLOAT) RAISE("not a Float");
+ return ((RFloat*)x)->value;}
+static float32 convert(Ruby x, float32 *foo) {
+ return (float32) convert(x,(float64 *)0);}
+typedef Ruby Symbol, Array, String, Integer;
+static Ruby convert(Ruby x, Ruby *bogus) { return x; }
+typedef Ruby (*RMethod)(...); /* !@#$ fishy */
+
+#define BUILTIN_SYMBOLS(MACRO) \
+ MACRO(_grid,"grid") MACRO(_bang,"bang") MACRO(_float,"float") \
+ MACRO(_list,"list") MACRO(_sharp,"#") \
+ MACRO(iv_outlets,"@outlets") \
+ MACRO(iv_ninlets,"@ninlets") \
+ MACRO(iv_noutlets,"@noutlets")
+extern struct BuiltinSymbols {
+#define FOO(_sym_,_str_) Ruby _sym_;
+BUILTIN_SYMBOLS(FOO)
+#undef FOO
+} bsym;
+
+typedef struct R {
+ VALUE r;
+ R() {r=Qnil;}
+ R(int x) {r=INT2NUM(x);}
+ R(unsigned x) {r=UINT2NUM(x);}
+ R(long x) {r=LONG2NUM(x);}
+ R(unsigned long x) {r=ULONG2NUM(x);}
+ R(double x) {r=rb_float_new(x);}
+ R( int64 x) {r= gf_ll2num(x);}
+ R(uint64 x) {r=gf_ull2num(x);}
+ operator bool() {return !!INT2NUM(r);}
+ operator uint8 () {return INT2NUM(r);}
+ operator int16 () {return INT2NUM(r);}
+ operator int32 () {return INT2NUM(r);}
+ operator int64 () {return convert(r,(int64*)0);}
+ operator float32 () {return convert(r,(float32*)0);}
+ operator float64 () {return convert(r,(float64*)0);}
+#define FOO(As,Op) \
+ R &operator As (int x) {r=rb_funcall(r, SI(Op),1,INT2NUM(x)); return *this;}
+ FOO(+=,+) FOO(-=,-) FOO(*=,*) FOO(/=,/) FOO(%=,%)
+ FOO(&=,&) FOO(|=,|) FOO(^=,^) FOO(<<=,<<) FOO(>>=,>>)
+#undef FOO
+// bool operator == (int x) {return rb_funcall(r,SI(==),1,INT2NUM(x));}
+#define FOO(Op) \
+ R operator Op (R x) {return rb_funcall(r,SI(Op),1,x.r);} \
+ R operator Op (int x) {return rb_funcall(r,SI(Op),1,INT2NUM(x));}
+ FOO(+) FOO(-) FOO(*) FOO(/) FOO(%)
+ FOO(&) FOO(|) FOO(^) FOO(<<) FOO(>>)
+ FOO(<) FOO(>) FOO(<=) FOO(>=) FOO(==) FOO(!=)
+#undef FOO
+ static R value(VALUE r) {R x; x.r=r; return x;}
+} ruby;
+
+static R operator -(int a, R b) {return rb_funcall(a,SI(Op),1,INT2NUM(b.r));}
+
+static inline R ipow(R a, R b) {return R::value(rb_funcall(a.r,SI(**),1,b.r));}
+static inline R gf_abs(R a) { return R::value(rb_funcall(a.r,SI(abs),0)); }
+static inline R cmp(R a, R b) { return R::value(rb_funcall(a.r,SI(<=>),1,b.r));}
+
+//****************************************************************
// hook into pointer manipulation. will help find memory corruption bugs.
template <class T> class Pt {
@@ -377,10 +500,11 @@ public:
#ifndef IS_BRIDGE
extern "C" void *gfmalloc(size_t n);
extern "C" void gffree(void *p);
-inline void *::operator new (size_t n) { return gfmalloc(n); }
-inline void *::operator new[] (size_t n) { return gfmalloc(n); }
-inline void ::operator delete (void *p) { gffree(p); }
-inline void ::operator delete[] (void *p) { gffree(p); }
+// note that C++ (GCC 3.4) now refuses the :: prefix so i removed it in the 4 following lines:
+inline void *operator new (size_t n) { return gfmalloc(n); }
+inline void *operator new[] (size_t n) { return gfmalloc(n); }
+inline void operator delete (void *p) { gffree(p); }
+inline void operator delete[] (void *p) { gffree(p); }
#endif
#define STACK_ARRAY(T,V,N) T V##_foo[N]; Pt<T> V(V##_foo,N);
@@ -400,88 +524,6 @@ template <class T> static void memswap (Pt<T> a, Pt<T> b, int n) {
}
//****************************************************************
-// my own little Ruby <-> C++ layer
-
-struct Arg { Ruby a; };
-struct ArgList { int n; Pt<Arg> v; };
-static inline bool INTEGER_P(Ruby x) {return FIXNUM_P(x)||TYPE(x)==T_BIGNUM;}
-static inline bool FLOAT_P(Ruby x) {return TYPE(x)==T_FLOAT;}
-#define INT(x) TO(int32,x)
-#define TO(t,x) convert(x,(t*)0)
-
-// not using NUM2INT because Ruby can convert Symbol to int
-// (by compatibility with Ruby 1.4)
-static inline int32 convert(Ruby x, int32 *foo) {
- if (INTEGER_P(x)) return NUM2INT(x);
- if (FLOAT_P(x)) return NUM2INT(rb_funcall(x,SI(round),0));
- RAISE("expected Integer or Float (got %s)",
- rb_str_ptr(rb_funcall(x,SI(inspect),0)));
-}
-static int16 convert(Ruby x, int16 *foo) {
- int v = INT(x);
- if (v<-0x8000 || v>=0x8000) RAISE("value %d is out of range",v);
- return v;}
-static uint16 convert(Ruby x, uint16 *foo) {
- int v = INT(x);
- if (v<0 || v>=0x10000) RAISE("value %d is out of range",v);
- return v;}
-static bool convert(Ruby x, bool *foo) {
- if (x==Qtrue) return true;
- if (x==Qfalse) return false;
- switch (TYPE(x)) {
- case T_FIXNUM: case T_BIGNUM: case T_FLOAT: return !!INT(x);
- default: RAISE("can't convert to bool");
- }
-}
-
-static uint64 convert(Ruby val, uint64 *foo) {
- if (FIXNUM_P(val)) return (uint64)FIX2LONG(val);
- if (TYPE(val)!=T_BIGNUM) RAISE("type error");
- uint64 v = (uint64)NUM2UINT(rb_funcall(val,SI(>>),1,INT2FIX(32))) << 32;
- return v + NUM2UINT(rb_funcall(val,SI(&),1,UINT2NUM(0xffffffff)));}
-static int64 convert(Ruby val, int64 *foo) {
- if (FIXNUM_P(val)) return (int64)FIX2LONG(val);
- if (TYPE(val)!=T_BIGNUM) RAISE("type error");
- int64 v = (int64)NUM2INT(rb_funcall(val,SI(>>),1,INT2FIX(32))) << 32;
- return v + NUM2UINT(rb_funcall(val,SI(&),1,UINT2NUM(0xffffffff)));}
-
-static Ruby gf_ull2num(uint64 val) {
- return rb_funcall(
- rb_funcall(UINT2NUM((uint32)(val>>32)),SI(<<),1,INT2FIX(32)),
- SI(+),1,UINT2NUM((uint32)val));}
-static Ruby gf_ll2num(int64 val) {
- return rb_funcall(
- rb_funcall(INT2NUM((int32)(val>>32)),SI(<<),1,INT2FIX(32)),
- SI(+),1,UINT2NUM((uint32)val));}
-
-static long convert(Ruby x, long *foo) {
- return sizeof(long)==sizeof(int32) ?
- convert(x,(int32 *)0) :
- convert(x,(int64 *)0);
-}
-static float64 convert(Ruby x, float64 *foo) {
- if (INTEGER_P(x)) return INT(x);
- if (TYPE(x)!=T_FLOAT) RAISE("not a Float");
- return ((RFloat*)x)->value;}
-static float32 convert(Ruby x, float32 *foo) {
- return (float32) convert(x,(float64 *)0);}
-typedef Ruby Symbol, Array, String, Integer;
-static Ruby convert(Ruby x, Ruby *bogus) { return x; }
-typedef Ruby (*RMethod)(...); /* !@#$ fishy */
-
-#define BUILTIN_SYMBOLS(MACRO) \
- MACRO(_grid,"grid") MACRO(_bang,"bang") MACRO(_float,"float") \
- MACRO(_list,"list") MACRO(_sharp,"#") \
- MACRO(iv_outlets,"@outlets") \
- MACRO(iv_ninlets,"@ninlets") \
- MACRO(iv_noutlets,"@noutlets")
-extern struct BuiltinSymbols {
-#define FOO(_sym_,_str_) Ruby _sym_;
-BUILTIN_SYMBOLS(FOO)
-#undef FOO
-} bsym;
-
-//****************************************************************
// CObject is the base class for C++ classes that get exported to Ruby.
// BTW: It's quite convenient to have virtual-methods in the base class
// because otherwise the vtable* isn't at the beginning of the object
@@ -509,32 +551,23 @@ void CObject_free (void *);
// you shouldn't use MethodDecl directly (used by source_filter.rb)
struct MethodDecl { const char *selector; RMethod method; };
void define_many_methods(Ruby rself, int n, MethodDecl *methods);
-
extern Ruby mGridFlow, cFObject, cGridObject, cFormat;
//****************************************************************
// a Dim is a list of dimensions that describe the shape of a grid
\class Dim < CObject
struct Dim : CObject {
- static const int MAX_DIMENSIONS=16; // maximum number of dimensions in a grid
+ static const int MAX_DIM=16; // maximum number of dimensions in a grid
int n;
Pt<int32> v; // safe pointer
- int32 v2[MAX_DIMENSIONS]; // real stuff
+ int32 v2[MAX_DIM]; // real stuff
void check(); // test invariants
- Dim(int n, Pt<int32> v) {
- this->v = Pt<int32>(v2,MAX_DIMENSIONS);
- this->n = n;
- COPY(this->v,v,n); check();
- }
- Dim(int n, int32* v) {
- this->v = Pt<int32>(v2,MAX_DIMENSIONS);
- this->n = n;
- COPY(this->v,Pt<int32>(v,n),n); check();
- }
- Dim() {v=Pt<int32>(v2,MAX_DIMENSIONS); n=0; check();}
- Dim(int a) {v=Pt<int32>(v2,MAX_DIMENSIONS); n=1;v[0]=a; check();}
- Dim(int a,int b) {v=Pt<int32>(v2,MAX_DIMENSIONS); n=2;v[0]=a;v[1]=b; check();}
- Dim(int a,int b,int c){v=Pt<int32>(v2,MAX_DIMENSIONS); n=3;v[0]=a;v[1]=b;v[2]=c;check();}
+ Dim(int n, Pt<int32> v) { this->v = Pt<int32>(v2,MAX_DIM); this->n = n; COPY(this->v,v,n); check();}
+ Dim(int n, int32 *v) { this->v = Pt<int32>(v2,MAX_DIM); this->n = n; COPY(this->v,Pt<int32>(v,n),n); check();}
+ Dim() {v=Pt<int32>(v2,MAX_DIM); n=0; check();}
+ Dim(int a) {v=Pt<int32>(v2,MAX_DIM); n=1;v[0]=a; check();}
+ Dim(int a,int b) {v=Pt<int32>(v2,MAX_DIM); n=2;v[0]=a;v[1]=b; check();}
+ Dim(int a,int b,int c){v=Pt<int32>(v2,MAX_DIM); n=3;v[0]=a;v[1]=b;v[2]=c;check();}
int count() {return n;}
int get(int i) { return v[i]; }
int32 prod(int start=0, int end=-1) {
@@ -610,6 +643,7 @@ NUMBER_TYPE_LIMITS( int32,-0x80000000,0x7fffffff,-1)
NUMBER_TYPE_LIMITS( int64,-0x8000000000000000LL,0x7fffffffffffffffLL,-1)
NUMBER_TYPE_LIMITS(float32,-HUGE_VAL,+HUGE_VAL,(RAISE("all_ones"),0))
NUMBER_TYPE_LIMITS(float64,-HUGE_VAL,+HUGE_VAL,(RAISE("all_ones"),0))
+NUMBER_TYPE_LIMITS( ruby,ruby(-HUGE_VAL),ruby(+HUGE_VAL),(RAISE("all_ones"),0))
#ifdef HAVE_LITE
#define NT_NOTLITE NT_UNIMPL
@@ -624,7 +658,8 @@ NUMBER_TYPE_LIMITS(float64,-HUGE_VAL,+HUGE_VAL,(RAISE("all_ones"),0))
MACRO( uint32,32,NT_UNSIGNED|NT_UNIMPL, "u32") MACRO(int32,32,0, "i32,i") \
MACRO( uint64,64,NT_UNSIGNED|NT_UNIMPL, "u64") MACRO(int64,64,NT_NOTLITE, "i64,l") \
MACRO(float32,32,NT_NOTLITE|NT_FLOAT, "f32,f") \
- MACRO(float64,64,NT_NOTLITE|NT_FLOAT, "f64,d")
+ MACRO(float64,64,NT_NOTLITE|NT_FLOAT, "f64,d") \
+ MACRO( ruby,sizeof(long),NT_NOTLITE,"r")
enum NumberTypeE {
#define FOO(_sym_,args...) _sym_##_e,
@@ -661,11 +696,12 @@ NumberTypeE NumberTypeE_find (Ruby sym);
#define TYPESWITCH(T,C,E) switch (T) { \
case uint8_e: C(uint8) break; case int16_e: C(int16) break; \
case int32_e: C(int32) break; NONLITE(case int64_e: C(int64) break; \
- case float32_e: C(float32) break; case float64_e: C(float64) break;) \
+ case float32_e: C(float32) break; case float64_e: C(float64) break; \
+ case ruby_e: C(ruby) break;) \
default: E; RAISE("type '%s' not available here",number_type_table[T].sym);}
-#define TYPESWITCH_NOFLOAT(T,C,E) switch (T) { \
+#define TYPESWITCH_JUSTINT(T,C,E) switch (T) { \
case uint8_e: C(uint8) break; case int16_e: C(int16) break; \
- case int32_e: C(int32) break; NONLITE(case int64_e: C(int64) break;)\
+ case int32_e: C(int32) break; NONLITE(case int64_e: C(int64) break;) \
default: E; RAISE("type '%s' not available here",number_type_table[T].sym);}
// Numop objects encapsulate optimised loops of simple operations
@@ -683,21 +719,22 @@ struct NumopOn : CObject {
typedef bool (*AlgebraicCheck)(T x, LeftRight side);
// neutral: right: forall y {f(x,y)=x}; left: forall x {f(x,y)=y};
// absorbent: right: exists a forall y {f(x,y)=a}; ...
+ T (*neutral)(LeftRight); // default neutral: e.g. 0 for addition, 1 for multiplication
AlgebraicCheck is_neutral, is_absorbent;
- NumopOn(Map m, Zip z, Fold f, Scan s, AlgebraicCheck n, AlgebraicCheck a) :
- op_map(m), op_zip(z), op_fold(f), op_scan(s),
- is_neutral(n), is_absorbent(a) {}
+ NumopOn(Map m, Zip z, Fold f, Scan s, T (*neu)(LeftRight), AlgebraicCheck n, AlgebraicCheck a) :
+ op_map(m), op_zip(z), op_fold(f), op_scan(s), neutral(neu), is_neutral(n), is_absorbent(a) {}
NumopOn() {}
NumopOn(const NumopOn &z) {
op_map = z.op_map; op_zip = z.op_zip;
op_fold = z.op_fold; op_scan = z.op_scan;
- is_neutral = z.is_neutral; is_absorbent = z.is_absorbent; }
+ is_neutral = z.is_neutral; neutral = z.neutral;
+ is_absorbent = z.is_absorbent; }
};
// semigroup property: associativity: f(a,f(b,c))=f(f(a,b),c)
#define OP_ASSOC (1<<0)
// abelian property: commutativity: f(a,b)=f(b,a)
-#define OP_COMM (1<<1)
+#define OP_COMM (1<<1)
\class Numop < CObject
struct Numop : CObject {
@@ -773,7 +810,6 @@ struct Grid : CObject {
P<Dim> dim;
NumberTypeE nt;
void *data;
- void *rdata;
Grid(P<Dim> dim, NumberTypeE nt, bool clear=false) : dim(0), nt(int32_e), data(0) {
if (!dim) RAISE("hell");
init(dim,nt);
@@ -795,14 +831,13 @@ EACH_NUMBER_TYPE(FOO)
memcpy(foo->data,data,bytes());
return foo;
}
- ~Grid() {if (rdata) delete[] (uint8 *)rdata;}
+ ~Grid() {if (data) free(data);}
private:
void init(P<Dim> dim, NumberTypeE nt) {
this->dim = dim;
this->nt = nt;
- rdata = dim ? new int64[1+(bytes()+7)/8] : 0;
- int align = ((long)rdata) & 7;
- data = (char *)rdata + ((8-align)&7);
+ data = 0;
+ if (dim) data = memalign(16,bytes()+16);
//fprintf(stderr,"rdata=%p data=%p align=%d\n",rdata,data,align);
}
void init_from_ruby(Ruby x);
@@ -937,18 +972,18 @@ private:
// C is for class, I for inlet number
// GRIN1 : int32 only
// GRIN4 : all types
-// GRIN2 : integers only; no floats
+// GRIN2 : integers only; no floats (no R either actually)
// GRINF : floats only; no integers
#ifndef HAVE_LITE
-#define GRIN(TB,TS,TI,TL,TF,TD) {TB,TS,TI,TL,TF,TD}
+#define GRIN(TB,TS,TI,TL,TF,TD,TR) {TB,TS,TI,TL,TF,TD,TR}
#else
-#define GRIN(TB,TS,TI,TL,TF,TD) {TB,TS,TI}
+#define GRIN(TB,TS,TI,TL,TF,TD,TR) {TB,TS,TI}
#endif // HAVE_LITE
-#define GRIN1(C,I) GRIN(0,0,C::grinw_##I,0,0,0)
-#define GRIN4(C,I) GRIN(C::grinw_##I,C::grinw_##I,C::grinw_##I,C::grinw_##I,C::grinw_##I,C::grinw_##I)
-#define GRIN2(C,I) GRIN(C::grinw_##I,C::grinw_##I,C::grinw_##I,C::grinw_##I,0,0)
-#define GRINF(C,I) GRIN(0,0,0,0,C::grinw_##I,C::grinw_##I)
+#define GRIN1(C,I) GRIN(0,0,C::grinw_##I,0,0,0,0)
+#define GRIN4(C,I) GRIN(C::grinw_##I,C::grinw_##I,C::grinw_##I,C::grinw_##I,C::grinw_##I,C::grinw_##I,C::grinw_##I)
+#define GRIN2(C,I) GRIN(C::grinw_##I,C::grinw_##I,C::grinw_##I,C::grinw_##I,0,0,0)
+#define GRINF(C,I) GRIN(0,0,0,0,C::grinw_##I,C::grinw_##I,0)
struct FClass { // 0.7.8: removed all GridObject-specific stuff.
void *(*allocator)(); // returns a new C++ object
@@ -1081,6 +1116,8 @@ static void SAME_DIM(int n, P<Dim> a, int ai, P<Dim> b, int bi) {
// a stack for the profiler, etc.
#define GF_STACK_MAX 256
+//#define NO_INLINE(decl) decl __attribute__((noinline))
+#define NO_INLINE(decl) decl
struct GFStack {
struct GFStackFrame {
FObject *o;
@@ -1090,8 +1127,8 @@ struct GFStack {
GFStackFrame s[GF_STACK_MAX];
int n;
GFStack() { n = 0; }
- void push (FObject *o) __attribute__((noinline));
- void pop () __attribute__((noinline));
+ NO_INLINE(void push (FObject *o));
+ NO_INLINE(void pop ());
};
extern GFStack gf_stack;
struct GFStackMarker {
diff --git a/externals/gridflow/base/main.c b/externals/gridflow/base/main.c
index 5cdd92f4..d65c81d0 100644
--- a/externals/gridflow/base/main.c
+++ b/externals/gridflow/base/main.c
@@ -1,5 +1,5 @@
/*
- $Id: main.c,v 1.1 2005-10-04 02:02:13 matju Exp $
+ $Id: main.c,v 1.2 2006-03-15 04:37:08 matju Exp $
GridFlow
Copyright (c) 2001,2002,2003,2004 by Mathieu Bouchard
@@ -91,7 +91,7 @@ void CObject_free (void *foo) {
// Dim
void Dim::check() {
- if (n>MAX_DIMENSIONS) RAISE("too many dimensions");
+ if (n>MAX_DIM) RAISE("too many dimensions");
for (int i=0; i<n; i++) if (v[i]<0) RAISE("Dim: negative dimension");
}
@@ -435,7 +435,7 @@ static Ruby GridFlow_handle_braces(Ruby rself, Ruby argv) {
s++;
}
const char *se = s+strlen(s);
- while (se[-1]==')' || se[-1]=='}') { se--; close++; }
+ while (se>s && (se[-1]==')' || se[-1]=='}')) { se--; close++; }
if (s!=se) {
Ruby u = rb_str_new(s,se-s);
av[j++] = rb_funcall(rself,SI(FloatOrSymbol),1,u);
@@ -495,7 +495,8 @@ void gfmemcopy(uint8 *out, const uint8 *in, int n) {
extern "C" {
void *gfmalloc(size_t n) {
uint64 t = rdtsc();
- void *p = malloc(n);
+// void *p = malloc(n);
+ void *p = memalign(16,n);
long align = (long)p & 7;
if (align) fprintf(stderr,"malloc alignment = %ld mod 8\n",align);
t=rdtsc()-t;
@@ -573,7 +574,7 @@ BUILTIN_SYMBOLS(FOO)
rb_ivar_set(mGridFlow, SI(@bsym), PTR2FIX(&bsym));
rb_define_const(mGridFlow, "GF_VERSION", rb_str_new2(GF_VERSION));
rb_define_const(mGridFlow, "GF_COMPILE_TIME", rb_str_new2(GF_COMPILE_TIME));
-
+ rb_define_const(mGridFlow, "GCC_VERSION", rb_str_new2(GCC_VERSION));
cFObject = rb_define_class_under(mGridFlow, "FObject", rb_cObject);
EVAL(
\ruby
diff --git a/externals/gridflow/base/main.rb b/externals/gridflow/base/main.rb
index 82976fb6..5b33bfad 100644
--- a/externals/gridflow/base/main.rb
+++ b/externals/gridflow/base/main.rb
@@ -1,8 +1,8 @@
=begin
- $Id: main.rb,v 1.1 2005-10-04 02:02:13 matju Exp $
+ $Id: main.rb,v 1.2 2006-03-15 04:37:28 matju Exp $
GridFlow
- Copyright (c) 2001,2002 by Mathieu Bouchard
+ Copyright (c) 2001,2002,2003,2004,2005 by Mathieu Bouchard
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -94,6 +94,7 @@ def self.packstring_for_nt(nt)
when :u, :u8, :uint8; "C*"
when :s, :i16, :int16; "s*"
when :i, :i32, :int32; "l*"
+ when :l, :i64, :int64; raise "int64? lol"
when :f, :f32, :float32; "f*"
when :d, :f64, :float64; "d*"
else raise "no decoder for #{nt.inspect}"
@@ -156,12 +157,26 @@ class FObject
attr_accessor :do_loadbangs
attr_accessor :comment
def foreign_name; @foreign_name if defined? @foreign_name end
+ def doc(selector=nil,text=nil)
+ return @doc if not selector
+ if not defined? @doc; @doc={}; end
+ return @doc[selector] if not text
+ @doc[selector] = text
+ end
+ def doc_out(selector=nil,text=nil)
+ return @doc_out if not selector
+ if not defined? @doc_out; @doc_out={}; end
+ return @doc_out[selector] if not text
+ @doc_out[selector] = text
+ end
end
def post(*a) GridFlow.post(*a) end
def self.subclass(*args,&b)
qlass = Class.new self
qlass.install(*args)
- qlass.module_eval(&b)
+ #qlass.module_eval{qlass.instance_eval(&b)}
+ qlass.instance_eval{qlass.module_eval(&b)}
+ #qlass.module_eval(&b)
end
alias :total_time :total_time_get
alias :total_time= :total_time_set
diff --git a/externals/gridflow/base/number.c b/externals/gridflow/base/number.c
index c483cf0b..b362e2cb 100644
--- a/externals/gridflow/base/number.c
+++ b/externals/gridflow/base/number.c
@@ -1,5 +1,5 @@
/*
- $Id: number.c,v 1.1 2005-10-04 02:02:13 matju Exp $
+ $Id: number.c,v 1.2 2006-03-15 04:37:08 matju Exp $
GridFlow
Copyright (c) 2001,2002,2003,2004 by Mathieu Bouchard
@@ -44,8 +44,8 @@ template <class T> class Op {
public:
// I call abort() on those because I can't say they're purevirtual.
static T f(T a, T b) {abort();}
- static bool is_neutral(T x, LeftRight side) {assert(!"Op::is_neutral called?");}
- static bool is_absorbent(T x, LeftRight side) {assert(!"Op::is_absorbent called?");}
+ static bool is_neutral(T x, LeftRight side) {assert(!"Op::is_neutral called?"); return false;}
+ static bool is_absorbent(T x, LeftRight side) {assert(!"Op::is_absorbent called?"); return false;}
};
template <class O> class OpLoops {
@@ -58,7 +58,7 @@ public:
}
template <class T> static void op_zip (int n, T *as, T *bs) {
if (!n) return;
- int ba=bs-as; // really!
+ ptrdiff_t ba=bs-as; // really!
#define FOO(I) as[I]=O::f(as[I],as[ba+I]);
UNROLL_8(FOO,n,as)
#undef FOO
@@ -66,7 +66,7 @@ public:
// disabled
template <class T> static void op_zip2 (int n, T *as, T *bs, T *cs) {
if (!n) return;
- int ba=bs-as, ca=cs-as;
+ ptrdiff_t ba=bs-as, ca=cs-as;
#define FOO(I) as[ca+I]=O::f(as[I],as[ba+I]);
UNROLL_8(FOO,n,as)
#undef FOO
@@ -136,119 +136,113 @@ template <class T> static void quick_put_zip (int n, T *as, T *bs) {
}
// classic two-input operator
-#define DEF_OP(op,expr,neutral,absorbent) \
+#define DEF_OP(op,expr,neu,isneu,isorb) \
template <class T> class Y##op : Op<T> { public: \
inline static T f(T a, T b) { return expr; } \
- inline static bool is_neutral (T x, LeftRight side) { return neutral; } \
- inline static bool is_absorbent(T x, LeftRight side) { return absorbent; } };
-#define DEF_OPFT(op,expr,neutral,absorbent,T) \
+ inline static T neutral (LeftRight side) {return neu;} \
+ inline static bool is_neutral (T x, LeftRight side) {return isneu;} \
+ inline static bool is_absorbent(T x, LeftRight side) {return isorb;}};
+#define DEF_OPFT(op,expr,neu,isneu,isorb,T) \
template <> class Y##op<T> : Op<T> { public: \
inline static T f(T a, T b) { return expr; } \
- inline static bool is_neutral (T x, LeftRight side) { return neutral; } \
- inline static bool is_absorbent(T x, LeftRight side) { return absorbent; } }; \
+ inline static T neutral (LeftRight side) {return neu;} \
+ inline static bool is_neutral (T x, LeftRight side) {return isneu;} \
+ inline static bool is_absorbent(T x, LeftRight side) {return isorb;}};
// this macro is for operators that have different code for the float version
-#define DEF_OPF(op,expr,expr2,neutral,absorbent) \
- DEF_OP( op,expr, neutral,absorbent) \
- DEF_OPFT(op,expr2,neutral,absorbent,float32) \
- DEF_OPFT(op,expr2,neutral,absorbent,float64)
+#define DEF_OPF(op,expr,expr2,neu,isneu,isorb) \
+ DEF_OP( op,expr, neu,isneu,isorb) \
+ DEF_OPFT(op,expr2,neu,isneu,isorb,float32) \
+ DEF_OPFT(op,expr2,neu,isneu,isorb,float64)
#define DECL_OPON(base,op,T) NumopOn<T>( \
&base<Y##op<T> >::op_map, &base<Y##op<T> >::op_zip, \
&base<Y##op<T> >::op_fold, &base<Y##op<T> >::op_scan, \
- &Y##op<T>::is_neutral, &Y##op<T>::is_absorbent)
+ &Y##op<T>::neutral, &Y##op<T>::is_neutral, &Y##op<T>::is_absorbent)
#define DECL_OPON_NOFOLD(base,op,T) NumopOn<T>( \
&base<Y##op<T> >::op_map, &base<Y##op<T> >::op_zip, 0,0, \
- &Y##op<T>::is_neutral, &Y##op<T>::is_absorbent)
+ &Y##op<T>::neutral, &Y##op<T>::is_neutral, &Y##op<T>::is_absorbent)
#define DECL_OP(op,sym,flags) Numop(0, sym, \
DECL_OPON(OpLoops,op,uint8), DECL_OPON(OpLoops,op,int16), \
DECL_OPON(OpLoops,op,int32) NONLITE(, DECL_OPON(OpLoops,op,int64), \
- DECL_OPON(OpLoops,op,float32), DECL_OPON(OpLoops,op,float64)), flags)
+ DECL_OPON(OpLoops,op,float32), DECL_OPON(OpLoops,op,float64), \
+ DECL_OPON(OpLoops,op,ruby)), flags)
#define DECL_OP_NOFLOAT(op,sym,flags) Numop(0, sym, \
DECL_OPON(OpLoops,op,uint8), DECL_OPON(OpLoops,op,int16), \
DECL_OPON(OpLoops,op,int32) NONLITE(, DECL_OPON(OpLoops,op,int64), \
- NumopOn<float32>(0,0,0,0,0,0), NumopOn<float64>(0,0,0,0,0,0)), flags)
+ NumopOn<float32>(0,0,0,0,0,0,0), NumopOn<float64>(0,0,0,0,0,0,0), \
+ DECL_OPON(OpLoops,op,ruby)), flags)
#define DECL_OP_NOFOLD(op,sym,flags) Numop(0, sym, \
DECL_OPON_NOFOLD(OpLoops,op,uint8), DECL_OPON_NOFOLD(OpLoops,op,int16), \
DECL_OPON_NOFOLD(OpLoops,op,int32) NONLITE(, DECL_OPON_NOFOLD(OpLoops,op,int64), \
- DECL_OPON_NOFOLD(OpLoops,op,float32), DECL_OPON_NOFOLD(OpLoops,op,float64)), flags)
+ DECL_OPON_NOFOLD(OpLoops,op,float32), DECL_OPON_NOFOLD(OpLoops,op,float64), \
+ DECL_OPON_NOFOLD(OpLoops,op,ruby)), flags)
template <class T> static inline T gf_floor (T a) {
return (T) floor((double)a); }
template <class T> static inline T gf_trunc (T a) {
return (T) floor(abs((double)a)) * (a<0?-1:1); }
-/*
-uint8 clipadd(uint8 a, uint8 b) { int32 c=a+b; return c<0?0:c>255?255:c; }
-int16 clipadd(int16 a, int16 b) { int32 c=a+b; return c<-0x8000?-0x8000:c>0x7fff?0x7fff:c; }
-int32 clipadd(int32 a, int32 b) { int64 c=a+b; return c<-0x80000000?-0x80000000:c>0x7fffffff?0x7fffffff:c; }
-int64 clipadd(int64 a, int64 b) { int64 c=(a>>1)+(b>>1)+(a&b&1);
- return c<(nt_smallest(0LL)/2?nt_smallest(0LL):c>nt_greatest(0LL)/2?nt_greatest(0LL):a+b; }
-uint8 clipsub(uint8 a, uint8 b) { int32 c=a-b; return c<0?0:c>255?255:c; }
-int16 clipsub(int16 a, int16 b) { int32 c=a-b; return c<-0x8000?-0x8000:c>0x7fff?0x7fff:c; }
-int32 clipsub(int32 a, int32 b) { int64 c=a-b; return c<-0x80000000?-0x80000000:c>0x7fffffff?0x7fffffff:c; }
-int64 clipsub(int64 a, int64 b) { int64 c=(a>>1)-(b>>1); //???
- return c<(nt_smallest(0LL)/2?nt_smallest(0LL):c>nt_greatest(0LL)/2?nt_greatest(0LL):a-b; }
-*/
+// trying to avoid GCC warning about uint8 too small for ==256
+template <class T> static bool equal256 (T x) {return x==256;}
+template <> static bool equal256 (uint8 x) {return false;}
#ifdef PASS1
-DEF_OP(ignore, a, side==at_right, side==at_left)
-DEF_OP(put, b, side==at_left, side==at_right)
-DEF_OP(add, a+b, x==0, false)
-DEF_OP(sub, a-b, side==at_right && x==0, false)
-DEF_OP(bus, b-a, side==at_left && x==0, false)
-DEF_OP(mul, a*b, x==1, x==0)
-DEF_OP(mulshr8, ((int32)a*(int32)b)>>8, (int64)x==256, x==0) //!@#$ bug with int64
-DEF_OP(div, b==0 ? 0 : a/b, side==at_right && x==1, false)
-DEF_OP(div2, b==0 ? 0 : div2(a,b), side==at_right && x==1, false)
-DEF_OP(vid, a==0 ? 0 : b/a, side==at_left && x==1, false)
-DEF_OP(vid2, a==0 ? 0 : div2(b,a), side==at_left && x==1, false)
-DEF_OPF(mod, b==0 ? 0 : mod(a,b), b==0 ? 0 : a-b*gf_floor(a/b),
- false, side==at_left && x==0 || side==at_right && x==1)
-DEF_OPF(dom, a==0 ? 0 : mod(b,a), a==0 ? 0 : b-a*gf_floor(b/a),
- false, side==at_left && x==0 || side==at_right && x==1)
+DEF_OP(ignore, a, 0, side==at_right, side==at_left)
+DEF_OP(put, b, 0, side==at_left, side==at_right)
+DEF_OP(add, a+b, 0, x==0, false)
+DEF_OP(sub, a-b, 0, side==at_right && x==0, false)
+DEF_OP(bus, b-a, 0, side==at_left && x==0, false)
+DEF_OP(mul, a*b, 1, x==1, x==0)
+DEF_OP(mulshr8, (a*b)>>8, 256, equal256(x), x==0)
+DEF_OP(div, b==0 ? (T)0 : a/b , 1, side==at_right && x==1, false)
+DEF_OP(div2, b==0 ? 0 : div2(a,b), 1, side==at_right && x==1, false)
+DEF_OP(vid, a==0 ? (T)0 : b/a , 1, side==at_left && x==1, false)
+DEF_OP(vid2, a==0 ? 0 : div2(b,a), 1, side==at_left && x==1, false)
+DEF_OPF(mod, b==0 ? 0 : mod(a,b), b==0 ? 0 : a-b*gf_floor(a/b), 0, false, side==at_left && x==0 || side==at_right && x==1)
+DEF_OPF(dom, a==0 ? 0 : mod(b,a), a==0 ? 0 : b-a*gf_floor(b/a), 0, false, side==at_left && x==0 || side==at_right && x==1)
//DEF_OPF(rem, b==0 ? 0 : a%b, b==0 ? 0 : a-b*gf_trunc(a/b))
//DEF_OPF(mer, a==0 ? 0 : b%a, a==0 ? 0 : b-a*gf_trunc(b/a))
-DEF_OP(rem, b==0?0:a%b, false, side==at_left&&x==0 || side==at_right&&x==1)
-DEF_OP(mer, a==0?0:b%a, false, side==at_left&&x==0 || side==at_right&&x==1)
+DEF_OP(rem, b==0?(T)0:a%b, 0, false, side==at_left&&x==0 || side==at_right&&x==1)
+DEF_OP(mer, a==0?(T)0:b%a, 0, false, side==at_left&&x==0 || side==at_right&&x==1)
#endif
#ifdef PASS2
-DEF_OP(gcd, gcd(a,b), x==0, x==1)
-DEF_OP(gcd2, gcd2(a,b), x==0, x==1) // should test those and pick one of the two
-DEF_OP(lcm, a==0 || b==0 ? 0 : lcm(a,b), x==1, x==0)
-DEF_OPF(or , a|b, (float32)((int32)a | (int32)b), x==0, x==nt_all_ones(&x))
-DEF_OPF(xor, a^b, (float32)((int32)a ^ (int32)b), x==0, false)
-DEF_OPF(and, a&b, (float32)((int32)a & (int32)b), x==nt_all_ones(&x), x==0)
-DEF_OPF(shl, a<<b, a*pow(2.0,+b), side==at_right && x==0, false)
-DEF_OPF(shr, a>>b, a*pow(2.0,-b), side==at_right && x==0, false)
-DEF_OP(sc_and, a ? b : a, side==at_left && x!=0, side==at_left && x==0)
-DEF_OP(sc_or, a ? a : b, side==at_left && x==0, side==at_left && x!=0)
-DEF_OP(min, min(a,b), x==nt_greatest(&x), x==nt_smallest(&x))
-DEF_OP(max, max(a,b), x==nt_smallest(&x), x==nt_greatest(&x))
+DEF_OP(gcd, gcd(a,b), 0, x==0, x==1)
+DEF_OP(gcd2, gcd2(a,b), 0, x==0, x==1) // should test those and pick one of the two
+DEF_OP(lcm, a==0 || b==0 ? (T)0 : lcm(a,b), 1, x==1, x==0)
+DEF_OPF(or , a|b, (float32)((int32)a | (int32)b), 0, x==0, x==nt_all_ones(&x))
+DEF_OPF(xor, a^b, (float32)((int32)a ^ (int32)b), 0, x==0, false)
+DEF_OPF(and, a&b, (float32)((int32)a & (int32)b), -1 /*nt_all_ones((T*)0)*/, x==nt_all_ones(&x), x==0)
+DEF_OPF(shl, a<<b, a*pow(2.0,+b), 0, side==at_right && x==0, false)
+DEF_OPF(shr, a>>b, a*pow(2.0,-b), 0, side==at_right && x==0, false)
+DEF_OP(sc_and, a ? b : a, 1, side==at_left && x!=0, side==at_left && x==0)
+DEF_OP(sc_or, a ? a : b, 0, side==at_left && x==0, side==at_left && x!=0)
+DEF_OP(min, min(a,b), nt_greatest((T*)0), x==nt_greatest(&x), x==nt_smallest(&x))
+DEF_OP(max, max(a,b), nt_smallest((T*)0), x==nt_smallest(&x), x==nt_greatest(&x))
+DEF_OP(cmp, cmp(a,b), 0, false, false)
+DEF_OP(eq, a == b, 0, false, false)
+DEF_OP(ne, a != b, 0, false, false)
+DEF_OP(gt, a > b, 0, false, side==at_left&&x==nt_smallest(&x)||side==at_right&&x==nt_greatest(&x))
+DEF_OP(le, a <= b, 0, false, side==at_left&&x==nt_smallest(&x)||side==at_right&&x==nt_greatest(&x))
+DEF_OP(lt, a < b, 0, false, side==at_left&&x==nt_greatest(&x)||side==at_right&&x==nt_smallest(&x))
+DEF_OP(ge, a >= b, 0, false, side==at_left&&x==nt_greatest(&x)||side==at_right&&x==nt_smallest(&x))
#endif
#ifdef PASS3
-DEF_OP(cmp, cmp(a,b), false, false)
-DEF_OP(eq, a == b, false, false)
-DEF_OP(ne, a != b, false, false)
-DEF_OP(gt, a > b, false, side==at_left&&x==nt_smallest(&x)||side==at_right&&x==nt_greatest(&x))
-DEF_OP(le, a <= b, false, side==at_left&&x==nt_smallest(&x)||side==at_right&&x==nt_greatest(&x))
-DEF_OP(lt, a < b, false, side==at_left&&x==nt_greatest(&x)||side==at_right&&x==nt_smallest(&x))
-DEF_OP(ge, a >= b, false, side==at_left&&x==nt_greatest(&x)||side==at_right&&x==nt_smallest(&x))
-DEF_OP(sin, (T)(b * sin(a * (M_PI / 18000))), false, false) // "LN=9000+36000n RA=0 LA=..."
-DEF_OP(cos, (T)(b * cos(a * (M_PI / 18000))), false, false) // "LN=36000n RA=0 LA=..."
-DEF_OP(atan, (T)(atan2(a,b) * (18000 / M_PI)), false, false) // "LA=0"
-DEF_OP(tanh, (T)(b * tanh(a * (M_PI / 18000))), false, x==0)
-DEF_OP(gamma, b<=0 ? 0 : (T)(0+floor(pow(a/256.0,256.0/b)*256.0)), false, false) // "RN=256"
-DEF_OP(pow, ipow(a,b), false, false) // "RN=1"
-DEF_OP(log, (T)(a==0 ? 0 : b * log(gf_abs(a))), false, false) // "RA=0"
-// 0.7.8
-//DEF_OPF(clipadd, clipadd(a,b), a+b, x==0, false)
-//DEF_OPF(clipsub, clipsub(a,b), a-b, side==at_right && x==0, false)
-DEF_OP(abssub, gf_abs(a-b), false, false)
-DEF_OP(sqsub, (a-b)*(a-b), false, false)
-DEF_OP(avg, (a+b)/2, false, false)
-DEF_OP(hypot, (T)(0+floor(sqrt(a*a+b*b))), false, false)
-DEF_OP(sqrt, (T)(0+floor(sqrt(a))), false, false)
-DEF_OP(rand, a==0 ? 0 : random()%(int32)a, false, false)
+DEF_OP(sin, (T)((float64)b * sin((float64)a * (M_PI / 18000))), 0, false, false) // "LN=9000+36000n RA=0 LA=..."
+DEF_OP(cos, (T)((float64)b * cos((float64)a * (M_PI / 18000))), 0, false, false) // "LN=36000n RA=0 LA=..."
+DEF_OP(atan, (T)(atan2(a,b) * (18000 / M_PI)), 0, false, false) // "LA=0"
+DEF_OP(tanh, (T)((float64)b * tanh((float64)a * (M_PI / 18000))), 0, false, x==0)
+DEF_OP(gamma, b<=0 ? (T)0 : (T)(0+floor(pow((float64)a/256.0,256.0/(float64)b)*256.0)), 0, false, false) // "RN=256"
+DEF_OP(pow, ipow(a,b), 0, false, false) // "RN=1"
+DEF_OP(log, (T)(a==0 ? (T)0 : (T)((float64)b * log((float64)gf_abs(a)))), 0, false, false) // "RA=0"
+// 0.8
+DEF_OPF(clipadd, clipadd(a,b), a+b, 0, x==0, false)
+DEF_OPF(clipsub, clipsub(a,b), a-b, 0, side==at_right && x==0, false)
+DEF_OP(abssub, gf_abs(a-b), 0, false, false)
+DEF_OP(sqsub, (a-b)*(a-b), 0, false, false)
+DEF_OP(avg, (a+b)/2, 0, false, false)
+DEF_OP(hypot, (T)(0+floor(sqrt(a*a+b*b))), 0, false, false)
+DEF_OP(sqrt, (T)(0+floor(sqrt(a))), 0, false, false)
+DEF_OP(rand, a==0 ? (T)0 : (T)(random()%(int32)a), 0, false, false)
//DEF_OP(erf,"erf*", 0)
#endif
@@ -289,28 +283,43 @@ Numop op_table2[] = {
DECL_OP_NOFOLD(sc_or, "||", 0),
DECL_OP(min, "min", OP_ASSOC|OP_COMM),
DECL_OP(max, "max", OP_ASSOC|OP_COMM),
+ DECL_OP_NOFOLD(eq, "==", OP_COMM),
+ DECL_OP_NOFOLD(ne, "!=", OP_COMM),
+ DECL_OP_NOFOLD(gt, ">", 0),
+ DECL_OP_NOFOLD(le, "<=", 0),
+ DECL_OP_NOFOLD(lt, "<", 0),
+ DECL_OP_NOFOLD(ge, ">=", 0),
+ DECL_OP_NOFOLD(cmp, "cmp", 0),
};
const long op_table2_n = COUNT(op_table2);
#endif
#ifdef PASS3
+uint8 clipadd(uint8 a, uint8 b) { int32 c=a+b; return c<0?0:c>255?255:c; }
+int16 clipadd(int16 a, int16 b) { int32 c=a+b; return c<-0x8000?-0x8000:c>0x7fff?0x7fff:c; }
+int32 clipadd(int32 a, int32 b) { int64 c=a+b; return c<-0x80000000?-0x80000000:c>0x7fffffff?0x7fffffff:c; }
+int64 clipadd(int64 a, int64 b) { int64 c=(a>>1)+(b>>1)+(a&b&1), p=nt_smallest((int64 *)0), q=nt_greatest((int64 *)0);
+ return c<p/2?p:c>q/2?q:a+b; }
+uint8 clipsub(uint8 a, uint8 b) { int32 c=a-b; return c<0?0:c>255?255:c; }
+int16 clipsub(int16 a, int16 b) { int32 c=a-b; return c<-0x8000?-0x8000:c>0x7fff?0x7fff:c; }
+int32 clipsub(int32 a, int32 b) { int64 c=a-b; return c<-0x80000000?-0x80000000:c>0x7fffffff?0x7fffffff:c; }
+int64 clipsub(int64 a, int64 b) { int64 c=(a>>1)-(b>>1); //???
+ int64 p=nt_smallest((int64 *)0), q=nt_greatest((int64 *)0);
+ return c<p/2?p:c>q/2?q:a-b; }
+
+ruby clipadd(ruby a, ruby b) { return a+b; }
+ruby clipsub(ruby a, ruby b) { return a-b; }
+
Numop op_table3[] = {
- DECL_OP_NOFOLD(eq, "==", OP_COMM),
- DECL_OP_NOFOLD(ne, "!=", OP_COMM),
- DECL_OP_NOFOLD(gt, ">", 0),
- DECL_OP_NOFOLD(le, "<=", 0),
- DECL_OP_NOFOLD(lt, "<", 0),
- DECL_OP_NOFOLD(ge, ">=", 0),
- DECL_OP_NOFOLD(cmp, "cmp", 0),
- DECL_OP_NOFOLD(sin, "sin*", 0),
- DECL_OP_NOFOLD(cos, "cos*", 0),
+ DECL_OP_NOFOLD(sin, "sin*", 0),
+ DECL_OP_NOFOLD(cos, "cos*", 0),
DECL_OP_NOFOLD(atan, "atan", 0),
DECL_OP_NOFOLD(tanh, "tanh*", 0),
DECL_OP_NOFOLD(gamma, "gamma", 0),
DECL_OP_NOFOLD(pow, "**", 0),
DECL_OP_NOFOLD(log, "log*", 0),
-// 0.7.8
-// DECL_OP(clipadd,"clip+", OP_ASSOC|OP_COMM),
-// DECL_OP(clipsub,"clip-", 0),
+// 0.8
+ DECL_OP(clipadd,"clip+", OP_ASSOC|OP_COMM),
+ DECL_OP(clipsub,"clip-", 0),
DECL_OP_NOFOLD(abssub,"abs-", OP_COMM),
DECL_OP_NOFOLD(sqsub,"sq-", OP_COMM),
DECL_OP_NOFOLD(avg,"avg", OP_COMM),
diff --git a/externals/gridflow/base/source_filter.rb b/externals/gridflow/base/source_filter.rb
index 59e24867..c55f4d95 100644
--- a/externals/gridflow/base/source_filter.rb
+++ b/externals/gridflow/base/source_filter.rb
@@ -1,14 +1,16 @@
+#!/usr/bin/env ruby
+
$keywords = %w(class decl def end grdecl)
$stack = []
$classes = []
ClassDecl = Struct.new(:name,:supername,:methods,:grins,:attrs,:info)
-MethodDecl = Struct.new(:rettype,:selector,:arglist,:minargs,:maxargs,:where)
+MethodDecl = Struct.new(:rettype,:selector,:arglist,:minargs,:maxargs,:where,:static)
Arg = Struct.new(:type,:name,:default)
class MethodDecl
def ==(o)
- return false unless rettype==o.rettype &&
+ return false unless rettype==o.rettype && static==o.static &&
maxargs==o.maxargs # && minargs==o.minargs
arglist.each_index{|i| arglist[i] == o.arglist[i] or return false }
return true
@@ -35,11 +37,11 @@ def handle_class(line)
end
def parse_methoddecl(line,term)
- /^(\w+)\s+(\w+)\s*\(([^\)]*)\)\s*#{term}/.match line or
+ /^(static\s)?\s*(\w+)\s+(\w+)\s*\(([^\)]*)\)\s*#{term}/.match line or
raise "syntax error #{where} #{line}"
- rettype,selector,arglist = $1,$2,$3
+ static,rettype,selector,arglist = $1,$2,$3,$4
arglist,minargs,maxargs = parse_arglist arglist
- MethodDecl.new(rettype,selector,arglist,minargs,maxargs,where)
+ MethodDecl.new(rettype,selector,arglist,minargs,maxargs,where,static)
end
def parse_arglist(arglist)
@@ -75,10 +77,9 @@ def handle_attr(line)
raise "missing \\class #{where}" if
not $stack[-1] or not ClassDecl===$stack[-1]
$stack[-1].attrs[name]=Arg.new(type,name,nil)
- Out.print line
- Out.puts "//FCS"
+ Out.print line.gsub(/\/\/.*$/,"") # hack!
handle_decl "void _0_#{name}_m (#{type} #{name});"
- Out.puts "# #{$linenumber}"
+# Out.puts "# #{$linenumber}"
end
def handle_decl(line)
@@ -88,16 +89,17 @@ def handle_decl(line)
m = parse_methoddecl(line,";\s*$")
$stack[-1].methods[m.selector] = m
+ Out.print "static " if m.static
Out.print "#{m.rettype} #{m.selector}(int argc, Ruby *argv"
Out.print "," if m.arglist.length>0
Out.print "#{unparse_arglist m.arglist});"
Out.puts "static Ruby #{m.selector}_wrap"+
"(int argc, Ruby *argv, Ruby rself);//FCS"
- Out.puts "# #{$linenumber+1}"
+# Out.puts "# #{$linenumber}"
end
def handle_def(line)
- m = parse_methoddecl(line,"\{?.*$")
+ m = parse_methoddecl(line,"\\{?.*$")
term = line[/\{.*/]
qlass = $stack[-1]
raise "missing \\class #{where}" if not qlass or not ClassDecl===qlass
@@ -176,7 +178,7 @@ def handle_classinfo(line)
c,s = frame.name,method.selector
"{ \"#{s}\",(RMethod)#{c}::#{s}_wrap }"
}.join(",")
- Out.puts "}; FClass ci#{cl} = { #{cl}_allocator, #{cl}_startup,"
+ Out.puts "}; static FClass ci#{cl} = { #{cl}_allocator, #{cl}_startup,"
Out.puts "#{cl.inspect}, COUNT(#{cl}_methods), #{cl}_methods };"
Out.puts "void #{frame.name}_startup (Ruby rself) "+line
end
diff --git a/externals/gridflow/base/test.rb b/externals/gridflow/base/test.rb
index 1d44f918..86c17af3 100644
--- a/externals/gridflow/base/test.rb
+++ b/externals/gridflow/base/test.rb
@@ -1,4 +1,4 @@
-# $Id: test.rb,v 1.1 2005-10-04 02:02:13 matju Exp $
+# $Id: test.rb,v 1.2 2006-03-15 04:37:28 matju Exp $
$:.delete_if {|x| x=='.' }
require "gridflow"
@@ -7,13 +7,15 @@ include GridFlow
GridFlow.verbose=true
$imdir = "./images"
-$animdir = "/opt/mex"
+$animdir = "./images/movies"
srand Time.new.to_i
$port = 4200+rand(100)
def pressakey; puts "press return to continue."; readline; end
-class Expect < FObject
+FO = FObject # shortcut
+
+class Expect < FO
def praise(*a)
#raise(*a)
puts a
@@ -38,64 +40,71 @@ class Expect < FObject
install "expect", 1, 0
end
+def cast value, type
+ case type
+ when :b, :u8,:uint8; value & 0xff
+ when :s,:i16,:int16; (value & 0x7fff) - (value & 0x8000)
+ when :i,:i32,:int32; value
+ when :l,:i64,:int64; value
+ when :f,:f32,:float32; value.to_f
+ when :d,:f64,:float64; value.to_f
+ when :r,:ruby; value
+ else raise "hell"
+ end
+end
+
def test_bitpacking
#!@#$ WRITE ME
end
-def test_operators
+def test_numops
#!@#$ WRITE ME
end
-def cast value, type
- case type
- when :uint8; value & 0xff
- when :int16; (value & 0x7fff) - (value & 0x8000)
- when :int32; value
- when :int64; value
- when :float32; value.to_f
- when :float64; value.to_f
- else raise "hell"
- end
+#def tnt() for nt in [:b,:s,:i,:l,:f,:d,:r] do yield end end
+def _(o,s,i,d) o.connect(s,i,d) end
+def chain(*a)
+ (a.length-1).times {|i| a[i].connect 0,a[i+1],a }
+ a[-1]
end
def test_math
+for nt in [:b,:s,:i,:l,:f,:d,:r] do
hm = "#".intern
-#for nt in [:uint8, :int16, :int32, :int64, :float32, :float64] do
-for nt in [:uint8, :int16, :int32, :float32] do
-
#GridFlow.verbose = false
- GridFlow.gfpost "starting test for #{nt}"
- e = FObject["@export_list"]
- x = Expect.new
- e.connect 0,x,0
+
+ (e=FO["#export_list"])
+ (x=Expect.new)
+ _ e,0,x,0
x.expect([1,2,3,11,12,13,21,22,23]) {
e.send_in 0, 3,3,nt,hm,1,2,3,11,12,13,21,22,23 }
- a = FObject["fork"]
- b = FObject["@ +"]
- a.connect 0,b,0
- a.connect 1,b,1
- b.connect 0,e,0
+ (a=FO["fork"])
+ (b=FO["@ +"])
+ _ a,0,b,0
+ _ a,1,b,1
+ _ b,0,e,0
x.expect([4]) { a.send_in 0, 2 }
- x.expect([2,3,5,7]) { e.send_in 0,"list #{nt} 2 3 5 7" }
- a = FObject["@fold + {#{nt} # 0}"]
- a.connect 0,e,0
+ x.expect([2,3,5,7]) { e.send_in 0,:list,nt,2,3,5,7 }
+ a = FO["#fold + , seed {#{nt} # 0}"]
+ _ a,0,e,0
x.expect([cast(420000,nt)]) { a.send_in 0,"10000 #{nt} # 42" }
- (a = FObject["@ + {#{nt} 0 10}"]).connect 0,e,0
+ a = FO["# + {#{nt} 0 10}"]
+ _ a,0,e,0
x.expect([1,12,4,18,16,42,64]) {
a.send_in 0,:list,nt, 1,2,4,8,16,32,64 }
- a = FObject["@ + {#{nt} 2 3 5}"]
- b = FObject["@fold + {#{nt} # 0}"]
- a.connect 0,b,0
- b.connect 0,e,0
+ a = FO["# + {#{nt} 2 3 5}"]
+ b = FO["#fold + , seed {#{nt} # 0}"]
+ _ a,0,b,0
+ _ b,0,e,0
x.expect([cast(45332,nt)]) { a.send_in 0, 1000,nt,hm,42 }
-
- (a = FObject["@ + {#{nt} # 42}"]).connect 0,e,0
+ a = FO["@ + {#{nt} # 42}"]
+ _ a,0,e,0
x.expect((43..169).to_a) {
a.send_in 0,:list,nt, *(1..127).to_a }
@@ -106,52 +115,47 @@ for nt in [:uint8, :int16, :int32, :float32] do
a.send_in 1, "list #{nt} # 10"
a.send_in 0,:list,nt, 1,2,4,8 }
-if nt!=:uint8 and nt!=:float32 and nt!=:float64
- (a = FObject["@ / {#{nt} # 3}"]).connect 0,e,0
- x.expect([-2,-1,-1,-1,0,0,0,0,0,1,1,1,2]) {
- a.send_in(0,:list,nt, *(-6..6).to_a) }
-
- (a = FObject["@ div {#{nt} # 3}"]).connect 0,e,0
- x.expect([-2,-2,-2,-1,-1,-1,0,0,0,1,1,1,2]) {
- a.send_in(0, :list, nt, *(-6..6).to_a) }
+if nt!=:b and nt!=:f and nt!=:d
+ a=FO["# / {#{nt} # 3}" ]; _ a,0,e,0; x.expect([-2,-1,-1,-1,0,0,0,0,0,1,1,1,2]) { a.send_in(0,:list,nt, *(-6..6).to_a) }
+ a=FO["# div {#{nt} # 3}"]; _ a,0,e,0; x.expect([-2,-2,-2,-1,-1,-1,0,0,0,1,1,1,2]) { a.send_in(0, :list, nt, *(-6..6).to_a) }
end
- (a = FObject["@ ignore {#{nt} # 42}"]).connect 0,e,0
+ (a = FO["# ignore {#{nt} # 42}"]).connect 0,e,0
x.expect((42..52).to_a) { a.send_in(0, :list, nt, *(42..52).to_a) }
- (a = FObject["@ put {#{nt} # 42}"]).connect 0,e,0
+ (a = FO["# put {#{nt} # 42}"]).connect 0,e,0
x.expect([42]*13) { a.send_in(0, :list, nt, *(-6..6).to_a) }
-if nt!=:uint8
- (a = FObject["@! abs"]).connect 0,e,0
+if nt!=:b
+ (a = FO["# abs-"]).connect 0,e,0
x.expect([2,3,5,7]) {
a.send_in 0,:list,nt, -2,3,-5,7 }
end
- (a = FObject["@fold * {#{nt} # 1}"]).connect 0,e,0
+ (a = FO["#fold *, seed {#{nt} # 1}"]).connect 0,e,0
x.expect([210]) { a.send_in 0,:list,nt, 2,3,5,7 }
x.expect([128]) { a.send_in 0,:list,nt, 1,1,2,1,2,2,2,1,1,2,1,2,2 }
- (a = FObject["@fold + {#{nt} 0 0}"]).connect 0,e,0
+ (a = FO["#fold +, seed {#{nt} 0 0}"]).connect 0,e,0
x.expect([18,23]) { a.send_in 0, 3,2,nt,hm,2,3,5,7,11,13 }
- (a = FObject["@scan + {#{nt} 0 0}"]).connect 0,e,0
+ (a = FO["#scan +, seed {#{nt} 0 0}"]).connect 0,e,0
x.expect([2,3,7,10,18,23]) { a.send_in 0, 3,2,nt,hm,2,3,5,7,11,13 }
- (a = FObject["@scan * {#{nt} # 1}"]).connect 0,e,0
+ (a = FO["#scan *, seed {#{nt} # 1}"]).connect 0,e,0
x.expect([2,6,30,210]) { a.send_in 0,:list,nt, 2,3,5,7 }
x.expect([1,1,2,2,4,8,16,16,16,32,32,64,128]) {
a.send_in 0,:list,nt, 1,1,2,1,2,2,2,1,1,2,1,2,2 }
- (a = FObject["@scan + {#{nt} 0 0 0}"]).connect 0,e,0
+ (a = FO["#scan +, seed {#{nt} 0 0 0}"]).connect 0,e,0
x.expect([1,2,3,5,7,9,12,15,18]) {
a.send_in 0,:list,3,3,nt,hm,*(1..9).to_a }
- (a = FObject["@scan + {#{nt} # 0}"]).connect 0,e,0
+ (a = FO["#scan +, seed {#{nt} # 0}"]).connect 0,e,0
x.expect([1,3,6, 4,9,15, 7,15,24]) {
a.send_in 0,:list,3,3,nt,hm,*(1..9).to_a }
- (a = FObject["@outer +"]).connect 0,e,0
+ (a = FO["#outer +"]).connect 0,e,0
x.expect([9,10,12,17,18,20,33,34,36]) {
a.send_in 1,:list,nt, 1,2,4
a.send_in 0,:list,nt, 8,16,32 }
@@ -160,47 +164,29 @@ end
a.send_in 1,(0...10).to_a
a.send_in 0,(0...10).map{|i| 10*i }}
-if nt!=:uint8 and nt!=:float32 and nt!=:float64
- (a = FObject["@outer",:%,[nt,3,-3]]).connect 0,e,0
+if nt!=:b and nt!=:f and nt!=:d
+ (a = FO["#outer",:%,[nt,3,-3]]).connect 0,e,0
x.expect([0,0,1,-2,2,-1,0,0,1,-2,2,-1,0,0]) {
a.send_in 0,:list,nt, -30,-20,-10,0,+10,+20,+30 }
- (a = FObject["@outer","swap%".intern,[nt,3,-3]]).connect 0,e,0
+ (a = FO["#outer","swap%".intern,[nt,3,-3]]).connect 0,e,0
x.expect([-27,-3,-17,-3,-7,-3,0,0,3,7,3,17,3,27]) {
a.send_in 0,:list,nt, -30,-20,-10,0,+10,+20,+30 }
end
- (a = FObject["@import {3}"]).connect 0,e,0
- x.expect([2,3,5]) { [2,3,5].each {|v| a.send_in 0,:list,nt,hm,v }}
-
- (a = FObject["@import {3}"]).connect 0,e,0
- x.expect([2,3,5]) { [2,3,5].each {|v| a.send_in 0,:list,nt,v }}
-
- (a = FObject["@redim {5}"]).connect 0,e,0
- x.expect([2,3,5,2,3]) { a.send_in 0,:list,2,3,5 }
-
- (a = FObject["@redim {5}"]).connect 0,e,0
- x.expect([0,0,0,0,0]) { a.send_in 0,:list }
+ (a = FO["#import {3}"]).connect 0,e,0; x.expect([2,3,5]) { [2,3,5].each {|v| a.send_in 0,:list,nt,hm,v }}
+ (a = FO["#import {3}"]).connect 0,e,0; x.expect([2,3,5]) { [2,3,5].each {|v| a.send_in 0,:list,nt,v }}
+ (a = FO["#redim {5}"]).connect 0,e,0; x.expect([2,3,5,2,3]) { a.send_in 0,:list,2,3,5 }
+ (a = FO["#redim {5}"]).connect 0,e,0; x.expect([0,0,0,0,0]) { a.send_in 0,:list }
+ (a = FO["#redim {0}"]).connect 0,e,0; x.expect([]) { a.send_in 0,:list,42,37,69 }
- (a = FObject["@redim {0}"]).connect 0,e,0
- x.expect([]) { a.send_in 0,:list,42,37,69 }
-
- (a = FObject["@inner * + {#{nt} # 0} {2 2 #{nt} # 2 3 5 7}"]).connect 0,e,0
- (i0 = FObject["@redim {2 2}"]).connect 0,a,0
+ (a = FO["#inner {2 2 #{nt} # 2 3 5 7}, seed {#{nt} # 0}"]).connect 0,e,0
+ (i0 = FO["@redim {2 2}"]).connect 0,a,0
x.expect([12,17,48,68]) { i0.send_in 0,:list,nt, 1,2,4,8 }
-#if nt!=:int64
-if false
- a = FObject["@print"]
- a.send_in 0, "3 3 #{nt} # 1 0 0 0"
- a.send_in 0, "3 3 3 #{nt} # 1 2 3 4"
- a.send_in 0, "base 16"
- a.send_in 0, "3 3 3 #{nt} # 255 0 0 0"
-end
-
- (a = FObject["@outer * {3 2 #{nt} # 1 2 3}"]).connect 0,e,0
- b = FObject["@dim"]
- c = FObject["@export_list"]
+ (a = FO["#outer * {3 2 #{nt} # 1 2 3}"]).connect 0,e,0
+ b = FO["#dim"]
+ c = FO["#export_list"]
a.connect 0,b,0
y = Expect.new
b.connect 0,c,0
@@ -211,29 +197,29 @@ end
a.send_in 0,:list,nt, 1, 10 }}
#pr=GridPrint.new
- (b = FObject["@redim {5 5}"]).connect 0,e,0
- (a = FObject["@convolve * + {#{nt} # 0}"]).connect 0,b,0
- (i0 = FObject["@redim {5 5 1}"]).connect 0,a,0
- (i1 = FObject["@redim {3 1}"]).connect 0,a,1
+ (b = FO["#redim {5 5}"]).connect 0,e,0
+ (a = FO["#convolve, seed {#{nt} # 0}"]).connect 0,b,0
+ (i0 = FO["#redim {5 5 1}"]).connect 0,a,0
+ (i1 = FO["#redim {3 1}"]).connect 0,a,1
i1.send_in 1, 3,3
x.expect([5,6,5,4,4,4,6,7,6,4,3,3,6,7,5,4,2,3,6,6,5,4,3,4,5]) {
a.send_in 1,:list,3,3,nt,hm, 1,1,1,1,1,1,1,1,1
i0.send_in 0,:list,nt, 1,1,1,0,0,0 }
- (a = FObject["@convolve * + {#{nt} # 0}"]).connect 0,e,0
+ (a = FO["#convolve, seed {#{nt} # 0}"]).connect 0,e,0
x.expect([1,3,6,4,0]) {
a.send_in 1, 1,2,nt,hm, 1,1
a.send_in 0, 1,5,nt,hm, 0,1,2,4,0 }
- (a = FObject["@import {4}"]).connect 0,e,0
+ (a = FO["#import {4}"]).connect 0,e,0
x.expect([2,3,5,7]) {
[2,3,5,7].each {|v| a.send_in 0,v }}
x.expect([1,2,3],[4,5,6],[7,8,9]) {
a.send_in 1, :list, 3
a.send_in 0, :list, *(1..9).to_a}
- for o in ["@store"]
- (a = FObject[o]).connect 0,e,0
+ for o in ["#store"]
+ (a = FO[o]).connect 0,e,0
a.send_in 1, 5, 4, nt, hm, 1,2,3,4,5
x.expect([1,2,3,4,4,5,1,2,2,3,4,5]) {
a.send_in 0, 3,1, hm, 0,2,4 }
@@ -251,109 +237,106 @@ end
x.expect([6,7,3,4, 8,11,13,3, 4,17,19,2, 3,4,5,1, 2,3,4,5]) { a.send_in 0 }
end
- b = FObject["@dim"]
- c = FObject["@export_list"]
+ b = FO["#dim"]
+ c = FO["#export_list"]
a.connect 0,b,0
y = Expect.new
b.connect 0,c,0
c.connect 0,y,0
-if nt!=:uint8 and nt!=:float32 and nt!=:float64 and nt!=:int64
- (a = FObject["@for {#{nt} # 0} {#{nt} # 10} {#{nt} # 1}"]).connect 0,e,0
+if nt!=:b and nt!=:f and nt!=:d and nt!=:l
+ (a = FO["#for {#{nt} # 0} {#{nt} # 10} {#{nt} # 1}"]).connect 0,e,0
a.connect 0,b,0
y.expect([10]) {
x.expect((0...10).to_a) {
a.send_in 0 } }
- (a = FObject["@for {#{nt} # 0} {#{nt} # -10} {#{nt} # 1}"]).connect 0,e,0
+ (a = FO["#for {#{nt} # 0} {#{nt} # -10} {#{nt} # 1}"]).connect 0,e,0
a.connect 0,b,0
y.expect([0]) { x.expect([]) { a.send_in 0 } }
- (a = FObject["@for {#{nt} # 0} {#{nt} # -10} {#{nt} # -1}"]).connect 0,e,0
+ (a = FO["#for {#{nt} # 0} {#{nt} # -10} {#{nt} # -1}"]).connect 0,e,0
a.connect 0,b,0
y.expect([10]) { x.expect([0,-1,-2,-3,-4,-5,-6,-7,-8,-9]) { a.send_in 0 } }
- (a = FObject["@for {#{nt} 0} {#{nt} 10} {#{nt} 1}"]).connect 0,e,0
+ (a = FO["#for {#{nt} 0} {#{nt} 10} {#{nt} 1}"]).connect 0,e,0
a.connect 0,b,0
y.expect([10,1]) {
x.expect((0...10).to_a) {
a.send_in 0 } }
- (a = FObject["@for {#{nt} 2 3} {#{nt} 5 7} {#{nt} 1 1}"]).connect 0,e,0
+ (a = FO["#for {#{nt} 2 3} {#{nt} 5 7} {#{nt} 1 1}"]).connect 0,e,0
a.connect 0,b,0
y.expect([3,4,2]) {
x.expect([2,3,2,4,2,5,2,6,3,3,3,4,3,5,3,6,4,3,4,4,4,5,4,6]) {
a.send_in 0 } }
end
- (a = FObject["@complex_sq"]).connect 0,e,0
+ (a = FO["@complex_sq"]).connect 0,e,0
x.expect([8,0]) { a.send_in 0, 2, 2 }
x.expect([0,9]) { a.send_in 0, 0, 3 }
- (a = FObject["@rotate 3000 {1 2 5}"]).connect 0,e,0
-# pr = GridPrint.new
-# a.connect 0,pr,0
-# x.expect([]) {
+ (a = FO["#rotate 3000 {1 2 5}"]).connect 0,e,0
a.send_in 0, "5 5 # 1000 0 0 0 0 0"
-# }
-#if nt==:float32 or nt==:float64
-# (a = FObject["@matrix_solve"]).connect 0,e,0
+#if nt==:f or nt==:d
+# (a = FO["@matrix_solve"]).connect 0,e,0
# x.expect([1,0,0,0,1,0,0,0,1]) { a.send_in 0, 3, 3, nt, hm, 1,0,0,0,1,0,0,0,1 }
#end
GridFlow.gfpost "ending test for #{nt}"
end # for nt
- (a = FObject["@two"]).connect 0,e,0
+ (a = FO["#pack 2"]).connect 0,e,0
x.expect([42,0]) { a.send_in 0,42 }
x.expect([42,28]) { a.send_in 1,28 }
x.expect([1313,28]) { a.send_in 0,1313 }
- (a = FObject["@three"]).connect 0,e,0
+ (a = FO["#pack 3"]).connect 0,e,0
x.expect([42,0,0]) { a.send_in 0,42 }
x.expect([42,28,0]) { a.send_in 1,28 }
x.expect([42,28,-1]) { a.send_in 2,-1 }
- (a = FObject["@four"]).connect 0,e,0
+ (a = FO["#pack 4"]).connect 0,e,0
x.expect([42,0,0,0]) { a.send_in 0,42 }
x.expect([42,0,0,-42]) { a.send_in 3,-42 }
-# glob = FObject["@global"]
-# glob.send_in 0, "profiler_dump"
+ (a = FO["#pack 5"]).connect 0,e,0
+ x.expect([3.5,0,0,0]) { a.send_in 0,3.5 }
+ x.expect([3.5,0,0,-3.5]) { a.send_in 3,-3.5 }
- e = FObject["@export_list"]
+ e = FO["#export_list"]
e.connect 0,x,0
- a = FObject["@import per_message"]
+ a = FO["#import per_message"]
a.connect 0,e,0
x.expect([1,2,3]) { a.send_in 0,1,2,3 }
x.expect([102,111,111]) { a.send_in 0,:symbol,:foo }
x.expect([ 70, 79, 79]) { a.send_in 0,:symbol,:FOO }
- a = FObject["@join 1"]
+ a = FO["@join 1"]
a.connect 0,e,0
a.send_in 1,2,2,nt,hm,11,13,17,19
x.expect([2,3,11,13,5,7,17,19]) { a.send_in 0,2,2,nt,hm,2,3,5,7 }
-if nt!=:float64; #!@#$
+if nt!=:d
a.send_in 1, 5,1,nt,hm,42
y.expect([5,4]) {
x.expect([2,3,5,42,7,11,13,42,17,19,23,42,29,31,37,42,41,43,47,42]) {
a.send_in 0, 5,3,nt,hm,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 }}
end
- a = FObject["@join 0"]
+ a = FO["@join 0"]
a.connect 0,e,0
a.send_in 1,2,2,nt,hm,11,13,17,19
x.expect([2,3,5,7,11,13,17,19]) { a.send_in 0,2,2,nt,hm,2,3,5,7 }
- a = FObject["@join 0 {2 2 2 #{nt} # 1 2 3}"]
+ a = FO["@join 0 {2 2 2 #{nt} # 1 2 3}"]
a.connect 0,e,0
a.connect 0,b,0
y.expect([2,2,2]) { x.expect([1,2,3,1,2,3,1,2]) { a.send_in 0,0,2,2,nt,hm }}
- a = FObject["@ravel"]
- b = FObject["@dim"]
- be = FObject["@export_list"]
+ a = FO["#ravel"]
+ b = FO["#dim"]
+ be = FO["#export_list"]
bx = Expect.new
a.connect 0,e,0
a.connect 0,b,0
@@ -361,28 +344,28 @@ end
be.connect 0,bx,0
bx.expect([9]) {
x.expect([1,2,3,2,4,6,3,6,9]) {
- o = FObject["@outer *"]
+ o = FO["#outer *"]
o.connect 0,a,0
o.send_in 1,1,2,3
o.send_in 0,1,2,3
}
}
- a = FObject["@grade"]
+ a = FO["#grade"]
a.connect 0,e,0
x.expect([0,2,4,6,8,9,7,5,3,1]) { a.send_in 0, 0,9,1,8,2,7,3,6,4,5 }
x.expect([0,9,1,8,2,7,3,6,4,5]) { a.send_in 0, 0,2,4,6,8,9,7,5,3,1 }
x.expect([7,6,5,4,3,2,1,0]) { a.send_in 0, 7,6,5,4,3,2,1,0 }
- a = FObject["@grade"]
- b = FObject["@fold +"]
+ a = FO["#grade"]
+ b = FO["#fold +"]
a.connect 0,b,0
b.connect 0,e,0
x.expect([100*99/2]) { a.send_in 0, (0...100).map { (rand*0x10000).to_i }}
x.expect([100*99/2]) { a.send_in 0, (0...100).map { (rand*0x10).to_i }}
x.expect([100*99/2]) { a.send_in 0, (0...100).map { 0 }}
- a = FObject["@perspective"]
+ a = FO["#perspective"]
a.connect 0,e,0
c = []
8.times {|v|
@@ -396,12 +379,12 @@ end
a.send_in 0, 8,3,hm,*c }
# regressiontests for past bugs
- a = FObject["@inner"] # that's it.
+ a = FO["#inner"] # that's it.
end
def test_rtmetro
- rt = FObject["rtmetro 1000"]
- pr = FObject["rubyprint"]
+ rt = FO["rtmetro 1000"]
+ pr = FO["rubyprint"]
rt.connect 0,pr,0
GridFlow.post "trying to start the rtmetro"
rt.send_in 0,1
@@ -413,8 +396,8 @@ def test_rtmetro
end
def test_print
- i = FObject["@redim {3}"]
- pr = FObject["@print"]
+ i = FO["#redim {3}"]
+ pr = FO["#print"]
# pr = GridFlow::RubyPrint.new
i.connect 0,pr,0
i.send_in 0, 85, 170, 255
@@ -433,11 +416,11 @@ class Barf < GridObject
end
def test_nonsense
-# (a = FObject["@! abs"]).connect 0,e,0
+# (a = FO["@! abs"]).connect 0,e,0
# x.expect_error {
# a.send_in 1, 42,42 }
- a = FObject["@import {3}"]
+ a = FO["#import {3}"]
b = Barf.new
a.connect 0,b,0
begin
@@ -451,20 +434,20 @@ def test_nonsense
end
def test_store
- a = FObject["@in file #{$imdir}/teapot.png"]
- b = FObject["@store"]
- c = FObject["@out x11"]
+ a = FO["#in file #{$imdir}/teapot.png"]
+ b = FO["#store"]
+ c = FO["#out x11"]
a.connect 0,b,1
a.send_in 0,"cast uint8"
a.send_in 0
b.connect 0,c,0
- d = FObject["@for {0 0} {256 256} {1 1}"]
- e = FObject["@ ^ 85"]
+ d = FO["#for {0 0} {256 256} {1 1}"]
+ e = FO["# ^ 85"]
d.connect 0,e,0
e.connect 0,b,0
- f = FObject["fps detailed"]
+ f = FO["fps detailed"]
c.connect 0,f,0
- pr = FObject["rubyprint"]
+ pr = FO["rubyprint"]
f.connect 0,pr,0
GridFlow.verbose = false
256.times {|t|
@@ -475,8 +458,8 @@ end
# generates recursive checkerboard pattern (munchies) in bluish colours.
class Munchies < FPatcher
- @fobjects = ["fork","fork","@for 0 64 1","@for 0 64 1","@for 2 5 1",
- "@outer ^","@outer *"]
+ @FOs = ["fork","fork","#for 0 64 1","#for 0 64 1","#for 2 5 1",
+ "#outer ^","#outer *"]
@wires = [-1,0,0,0, 0,0,1,0, 1,1,4,0, 4,0,6,1,
1,0,3,0, 3,0,5,1, 0,0,2,0, 2,0,5,0, 5,0,6,0, 6,0,-1,0 ]
def initialize() super end
@@ -485,15 +468,15 @@ end
def test_munchies
m=Munchies.new
- gout = FObject["@out quartz"]
+ gout = FO["#out window"]
m.connect 0,gout,0
m.send_in 0
$mainloop.loop
end
def test_image command
- gin = FObject["@in"]
- gout = FObject["@out x11"]
+ gin = FO["#in"]
+ gout = FO["#out window"]
gin.connect 0,gout,0
# 31.times {
3.times {
@@ -501,17 +484,17 @@ def test_image command
gout.send_in 0,"timelog 1"
gin.send_in 0
}
- FObject["@global"].send_in 0, "profiler_dump"
+ FO["#global"].send_in 0, "profiler_dump"
$mainloop.loop
end
def test_ppm2
- gin = FObject["@in"]
- store = FObject["@store"]
- pa = FObject["@convolve << + 0"]
- pb = FObject["@ / 9"]
- ra = FObject["@redim {3 3}"]
- gout = FObject["@out x11"]
+ gin = FO["#in"]
+ store = FO["#store"]
+ pa = FO["#convolve << + 0"]
+ pb = FO["# / 9"]
+ ra = FO["#redim {3 3}"]
+ gout = FO["#out window"]
gin.connect 0,store,1
store.connect 0,pa,0
pa.connect 0,pb,0
@@ -524,16 +507,16 @@ def test_ppm2
gin.send_in 0
# 40.times { store.send_in 0 }
loop { store.send_in 0 }
- v4j = FObject["@global"]
+ v4j = FO["#global"]
v4j.send_in 0,"profiler_dump"
# $mainloop.loop
end
def test_foo
- foo = FObject["@for {0 0} {64 64} {1 1}"]
- che = FObject["@checkers"]
- sca = FObject["@scale_by {5 3}"]
- out = FObject["@out x11"]
+ foo = FO["#for {0 0} {64 64} {1 1}"]
+ che = FO["#checkers"]
+ sca = FO["#scale_by {5 3}"]
+ out = FO["#out window"]
foo.connect 0,che,0
che.connect 0,sca,0
sca.connect 0,out,0
@@ -543,43 +526,42 @@ end
def test_anim(*msgs)
GridFlow.verbose = false
- gin = FObject["@in"]
- #gout1 = FObject["@out x11"]
- gout1 = FObject["@out sdl"]
- #gout1 = FObject["@out quicktime file test.mov"]
+ gin = FO["#in"]
+ gout1 = FO["#out window"]
+ #gout1 = FO["@out quicktime file test.mov"]
#gout1.send_in 0, :codec, :jpeg
- fps = FObject["fps detailed"]
- rpr = FObject["rubyprint"]
+ fps = FO["fps detailed"]
+ rpr = FO["rubyprint"]
gout1.connect 0,fps,0
#fps.connect 0,rpr,0
=begin
- gout1 = FObject["@downscale_by {3 2}"]
- gout2 = FObject["@rgb_to_greyscale"]
- gout3 = FObject["@out aalib X11 -height 60 -width 132"]
+ gout1 = FO["#downscale_by {3 2}"]
+ gout2 = FO["#rgb_to_greyscale"]
+ gout3 = FO["#out aalib X11 -height 60 -width 132"]
gout1.connect 0,gout2,0
gout2.connect 0,gout3,0
=end
- rpr = FObject["rubyprint"]
+ rpr = FO["rubyprint"]
# gin.connect 1,rpr,0
gin.connect 0,gout1,0
=begin
- layer=FObject["@layer"]
+ layer=FO["@layer"]
gin.connect 0,layer,0
layer.connect 0,gout1,0
- check=FObject["@checkers"]
- phor=FObject["@for {0 0} {256 256} {1 1}"]
+ check=FO["@checkers"]
+ phor=FO["@for {0 0} {256 256} {1 1}"]
phor.connect 0,check,0
check.connect 0,layer,1
phor.send_in 0
=end
-# scale = FObject["@scale_by 3"]
+# scale = FO["@scale_by 3"]
# gin.connect 0,scale,0
# scale.connect 0,gout1,0
-# pr = FObject["rubyprint time"]; gout.connect 0,pr,0
+# pr = FO["rubyprint time"]; gout.connect 0,pr,0
msgs.each {|m| gin.send_in 0,m }
gin.send_in 0, "cast uint8"
# gout.send_in 0,"timelog 1"
@@ -591,7 +573,7 @@ def test_anim(*msgs)
#gin.send_in 0, rand(1000)
}
# loop { gin.send_in 0 }
-# metro = FObject["rtmetro 80"]
+# metro = FO["rtmetro 80"]
# metro.connect 0,gin,0
# metro.send_in 0,1
# $mainloop.loop
@@ -601,11 +583,11 @@ def test_anim(*msgs)
frames, d, 1000*d/frames, frames/d
# global.send_in 0,"dfgdfgdkfjgl"
gout1.send_in 0, :close
- global = FObject["@global"]
+ global = FO["@global"]
global.send_in 0,"profiler_dump"
end
-class TestTCP < FObject
+class TestTCP < FO
attr_accessor :idle
def initialize
@idle = true
@@ -624,8 +606,8 @@ def test_tcp
if fork
# client (is receiving)
GridFlow.post_header = "[client] "
- $in_client = in1 = FObject["@in"]
- out = FObject["@out x11"]
+ $in_client = in1 = FO["@in"]
+ out = FO["@out x11"]
in1.connect 0,out,0
out.send_in 0,"timelog 1"
out.send_in 0,"autodraw 2"
@@ -646,9 +628,9 @@ def test_tcp
else
# server (is sending)
GridFlow.post_header = "[server] "
- $in1_server = in1 = FObject["@in"]
- $in2_server = in2 = FObject["@in"]
- $out = out = FObject["@out"]
+ $in1_server = in1 = FO["@in"]
+ $in2_server = in2 = FO["@in"]
+ $out = out = FO["@out"]
toggle = 0
in1.connect 0,out,0
in2.connect 0,out,0
@@ -656,7 +638,7 @@ def test_tcp
in2.send_in 0,"open #{$imdir}/b001.jpg"
out.send_in 0,"open grid tcpserver #{$port}"
out.send_in 0,"type uint8"
- test_tcp = GridFlow::FObject.new
+ test_tcp = GridFlow::FO.new
def test_tcp._0_bang
# GridFlow.post "tick"
@toggle ||= 0
@@ -678,22 +660,22 @@ end
def test_layer
- gin = FObject["@in png file ShaunaKennedy/atmosphere-bleu.png"]
-# gin1 = FObject["@in file #{$imdir}/r001.jpg"]
-# gin = FObject["@join 2 {240 320 1 # 128}"]
+ gin = FO["@in png file ShaunaKennedy/atmosphere-bleu.png"]
+# gin1 = FO["@in file #{$imdir}/r001.jpg"]
+# gin = FO["@join 2 {240 320 1 # 128}"]
# gin1.connect 0,gin,0
-# gfor = FObject["@for {0 0} {120 160} {1 1}"]
-# gfor = FObject["@for {0 0} {240 320} {1 1}"]
- gfor = FObject["@for {0 0} {480 640} {1 1}"]
- gche = FObject["@checkers"]
+# gfor = FO["@for {0 0} {120 160} {1 1}"]
+# gfor = FO["@for {0 0} {240 320} {1 1}"]
+ gfor = FO["@for {0 0} {480 640} {1 1}"]
+ gche = FO["@checkers"]
- gove = FObject["@layer"]
-# gove = FObject["@fold + {0 0 0 0}"]
-# gout = FObject["@print"]
-# gove = FObject["@inner2 * + 0 {3 4 # 1 0 0 0 0}"]
-# gout = FObject["@out sdl"]
- gout = FObject["@out x11"]
+ gove = FO["@layer"]
+# gove = FO["@fold + {0 0 0 0}"]
+# gout = FO["@print"]
+# gove = FO["@inner2 * + 0 {3 4 # 1 0 0 0 0}"]
+# gout = FO["@out sdl"]
+ gout = FO["@out x11"]
gin.connect 0,gove,0
gfor.connect 0,gche,0
@@ -702,8 +684,8 @@ def test_layer
gfor.send_in 0
- fps = FObject["fps detailed"]
- pr = FObject["rubyprint"]
+ fps = FO["fps detailed"]
+ pr = FO["rubyprint"]
gout.connect 0,fps,0
fps.connect 0,pr,0
@@ -715,20 +697,17 @@ end
Images = [
"png file opensource.png",
-# "png file ShaunaKennedy/atmosphere.png",
-# "targa file #{$imdir}/tux.tga",
-# "png file #{$imdir}/lena.png",
- "file #{$imdir}/ruby0216.jpg",
- "file #{$imdir}/g001.jpg",
- "file #{$imdir}/teapot.tga",
+ "#{$imdir}/ruby0216.jpg",
+ "#{$imdir}/g001.jpg",
+# "#{$imdir}/teapot.tga",
"grid gzfile #{$imdir}/foo.grid.gz",
"grid gzfile #{$imdir}/foo2.grid.gz",
# "videodev /dev/video0",
]
def test_formats_speed
- gin = FObject["@in"]
- gout = FObject["@out x11"]
+ gin = FO["@in"]
+ gout = FO["@out x11"]
gin.connect 0,gout,0
GridFlow.verbose=false
t1=[]
@@ -743,14 +722,15 @@ def test_formats_speed
end
def test_formats
- gin = FObject["@in"]
- gout = FObject["@out window"]
- gs = FObject["@ + {int16 # 0}"]
+ gin = FO["@in"]
+ gout = FO["@out window"]
+ gs = FO["@ + {int16 # 0}"]
gin.connect 0,gs,0
gs.connect 0,gout,0
# GridFlow.verbose=false
t1=[]
Images.each {|command|
+ GridFlow.post "SENDING open %s", command
gin.send_in 0,"open #{command}"
gin.send_in 0,"cast int16"
# test for load, rewind, load
@@ -763,10 +743,10 @@ def test_formats
end
def test_rewind
- gin = FObject["@in videodev /dev/video1 noinit"]
+ gin = FO["@in videodev /dev/video1 noinit"]
gin.send_in 0, "transfer read"
- gout = FObject["@out ppm file /tmp/foo.ppm"]
-# gout = FObject["@out x11"]
+ gout = FO["@out ppm file /tmp/foo.ppm"]
+# gout = FO["@out x11"]
gin.connect 0,gout,0
loop {
gin.send_in 0
@@ -776,15 +756,15 @@ end
def test_formats_write
# read files, store and save them, reload, compare, expect identical
- a = FObject["@in"]
- b = FObject["@out"]; a.connect 0,b,0
- c = FObject["@ -"]; a.connect 0,c,1
- d = FObject["@in"]; d.connect 0,c,0
- e = FObject["@fold +"]; c.connect 0,e,0
- f = FObject["@fold +"]; e.connect 0,f,0
- g = FObject["@fold +"]; f.connect 0,g,0
- h = FObject["@ / 15000"]; g.connect 0,h,0
- i = FObject["@export_list"]; h.connect 0,i,0
+ a = FO["@in"]
+ b = FO["@out"]; a.connect 0,b,0
+ c = FO["@ -"]; a.connect 0,c,1
+ d = FO["@in"]; d.connect 0,c,0
+ e = FO["@fold +"]; c.connect 0,e,0
+ f = FO["@fold +"]; e.connect 0,f,0
+ g = FO["@fold +"]; f.connect 0,g,0
+ h = FO["@ / 15000"]; g.connect 0,h,0
+ i = FO["@export_list"]; h.connect 0,i,0
x = Expect.new; i.connect 0,x,0
[
["ppm file", "#{$imdir}/g001.jpg"],
@@ -807,21 +787,21 @@ def test_formats_write
end
def test_mpeg_write
- a = FObject["@in ppm file /opt/mex/r.ppm.cat"]
- b = FObject["@out x11"]
+ a = FO["@in ppm file /opt/mex/r.ppm.cat"]
+ b = FO["@out x11"]
a.connect 0,b,0
loop{a.send_in 0}
end
def test_headerless
- gout = FObject["@out"]
+ gout = FO["@out"]
gout.send_in 0, "open grid file #{$imdir}/hello.txt"
gout.send_in 0, "headerless"
gout.send_in 0, "type uint8"
gout.send_in 0, "104 101 108 108 111 32 119 111 114 108 100 33 10"
gout.send_in 0, "close"
- gin = FObject["@in"]
- pr = FObject["@print"]
+ gin = FO["@in"]
+ pr = FO["@print"]
gin.connect 0,pr,0
gin.send_in 0, "open grid file #{$imdir}/hello.txt"
gin.send_in 0, "headerless 13"
@@ -831,14 +811,14 @@ end
def test_sound
-# o2 = FObject["@ * 359"] # @ 439.775 Hz
-# o1 = FObject["@for 0 44100 1"] # 1 sec @ 1.225 Hz ?
- o1 = FObject["@for 0 4500 1"]
- o2 = FObject["@ * 1600"] # @ 439.775 Hz
- o3 = FObject["@ sin* 255"]
- o4 = FObject["@ gamma 400"]
- o5 = FObject["@ << 7"]
- out = FObject["@out"]
+# o2 = FO["@ * 359"] # @ 439.775 Hz
+# o1 = FO["@for 0 44100 1"] # 1 sec @ 1.225 Hz ?
+ o1 = FO["@for 0 4500 1"]
+ o2 = FO["@ * 1600"] # @ 439.775 Hz
+ o3 = FO["@ sin* 255"]
+ o4 = FO["@ gamma 400"]
+ o5 = FO["@ << 7"]
+ out = FO["@out"]
o1.connect 0,o2,0
o2.connect 0,o3,0
o3.connect 0,o4,0
@@ -857,29 +837,29 @@ end
include Math
def test_polygon
- o1 = FObject["@for 0 5 1"]
- o2 = FObject["@ * 14400"]
- o3 = FObject["@outer + {0 9000}"]
- o4 = FObject["@ +"]
- o5 = FObject["@ cos* 112"]
- o6 = FObject["@ + {120 160}"]
- poly = FObject["@draw_polygon + {3 uint8 # 255}"]
+ o1 = FO["@for 0 5 1"]
+ o2 = FO["@ * 14400"]
+ o3 = FO["@outer + {0 9000}"]
+ o4 = FO["@ +"]
+ o5 = FO["@ cos* 112"]
+ o6 = FO["@ + {120 160}"]
+ poly = FO["@draw_polygon + {3 uint8 # 255}"]
if false
- out1 = FObject["@cast int32"]
- out2 = FObject["@solarize"]
-# out1 = FObject["@downscale_by 2 smoothly"]
- out3 = FObject["@out x11"]
+ out1 = FO["@cast int32"]
+ out2 = FO["@solarize"]
+# out1 = FO["@downscale_by 2 smoothly"]
+ out3 = FO["@out x11"]
out1.connect 0,out2,0
out2.connect 0,out3,0
else
- out1 = FObject["@out x11"]
- fps = FObject["fps detailed cpu"]
+ out1 = FO["@out x11"]
+ fps = FO["fps detailed cpu"]
out1.connect 0,fps,0
- pr = FObject["rubyprint"]
+ pr = FO["rubyprint"]
fps.connect 0,pr,0
end
- store = FObject["@store"]; store.send_in 1, "240 320 3 uint8 # 0"
-# store2 = FObject["@store"]
+ store = FO["@store"]; store.send_in 1, "240 320 3 uint8 # 0"
+# store2 = FO["@store"]
store.connect 0,poly,0
poly.connect 0,store,1
# store2.connect 0,store,1
@@ -889,7 +869,7 @@ end
o4.connect 0,o5,0
o5.connect 0,o6,0
o6.connect 0,poly,2
-# cast = FObject["@cast int32"]
+# cast = FO["@cast int32"]
# poly.connect 0,cast,0
# cast.connect 0,out1,0
poly.connect 0,out1,0
@@ -910,7 +890,7 @@ end
$mainloop.loop
end
-class FRoute2 < FObject
+class FRoute2 < FO
def initialize(selector)
@selector = selector.to_s
end
@@ -924,15 +904,15 @@ class FRoute2 < FObject
end
def test_aalib
-# gin = FObject["@in ppm file #{$imdir}/r001.jpg"]
- gin = FObject["@in ppm file #{$animdir}/b.jpg.cat"]
- grey = FObject["@rgb_to_greyscale"]
- cont = FObject["@ << 1"]
- clip = FObject["@ min 255"]
- gout = FObject["@out aalib X11"]
- sto = FObject["@store"]
- op = FObject["aa_fill_with_text {localhost 4242}"]
- filt = FObject["route2 grid"]
+# gin = FO["@in ppm file #{$imdir}/r001.jpg"]
+ gin = FO["@in ppm file #{$animdir}/b.jpg.cat"]
+ grey = FO["@rgb_to_greyscale"]
+ cont = FO["@ << 1"]
+ clip = FO["@ min 255"]
+ gout = FO["@out aalib X11"]
+ sto = FO["@store"]
+ op = FO["aa_fill_with_text {localhost 4242}"]
+ filt = FO["route2 grid"]
gin.connect 0,grey,0
grey.connect 0,cont,0
cont.connect 0,clip,0
@@ -956,14 +936,14 @@ end
def test_store2
o = [
- FObject["@for {0 0} {240 320} {1 1}"],
- FObject["@ / 2"],
- FObject["@ + 0"],
- FObject["@ + 0"],
- FObject["@store"],
- FObject["@out x11"]]
+ FO["@for {0 0} {240 320} {1 1}"],
+ FO["@ / 2"],
+ FO["@ + 0"],
+ FO["@ + 0"],
+ FO["@store"],
+ FO["@out x11"]]
(0..4).each {|x| o[x].connect 0,o[x+1],0 }
- q = FObject["@in ppm file images/r001.jpg"]
+ q = FO["@in ppm file images/r001.jpg"]
q.connect 0,o[4],1
q.send_in 0
o[0].send_in 0
@@ -971,12 +951,12 @@ def test_store2
end
def test_remap
- rem = FObject["@remap_image"]
- rot = FObject["@rotate 4000"]
+ rem = FO["@remap_image"]
+ rot = FO["@rotate 4000"]
rem.connect 1,rot,0
rot.connect 0,rem,1
- gin = FObject["@in ppm file #{$imdir}/teapot.png"]
- gout = FObject["@out x11"]
+ gin = FO["@in ppm file #{$imdir}/teapot.png"]
+ gout = FO["@out x11"]
gin.connect 0,rem,0
rem.connect 0,gout,0
gin.send_in 0
@@ -985,15 +965,15 @@ end
def test_asm
GridFlow.verbose=false
- a = FObject["@in ppm file images/r001.jpg"]
- aa = FObject["@cast uint8"]
- b = FObject["@store"]
- d = FObject["@store"]
+ a = FO["@in ppm file images/r001.jpg"]
+ aa = FO["@cast uint8"]
+ b = FO["@store"]
+ d = FO["@store"]
a.connect 0,aa,0
aa.connect 0,b,1
aa.connect 0,d,1
a.send_in 0
- c = FObject["@ + {uint8 # 0}"]
+ c = FO["@ + {uint8 # 0}"]
t0 = Time.new; 1000.times {b.send_in 0}; t1 = Time.new-t0
t1 *= 1
b.connect 0,c,0
@@ -1021,17 +1001,17 @@ def test_metro
end
def test_outer
- o = FObject["@outer + {0}"]
+ o = FO["@outer + {0}"]
o.send_in 0, 25, 240, 320, 3, "#".intern, 42
- g = FObject["@global"]
+ g = FO["@global"]
g.send_in 0, :profiler_dump
end
def test_jmax_to_pd filename
require "gridflow/extra/jmax_format.rb"
require "gridflow/extra/puredata_format.rb"
- jfr = JMaxFileReader.new(File.open(filename),FObject)
- FObject.broken_ok = true
+ jfr = JMaxFileReader.new(File.open(filename),FO)
+ FO.broken_ok = true
my_patcher = jfr.parse
# my_patcher.subobjects.each {|x,| x.trigger if LoadBang===x }
# $mainloop.loop
@@ -1045,7 +1025,7 @@ def test_jmax_to_pd filename
end
def test_error
- x = FObject["@store"]
+ x = FO["@store"]
x.send_in 0
end
@@ -1084,3 +1064,11 @@ end
#test_sound
#test_metro
#$mainloop.loop
+
+=begin
+a = FO["@print"]
+a.send_in 0, "3 3 #{nt} # 1 0 0 0"
+a.send_in 0, "3 3 3 #{nt} # 1 2 3 4"
+a.send_in 0, "base 16"
+a.send_in 0, "3 3 3 #{nt} # 255 0 0 0"
+=end