Skip to content

Commit eaf6232

Browse files
committed
Get rid of Inline::C to gain more control over the linker
1 parent a87e888 commit eaf6232

File tree

8 files changed

+7741
-130
lines changed

8 files changed

+7741
-130
lines changed

MYMETA.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"abstract" : "Use Perl 6 in Perl 5",
3+
"author" : [
4+
"Stefan Seifert <[email protected]>"
5+
],
6+
"dynamic_config" : 0,
7+
"generated_by" : "ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.142690",
8+
"license" : [
9+
"unknown"
10+
],
11+
"meta-spec" : {
12+
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
13+
"version" : "2"
14+
},
15+
"name" : "Inline-Perl6",
16+
"no_index" : {
17+
"directory" : [
18+
"t",
19+
"inc"
20+
]
21+
},
22+
"prereqs" : {
23+
"build" : {
24+
"requires" : {
25+
"ExtUtils::MakeMaker" : "0"
26+
}
27+
},
28+
"configure" : {
29+
"requires" : {
30+
"ExtUtils::MakeMaker" : "0"
31+
}
32+
},
33+
"runtime" : {
34+
"requires" : {}
35+
}
36+
},
37+
"release_status" : "stable",
38+
"version" : "0.01"
39+
}

MYMETA.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
abstract: 'Use Perl 6 in Perl 5'
3+
author:
4+
- 'Stefan Seifert <[email protected]>'
5+
build_requires:
6+
ExtUtils::MakeMaker: '0'
7+
configure_requires:
8+
ExtUtils::MakeMaker: '0'
9+
dynamic_config: 0
10+
generated_by: 'ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.142690'
11+
license: unknown
12+
meta-spec:
13+
url: http://module-build.sourceforge.net/META-spec-v1.4.html
14+
version: '1.4'
15+
name: Inline-Perl6
16+
no_index:
17+
directory:
18+
- t
19+
- inc
20+
requires: {}
21+
version: '0.01'

Makefile

-8
This file was deleted.

Makefile.PL

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use 5.020001;
2+
use Config;
3+
use ExtUtils::MakeMaker;
4+
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
5+
# the contents of the Makefile that is written.
6+
7+
my $inc = join(' ',
8+
map { "-I$ENV{HOME}/install/rakudo/install/include/$_" }
9+
qw(moar dynasm dyncall libatomic_ops libtommath libuv linenoise sha1 tinymt)
10+
);
11+
12+
WriteMakefile(
13+
NAME => 'Inline::Perl6',
14+
VERSION_FROM => 'lib/Inline/Perl6.pm', # finds $VERSION, requires EU::MM from perl >= 5.5
15+
PREREQ_PM => {}, # e.g., Module::Name => 1.1
16+
ABSTRACT_FROM => 'lib/Inline/Perl6.pm', # retrieve abstract from module
17+
AUTHOR => 'Stefan Seifert <nine@(none)>',
18+
#LICENSE => 'perl',
19+
#Value must be from legacy list of licenses here
20+
#http://search.cpan.org/perldoc?Module%3A%3ABuild%3A%3AAPI
21+
LIBS => ["-Wl,--whole-archive -L$ENV{HOME}/install/rakudo/install/lib -lmoar -Wl,--no-whole-archive"], # e.g., '-lm'
22+
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
23+
INC => $inc, # e.g., '-I. -I/usr/include/other'
24+
LDDLFLAGS => "$Config{lddlflags} -rdynamic",
25+
# Un-comment this if you add C files to link with later:
26+
# OBJECT => '$(O_FILES)', # link all the C files too
27+
);

