[nem-bug] [Nemerle 0000639]: A compile-time calculus and code generation

feedback at nemerle.org feedback at nemerle.org
Tue Mar 28 22:04:43 CEST 2006


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=639> 
======================================================================
Reported By:                VladD2
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   639
Category:                   Compiler
Reproducibility:            always
Severity:                   crash
Priority:                   normal
Status:                     new
======================================================================
Date Submitted:             03-28-2006 02:27 CEST
Last Modified:              03-28-2006 22:04 CEST
======================================================================
Summary:                    A compile-time calculus and code generation
Description: 
If write macro like this:
using System;

macro CompileTimeFactorial(x : uint)
{
  def factorial = Math.Factorial(x);
  <[ $(factorial : ulong) ]>
}

public module Math
{
  public static Factorial(x : uint) : ulong
  {
    def Loop(acc : ulong, x : uint)
    {
      if (x <= 1) acc else Loop(acc * x, x - 1)
    };
    
    Loop (1UL, x)
  }
}

and try to use it like this:
WriteLine(CompileTimeFactorial(0));

The compiler generate such IL:
.method private hidebysig static void Main() cil managed
{
      .entrypoint
      .maxstack 1
      L_0000: ldc.i8 1
      L_0009: conv.u8 
      L_000a: call void [mscorlib]System.Console::WriteLine(int32)
      L_000f: ret 
}

That is in a fanction which take int32 parameter pass uint64 argument.
If run this code AV is expected.
======================================================================

----------------------------------------------------------------------
 nazgul - 03-28-06 21:39 
----------------------------------------------------------------------
This is strange, the literal expression created inside macro is properly
initialized as UInt64 literal. I don't know why overloading engine treat
it as int.

----------------------------------------------------------------------
 VladD2 - 03-28-06 22:04 
----------------------------------------------------------------------
The bug going out if result value (constant) is big.

For example:
WriteLine(CompileTimeFactorial(20));
work correctly.

Apparently overloading engine work with result constant value.

I avoid this probleb in the following way:
macro CompileTimeFactorial(x : uint)
{
  //
&http://nemerle.org/bugs/view.php?id=1055;&http://nemerle.org/bugs/view.php?id=1088;&http://nemerle.org/bugs/view.php?id=1080;&http://nemerle.org/bugs/view.php?id=1074;&http://nemerle.org/bugs/view.php?id=1077;&http://nemerle.org/bugs/view.php?id=1076;&http://nemerle.org/bugs/view.php?id=1077;&http://nemerle.org/bugs/view.php?id=1085;&http://nemerle.org/bugs/view.php?id=1080;&http://nemerle.org/bugs/view.php?id=1077;
&http://nemerle.org/bugs/view.php?id=1090;&http://nemerle.org/bugs/view.php?id=1080;&http://nemerle.org/bugs/view.php?id=1087;&http://nemerle.org/bugs/view.php?id=1086;&http://nemerle.org/bugs/view.php?id=1074;
(&http://nemerle.org/bugs/view.php?id=1074;&http://nemerle.org/bugs/view.php?id=1090;&http://nemerle.org/bugs/view.php?id=1086;&http://nemerle.org/bugs/view.php?id=1088;&http://nemerle.org/bugs/view.php?id=1086;&http://nemerle.org/bugs/view.php?id=1081;
 : ulong)
&http://nemerle.org/bugs/view.php?id=1090;&http://nemerle.org/bugs/view.php?id=1088;&http://nemerle.org/bugs/view.php?id=1077;&http://nemerle.org/bugs/view.php?id=1073;&http://nemerle.org/bugs/view.php?id=1091;&http://nemerle.org/bugs/view.php?id=1077;&http://nemerle.org/bugs/view.php?id=1090;&http://nemerle.org/bugs/view.php?id=1089;&http://nemerle.org/bugs/view.php?id=1103;
&http://nemerle.org/bugs/view.php?id=1080;&http://nemerle.org/bugs/view.php?id=1079;-&http://nemerle.org/bugs/view.php?id=1079;&http://nemerle.org/bugs/view.php?id=1072;
&http://nemerle.org/bugs/view.php?id=1086;&http://nemerle.org/bugs/view.php?id=1096;&http://nemerle.org/bugs/view.php?id=1080;&http://nemerle.org/bugs/view.php?id=1073;&http://nemerle.org/bugs/view.php?id=1082;&http://nemerle.org/bugs/view.php?id=1080;
&http://nemerle.org/bugs/view.php?id=1074;
&http://nemerle.org/bugs/view.php?id=1082;&http://nemerle.org/bugs/view.php?id=1086;&http://nemerle.org/bugs/view.php?id=1084;&http://nemerle.org/bugs/view.php?id=1087;&http://nemerle.org/bugs/view.php?id=1080;&http://nemerle.org/bugs/view.php?id=1083;&http://nemerle.org/bugs/view.php?id=1103;&http://nemerle.org/bugs/view.php?id=1090;&http://nemerle.org/bugs/view.php?id=1086;&http://nemerle.org/bugs/view.php?id=1088;&http://nemerle.org/bugs/view.php?id=1077;
:(
  <[ ($(Math.Factorial(x) : ulong) : ulong) ]>
}

Issue History
Date Modified  Username       Field                    Change              
======================================================================
03-28-06 02:27 VladD2         New Issue                                    
03-28-06 21:39 nazgul         Note Added: 0001127                          
03-28-06 22:04 VladD2         Note Added: 0001128                          
======================================================================




More information about the bugs mailing list