picrin/src/value.c

59 lines
753 B
C
Raw Normal View History

2013-10-12 05:46:41 -04:00
#include <stdlib.h>
2013-10-10 04:05:58 -04:00
#include "picrin.h"
2013-10-10 04:48:01 -04:00
enum pic_tt
pic_type(pic_value v)
{
2013-10-10 04:54:35 -04:00
switch (v.type) {
2013-10-10 04:48:01 -04:00
case PIC_VTYPE_NIL:
return PIC_TT_NIL;
case PIC_VTYPE_FLOAT:
return PIC_TT_FLOAT;
2013-10-12 01:40:01 -04:00
case PIC_VTYPE_UNDEF:
return PIC_TT_UNDEF;
2013-10-10 04:48:01 -04:00
case PIC_VTYPE_HEAP:
2013-10-10 04:54:35 -04:00
return ((struct pic_object *)v.u.data)->tt;
2013-10-10 04:48:01 -04:00
}
}
2013-10-10 04:08:54 -04:00
pic_value
pic_nil_value()
{
pic_value v;
2013-10-10 04:54:35 -04:00
v.type = PIC_VTYPE_NIL;
2013-10-10 04:08:54 -04:00
v.u.data = NULL;
return v;
}
2013-10-10 04:05:58 -04:00
pic_value
2013-10-10 04:54:35 -04:00
pic_obj_value(void *ptr)
2013-10-10 04:05:58 -04:00
{
pic_value v;
2013-10-10 04:54:35 -04:00
v.type = PIC_VTYPE_HEAP;
v.u.data = ptr;
2013-10-10 04:05:58 -04:00
return v;
}
2013-10-11 11:15:46 -04:00
pic_value
pic_float_value(double f)
2013-10-11 11:15:46 -04:00
{
pic_value v;
v.type = PIC_VTYPE_FLOAT;
v.u.f = f;
2013-10-11 11:15:46 -04:00
return v;
}
2013-10-12 01:40:01 -04:00
pic_value
pic_undef_value()
{
pic_value v;
v.type = PIC_VTYPE_UNDEF;
v.u.data = NULL;
return v;
}