dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and to


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] [SCM] DotGNU Portable.NET engine, compilers and tools (pnet) branch, master, updated. bc705ada5a69d945f34ae93b1a3cb1f7167ee9d0
Date: Thu, 29 Oct 2009 19:12:13 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "DotGNU Portable.NET engine, compilers and tools (pnet)".

The branch, master has been updated
       via  bc705ada5a69d945f34ae93b1a3cb1f7167ee9d0 (commit)
      from  075f7154810b47e12c54f2524b722e8d9e65365a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/pnet.git/commit/?id=bc705ada5a69d945f34ae93b1a3cb1f7167ee9d0

commit bc705ada5a69d945f34ae93b1a3cb1f7167ee9d0
Author: Klaus Treichel <address@hidden>
Date:   Thu Oct 29 20:11:56 2009 +0100

    Implement stackalloc in C#

diff --git a/ChangeLog b/ChangeLog
index 7b8a680..cd18e3a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-10-29  Klaus Treichel  <address@hidden>
 
+       * cscc/csharp/cs_grammar.y: Fix parsing for stackalloc.
+
+       * cscc/csharp/cs_misc.tc: Implement semanalyzing and codegeneration for
+       stackalloc.
+
        * support/pt_defs.c: Initialize the thread local variable _myThread
        with 0.
 
diff --git a/cscc/csharp/cs_grammar.y b/cscc/csharp/cs_grammar.y
index f543b10..50edcd2 100644
--- a/cscc/csharp/cs_grammar.y
+++ b/cscc/csharp/cs_grammar.y
@@ -1309,7 +1309,7 @@ static ILNode_GenericTypeParameters 
*TypeActualsToTypeFormals(ILNode *typeArgume
 %type <catchinfo>      CatchNameInfo
 %type <target>         AttributeTarget
 
-%expect 20
+%expect 18
 
 %start CompilationUnit
 %%
@@ -1952,8 +1952,8 @@ PrimarySimpleExpression
        | PrimaryExpression PTR_OP Identifier   {
                                MakeBinary(DerefField, $1, $3);
                        }
-       | STACKALLOC Type '[' Expression ']'    {
-                               MakeBinary(StackAlloc, $2, $4);
+       | STACKALLOC ArrayTypeStart Expression ']'      {
+                               MakeBinary(StackAlloc, $2, $3);
                        }
        | BUILTIN_CONSTANT '(' STRING_LITERAL ')'       {
                                /*
diff --git a/cscc/csharp/cs_misc.tc b/cscc/csharp/cs_misc.tc
index 05a4643..dfa2059 100644
--- a/cscc/csharp/cs_misc.tc
+++ b/cscc/csharp/cs_misc.tc
@@ -279,7 +279,8 @@ ILNode_GetType(ILNode_StackAlloc)
  */
 ILNode_GenValue(ILNode_StackAlloc)
 {
-       /* TODO */
+       ILNode_GenValue(node->expr2, info);
+       ILGenSimple(info, IL_PREFIX_OP_LOCALLOC + IL_OP_PREFIX);
        return ILMachineType_UnmanagedPtr;
 }
 
@@ -297,28 +298,56 @@ JavaGenValue(ILNode_StackAlloc)
  */
 ILNode_SemAnalysis(ILNode_StackAlloc)
 {
-       CSSemValue value1;
-       CSSemValue value2;
+       ILNode *tempNode;
+       ILType *type;
+       CSSemValue value;
 
        /* Print an error or warning for this construct if necessary */
        CCUnsafeMessage(info, (ILNode *)node, "unsafe `stackalloc' operator");
 
        /* Perform semantic analysis on the sub-expressions */
-       value1 = ILNode_SemAnalysis(node->expr1, info, &(node->expr1));
-       value2 = ILNode_SemAnalysis(node->expr2, info, &(node->expr2));
+       /* The first must be a type */
+       type = CSSemType(node->expr1, info, &(node->expr1));
 
-       /* The first must be a value type */
-       if(!CSSemIsType(value1))
+       /* The second one must be an integer expression */
+       value = ILNode_SemAnalysis(node->expr2, info, &(node->expr2));
+       if(!CSSemIsValue(value))
        {
-               /* TODO */
+               CCErrorOnLine(yygetfilename(node), yygetlinenum(node),
+                                         "invalid element number count in 
stackalloc expression");
        }
+       else
+       {
+               if(!ILCoerce(info, node->expr2, &node->expr2,
+                                        CSSemGetType(value), ILType_Int32, 1))
+               {
+                       CCErrorOnLine(yygetfilename(node->expr2), 
yygetlinenum(node->expr2),
+                                                 "incompatible types in 
stackalloc element number specifier: "
+                                                 "no conversion from `%s' to 
`int'",
+                                                 
CSTypeToName(CSSemGetType(value)));
+               }
+       }
+       /*
+        * Replace expr1 and expr2 with semguards so that they will not get
+        * semanalyzed again
+        */
+       node->expr2 = ILNode_SemGuard_create(node->expr2, value);
+       CSSemSetType(value, type);
+       tempNode = ILNode_SemGuard_create(node->expr1, value);
+       tempNode = ILNode_SizeOf_create(tempNode);
+       node->expr2 = ILNode_Mul_create(tempNode, node->expr2);
+       /* Now semanalyze the final expression again */
+       value = ILNode_SemAnalysis(node->expr2, info, &(node->expr2));
 
-       /* The second must be an "int" */
-       /* TODO */
+       /* The result has the type "pointer to type" */
+       type = ILTypeCreateRef(info->context, IL_TYPE_COMPLEX_PTR, type);
+       if(!type)
+       {
+               CCOutOfMemory();
+       }
 
-       /* The result has the type "pointer to value1.type" */
-       CSSemSetRValue(value1, ILType_Int32);   /* TODO */
-       return value1;
+       CSSemSetRValue(value, type);
+       return value;
 }
 
 ILNode_SemAnalysis(ILNode_NewExpression)
@@ -651,6 +680,7 @@ ILNode_SemAnalysis(ILNode_RefValue)
        CSSemSetRValue(value, node->type);
        return value;
 }
+
 ILNode_SemAnalysis(ILNode_BaseDestructor)
 {
        ILNode_MethodDeclaration *caller;
@@ -672,7 +702,18 @@ ILNode_SemAnalysis(ILNode_BaseDestructor)
        }
        return ILNode_SemAnalysis(node->destructor,info,&(node->destructor));
 }
+
+/*
+ * Generate value code for the "stackalloc" operator.
+ */
+ILNode_GenDiscard(ILNode_StackAlloc)
+{
+       /* For handling side effects only */
+       ILNode_GenDiscard(node->expr2, info);
+}
+
 ILNode_GenDiscard(ILNode_BaseDestructor)
 {
        ILNode_GenDiscard(node->destructor,info);
 }
+

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                |    5 +++
 cscc/csharp/cs_grammar.y |    6 ++--
 cscc/csharp/cs_misc.tc   |   67 +++++++++++++++++++++++++++++++++++++---------
 3 files changed, 62 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
DotGNU Portable.NET engine, compilers and tools (pnet)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]