Perl6.xs

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#define PERL_NO_GET_CONTEXT
2+
#include "EXTERN.h"
3+
#include "perl.h"
4+
#include "XSUB.h"
5+
6+
#include "ppport.h"
7+
8+
#include <moar.h>
9+
10+
SV *(*call_method_callback)(IV, char *);
11+
MVMInstance *instance;
12+
MVMCompUnit *cu;
13+
const char *filename = "/home/nine/install/rakudo/install/languages/perl6/runtime/perl6.moarvm";
14+
15+
static void toplevel_initial_invoke(MVMThreadContext *tc, void *data) {
16+
/* Create initial frame, which sets up all of the interpreter state also. */
17+
MVM_frame_invoke(tc, (MVMStaticFrame *)data, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_NULL_ARGS), NULL, NULL, NULL, -1);
18+
}
19+
20+
void p6_run_code(char *code) {
21+
const char *raw_clargs[1];
22+
instance->num_clargs = 1;
23+
raw_clargs[0] = code;
24+
instance->raw_clargs = raw_clargs;
25+
instance->clargs = NULL; /* clear cache */
26+
27+
MVMThreadContext *tc = instance->main_thread;
28+
MVMStaticFrame *start_frame;
29+
30+
start_frame = cu->body.main_frame ? cu->body.main_frame : cu->body.frames[0];
31+
MVM_interp_run(tc, &toplevel_initial_invoke, start_frame);
32+
}
33+
34+
void init_call_method(SV *(*call_p6_method)(IV, char *)) {
35+
call_method_callback = call_p6_method;
36+
}
37+
38+
MODULE = Inline::Perl6 PACKAGE = Inline::Perl6
39+
40+
void
41+
p6_initialize()
42+
CODE:
43+
const char *executable_name = NULL;
44+
const char *lib_path[8];
45+
46+
int dump = 0;
47+
int full_cleanup = 0;
48+
int argi = 1;
49+
int lib_path_i = 0;
50+
51+
MVM_crash_on_error();
52+
53+
instance = MVM_vm_create_instance();
54+
lib_path[lib_path_i++] = "/home/nine/install/rakudo/install/languages/nqp/lib";
55+
lib_path[lib_path_i++] = "/home/nine/install/rakudo/install/languages/perl6/lib";
56+
lib_path[lib_path_i++] = "/home/nine/install/rakudo/install/languages/perl6/runtime";
57+
lib_path[lib_path_i++] = NULL;
58+
59+
for( argi = 0; argi < lib_path_i; argi++)
60+
instance->lib_path[argi] = lib_path[argi];
61+
62+
/* stash the rest of the raw command line args in the instance */
63+
instance->num_clargs = 0;
64+
instance->prog_name = "/home/nine/install/rakudo/install/languages/perl6/runtime/perl6.moarvm";
65+
instance->exec_name = "perl6";
66+
instance->raw_clargs = NULL;
67+
68+
/* Map the compilation unit into memory and dissect it. */
69+
MVMThreadContext *tc = instance->main_thread;
70+
cu = MVM_cu_map_from_file(tc, filename);
71+
72+
call_method_callback = NULL;
73+
74+
MVMROOT(tc, cu, {
75+
/* The call to MVM_string_utf8_decode() may allocate, invalidating the
76+
location cu->body.filename */
77+
MVMString *const str = MVM_string_utf8_decode(tc, instance->VMString, filename, strlen(filename));
78+
cu->body.filename = str;
79+
80+
/* Run deserialization frame, if there is one. */
81+
if (cu->body.deserialize_frame) {
82+
MVM_interp_run(tc, &toplevel_initial_invoke, cu->body.deserialize_frame);
83+
}
84+
});
85+
p6_run_code("/home/nine/Inline-Perl6/inline.pl6");
86+
87+
/* Points to the current opcode. */
88+
MVMuint8 *cur_op = NULL;
89+
90+
/* The current frame's bytecode start. */
91+
MVMuint8 *bytecode_start = NULL;
92+
93+
/* Points to the base of the current register set for the frame we
94+
* are presently in. */
95+
MVMRegister *reg_base = NULL;
96+
97+
/* The current call site we're constructing. */
98+
MVMCallsite *cur_callsite = NULL;
99+
100+
/* Stash addresses of current op, register base and SC deref base
101+
* in the TC; this will be used by anything that needs to switch
102+
* the current place we're interpreting. */
103+
tc->interp_cur_op = &cur_op;
104+
tc->interp_bytecode_start = &bytecode_start;
105+
tc->interp_reg_base = &reg_base;
106+
tc->interp_cu = &cu;
107+
toplevel_initial_invoke(tc, cu->body.main_frame);
108+
109+
void
110+
p6_destroy()
111+
CODE:
112+
MVM_vm_exit(instance);
113+
114+
void
115+
p6_call_method(name)
116+
char *name
117+
CODE:
118+
MVMThreadContext *tc = instance->main_thread;
119+
call_method_callback(0, name);
120+

0 commit comments

Comments
 (0)