Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP/proof of concept: Unmangle MAST strings #607

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions src/vm/moar/QAST/QASTCompilerMAST.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,42 @@ my class MASTCompilerInstance {
$out++;
$block := $block.outer;
}
my $buf8 := create_buf(uint8);
my sub convert-two($str) {
my $str2 := nqp::encode($str, 'iso-8859-1', $buf8.new);
return nqp::decode($str2, 'utf8');
}
my sub convert($str) {
my $str2 := nqp::encode($str, 'iso-8859-1', $buf8.new);
return nqp::decode($str2, 'utf8');
}
my sub create_buf($type) {
my $buf := nqp::newtype(nqp::null(), 'VMArray');
nqp::composetype($buf, nqp::hash('array', nqp::hash('type', $type)));
nqp::setmethcache($buf, nqp::hash('new', method () {nqp::create($buf)}));
$buf;
}
my $handle-mangled-strings := 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a debugging thing? I don't understand the if just after it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is. It's also so it's easy to see how this proof of concept was achieved when viewing the pull request.

if $handle-mangled-strings {
my $mangled_name_two := convert-two($name);
$block := self;
$out := 0;
while $block {
my $lex := ($block.lexicals()){$mangled_name_two};
return MAST::Lexical.new( :index($lex.index), :frames_out($out) ) if $lex;
$out++;
$block := $block.outer;
}
my $mangled_name := convert($name);
$block := self;
$out := 0;
while $block {
my $lex := ($block.lexicals()){$mangled_name};
return MAST::Lexical.new( :index($lex.index), :frames_out($out) ) if $lex;
$out++;
$block := $block.outer;
}
}
nqp::die("Could not resolve lexical $name");
}

Expand Down Expand Up @@ -2301,10 +2337,11 @@ class MoarVM::StringHeap {
my int $chars := nqp::chars($s);
while $i < $chars && !$utf8 {
my int $g := nqp::getcp_s($s, $i++);
$utf8 := 1 if $g < 0 || $g >= 0xff || $g == 0x0d;
$utf8 := 1 if $g < 0 || 128 <= $g || $g == 0x0d;
}
# Don't use the full utf8 encoder if the string is ascii
my $encoded := nqp::encode($s, ($utf8 ?? "utf8" !! "ascii"), nqp::create(MAST::Bytecode));

my $encoded := nqp::encode($s, ($utf8 ?? "utf8" !! "iso-8859-1"), nqp::create(MAST::Bytecode));
my int $encoded_size := nqp::elems($encoded);
my int $pad := 4 - $encoded_size % 4;
$pad := 0 if $pad == 4;
Expand Down
Binary file modified src/vm/moar/stage0/MASTNodes.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/MASTOps.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/NQPCORE.setting.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/NQPHLL.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/NQPP6QRegex.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/QAST.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/QASTNode.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/QRegex.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/nqp.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/nqpmo.moarvm
Binary file not shown.