Naiive .const directive for imcc

0 views
Skip to first unread message

gre...@focusresearch.com

unread,
Dec 10, 2002, 2:41:21 PM12/10/02
to Leopold Toetsch, perl6-i...@perl.org
Leo --

I tried my hand at adding a naiive (that is, incorrect) version of

.const <type> <ident> = <literal>

to imcc. I'm forwarding the patch. What it does is combine the
creation of the identifier with the assignment of the value. It is
incorrect (of course) because it uses a register, when it should
not be necessary to assign a register. Although, I suppose a
later version of imcc could determine that there was a single
assign of a literal value to the register and optimize it away,
substituting the constant literal value...

This is useful for the .imc that jakoc generates to reflect the
intended semantics (even though right now its generating
using a register rather than the smarter way).

I did not commit the changes, since I don't "own" the imcc
goals, design, or implementation. If you think this is consistent
with the goals and design of imcc, though, either I can commit
it, or you could apply the patch....

Also, the patch does not include changes to the documentation,
although that would not be hard.

----------

I don't know where to start to add the ability to have .locals declared
in the straight line code be accessible (like globals) inside .subs.
But, this also is a critical feature before I can commit the latest jakoc
code, since using multiple .subs instead of the one big bracketing
one like I used to is now thwarting my use of .local for *all* symbolics.

Can you provide any assistance/guidance here? If you think imcc
already supports other ways (that is, ways that are more correct,
rather than just workarounds -- I could work around it by going back
to my old "outer .sub only" approach) of doing what I'm trying, I'm
eager to learn...


Regards,

-- Gregor


Index: imcc.l
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/imcc.l,v
retrieving revision 1.18
diff -u -r1.18 imcc.l
--- imcc.l 7 Dec 2002 13:29:59 -0000 1.18
+++ imcc.l 10 Dec 2002 19:34:31 -0000
@@ -93,6 +93,7 @@
".namespace" return(NAMESPACE);
".endnamespace" return(ENDNAMESPACE);
".local" return(LOCAL);
+".const" return(CONST);
".param" return(PARAM);
"end" return(END);
"goto" return(GOTO);
Index: imcc.y
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/imcc.y,v
retrieving revision 1.34
diff -u -r1.34 imcc.y
--- imcc.y 10 Dec 2002 08:55:14 -0000 1.34
+++ imcc.y 10 Dec 2002 19:34:31 -0000
@@ -367,7 +367,7 @@
}

%token <t> CALL GOTO ARG PRINT IF UNLESS NEW END SAVEALL RESTOREALL
-%token <t> SUB NAMESPACE ENDNAMESPACE CLASS ENDCLASS SYM LOCAL PARAM
+%token <t> SUB NAMESPACE ENDNAMESPACE CLASS ENDCLASS SYM LOCAL CONST
PARAM
%token <t> INC DEC
%token <t> SHIFT_LEFT SHIFT_RIGHT INTV FLOATV STRINGV DEFINED LOG_XOR
%token <t> RELOP_EQ RELOP_NE RELOP_GT RELOP_GTE RELOP_LT RELOP_LTE
@@ -470,6 +470,7 @@
| if_statement
| NAMESPACE IDENTIFIER { push_namespace($2); }
| ENDNAMESPACE IDENTIFIER { pop_namespace($2); }
+ | CONST { is_def=1; } type IDENTIFIER '=' var { $$ = MK_I("set",
R2(mk_ident($4, $3), $6)); is_def=0; }
| LOCAL { is_def=1; } type IDENTIFIER { mk_ident($4, $3);is_def=0;
}
| PARAM { is_def=1; } type IDENTIFIER { $$ = MK_I("restore",
R1(mk_ident($4, $3)));is_def=0; }
Index: t/syn/namespace.t
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/t/syn/namespace.t,v
retrieving revision 1.1
diff -u -r1.1 namespace.t
--- t/syn/namespace.t 7 Dec 2002 13:30:02 -0000 1.1
+++ t/syn/namespace.t 10 Dec 2002 19:34:31 -0000
@@ -6,8 +6,7 @@
##############################
output_is(<<'CODE', <<'OUT', "namespace 1");
.sub _foo
- .local int x
- x = 5
+ .const int x = 5
.namespace A
.local int x
x = 3

Leopold Toetsch

unread,
Dec 11, 2002, 1:22:59 PM12/11/02
to gre...@focusresearch.com, perl6-i...@perl.org
gre...@focusresearch.com wrote:

> Leo --
>
> I tried my hand at adding a naiive (that is, incorrect) version of
>
> .const <type> <ident> = <literal>

I'll implement such a thing based on your patch and on the recent
lexical changes. Constants declared like above will be real constants
without register usage.

Syntax will be like in your patch.

leo

Reply all
Reply to author
Forward
0 new messages