1. my constant $?COMPILATION-ID :=
  2. nqp::sha1(nqp::concat(
  3. $*W.handle,
  4. nqp::getcomp('perl6').compilation-id
  5. ));
  6. class VM does Systemic {
  7. has $.config;
  8. has $.prefix;
  9. has $.precomp-ext;
  10. has $.precomp-target;
  11. has $.precomp-dir;
  12. submethod BUILD(
  13. :$!config,
  14. :$!desc = Str,
  15. --> Nil
  16. ) {
  17. $!name = 'moar';
  18. $!auth = "The MoarVM Team";
  19. $!version = Version.new($!config<version> // "unknown");
  20. $!prefix = $!config<prefix>;
  21. $!precomp-ext = "moarvm";
  22. $!precomp-target = "mbc";
  23. $!precomp-dir = $!prefix ~ '/' ~ '.precomp' ~ '/' ~ $?COMPILATION-ID;
  24. # add new backends here please
  25. }
  26. method platform-library-name(IO::Path $library, Version :$version) {
  27. my int $is-win = Rakudo::Internals.IS-WIN;
  28. my int $is-darwin = $*VM.config<osname> eq 'darwin';
  29. my $basename = $library.basename;
  30. my int $full-path = $library ne $basename;
  31. my $dirname = $library.dirname;
  32. # OS X needs version before extension
  33. $basename ~= ".$version" if $is-darwin && $version.defined;
  34. my $dll = self.config<dll>;
  35. my $platform-name = sprintf($dll, $basename);
  36. $platform-name ~= '.' ~ $version
  37. if $version.defined and nqp::iseq_i(nqp::add_i($is-darwin,$is-win),0);
  38. $full-path
  39. ?? $dirname.IO.child($platform-name).abspath
  40. !! $platform-name.IO
  41. }
  42. }
  43. sub INITIALIZE-A-VM-NOW() {
  44. my $desc := DateTime.now.Str;
  45. VM.new(:config(nqp::backendconfig),:$desc);
  46. }
  47. Rakudo::Internals.REGISTER-DYNAMIC: '$*VM', {
  48. PROCESS::<$VM> := INITIALIZE-A-VM-NOW();
  49. }