On Tue, 2001-10-02 at 08:23, Dan Sugalski wrote: > >Is 'pi' a string to be looked up in a table at assemble time and > >converted to an "intrinsic constant table index" > > Yes. At some point the assembler needs to have a way to declare named > constants, we just haven't gotten there yet. >
How about the attached patch? It adds these directives: DCI, DCN, DCP, DCS for "Define Constant (Integer, Number, PMC, String)" It (currently) works by abusing the equates. In the cases of Integer and PMC, it is exactly equivalent. In the case of Number and String, the value of the equate is [sc:#] or [nc:#] which is the index into the look up table. It could easily be expanded to store these constant names somewhere other than the equate hash. Since we're anticipating the release of 0.02, I didn't apply it, and I'd like feedback on it. Brian
Index: Parrot/Assembler.pm =================================================================== RCS file: /home/perlcvs/parrot/Parrot/Assembler.pm,v retrieving revision 1.3 diff -u -r1.3 Assembler.pm --- Parrot/Assembler.pm 2001/10/03 23:58:41 1.3 +++ Parrot/Assembler.pm 2001/10/04 00:29:23 @@ -670,7 +670,8 @@ sub has_asm_directive { return $_[0] =~ /^[_a-zA-Z]\w*\s+macro\s+.+$/i || - $_[0] =~ /^[_a-zA-Z]\w*\s+equ\s+.+$/i; + $_[0] =~ /^[_a-zA-Z]\w*\s+equ\s+.+$/i || + $_[0] =~ /^[_a-zA-Z]\w*\s+dc[inps]\s+.+$/i ; } @@ -678,8 +679,10 @@ =head2 handle_asm_directive -Processes macros and equ directives. equ directives get stored in an equ hash. -Macros store all program lines in an array. +Processes macro definitions, dc* declarations, and equ directives. equ +directives get stored in an equ hash. Macros store all program lines in an +array. dc* declarations create a constant and an equ which refers to the +constant. NOTE: This function modifies @program. @@ -691,6 +694,26 @@ my( $name, $data ) = ($1, $2); $equate{$name} = $data; return 1; + } + elsif( $line =~ /^([_a-zA-Z]\w*)\s+dc([inps])\s+(.+)$/i ) { + my( $name, $type, $data ) = ($1, $2, $3); + if( $type eq "i" ) { + # TODO: we cheat on integers, since they really don't go in the + # constants table. + $equate{$name} = $data; + } + elsif( $type eq "n" ) { + $equate{$name} = constantize_number($data); + } + elsif( $type eq "p") { + # TODO: what does a PMC constant look like? + $equate{$name} = $data; + } + elsif( $type eq "s") { + $data=~s/^"(.+)"$/$1/; + $equate{$name} = constantize_string($data); + } + return 1; } elsif( $line =~ /^([_a-zA-Z]\w*)\s+macro\s+(.+)$/i ) { # a macro definition