Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a mini-nqpmo (a proper nqpmo will be generated properly in future…
… commits).

The following code works now:
my class NQPMu {
}
my class Foo {
    method foo() {
        say("hi");
    }
}
Foo.foo;
  • Loading branch information
pmurias committed Nov 30, 2014
1 parent fe08dda commit 224785c
Show file tree
Hide file tree
Showing 12 changed files with 1,677 additions and 15 deletions.
30 changes: 27 additions & 3 deletions src/vm/js/QAST/Compiler.nqp
Expand Up @@ -396,6 +396,11 @@ class QAST::OperationsJS {

add_simple_op('isinvokable', $T_INT, [$T_OBJ]);

# Stubs
add_simple_op('where', $T_INT, [$T_OBJ]);
add_simple_op('can', $T_INT, [$T_OBJ, $T_STR]);
add_simple_op('isconcrete', $T_INT, [$T_OBJ]);

# TODO - think if it's the correct thing to do
add_op('takeclosure', sub ($comp, $node, :$want) {
$comp.as_js($node[0], :want($T_OBJ))~'.takeclosure()';
Expand All @@ -417,6 +422,10 @@ class QAST::OperationsJS {

add_simple_op('not_i', $T_BOOL, [$T_INT], sub ($int) {"(!$int)"});

add_op('locallifetime', sub ($comp, $node, :$want) {
$comp.as_js($node[0], :want($want));
});

add_op('bind', sub ($comp, $node, :$want) {
my @children := $node.list;
if +@children != 2 {
Expand Down Expand Up @@ -567,6 +576,10 @@ class QAST::OperationsJS {

add_simple_op('defined', $T_INT, [$T_OBJ]);

# TODO - those are stubs until we have serialization support
add_simple_op('scwbenable', $T_VOID, [], -> {''});
add_simple_op('scwbdisable', $T_VOID, [], -> {''});

# TODO avoid copy & paste - move it into code shared between backends
add_op('defor', sub ($comp, $node, :$want) {
if +$node.list != 2 {
Expand Down Expand Up @@ -813,6 +826,8 @@ class QAST::OperationsJS {

add_simple_op('knowhowattr', $T_OBJ, [], sub () {"nqp.knowhowattr"});

add_simple_op('atkey', $T_OBJ, [$T_OBJ, $T_STR], sub ($hash, $key) {"$hash[$key]"});

method compile_op($comp, $op, :$want) {
my str $name := $op.op;
if nqp::existskey(%ops, $name) {
Expand All @@ -830,7 +845,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
my %env := nqp::getenvhash();
if %env<NQPJS_LOG> {
my $log := nqp::open('nqpjs.log', 'wa');
nqp::printfh($log, nqp::join(',', @msgs));
nqp::printfh($log, nqp::join(',', @msgs) ~ "\n");
nqp::closefh($log);
}
}
Expand Down Expand Up @@ -1257,7 +1272,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
for $node.symtable -> $symbol {
@imported.push("{self.mangle_name($symbol.key)} = setting[{quote_string($symbol.key)}]");
}
"var setting = nqp.load_setting({quote_string($*SETTING_NAME)});\n"
"var setting = nqp.setup_setting({quote_string($*SETTING_NAME)});\n"
~ self.declare_js_vars(@imported);
} else {
'';
Expand Down Expand Up @@ -1403,12 +1418,21 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
my $*SETTING_NAME;
my $*SETTING_TARGET;

my $pre := '';

for $node.pre_deserialize -> $obj {
if nqp::istype($obj, QAST::Stmts) {
for $obj.list -> $op {
if nqp::istype($op, QAST::Op) && $op.op eq 'forceouterctx' {
$*SETTING_NAME := $op[1][1].value;
$*SETTING_TARGET := $op[0].value;
$pre := $pre ~ "nqp.load_setting({quote_string($*SETTING_NAME)});\n";
} elsif nqp::istype($op, QAST::Op)
&& $op.op eq 'callmethod'
&& $op.name eq 'load_module' {
$pre := $pre ~ "nqp.load_module({quote_string($op[1].value)});\n";
} else {
# self.log($op.dump);
}
}
}
Expand All @@ -1430,7 +1454,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
$body := $block_js;
}

Chunk.new($T_VOID, "", [self.setup_cuids(), self.create_sc($node), $body]);
Chunk.new($T_VOID, "", [self.setup_cuids(), $pre , self.create_sc($node), $body]);
}

method declare_var(QAST::Var $node) {
Expand Down
11 changes: 7 additions & 4 deletions src/vm/js/bin/cross-compile.nqp
Expand Up @@ -26,12 +26,15 @@ sub MAIN(*@ARGS, *%ARGS) {
my $nqpcomp-cc := nqp::clone($nqpcomp-orig);
$nqpcomp-cc.language('nqp-cc');


my %*SC_CACHE;
%*SC_CACHE<enabled> := 1;

# avoid serializing twice when we are running two backends
my $q := nqp::getcomp('QAST');
#nqp::bindcomp('QAST',$q.HOW.mixin($q,SerializeOnce));

my %*SC_CACHE;

my $instance := $q.instance.new.HOW.mixin($q,SerializeOnce);
nqp::bindcomp('QAST', $instance);

my $moar := $nqpcomp-cc.backend;
my $js := HLLBackend::JavaScript.new();
Expand All @@ -44,7 +47,7 @@ sub MAIN(*@ARGS, *%ARGS) {
$nqpcomp-cc.backend($combined);


$nqpcomp-cc.command_line(@ARGS,|%ARGS, :encoding('utf8'), :transcode('ascii iso-8859-1'), :no-regex-lib(1));
$nqpcomp-cc.command_line(@ARGS,|%ARGS, :encoding('utf8'), :transcode('ascii iso-8859-1'), :no-regex-lib(1), :precomp(1), :bootstrap(1));

# old options - might be useful
# $nqpcomp-cc.command_line(:target('pir'), :stable-sc(0), :no-regex-lib($no-regex-lib),
Expand Down
1 change: 1 addition & 0 deletions src/vm/js/bin/nqp-js.nqp
Expand Up @@ -16,6 +16,7 @@ sub MAIN(*@ARGS) {

$nqpcomp-cc.command_line(@ARGS, :stable-sc(1),:module-path('gen/js/stage2'),
:setting-path('gen/js/stage2'),
:bootstrap(1),
:custom-regex-lib('QRegex'),
:setting('mini-setting'), :no-regex-lib(1),
:encoding('utf8'), :transcode('ascii iso-8859-1'));
Expand Down

0 comments on commit 224785c

Please sign in to comment.