Implement basics of a AST -> JS generator
ClosedPublic

Authored by jangmarker on Sep 12 2015, 12:24 PM.

Details

Summary

For a list of currently supported language features,
please see the commits below.

It relates to T509

[Compiler] Start

[Compiler] Add basic integration test for JS Generator

[Compiler] Make first integration test work

  • assignments
  • post-/predecrements
  • post-/preincrements

[Compiler] Adopt integration name class to naming schema

[Compiler] Start work on functions

[Compiler] Refactor to use stack only

This allows for a more consequent concept.

  • add handling of lists for SourceElements and StatementList needed to have same pass level of integration tests as before the refactoring
  • change macros to reflect new concept
  • introduces a new error type InternalError this error is created if the stack was not correctly reduced, which should not happen in practice

[Compiler] Finish work on functions

[Compiler] Better logic for nullptr members

  • no more "" on stack
  • more expressive logic
  • generates code for var i correctly

[Compiler] Complete binary operations

[Compiler] Make function declarations more robust

  • handle multiple parameters more correctly
  • handle empty body correctly
  • move integration test for EmptyStatement in its own file

[Compiler] Make functoin declaration lists work

[Compiler] Make return statements work

[Compiler] Implement branching

[Compiler] Make switch statement work

[Compiler] Make test better readable and maintainable

Diff Detail

Repository
R18 QMLWeb
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
jangmarker updated this revision to Diff 865.Sep 12 2015, 12:24 PM
jangmarker retitled this revision from to Implement basics of a AST -> JS generator.
jangmarker updated this object.
jangmarker edited the test plan for this revision. (Show Details)
jangmarker added a reviewer: akreuzkamp.
akreuzkamp edited edge metadata.Sep 12 2015, 2:34 PM

Thanks! :)

src/qmljsc/purejavascriptgenerator.cpp
86

we shouldn't add braces to the stack. We should only add the content of the block to the stack and add the braces on compositing the code of the block in endVisit.

91

I'd rather call it reduceJumpStatement, the fact that it has an optional label statement is too much for a name, I think and rather causes confusion than helping to understand what it is.

Then I'd rather sort the method definitions logically, i.e. putting continue and the reduceJump.*Statement here.

101

add on compositing, please.

129

add on compositing, please.

135

add on compositing, please.

145

add on compositing, please.

150

QString::number is what you want :)

155

add on compositing, please.

160

add on compositing, please.

165

add on compositing, please.

170

add on compositing, please.

175

add on compositing, please.

185

add on compositing, please.

197

add on compositing, please.

208

add on compositing, please.

363

I'd call this reducePostOperation.

369

I'd call this reducePreOperation

tests/auto/qmljsc/testpurejavascriptgenerator.cpp
302

yes, quotes are missing, apparently. String literals at least need to produce the quotes.

313

if cases stands for anything which is a statement (a case block ends with a statement) you should at least add a ";" to it, so you can read it. So it should be "{cases;default}" and ({"{". "cases;", "default"}).

jangmarker updated this revision to Diff 879.Sep 15 2015, 7:48 PM
jangmarker marked 19 inline comments as done.
jangmarker edited edge metadata.

[Compiler] Fix issues pointed out in review

This revision was automatically updated to reflect the committed changes.
jangmarker reopened this revision.Sep 20 2015, 2:16 PM

the commit which closed this revision was not development/qmlweb2

Please explain me, what you did in Diff 3.
Diff 2 would have got a ship it...

src/qmljsc/purejavascriptgenerator.cpp
26

you've got a new without a delete here.

39

You're adding to the generated code directly, instead of using the expression stack. Is that done on purpose?
(also in the function below)

81

why did you remove that?

98

again adding to generated code...
(also below)

140

adding to generated code

235

coding style (please add spaces around operators).

257

coding style.

265

coding style.

jangmarker updated this revision to Diff 933.Sep 29 2015, 10:37 AM

Use correct patch

  • [Compiler] Start implementation of AST -> JS generator
  • [Compiler] Add basic integration test for JS Generator
  • [Compiler] Make first integration test work
  • [Compiler] Adopt integration name class to naming schema
  • [Compiler] Start work on functions
  • [Compiler] Refactor to use stack only
  • [Compiler] Finish work on functions
  • [Compiler] Better logic for nullptr members
  • [Compiler] Complete binary operations
  • [Compiler] Make function declarations more robust
  • [Compiler] Make functoin declaration lists work
  • [Compiler] Make return statements work
  • [Compiler] Implement branching
  • [Compiler] Make switch statement work
  • [Compiler] Make test better readable and maintainable
  • [Compiler] Fix issues pointed out in review

There was an issue with phabricator, it created a patch from something it shouldn't use.
Ignore Patch 3

Patch 4 and 2 should be identical and be merged.

akreuzkamp accepted this revision.Sep 30 2015, 8:10 PM
akreuzkamp edited edge metadata.

Then please address the coding style issues and then land it. :)

Thanks a lot for doing the boring work! :)

src/qmljsc/purejavascriptgenerator.cpp
235

coding style: please put whitespaces around the trinary operators

257

coding style

265

coding style

This revision is now accepted and ready to land.Sep 30 2015, 8:10 PM
Closed by commit R18:2c9cc50c5bf4: Implement basics of a AST -> JS generator (authored by Jan Marker <jan@jangmarker.de>). · Explain WhySep 30 2015, 8:31 PM
This revision was automatically updated to reflect the committed changes.