Logo

dev-resources.site

for different kinds of informations.

SPVM now supports object-oriented programming in Perl

Published at
3/10/2023
Categories
perl
spvm
Author
yukikimoto
Categories
2 categories in total
perl
open
spvm
open
Author
10 person written this
yukikimoto
open
SPVM now supports object-oriented programming in Perl

SPVM now supports object-oriented programming in Perl.

One of the goals of SPVM is to realize object-oriented programming in Perl as a statically-typed language.

To achieve this, it was necessary to understand object-oriented programming in Perl properly, and then to see how it could be realized in a statically-typed language, through a number of implementations.

The first challenge is that no one knows if it can be done, because no programming language has ever realized Perl's object-oriented programming in a statically-typed language.

It is a task that we do not even know if we can do.

We were getting close to Perl's object-oriented way of doing things, but there was a lot of trial and error and backward-compatibility breaking.

Last Saturday and Sunday, I came up with the final piece that would make SPVM object-oriented in Perl. And that is what I implemented this Monday. Then I applied it to SPVM::File::Spec and SPVM::IO.

Please read the source code and you will see that SPVM's object orientation can be described in exactly the same way as Perl's object orientation.

Overview of SPVM's object orientation

To understand SPVM's object orientation, Point3D and Point are good examples. Class::Accessor(::Fast), Moose/Moo-based implementations, Mojo::Base implementations, and implementations using bless. My personal feeling is that 90% of the time, these are the easiest to port to SPVM.

class Point {
  # Interfaces
  interface Stringable;
  interface Cloneable;

  # Fields
  has x : rw protected int;
  has y : rw protected int;

  # Class methods
  static method new : Point ($x = 0 : int, $y = 0 : int) {
    my $self = new Point;

    $self->init($x, $y);

    return $self;
  }

  # Instance methods
  protected method init : Point ($x = 0 : int, $y = 0 : int) {
    $self->{x} = $x;
    $self->{y} = $y;
  }

  method clear : void () {
    $self->{x} = 0;
    $self->{y} = 0;
  }

  method clone : Point () {
    my $self_clone = Point->new($self->x, $self->y);

    return $self_clone;
  }

  method to_string : string () {
    my $x = $self->x;
    my $y = $self->y;

    my $string = "($x,$y)";

    return $string;
  }
}

class Point3D extends Point {

  # Fields
  has z : rw protected int;

  # Class method
  static method new : Point3D ($x = 0 : int, $y = 0 : int, $z = 0 : int) {
    my $self = new Point3D;

    $self->init($x, $y, $z);

    return $self;
  }

  protected method init : Point3D ($x = 0 : int, $y = 0 : int, $z = 0 : int) {
    $self->SUPER::init($x, $y);
    $self->{z} = $z;
  }

  method clear : void () {
    $self->SUPER::clear;
    $self->{z} = 0;
  }

  method clone : Point3D () {
    my $self_clone = Point3D->new($self->x, $self->y, $self->z);

    return $self_clone;
  }

  method to_string : string () {
    my $x = $self->x;
    my $y = $self->y;
    my $z = $self->z;

    my $string = "($x,$y,$z)";

    return $string;
  }
}
Enter fullscreen mode Exit fullscreen mode

Symbolic Link Support

As we mentioned last week, this week we are working on a portable, symbolic link implementation that also works on Windows. You can see our progress here. To implement this, the Perl win32/win32.c source code would be greatly appreciated.

Once the symbolic links are working, we can achieve a great deal of portability between Windows/Linux/Mac. I look forward to implementing a browser that works on Windows/Mac/Linux/Android/iPhone/iPad with SPVM on top of this. My goal is to have a working game within 5 years.

Translated with www.DeepL.com/Translator (free version)

spvm Article's
30 articles in total
Favicon
How to create Mac GUI applications in SPVM?
Favicon
How to create a parallel echo server using goroutines in SPVM?
Favicon
How to generate an executable file for an AI program using SPVM ?
Favicon
SPVM::R - A Port of The R Language Features.
Favicon
SPVM::Resource::Eigen released
Favicon
SPVM Documentation
Favicon
How to use OpenMP from Perl with SPVM.
Favicon
How to use zlib (a C library) from Perl with SPVM
Favicon
SPVM::Digest::MD5 - MD5
Favicon
SPVM::MIME::Base64 - Base64 Encoding/Decoding
Favicon
SPVM::MIME::QuotedPrint - Quoted-Printable encoding/decoding
Favicon
SPVM::Math - Mathematical Functions
Favicon
SPVM
Favicon
SPVM::Sys now supports symbolic links on Windows, adds Perl-compatible API.
Favicon
SPVM now supports object-oriented programming in Perl
Favicon
First release of SPVM::Resource::RE2 Resourcing the regular expression library Google RE2
Favicon
First release of SPVM::File::Temp and SPVM::File::Find
Favicon
SPVM::File::Path and SPVM::File::Glob are newly released.
Favicon
First release of SPVM::File::Copy and SPVM::FindBin
Favicon
First release of SPVM::File::Spec - complex regular expressions, file tests, SPVM::Cwd, inheritance
Favicon
SPVM::File::Basename is released. This is the first module of SPVM using regular expressions.
Favicon
SPVM improved Exchange API at v0.9684. Welcome to this easy world of type conversion!
Favicon
SPVM supported self Compiler in 0.9683.
Favicon
SPVM 0.9680 is released
Favicon
SPVM 0.9677 is released
Favicon
SPVM 0.9676 is released
Favicon
SPVM 0.9672 is released
Favicon
SPVM 0.9670 is released
Favicon
SPVM 0.9669 is released
Favicon
SPVM 0.9668 is released

Featured ones: