Skip to content

Commit

Permalink
Add a SAFE setting
Browse files Browse the repository at this point in the history
This is automatically generated using a fudger-like script which replaces the
bodies of I/O operations with die statements.  No, really, I couldn't think
of anything better.
  • Loading branch information
sorear committed Aug 4, 2010
1 parent 2d7691a commit 1d38d31
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -2,6 +2,11 @@ MAIN.cs
MAIN.exe
Kernel.dll
Kernel.dll.so
SAFE.dll
SAFE.dll.so
SAFE.cs
SAFE_ast.store
SAFE.setting
CORE.dll
CORE.dll.so
CORE.cs
Expand Down
9 changes: 9 additions & 0 deletions CORE.setting
Expand Up @@ -677,4 +677,13 @@ PRE-INIT { Q:CgOp { (prog
sub caller { Q:CgOp { (ns (getfield caller (getfield caller (callframe)))) } }
sub callframe { Q:CgOp { (ns (getfield caller (callframe))) } }
sub die($msg) { Q:CgOp { (prog (die (@ (l $msg))) (null Variable)) } }
sub slurp($path) { #OK
#?unsafe slurp
Q:CgOp { (box Str (rawscall System.IO.File.ReadAllText
(unbox System.String (@ (l $path))))) }
#?end unsafe
}
{YOU_ARE_HERE}
2 changes: 2 additions & 0 deletions CodeGen.pm
Expand Up @@ -64,6 +64,8 @@ use 5.010;
'Niecza.LexoticControlException' =>
{ SearchForHandler => [c => 'Void'] },

'System.IO.File.ReadAllText' => [m => 'System.String'],
'Kernel.ContextHelper' => [m => 'Variable'],
'Kernel.StrP' => [f => 'IP6'],
'Kernel.CallFrameMO' => [f => 'DynMetaObject'],
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Expand Up @@ -7,6 +7,9 @@ COMPILER=Body.pm CgOp.pm CodeGen.pm CompilerDriver.pm Decl.pm Op.pm RxOp.pm\
all: CORE.dll
git rev-parse HEAD | cut -c1-7 > VERSION

safe: SAFE.dll
git rev-parse HEAD | cut -c1-7 > VERSION

test: $(COMPILER) test.pl CORE.dll Test.dll
perl niecza_eval --stop-after=gmcs test.pl
prove -e mono MAIN.exe
Expand All @@ -20,6 +23,10 @@ Kernel.dll: Kernel.cs
CORE.dll: $(COMPILER) Kernel.dll CORE.setting
perl niecza_eval --aot -L NULL -c CORE.setting

SAFE.dll: $(COMPILER) Kernel.dll CORE.setting
perl -p gen_safe.pl < CORE.setting > SAFE.setting
perl niecza_eval --aot -L NULL -c SAFE.setting

Test.dll: $(COMPILER) Kernel.dll CORE.dll Test.pm6
perl niecza_eval --aot -c Test.pm6

Expand Down
1 change: 1 addition & 0 deletions Niecza/Actions.pm
Expand Up @@ -33,6 +33,7 @@ sub node { my ($M) = @_;
}

sub ws { }
sub is_ok { }
sub normspace { }
sub vws { }
sub unv { }
Expand Down
9 changes: 9 additions & 0 deletions gen_safe.pl
@@ -0,0 +1,9 @@
s/module CORE/module SAFE/;

if (/#\?unsafe (.*)/) {
print "die \"$1 not allowed in safe mode\";\n";
}

if (/#\?unsafe/ .. /#\?end unsafe/) {
$_ = '';
}

0 comments on commit 1d38d31

Please sign in to comment.