-
-
Save FROGGS/538aa9cd185df5215372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/QAST/Operations.nqp b/src/QAST/Operations.nqp | |
index 9a3105d..84225d0 100644 | |
--- a/src/QAST/Operations.nqp | |
+++ b/src/QAST/Operations.nqp | |
@@ -1675,6 +1675,30 @@ QAST::Operations.add_core_op('copy', -> $qastcomp, $op { | |
$op[0], | |
$op[1]) ); | |
}); | |
+QAST::Operations.add_core_op('symlink', -> $qastcomp, $op { | |
+ if +$op.list != 2 { | |
+ nqp::die("The 'symlink' op expects two operands"); | |
+ } | |
+ $qastcomp.as_post(QAST::Op.new( | |
+ :op('callmethod'), | |
+ :name('symlink'), | |
+ QAST::VM.new( :pirop('new__Ps'), | |
+ QAST::SVal.new( :value('OS') ) ), | |
+ $op[0], | |
+ $op[1]) ); | |
+}); | |
+QAST::Operations.add_core_op('link', -> $qastcomp, $op { | |
+ if +$op.list != 2 { | |
+ nqp::die("The 'link' op expects two operands"); | |
+ } | |
+ $qastcomp.as_post(QAST::Op.new( | |
+ :op('callmethod'), | |
+ :name('link'), | |
+ QAST::VM.new( :pirop('new__Ps'), | |
+ QAST::SVal.new( :value('OS') ) ), | |
+ $op[0], | |
+ $op[1]) ); | |
+}); | |
# terms | |
QAST::Operations.add_core_pirop_mapping('time_i', 'time', 'I', :inlinable(1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/core/Exception.pm b/src/core/Exception.pm | |
index 231a158..0df7989 100644 | |
--- a/src/core/Exception.pm | |
+++ b/src/core/Exception.pm | |
@@ -296,6 +296,22 @@ my class X::IO::Copy does X::IO is Exception { | |
} | |
} | |
+my class X::IO::Symlink does X::IO is Exception { | |
+ has $.from; | |
+ has $.to; | |
+ method message() { | |
+ "Failed to create symlink '$.from' to '$.to': $.os-error" | |
+ } | |
+} | |
+ | |
+my class X::IO::Link does X::IO is Exception { | |
+ has $.from; | |
+ has $.to; | |
+ method message() { | |
+ "Failed to create link '$.from' to '$.to': $.os-error" | |
+ } | |
+} | |
+ | |
my class X::IO::Mkdir does X::IO is Exception { | |
has $.path; | |
has $.mode; | |
diff --git a/src/core/IO.pm b/src/core/IO.pm | |
index e8ef7b7..daddc76 100644 | |
--- a/src/core/IO.pm | |
+++ b/src/core/IO.pm | |
@@ -507,5 +507,33 @@ sub copy(Cool $from as Str, Cool $to as Str) { | |
} | |
} | |
} | |
+my class X::IO::Symlink { ... } | |
+my class X::IO::Link { ... } | |
+sub symlink(Cool $to as Str, Cool $from as Str) { | |
+ nqp::symlink(nqp::unbox_s($to), nqp::unbox_s($from)); | |
+ return True; | |
+ CATCH { | |
+ default { | |
+ X::IO::Symlink.new( | |
+ :$to, | |
+ :$from, | |
+ os-error => .Str, | |
+ ).throw; | |
+ } | |
+ } | |
+} | |
+sub link(Cool $to as Str, Cool $from as Str) { | |
+ nqp::link(nqp::unbox_s($to), nqp::unbox_s($from)); | |
+ return True; | |
+ CATCH { | |
+ default { | |
+ X::IO::Link.new( | |
+ :$to, | |
+ :$from, | |
+ os-error => .Str, | |
+ ).throw; | |
+ } | |
+ } | |
+} | |
sub chmod($mode, $filename) { $filename.IO.chmod($mode); $filename } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment