This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implement P6int/P6num/P6str reprs so far as they are in the .Net vers…
…ion of 6model and add them to the build.
- Loading branch information
Showing
5 changed files
with
468 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| /* This is the implementation of the P6int representation, which holds a native | ||
| * integer. */ | ||
|
|
||
| #define PARROT_IN_EXTENSION | ||
| #include "parrot/parrot.h" | ||
| #include "parrot/extend.h" | ||
| #include "../rakudoobject.h" | ||
| #include "P6int.h" | ||
|
|
||
| /* Creates a new type object of this representation, and associates it with | ||
| * the given HOW. */ | ||
| static PMC * type_object_for(PARROT_INTERP, PMC *self, PMC *HOW) { | ||
| /* Create new object instance. */ | ||
| P6intInstance *obj = mem_allocate_zeroed_typed(P6intInstance); | ||
|
|
||
| /* Build an STable. */ | ||
| PMC *st_pmc = create_stable(interp, self, HOW); | ||
| STable *st = STABLE_STRUCT(st_pmc); | ||
|
|
||
| /* Create type object and point it back at the STable. */ | ||
| st->WHAT = wrap_object(interp, obj); | ||
| obj->common.stable = st_pmc; | ||
|
|
||
| return st->WHAT; | ||
| } | ||
|
|
||
| /* Creates a new instance based on the type object. */ | ||
| static PMC * instance_of(PARROT_INTERP, PMC *self, PMC *WHAT) { | ||
| P6intInstance *obj = mem_allocate_zeroed_typed(P6intInstance); | ||
| obj->common.stable = STABLE_PMC(WHAT); | ||
| obj->value = 0; | ||
| return wrap_object(interp, obj); | ||
| } | ||
|
|
||
| /* Checks if a given object is defined (from the point of view of the | ||
| * representation). */ | ||
| static INTVAL defined(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| /* Native types cannot be undefined. */ | ||
| return 1; | ||
| } | ||
|
|
||
| /* Gets the current value for an attribute. */ | ||
| static PMC * get_attribute(PARROT_INTERP, PMC *self, PMC *obj, PMC *class_handle, STRING *name) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6int does not support attribute storage"); | ||
| } | ||
|
|
||
| /* Gets the current value for an attribute, obtained using the given hint.*/ | ||
| static PMC * get_attribute_with_hint(PARROT_INTERP, PMC *self, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6int does not support attribute storage"); | ||
| } | ||
|
|
||
| /* Binds the given value to the specified attribute. */ | ||
| static void bind_attribute(PARROT_INTERP, PMC *self, PMC *obj, PMC *class_handle, STRING *name, PMC *value) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6int does not support attribute storage"); | ||
| } | ||
|
|
||
| /* Binds the given value to the specified attribute, using the given hint. */ | ||
| static void bind_attribute_with_hint(PARROT_INTERP, PMC *self, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6int does not support attribute storage"); | ||
| } | ||
|
|
||
| /* Gets the hint for the given attribute ID. */ | ||
| static INTVAL hint_for(PARROT_INTERP, PMC *self, PMC *class_handle, STRING *name) { | ||
| return NO_HINT; | ||
| } | ||
|
|
||
| /* Used with boxing. Sets an integer value, for representations that can hold | ||
| * one. */ | ||
| static void set_int(PARROT_INTERP, PMC *self, PMC *obj, INTVAL value) { | ||
| ((P6intInstance *)PMC_data(obj))->value = value; | ||
| } | ||
|
|
||
| /* Used with boxing. Gets an integer value, for representations that can | ||
| * hold one. */ | ||
| static INTVAL get_int(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| return ((P6intInstance *)PMC_data(obj))->value; | ||
| } | ||
|
|
||
| /* Used with boxing. Sets a floating point value, for representations that can | ||
| * hold one. */ | ||
| static void set_num(PARROT_INTERP, PMC *self, PMC *obj, FLOATVAL value) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6int cannot box a native num"); | ||
| } | ||
|
|
||
| /* Used with boxing. Gets a floating point value, for representations that can | ||
| * hold one. */ | ||
| static FLOATVAL get_num(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6int cannot unbox to a native num"); | ||
| } | ||
|
|
||
| /* Used with boxing. Sets a string value, for representations that can hold | ||
| * one. */ | ||
| static void set_str(PARROT_INTERP, PMC *self, PMC *obj, STRING *value) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6int cannot box a native string"); | ||
| } | ||
|
|
||
| /* Used with boxing. Gets a string value, for representations that can hold | ||
| * one. */ | ||
| static STRING * get_str(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6int cannot unbox to a native string"); | ||
| } | ||
|
|
||
| /* This Parrot-specific addition to the API is used to mark an object. */ | ||
| static void gc_mark(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| P6intInstance *instance = (P6intInstance *)PMC_data(obj); | ||
| if (!PMC_IS_NULL(instance->common.stable)) | ||
| Parrot_gc_mark_PMC_alive(interp, instance->common.stable); | ||
| } | ||
|
|
||
| /* This Parrot-specific addition to the API is used to free an object. */ | ||
| static void gc_free(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| mem_sys_free(PMC_data(obj)); | ||
| PMC_data(obj) = NULL; | ||
| } | ||
|
|
||
| /* Initializes the P6int representation. */ | ||
| PMC * P6int_initialize(PARROT_INTERP) { | ||
| REPRCommonalities *repr; | ||
| PMC *repr_pmc; | ||
|
|
||
| /* Allocate and populate the representation function table. */ | ||
| repr = mem_allocate_typed(REPRCommonalities); | ||
| repr->type_object_for = type_object_for; | ||
| repr->instance_of = instance_of; | ||
| repr->defined = defined; | ||
| repr->get_attribute = get_attribute; | ||
| repr->get_attribute_with_hint = get_attribute_with_hint; | ||
| repr->bind_attribute = bind_attribute; | ||
| repr->bind_attribute_with_hint = bind_attribute_with_hint; | ||
| repr->hint_for = hint_for; | ||
| repr->set_int = set_int; | ||
| repr->get_int = get_int; | ||
| repr->set_num = set_num; | ||
| repr->get_num = get_num; | ||
| repr->set_str = set_str; | ||
| repr->get_str = get_str; | ||
| repr->gc_mark = gc_mark; | ||
| repr->gc_free = gc_free; | ||
|
|
||
| /* Wrap it in a PMC. */ | ||
| return wrap_repr(interp, repr); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| /* This is the implementation of the P6num representation, which holds a native | ||
| * floating point number. */ | ||
|
|
||
| #define PARROT_IN_EXTENSION | ||
| #include "parrot/parrot.h" | ||
| #include "parrot/extend.h" | ||
| #include "../rakudoobject.h" | ||
| #include "P6num.h" | ||
|
|
||
| /* Creates a new type object of this representation, and associates it with | ||
| * the given HOW. */ | ||
| static PMC * type_object_for(PARROT_INTERP, PMC *self, PMC *HOW) { | ||
| /* Create new object instance. */ | ||
| P6numInstance *obj = mem_allocate_zeroed_typed(P6numInstance); | ||
|
|
||
| /* Build an STable. */ | ||
| PMC *st_pmc = create_stable(interp, self, HOW); | ||
| STable *st = STABLE_STRUCT(st_pmc); | ||
|
|
||
| /* Create type object and point it back at the STable. */ | ||
| st->WHAT = wrap_object(interp, obj); | ||
| obj->common.stable = st_pmc; | ||
|
|
||
| return st->WHAT; | ||
| } | ||
|
|
||
| /* Creates a new instance based on the type object. */ | ||
| static PMC * instance_of(PARROT_INTERP, PMC *self, PMC *WHAT) { | ||
| P6numInstance *obj = mem_allocate_zeroed_typed(P6numInstance); | ||
| obj->common.stable = STABLE_PMC(WHAT); | ||
| obj->value = 0.0; | ||
| return wrap_object(interp, obj); | ||
| } | ||
|
|
||
| /* Checks if a given object is defined (from the point of view of the | ||
| * representation). */ | ||
| static INTVAL defined(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| /* Native types cannot be undefined. */ | ||
| return 1; | ||
| } | ||
|
|
||
| /* Gets the current value for an attribute. */ | ||
| static PMC * get_attribute(PARROT_INTERP, PMC *self, PMC *obj, PMC *class_handle, STRING *name) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6num does not support attribute storage"); | ||
| } | ||
|
|
||
| /* Gets the current value for an attribute, obtained using the given hint.*/ | ||
| static PMC * get_attribute_with_hint(PARROT_INTERP, PMC *self, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6num does not support attribute storage"); | ||
| } | ||
|
|
||
| /* Binds the given value to the specified attribute. */ | ||
| static void bind_attribute(PARROT_INTERP, PMC *self, PMC *obj, PMC *class_handle, STRING *name, PMC *value) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6num does not support attribute storage"); | ||
| } | ||
|
|
||
| /* Binds the given value to the specified attribute, using the given hint. */ | ||
| static void bind_attribute_with_hint(PARROT_INTERP, PMC *self, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6num does not support attribute storage"); | ||
| } | ||
|
|
||
| /* Gets the hint for the given attribute ID. */ | ||
| static INTVAL hint_for(PARROT_INTERP, PMC *self, PMC *class_handle, STRING *name) { | ||
| return NO_HINT; | ||
| } | ||
|
|
||
| /* Used with boxing. Sets an integer value, for representations that can hold | ||
| * one. */ | ||
| static void set_int(PARROT_INTERP, PMC *self, PMC *obj, INTVAL value) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6num cannot box a native int"); | ||
| } | ||
|
|
||
| /* Used with boxing. Gets an integer value, for representations that can | ||
| * hold one. */ | ||
| static INTVAL get_int(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6num cannot unbox to a native int"); | ||
| } | ||
|
|
||
| /* Used with boxing. Sets a floating point value, for representations that can | ||
| * hold one. */ | ||
| static void set_num(PARROT_INTERP, PMC *self, PMC *obj, FLOATVAL value) { | ||
| ((P6numInstance *)PMC_data(obj))->value = value; | ||
| } | ||
|
|
||
| /* Used with boxing. Gets a floating point value, for representations that can | ||
| * hold one. */ | ||
| static FLOATVAL get_num(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| return ((P6numInstance *)PMC_data(obj))->value; | ||
| } | ||
|
|
||
| /* Used with boxing. Sets a string value, for representations that can hold | ||
| * one. */ | ||
| static void set_str(PARROT_INTERP, PMC *self, PMC *obj, STRING *value) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6num cannot box a native string"); | ||
| } | ||
|
|
||
| /* Used with boxing. Gets a string value, for representations that can hold | ||
| * one. */ | ||
| static STRING * get_str(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, | ||
| "P6num cannot unbox to a native string"); | ||
| } | ||
|
|
||
| /* This Parrot-specific addition to the API is used to mark an object. */ | ||
| static void gc_mark(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| P6numInstance *instance = (P6numInstance *)PMC_data(obj); | ||
| if (!PMC_IS_NULL(instance->common.stable)) | ||
| Parrot_gc_mark_PMC_alive(interp, instance->common.stable); | ||
| } | ||
|
|
||
| /* This Parrot-specific addition to the API is used to free an object. */ | ||
| static void gc_free(PARROT_INTERP, PMC *self, PMC *obj) { | ||
| mem_sys_free(PMC_data(obj)); | ||
| PMC_data(obj) = NULL; | ||
| } | ||
|
|
||
| /* Initializes the P6num representation. */ | ||
| PMC * P6num_initialize(PARROT_INTERP) { | ||
| REPRCommonalities *repr; | ||
| PMC *repr_pmc; | ||
|
|
||
| /* Allocate and populate the representation function table. */ | ||
| repr = mem_allocate_typed(REPRCommonalities); | ||
| repr->type_object_for = type_object_for; | ||
| repr->instance_of = instance_of; | ||
| repr->defined = defined; | ||
| repr->get_attribute = get_attribute; | ||
| repr->get_attribute_with_hint = get_attribute_with_hint; | ||
| repr->bind_attribute = bind_attribute; | ||
| repr->bind_attribute_with_hint = bind_attribute_with_hint; | ||
| repr->hint_for = hint_for; | ||
| repr->set_int = set_int; | ||
| repr->get_int = get_int; | ||
| repr->set_num = set_num; | ||
| repr->get_num = get_num; | ||
| repr->set_str = set_str; | ||
| repr->get_str = get_str; | ||
| repr->gc_mark = gc_mark; | ||
| repr->gc_free = gc_free; | ||
|
|
||
| /* Wrap it in a PMC. */ | ||
| return wrap_repr(interp, repr); | ||
| } |
Oops, something went wrong.