SPVM::N...ompiler(3)
πΈ Name
SPVM::Native::Compiler β Native::Compiler. Okay bestie, this is the SPVM::Native::Compiler(3) manual page from User Contributed Perl Documentation, and we're about to get into it. π
β¨ Description
SPVM::Native::Compiler is the Native::Compiler class in the SPVM language. It compiles SPVM source codes and builds the runtime. The instance of the Native::Runtime class gets built by the get_runtime method in this class β main character behavior. β¨
π Usage
Here's the usage moment, verbatim:
use Native::Compiler;
my $compiler = Native::Compiler->new;
$compiler->add_include_dir("lib");
$compiler->set_start_file(__FILE__);
{
my $basic_type_name = "Foo";
$compiler->set_start_line(__LINE__ + 1);
$compiler->compile($basic_type_name);
}
{
my $basic_type_name = "Bar";
$compiler->set_start_line(__LINE__ + 1);
$compiler->compile($basic_type_name);
}
my $runtime = $compiler->get_runtime;
π¦ Pointer
The Native::Compiler class is a pointer class. Its insntace has a pointer to a compiler object. That's the pointer tea. π«Ά
π Class Methods
π new
static method new : Native::Compiler ();
Creates a new Native::Compiler object and returns it. Iconic constructor moment. π
π Instance Methods
get_include_dirs_length
method get_include_dirs_length : int ();
Returns the length of the class search directories. Counting the search dirs, no cap.
get_include_dir
method get_include_dir : string ($index : int);
Returns a class search directory at the index $index.
add_include_dir
method add_include_dir : void ($include_dir : string);
Adds a class search directory at the tail of the current class search directories.
prepend_include_dir
method prepend_include_dir : void ($include_dir : string);
Adds a class search directory at the head of the current class search directories.
clear_include_dirs
method clear_include_dirs : void ();
Removes all class search directories. Poof, gone. π
set_start_file
method set_start_file : void ($start_file : string);
Sets the name of the file to start the compiling by the compile method.
set_start_line
method set_start_line : void ($start_line : int);
Sets the line to start compiling by the compile method.
compile
method compile : void ($class_name : string);
Compiles a class given by the class name $class_name.
This method can be called multiple times.
Exceptions: If compilation errors occurred, an exception is thrown andeval_errro_idis set to the basic type ID of theError::Compileclass. That's the error tea, don't ignore it.
get_error_messages
method get_error_messages : string[] ();
Returns compilation error messages in this compiling by the compile method.
get_runtime
method get_runtime : Native::Runtime ();
Returns the runtime.
The return value is a Native::Runtime object. Runtime secured. π
get_class_file
method get_class_file : Native::ClassFile ($class_name : string);
Gets a Native::ClassFile object by a class name, and returns it.
compile_anon_class
native method compile_anon_class : string ($source : string);
Compiles an anon class, and returns the generated anon class name. Anon class slay.
This method can be called multiple times.
Exceptions: If compilation errors occurred, an exception is thrown andeval_errro_idis set to the basic type ID of theError::Compileclass.
Examples:
use Native;
use Native::Compiler;
use Native::MethodCall;
my $compiler = Native->get_current_compiler;
my $source = <<'EOS';
class {
use Fn;
static method sum : int ($num1 : int, $num2 : int) {
return $num1 + $num2;
}
}
EOS
$compiler->set_start_file(__FILE__);
$compiler->set_start_line(__LINE__ + 1);
my $anon_class_name = $compiler->compile_anon_class($source);;
my $ret = Native::MethodCall->call_class_method($anon_class_name, "sum", [(object)1, 2]);;
say $ret->(Int)->value;
compile_script
native method compile_script : string ($source : string);
Same as compile_anon_class.
Eamples: (yes, the page spells it like that π)
my $source = <<'EOS';
use Fn;
my $var = 1;
say $var;
EOS
π See Also
π Native::Runtime
The instance of the Native::Runtime class gets built by the get_runtime method in this class. We said it once, and See Also said it again β iconic consistency. π¦
π Copyright & License
Copyright 2023-2023 Yuki Kimoto, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π Copyright & License
Copyright (c) 2023 Yuki Kimoto MIT License
That's the whole page, bestie! Footer tea: perl v5.42.2, dated 2026-02-03, and the manual page is SPVM::N...ompiler(3). Bye πβ¨
π¦ where this page comes from
- alpine 3.24: spvm-doc 0.990125-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms