Author Topic: complex mathematical expression and re-used of script  (Read 12381 times)

TouEnMasm

  • Member
  • *****
  • Posts: 1764
    • EditMasm
complex mathematical expression and re-used of script
« on: April 15, 2013, 04:52:19 PM »
This one is a translate of a c++ sample.
It show how to use the javascript function "eval".
It use the windows function ShowHTMLDialog to run the script in a HTML page.
Further samples of complex mathematical expression  are given (4)

This can be done also writing a script .js.
evalue.js:
Quote
mydate = eval(-1 * (((3*2) + 1) / 0.528 + (2.225>>1) +   ((25.24/0x03) + (12.26/1.22))));
WScript.Echo (mydate);

I have made it better.
     Added:
     -Control of the number of parenthesis
     -Syntax case is unsensitive for the javascript Object Math
     - allow instructions without Math.

Quote
db "E",0,"PI",0"abs",0,"ceil",0,"floor",0,"round",0,"max",0,"min",0
        db "pow",0,"random",0,"sqrt",0,"exp",0,"LN2",0,"LN10",0,"log",0
       db "LOG2E",0,"SQRT1_2",0,"SQRT2",0,"sin",0,"asin",0,"cos",0,"acos",0
        db "tan",0,"atan",0,0

Note:Only Jwasm (last version) could compile this source

The very classic sample:
Code: [Select]
/*  ax²+bx+c = 0 */

var a = 8
var b = 10
var c = 3
var delta = pow(b,2) -4*a*c


if (delta > 0)  {
 var sola = (- b - sqrt(delta))/4;
var solb = (- b + sqrt(delta))/4;
sola + "  " +solb +"   two  soluces"
 }

if (delta == 0) {
var sola = - b/(2*a);
sola + "One soluce"
}

if (delta < 0) {
 "No soluce";}

« Last Edit: April 18, 2013, 08:14:32 PM by ToutEnMasm »
Fa is a musical note to play with CL

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: complex mathematical expression and re-used of script
« Reply #1 on: April 16, 2013, 12:06:04 AM »
really nice  :icon14:

For an general purpose evaluator, I would make a string replacement thus we can, for example, directly write sin() instead of Math.sin().

MREAL macros - when you need floating point arithmetic while assembling!

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: complex mathematical expression and re-used of script
« Reply #2 on: April 16, 2013, 12:41:02 AM »
very cool, Yves
i didn't know you could do that   :t

Gunther

  • Member
  • *****
  • Posts: 4198
  • Forgive your enemies, but never forget their names
Re: complex mathematical expression and re-used of script
« Reply #3 on: April 16, 2013, 01:29:25 AM »
Hi Yves,

well done.  :t

Gunther
You have to know the facts before you can distort them.

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: complex mathematical expression and re-used of script
« Reply #4 on: April 16, 2013, 03:45:15 AM »
very cool, Yves
i didn't know you could do that   :t

I didn't know it was possible - nice idea :t
Yves & Edgar are our COM champions ;-)

TouEnMasm

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: complex mathematical expression and re-used of script
« Reply #5 on: April 16, 2013, 04:20:05 AM »

For replacement as:
Quote
directly write sin() instead of Math.sin().
It is possible,just put the samples here,I will add the needed proc to do it.
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: complex mathematical expression and re-used of script
« Reply #6 on: April 16, 2013, 04:43:09 AM »
By the way, what is "IMoniker Release"? A macro? Necessary for a local variable?

TouEnMasm

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: complex mathematical expression and re-used of script
« Reply #7 on: April 16, 2013, 02:44:18 PM »
Quote
what is "IMoniker Release"?

IMoniker is an interface and as all com object had a pointer on it.
Here it's ppvIMoniker.
Get it by CreateURLMoniker.
This interface is used only by ShowHTMLDialogd.
When it is done "Release" the pointer and uninitialise  all things (memory ..)needed by the interface (if number of user =0).

The sdk translate use a very formal syntax to work with interface.
if the name of the interface is IMoniker
                   The name of the pointer is:                   ppvIMoniker
                   The name of structure of functions is:     STIMoniker
                   The invoke statement is named            IMoniker (a macro)

IMoniker Release mean:
Invoke the Release function of the IMoniker Interface

In case of there is need of a second pointer on the same interface (WMI use that)
The sdk translate provide the COM Macro (translate.inc) to solve that.


 



Fa is a musical note to play with CL

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1196
Re: complex mathematical expression and re-used of script
« Reply #8 on: April 16, 2013, 06:36:03 PM »
This would be more useful with an exponentiation operator.
Well Microsoft, here’s another nice mess you’ve gotten us into.

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: complex mathematical expression and re-used of script
« Reply #9 on: April 16, 2013, 07:59:15 PM »
Where is that one defined, Yves?

error LNK2001: unresolved external symbol _ShowHTMLDialog@20

Did anybody succeed in building the example??

TouEnMasm

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: complex mathematical expression and re-used of script
« Reply #10 on: April 16, 2013, 08:44:00 PM »
Quote
error LNK2001: unresolved external symbol _ShowHTMLDialog@20

The batch is named jwasm_build with a good reason,ml made this error.
Compile the sample with JWASM and all is good.
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: complex mathematical expression and re-used of script
« Reply #11 on: April 16, 2013, 10:31:31 PM »
Compile the sample with JWASM and all is good.

I got it running with the latest JWasm version :t

It throws a warning for line 685 of propidl.sdk:
IFDEF def __cplusplus
ELSE
ENDIF

Even with a fixed propidl, masm 8.0 + 9.0 throw exceptions ("internal error"), which is surprising for such a short code (I use version 7 of your SDK).

As you know, I am a great fan of JWasm, but IMHO a library should remain compatible to standard Masm, too. "All is good" looks different ;-)

By the way, your site is a bit difficult to access. Maybe you should put a fat text with a link to the SDK download. And you probably meant "Utilisez JWasm", not "Utilisé JWASM".

P.S.:
By the way, what is "IMoniker Release"? A macro? Necessary for a local variable?

ObjIdl.sdk, line 1228:

IMoniker MACRO  Function:REQ, args:VARARG

TouEnMasm

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: complex mathematical expression and re-used of script
« Reply #12 on: April 17, 2013, 12:49:40 AM »

If you want to play a little with bug (very funny  :icon_mrgreen:)
Try this
Math.pi;
Instead of
Quote
Math.PI;
correct syntax
This made an int 3 in
Code: [Select]
invoke SysFreeString,ebx     ;FreeBSTR PROC in bstr.inc
I search a way to avoid this.
 




Fa is a musical note to play with CL

TouEnMasm

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: complex mathematical expression and re-used of script
« Reply #13 on: April 17, 2013, 04:45:58 PM »

For the bug just delet this line
      ;invoke VariantClear,addr varArgs            
Fa is a musical note to play with CL

Siekmanski

  • Member
  • *****
  • Posts: 2725
Re: complex mathematical expression and re-used of script
« Reply #14 on: April 17, 2013, 05:01:35 PM »
Nice  :t
Creative coders use backward thinking techniques as a strategy.