Commit 7295f1a3 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

port vanilla symbol method for [float], add annotations for type oddities

parent 4b7b73cd
Pipeline #2129 passed with stage
in 412 minutes and 37 seconds
......@@ -44,7 +44,7 @@ t_blob *atom_getblob(t_atom *a) /* MP 20070108 */
else return (&st);
}
t_symbol *atom_gensym(t_atom *a) /* this works better for graph labels */
t_symbol *atom_gensym(t_atom *a) /* this works better for graph labels */
{
char buf[30];
if (a->a_type == A_SYMBOL) return (a->a_w.w_symbol);
......
......@@ -43,9 +43,45 @@ t_classtable *ct;
static t_symbol *class_extern_dir = &s_;
int symbol_can_float(t_symbol *s, t_float *f)
{
char c;
if (!s || s == &s_) return 0;
c = s->s_name[0];
if (c != '-' && c != '+' && c < 48 && c > 57) return 0;
char *str_end = NULL;
*f = strtod(s->s_name, &str_end);
/* Add error checking here like in cxc/hex2dec */
if (*f == 0 && s->s_name == str_end)
return 0;
return 1;
}
char *type_hint(t_symbol *s, int argc, t_atom *argv)
{
static char hint[MAXPDSTRING];
t_float f;
if (!s)
sprintf(hint, " (null selector detected)");
else if (s == &s_)
sprintf(hint, " (empty symbol selector)");
else if (s && s == &s_symbol && argc && argv->a_type == A_SYMBOL
&& argv->a_w.w_symbol == &s_)
sprintf(hint, " (empty symbol message detected)");
else if (symbol_can_float(s, &f))
sprintf(hint, " (%s is actually a symbol atom here)", s->s_name);
else if (symbol_can_float(atom_getsymbolarg(0, argc, argv), &f))
sprintf(hint, " (symbol message with floatlike payload detected."
" Did you mean 'float %s'?)", argv->a_w.w_symbol->s_name);
else
hint[0] = '\0';
return hint;
}
static void pd_defaultanything(t_pd *x, t_symbol *s, int argc, t_atom *argv)
{
pd_error(x, "%s: no method for '%s'", (*x)->c_name->s_name, s->s_name);
pd_error(x, "%s: no method for '%s'%s",
(*x)->c_name->s_name, s->s_name, type_hint(s, argc, argv));
}
static void pd_defaultbang(t_pd *x)
......
......@@ -72,10 +72,12 @@ t_inlet *signalinlet_new(t_object *owner, t_float f)
return (x);
}
static void inlet_wrong(t_inlet *x, t_symbol *s)
char *type_hint(t_symbol *s, int argc, t_atom *argv);
static void inlet_wrong(t_inlet *x, t_symbol *s, int argc, t_atom *argv)
{
pd_error(x->i_owner, "inlet: expected '%s' but got '%s'",
x->i_symfrom->s_name, s->s_name);
pd_error(x->i_owner, "inlet: expected '%s' but got '%s'%s",
x->i_symfrom->s_name, s->s_name, type_hint(s, argc, argv));
}
static void inlet_list(t_inlet *x, t_symbol *s, int argc, t_atom *argv);
......@@ -88,7 +90,7 @@ static void inlet_bang(t_inlet *x)
else if (!x->i_symfrom) pd_bang(x->i_dest);
else if (x->i_symfrom == &s_list)
inlet_list(x, &s_bang, 0, 0);
else inlet_wrong(x, &s_bang);
else inlet_wrong(x, &s_bang, 0, 0);
}
static void inlet_pointer(t_inlet *x, t_gpointer *gp)
......@@ -102,7 +104,7 @@ static void inlet_pointer(t_inlet *x, t_gpointer *gp)
SETPOINTER(&a, gp);
inlet_list(x, &s_pointer, 1, &a);
}
else inlet_wrong(x, &s_pointer);
else inlet_wrong(x, &s_pointer, 0, 0);
}
static void inlet_float(t_inlet *x, t_float f)
......@@ -119,7 +121,7 @@ static void inlet_float(t_inlet *x, t_float f)
SETFLOAT(&a, f);
inlet_list(x, &s_float, 1, &a);
}
else inlet_wrong(x, &s_float);
else inlet_wrong(x, &s_float, 0, 0);
}
static void inlet_symbol(t_inlet *x, t_symbol *s)
......@@ -127,13 +129,15 @@ static void inlet_symbol(t_inlet *x, t_symbol *s)
if (x->i_symfrom == &s_symbol)
pd_vmess(x->i_dest, x->i_symto, "s", s);
else if (!x->i_symfrom) pd_symbol(x->i_dest, s);
else if (x->i_symfrom == &s_list)
else
{
t_atom a;
SETSYMBOL(&a, s);
inlet_list(x, &s_symbol, 1, &a);
if (x->i_symfrom == &s_list)
inlet_list(x, &s_symbol, 1, &a);
else
inlet_wrong(x, &s_symbol, 1, &a);
}
else inlet_wrong(x, &s_symbol);
}
static void inlet_blob(t_inlet *x, t_blob *st) /* MP20061226 blob type */
......@@ -152,7 +156,7 @@ static void inlet_blob(t_inlet *x, t_blob *st) /* MP20061226 blob type */
else
{
/*post("inlet_blob calling inlet_wrong");*/
inlet_wrong(x, &s_blob);
inlet_wrong(x, &s_blob, 0, 0);
}
}
......@@ -168,7 +172,7 @@ static void inlet_list(t_inlet *x, t_symbol *s, int argc, t_atom *argv)
inlet_float(x, atom_getfloat(argv));
else if (argc==1 && argv->a_type == A_SYMBOL)
inlet_symbol(x, atom_getsymbol(argv));
else inlet_wrong(x, &s_list);
else inlet_wrong(x, &s_list, 0, 0);
}
static void inlet_anything(t_inlet *x, t_symbol *s, int argc, t_atom *argv)
......@@ -177,7 +181,7 @@ static void inlet_anything(t_inlet *x, t_symbol *s, int argc, t_atom *argv)
typedmess(x->i_dest, x->i_symto, argc, argv);
else if (!x->i_symfrom)
typedmess(x->i_dest, s, argc, argv);
else inlet_wrong(x, s);
else inlet_wrong(x, s, 0, 0);
}
void inlet_free(t_inlet *x)
......
......@@ -8,6 +8,7 @@
#include <string.h>
#include <stdio.h>
extern t_pd *newest;
/* -------------------------- int ------------------------------ */
......@@ -85,6 +86,24 @@ static void pdfloat_float(t_pdfloat *x, t_float f)
outlet_float(x->x_obj.ob_outlet, x->x_f = f);
}
int symbol_can_float(t_symbol *s, t_float *f);
char *type_hint(t_symbol *s, int argc, t_atom *argv);
static void pdfloat_symbol(t_pdfloat *x, t_symbol *s)
{
t_float f;
if (symbol_can_float(s, &f))
outlet_float(x->x_obj.ob_outlet, x->x_f = f);
else
{
t_atom at;
SETSYMBOL(&at, s);
pd_error(x, "couldn't convert %s to float%s",
s->s_name, type_hint(&s_symbol, 1, &at));
}
}
void pdfloat_setup(void)
{
pdfloat_class = class_new(gensym("float"), (t_newmethod)pdfloat_new, 0,
......@@ -92,6 +111,7 @@ void pdfloat_setup(void)
class_addcreator((t_newmethod)pdfloat_new2, gensym("f"), A_DEFFLOAT, 0);
class_addbang(pdfloat_class, pdfloat_bang);
class_addfloat(pdfloat_class, (t_method)pdfloat_float);
class_addsymbol(pdfloat_class, (t_method)pdfloat_symbol);
}
/* -------------------------- symbol ------------------------------ */
......
#N canvas 126 96 749 571 12;
#N canvas 95 38 749 571 12;
#X obj 465 281 r \$0-result;
#X obj 212 239 bng 31 250 50 0 empty empty Run_all 39 13 0 12 -262144
-1 -1;
......@@ -52,6 +52,7 @@ is handy for some binbuf tests.;
#X obj 127 172 print Done;
#X obj 198 1701 rtest wrap~_compatibility_bug;
#X obj 198 1756 rtest select_bang;
#X obj 198 1811 rtest float_symbol_method;
#X connect 0 0 27 0;
#X connect 1 0 4 0;
#X connect 2 0 42 0;
......@@ -89,3 +90,4 @@ is handy for some binbuf tests.;
#X connect 42 3 3 0;
#X connect 43 0 44 0;
#X connect 45 0 46 0;
#X connect 46 0 47 0;
#N canvas 43 89 962 524 12;
#X obj 94 24 inlet;
#X obj 355 123 unpost;
#X obj 424 227 float;
#X obj 280 93 trigger bang bang bang;
#X obj 330 188 list;
#X obj 94 53 trigger bang bang;
#X obj 330 217 list length;
#X obj 238 258 symbol;
#X obj 169 193 unpost;
#X obj 238 297 float;
#X obj 94 163 trigger bang bang bang;
#X obj 144 258 list;
#X obj 144 287 list length;
#X obj 424 188 makefilename %d;
#X msg 424 158 42;
#X obj 330 279 list append sending a symbol message with a numeric
payload to [float] should trigger a conversion to float;
#X obj 144 329 list append sending a symbol message with a non-numeric
payload to [float] should cause an error;
#X obj 144 444 outlet;
#X obj 330 246 == 0;
#X connect 0 0 5 0;
#X connect 1 0 4 1;
#X connect 1 1 14 0;
#X connect 3 0 4 0;
#X connect 3 1 1 0;
#X connect 3 2 4 1;
#X connect 4 0 6 0;
#X connect 5 0 10 0;
#X connect 5 1 3 0;
#X connect 6 0 18 0;
#X connect 7 0 9 0;
#X connect 8 0 11 1;
#X connect 8 1 7 0;
#X connect 10 0 11 0;
#X connect 10 1 8 0;
#X connect 10 2 11 1;
#X connect 11 0 12 0;
#X connect 12 0 16 0;
#X connect 13 0 2 0;
#X connect 14 0 13 0;
#X connect 15 0 17 0;
#X connect 16 0 17 0;
#X connect 18 0 15 0;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment