瀏覽代碼

pastojs: currency:=integer becomes c:=i*10000, integer(currency) becomes Math.floor(cur/10000)

git-svn-id: trunk@39944 -
Mattias Gaertner 6 年之前
父節點
當前提交
23fe74416c
共有 2 個文件被更改,包括 27 次插入3 次删除
  1. 18 3
      packages/pastojs/src/fppas2js.pp
  2. 9 0
      packages/pastojs/tests/tcmodules.pas

+ 18 - 3
packages/pastojs/src/fppas2js.pp

@@ -8588,7 +8588,13 @@ begin
       begin
       // integer to integer -> value
       Result:=ConvertElement(Param,AContext);
-      if to_bt=btCurrency then
+      if ParamResolved.BaseType=btCurrency then
+        begin
+        if to_bt<>btCurrency then
+          // currency to integer -> Math.floor(value/10000)
+          Result:=CreateMathFloor(Param,CreateDivideNumber(Param,Result,10000));
+        end
+      else if to_bt=btCurrency then
         // integer to currency -> value*10000
         Result:=CreateMulNumber(Param,Result,10000);
       if (to_bt<>btIntDouble) and not (Result is TJSLiteral) then
@@ -15240,12 +15246,21 @@ begin
       end
     else if AssignContext.LeftResolved.BaseType=btCurrency then
       begin
-      if AssignContext.RightResolved.BaseType<>btCurrency then
+      if AssignContext.RightResolved.BaseType=btCurrency then
+        // currency := currency
+      else if AssignContext.RightResolved.BaseType in btAllJSFloats then
         begin
         // currency := double  ->  currency := Math.floor(double*10000)
         AssignContext.RightSide:=CreateMulNumber(El,AssignContext.RightSide,10000);
         AssignContext.RightSide:=CreateMathFloor(El,AssignContext.RightSide);
-        end;
+        end
+      else if AssignContext.RightResolved.BaseType in btAllJSInteger then
+        begin
+        // currency := integer  ->  currency := double*10000
+        AssignContext.RightSide:=CreateMulNumber(El,AssignContext.RightSide,10000);
+        end
+      else
+        RaiseNotSupported(El,AContext,20181016094542,GetResolverResultDbg(AssignContext.RightResolved));
       end
     else if AssignContext.RightResolved.BaseType=btCurrency then
       begin

+ 9 - 0
packages/pastojs/tests/tcmodules.pas

@@ -5459,8 +5459,13 @@ begin
   '  c:=a;',
   '  d:=c;',
   '  c:=d;',
+  '  c:=currency(c);',
   '  c:=currency(d);',
   '  d:=double(c);',
+  '  c:=i;',
+  '  c:=currency(i);',
+  //'  i:=c;', not allowed
+  '  i:=nativeint(c);',
   '  c:=c+a;',
   '  c:=-c-a;',
   '  c:=d+c;',
@@ -5522,8 +5527,12 @@ begin
     '$mod.c = $mod.a;',
     '$mod.d = $mod.c / 10000;',
     '$mod.c = Math.floor($mod.d * 10000);',
+    '$mod.c = $mod.c;',
     '$mod.c = $mod.d * 10000;',
     '$mod.d = $mod.c / 10000;',
+    '$mod.c = $mod.i * 10000;',
+    '$mod.c = $mod.i * 10000;',
+    '$mod.i = Math.floor($mod.c / 10000);',
     '$mod.c = $mod.c + $mod.a;',
     '$mod.c = -$mod.c - $mod.a;',
     '$mod.c = ($mod.d * 10000) + $mod.c;',