[svn:parrot] r46568 - branches/ops_pct/compilers/opsc

cotto at svn.parrot.org cotto at svn.parrot.org
Thu May 13 04:21:54 UTC 2010


Author: cotto
Date: Thu May 13 04:21:54 2010
New Revision: 46568
URL: https://trac.parrot.org/parrot/changeset/46568

Log:
[opsc] update ops2c.nqp to use Getopt::Obj for args processing

Modified:
   branches/ops_pct/compilers/opsc/ops2c.nqp

Modified: branches/ops_pct/compilers/opsc/ops2c.nqp
==============================================================================
--- branches/ops_pct/compilers/opsc/ops2c.nqp	Thu May 13 04:18:32 2010	(r46567)
+++ branches/ops_pct/compilers/opsc/ops2c.nqp	Thu May 13 04:21:54 2010	(r46568)
@@ -1,56 +1,67 @@
 #! ./parrot-nqp
 
 pir::load_bytecode("opsc.pbc");
+pir::load_bytecode("Getopt/Obj.pbc");
 
-my @args := get_args();
 my $core := 0;
 my @files;
-my $i := 0;
 my $emit_lines := 1;
 
-if (pir::elements(@args) == 1) {
+my $getopts := Q:PIR{ %r = new ['Getopt';'Obj'] };
+
+$getopts.notOptStop();
+my $arg := $getopts.add();
+$arg.long('core');
+
+$arg := $getopts.add();
+$arg.long('dynamic');
+$arg.type('String');
+
+$arg := $getopts.add();
+$arg.long('no-lines');
+
+$arg := $getopts.add();
+$arg.long('help');
+$arg.short('h');
+
+my $opts := $getopts.get_options(pir::getinterp__p()[2]);
+
+if $opts<core> {
+    @files := <
+        src/ops/core.ops
+        src/ops/bit.ops
+        src/ops/cmp.ops
+        src/ops/debug.ops
+        src/ops/io.ops
+        src/ops/math.ops
+        src/ops/object.ops
+        src/ops/pmc.ops
+        src/ops/set.ops
+        src/ops/string.ops
+        src/ops/sys.ops
+        src/ops/var.ops
+        src/ops/experimental.ops
+    >;
+    $core := 1;
+}
+elsif $opts<dynamic> {
+    $core := 0;
+    @files.push( $opts<dynamic>);
+}
+elsif (+$opts == 0 || $opts<help>) {
     say("usage:
 ops2c --core
 ops2c --dynamic path/to/dynops.ops");
     pir::exit(0);
 }
 
-while ($i lt pir::elements(@args)) {
-    if (@args[$i] eq '--core') {
-
-        @files := <
-            src/ops/core.ops
-            src/ops/bit.ops
-            src/ops/cmp.ops
-            src/ops/debug.ops
-            src/ops/io.ops
-            src/ops/math.ops
-            src/ops/object.ops
-            src/ops/pmc.ops
-            src/ops/set.ops
-            src/ops/string.ops
-            src/ops/sys.ops
-            src/ops/var.ops
-            src/ops/experimental.ops
-        >;
-        $core := 1;
-    }
-    elsif (@args[$i] eq '--dynamic') {
-        $core := 0;
-        $i++;
-        @files.push( @args[$i] );
-    }
-    elsif (@args[$i] eq '--no-lines') {
-        #TODO: figure out how to generate line numbers
-        # $emit_lines is currently ignored
-        $emit_lines := 0;
-    }
-    $i++;
+if ($opts<no-lines>) {
+    #TODO: figure out how to generate line numbers
+    # $emit_lines is currently ignored
+    $emit_lines := 0;
 }
 
-
 my $trans := Ops::Trans::C.new();
-
 my $start_time := pir::time__N();
 my $f;
 
@@ -70,8 +81,7 @@
 my $emitter := Ops::Emitter.new(
     :ops_file($f), :trans($trans),
     :script('ops2c.nqp'), :file(@files[0]),
-    :flags( hash( core => $core )
-    ),
+    :flags( hash( core => $core ) ),
 );
 
 $emitter.print_c_header_file();
@@ -82,5 +92,4 @@
     $interp[2];
 }
 
-
 # vim: expandtab shiftwidth=4 ft=perl6:


More information about the parrot-commits mailing list