implement native record
native record primitives are defined in (picrin record-primitive) - (make-record rectype) - (record-of? record rectype) - (record-ref record rectype field-name) - (record-set! record rectype field-name value) define-record-type is defined using these primitives
This commit is contained in:
committed by
Yuito Murase
parent
2f44145d3e
commit
c76dfcb861
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* See Copyright Notice in picrin.h
|
||||
*/
|
||||
|
||||
#ifndef PICRIN_RECORD_H
|
||||
#define PICRIN_RECORD_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct pic_record {
|
||||
PIC_OBJECT_HEADER
|
||||
pic_value rectype;
|
||||
xhash hash;
|
||||
};
|
||||
|
||||
#define pic_record_p(v) (pic_type(v) == PIC_TT_RECORD)
|
||||
#define pic_record_ptr(v) ((struct pic_record *)pic_ptr(v))
|
||||
|
||||
struct pic_record *pic_record_new(pic_state *, pic_value);
|
||||
|
||||
bool pic_record_of(pic_state *, struct pic_record *, pic_value);
|
||||
pic_value pic_record_ref(pic_state *, struct pic_record *, pic_value, pic_sym);
|
||||
void pic_record_set(pic_state *, struct pic_record *, pic_value, pic_sym, pic_value);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -115,7 +115,8 @@ enum pic_tt {
|
||||
PIC_TT_VAR,
|
||||
PIC_TT_IREP,
|
||||
PIC_TT_DATA,
|
||||
PIC_TT_DICT
|
||||
PIC_TT_DICT,
|
||||
PIC_TT_RECORD
|
||||
};
|
||||
|
||||
#define PIC_OBJECT_HEADER \
|
||||
@@ -268,6 +269,8 @@ pic_type_repr(enum pic_tt tt)
|
||||
return "data";
|
||||
case PIC_TT_DICT:
|
||||
return "dict";
|
||||
case PIC_TT_RECORD:
|
||||
return "record";
|
||||
}
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user