1. my class Metamodel::Primitives {
  2. method create_type(Mu $how, $repr = 'P6opaque') {
  3. nqp::newtype($how, $repr.Str)
  4. }
  5. method set_package(Mu $type, $package) {
  6. nqp::setwho(nqp::decont($type), nqp::decont($package));
  7. $type
  8. }
  9. method install_method_cache(Mu $type, %cache, :$authoritative = True) {
  10. my Mu $cache := nqp::hash();
  11. for %cache.kv -> $name, $meth {
  12. nqp::bindkey($cache, $name, nqp::decont($meth));
  13. }
  14. nqp::setmethcache($type, $cache);
  15. nqp::setmethcacheauth($type, $authoritative ?? 1 !! 0);
  16. $type
  17. }
  18. method configure_type_checking(Mu $type, @cache, :$authoritative = True, :$call_accepts = False) {
  19. my Mu $cache := nqp::list();
  20. for @cache {
  21. nqp::push($cache, nqp::decont($_));
  22. }
  23. nqp::settypecache($type, $cache);
  24. nqp::settypecheckmode($type,
  25. ($authoritative ?? 0 !! 1) + ($call_accepts ?? 2 !! 0));
  26. $type
  27. }
  28. method configure_destroy(Mu $type, $destroy) {
  29. nqp::settypefinalize($type, $destroy ?? 1 !! 0);
  30. $type
  31. }
  32. method compose_type(Mu $type, $configuration) {
  33. multi sub to_vm_types(@array) {
  34. my Mu $list := nqp::list();
  35. for @array {
  36. nqp::push($list, to_vm_types($_));
  37. }
  38. $list
  39. }
  40. multi sub to_vm_types(%hash) {
  41. my Mu $hash := nqp::hash();
  42. for %hash.kv -> $k, $v {
  43. nqp::bindkey($hash, $k, to_vm_types($v));
  44. }
  45. $hash
  46. }
  47. multi sub to_vm_types($other) {
  48. nqp::decont($other)
  49. }
  50. nqp::composetype(nqp::decont($type), to_vm_types($configuration));
  51. $type
  52. }
  53. method rebless(Mu $obj, Mu $type) {
  54. nqp::rebless($obj, $type)
  55. }
  56. method is_type(Mu \obj, Mu \type) {
  57. nqp::p6bool(nqp::istype(obj, type))
  58. }
  59. }