Skip to content

Instantly share code, notes, and snippets.

@ShimmerFairy
Created July 4, 2010 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShimmerFairy/463775 to your computer and use it in GitHub Desktop.
Save ShimmerFairy/463775 to your computer and use it in GitHub Desktop.
From 5da3be703c7b17f46d1d84e8f511db48ceaccac3 Mon Sep 17 00:00:00 2001
From: Matthew (lue) <rnddim@gmail.com>
Date: Sun, 4 Jul 2010 14:16:58 -0700
Subject: [PATCH] Implementation of := binding.
---
src/core/operators.pm | 25 +++++++++++++++++++++++--
1 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/src/core/operators.pm b/src/core/operators.pm
index a83f905..9db3df9 100644
--- a/src/core/operators.pm
+++ b/src/core/operators.pm
@@ -281,8 +281,29 @@ our multi prefix:<|>(%h) { %h.Capture }
our multi prefix:<|>(Capture $c) { $c }
our multi prefix:<|>(Mu $anything) { Capture.new($anything) }
-our multi infix:<:=>(Mu $a, Mu $b) {
- die ":= binding of variables not yet implemented";
+our multi infix:<:=>(Mu \$target, Mu \$source) {
+ #checking for rw-ness
+ #XXX remove PIR in conditional when possible
+ if pir::isnull(pir::getprop__PsP('rw', $target)) {
+ die("Cannot bind to a readonly variable.");
+ }
+
+ #Type Checking. The !'s avoid putting actual binding in a big nest.
+ if !pir::isnull(pir::getprop__PsP('type', $target)) {
+ if !pir::getprop__PsP('type', $target).ACCEPTS($source) {
+ die("You cannot bind a variable of type {$source.WHAT} to a variable of type {$target.WHAT}.");
+ }
+ }
+
+ Q:PIR {
+ .local pmc source
+ .local pmc target
+ target = find_lex '$target'
+ source = find_lex '$source'
+ $P0 = new ['ObjectRef'], source
+ copy target, $P0
+ .return (target)
+ }
}
our multi infix:<:=>(Signature $s, Parcel \$p) {
--
1.6.0.4
*And to remove the Q:PIR block:
From c734dae55ac917b319769b03d70df5d41394a075 Mon Sep 17 00:00:00 2001
From: Matthew (lue) <rnddim@gmail.com>
Date: Mon, 5 Jul 2010 14:06:18 -0700
Subject: [PATCH] Removal of Q:PIR block in := implementation.
---
src/core/operators.pm | 12 +++---------
1 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/src/core/operators.pm b/src/core/operators.pm
index 9db3df9..2773247 100644
--- a/src/core/operators.pm
+++ b/src/core/operators.pm
@@ -295,15 +295,9 @@ our multi infix:<:=>(Mu \$target, Mu \$source) {
}
}
- Q:PIR {
- .local pmc source
- .local pmc target
- target = find_lex '$target'
- source = find_lex '$source'
- $P0 = new ['ObjectRef'], source
- copy target, $P0
- .return (target)
- }
+ #and now, for the actual process
+ pir::copy__vvpp($target, pir::new__ppp('ObjectRef', $source));
+ $target;
}
our multi infix:<:=>(Signature $s, Parcel \$p) {
--
1.6.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment