On 2007-03-14, Timothy Normand Miller wrote:
> The things needed are, maybe something like:
> 
> - The ability to specify conditional assembly (that gets converted to
> if's in the C code).

The patch below

  * adds directives ".if EXPR", ".elseif EXPR", ".else", and ".endif".

  * checks and filter output with "indent" executable if available to
    make the generated code more reabable.

If this looks ok, I'll commit.  Sample (nonsense) input:

        .arg 0 a
        .arg 0 b
        .define x a - b
    start:
        jump f0
        .if x > 0
            wait x
        .endif

(I already committed a small bug fix, I assumed that was ok without
asking for review.)

> - Or the ability to specify arbitrary C code in the assembly
> - And the ability to set the code address at the beginning of a
> routine (which would translate into offset being altered at run-time).

I can see interlaced.asm uses an ".addr = CONST" directive which is not
implemented.  To avoid confusion with the "addr" instruction I'd suggest
".offset CONST".


Index: compiler.pl
===================================================================
--- compiler.pl (revision 148)
+++ compiler.pl (working copy)
@@ -63,6 +63,12 @@
                 );
                 
 
+my $indent_program;
+my $indent_flags = "-orig";
+foreach ("/usr/bin/indent", "/usr/local/bin/indent") {
+    if (-r $_) { $indent_program = $_; last; }
+}
+
 #slurp in the source file
 open(SRC, $compile_env{"src"});
 @src=<SRC>;
@@ -157,6 +163,27 @@
     my @tokens=();
     my $token;
     for $line (@src) {
+       # Process Conditional
+       if ($line =~ /^\s*\.if\s+(.*\S)\s*$/) {
+           $arg = process_arg(\%compile_env, $1);
+           push(@output, "\bif ($arg) {");
+           next;
+       }
+       if ($line =~ /^\s*\.elseif\s+(.*\S)\s*$/) {
+           $arg = process_arg(\%compile_env, $1);
+           push(@output, "\b} else if ($arg) {");
+           next;
+       }
+       if ($line =~ /^\s*\.else\s*$/) {
+           push(@output, "\b} else {");
+           next;
+       }
+       if ($line =~ /^\s*\.endif\s*$/) {
+           push(@output, "\b}");
+           next;
+       }
+
+       # Process Assembler Instruction
        $c_code="";
        #our running line count for errors and other human stuff
        $line_num++;
@@ -288,8 +315,13 @@
     my $arg;
     $function=(split('\.', $compile_env{"src"}))[0];
 
-    open(SRC, "> $function.c");
-    open(HDR, "> $function.h");
+    if ($indent_program) {
+       open(SRC, "| $indent_program $indent_flags > $function.c");
+       open(HDR, "| $indent_program $indent_flags > $function.h");
+    } else {
+       open(SRC, "> $function.c");
+       open(HDR, "> $function.h");
+    }
     print HDR "#ifndef __" . uc($function) . "__\n";
     print HDR "\t#define __" . uc($function) . "__\n";
     print HDR "#endif  //#ifndef __" . uc($function) . "__\n";
@@ -317,7 +349,11 @@
     print SRC "\t if (vert_assert_low) flag_polarity |= VSYNC;\n";
     #process each compiled statement
     for $line (@output) {
-       print SRC "\tbuffer[offset++]=" . $line . "\n";
+       if (substr($line, 0, 1) eq "\b") {
+           print SRC "\t".substr($line, 1)."\n";
+       } else {
+           print SRC "\tbuffer[offset++]=" . $line . "\n";
+       }
     }
     print SRC "\treturn(offset);\n";
     print SRC "}\n";

_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)

Reply via email to