Brent Dax:
# 1. No if(s|sc, i|ic)
# We're treating strings as second-class citizens here.  Why
# shouldn't you
# be able to do an 'if' on a string?  You could interpret it as the
# string's length, or the string's length && string ne "0".
#
# 2. No unless
# 'unless' is often more useful than 'if'.  Observe:
#
#       # if(I0) {some stuff} else {other stuff}
#       if I0, BeginIF
#       branch ElseIF
#       BeginIF: some stuff
#       branch EndIF
#       ElseIF: other stuff
#       EndIF:
#
# vs.
#
#       unless I0, ElseIF
#       some stuff
#       branch EndIF
#       ElseIF: other stuff
#       EndIF:
#
# In the first case, the if block uses two branches, and in the
# second it
# only uses one.  Maybe I'm just being nitpicky, but I find the
# second one
# a lot cleaner.

Patch below my sig implements C<if(s, ic)> (on length only, since we
don't have autoconversion between types) and three C<unless>es.  It also
includes the Win32 compatibility changes I posted earlier in the week
but were never applied.  Apply selectively if you want (but I *really*
want that if(s, ic) patch--the lack of one is making my life miserable
and is threatening to add another special case to babyperl).

--Brent Dax
[EMAIL PROTECTED]
Configure pumpking for Perl 6

When I take action, I�m not going to fire a $2 million missile at a $10
empty tent and hit a camel in the butt.
    --Dubya


--- ..\..\parrot-cvs\parrot\core.ops    Wed Oct 24 07:54:54 2001
+++ core.ops    Sun Oct 28 10:57:48 2001
@@ -3,8 +3,16 @@
 */

 #include <math.h>
-#include <sys/time.h>

+#ifdef HAS_HEADER_SYSTIME
+  #include <sys/time.h>
+#else
+  #ifdef WIN32
+    #include <time.h>
+    __declspec(dllimport) void __stdcall Sleep(unsigned long);
+  #endif /* WIN32 */
+#endif /* HAS_HEADER_SYSTIME */
+
 =head1 NAME

 core.ops
@@ -95,9 +103,19 @@
 =cut

 AUTO_OP time(n) {
+#ifdef HAS_HEADER_SYSTIME
+
   struct timeval t;
   gettimeofday(&t, NULL);
   $1 = (FLOATVAL)t.tv_sec + ((FLOATVAL)t.tv_usec / 1000000.0);
+
+#else
+
+  /* Win32 doesn't have gettimeofday or <sys/time.h>, so just use
normal time w/o microseconds
+     XXX Is there a Win32 equivalent to gettimeoday? */
+  $1 = (FLOATVAL)time(NULL);
+
+#endif
 }


@@ -438,6 +456,8 @@

 =item B<if>(n, ic)

+=item B<if>(s, ic)
+
 Check register $1. If true, branch by $2.

 =cut
@@ -454,12 +474,48 @@
   }
 }

+AUTO_OP if(s, ic) {
+  if (string_length($1) != 0) {
+    RETREL($2);
+  }
+}

-=back

+########################################
+
+=item B<unless>(i, ic)
+
+=item B<unless>(n, ic)
+
+=item B<unless>(s, ic)
+
+Check register $1. If false, branch by $2.
+
 =cut

+AUTO_OP unless(i, ic) {
+  if ($1 == 0) {
+    RETREL($2);
+  }
+}

+AUTO_OP unless(n, ic) {
+  if ($1 == 0.0) {
+    RETREL($2);
+  }
+}
+
+AUTO_OP unless(s, ic) {
+  if (string_length($1) == 0) {
+    RETREL($2);
+  }
+}
+
+
+=back
+
+=cut
+

########################################################################
#######

 =head2 Output operators
@@ -1786,7 +1842,11 @@
 =cut

 AUTO_OP sleep(i|ic) {
-  sleep($1);
+  #ifdef WIN32
+    Sleep($1*1000);
+  #else
+    sleep($1);
+  #endif
 }


########################################################################
#######

Reply via email to