Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use own array implementation in VBS API #178

Merged
merged 9 commits into from
Nov 25, 2019
Merged

Conversation

freezy
Copy link
Member

@freezy freezy commented Nov 24, 2019

This PR adds a new object VbsArray, which should be used in the scripting API, i.e. what the table script and its dependencies deal with when they get an array.

It's a proxy that is iterable and can set and get values, but returns an VbsUndefined object instead of just undefined when an index doesn't exist. VbsUndefined is an empty proxy that either throws an exception when VBS error handling is enabled (On Error Goto 0), or sets the Err object accordingly (if On Error Resume) if it's accessed.

This should mitigate the problem we have in #141. It's actually another fifth solution to the proposed other four.

It might needs to be extended to objects, but I think it's the cleanest solution for now.

TODO

  • replace remaining JS arrays in API with VbsArray

@freezy freezy self-assigned this Nov 24, 2019
@codecov
Copy link

codecov bot commented Nov 24, 2019

Codecov Report

Merging #178 into master will decrease coverage by 0.02%.
The diff coverage is 91.49%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #178      +/-   ##
==========================================
- Coverage   90.84%   90.83%   -0.01%     
==========================================
  Files         273      275       +2     
  Lines       14342    14359      +17     
  Branches     1675     1678       +3     
==========================================
+ Hits        13028    13042      +14     
- Misses        812      816       +4     
+ Partials      502      501       -1
Impacted Files Coverage Δ
lib/vpt/collection/collection-api.ts 95.46% <ø> (ø) ⬆️
lib/scripting/transformer/transformer.ts 75.87% <100%> (ø) ⬆️
lib/scripting/objects/vpm-controller.ts 89.39% <100%> (ø) ⬆️
lib/scripting/stdlib/err.ts 93.75% <100%> (+4.87%) ⬆️
lib/scripting/stdlib/index.ts 100% <100%> (ø) ⬆️
lib/scripting/vbs-array.ts 100% <100%> (ø)
lib/scripting/vbs-undefined.ts 100% <100%> (ø)
lib/emu/emulator-state.ts 89.59% <100%> (+0.23%) ⬆️
lib/scripting/post-process/error.ts 100% <100%> (ø) ⬆️
lib/scripting/vbs-helper.ts 81.4% <69.24%> (-5.78%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fae065a...705826a. Read the comment docs.

Copy link
Contributor

@neophob neophob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might needs to be extended to objects, but I think it's the cleanest solution for now.

fully agree yes. So I tested this and my expectation is, that when we use mm-playfield.vpx and see the rom errors (due missing switch settings in the test table) AND press the ESC onscreen button, the rom should be loaded. however I still see

Uncaught TypeError: Cannot set property 'State' of undefined
    at TimerApi.eval (tablescript.js:31)
    at TimerApi.emit (events.js:146)
    at EventProxy.fireDispID (event-proxy.js:50)
    at EventProxy.fireGroupEvent (event-proxy.js:44)
    at PlayerPhysics.updatePhysics (player-physics.js:312)
    at Player.updatePhysics (player.js:89)
    at player.worker.js:88

which points to ` __vbsHelper.getOrCall(__scope.Lights, idx).State = __vbsHelper.getOrCall(ChgLamp, ii, 1);``

shouln't that be solved now? or do I need an updated table with specific error handling enabled?

lib/scripting/stdlib/err.ts Show resolved Hide resolved
lib/scripting/vbs-array.spec.ts Show resolved Hide resolved
lib/scripting/vbs-array.ts Show resolved Hide resolved
lib/scripting/vbs-array.spec.ts Show resolved Hide resolved
@freezy
Copy link
Member Author

freezy commented Nov 24, 2019

Your test result is unfortunate ;)

Lemme actually test this :)

@neophob
Copy link
Contributor

neophob commented Nov 24, 2019

stupid users are NEVER guilty ;)

@freezy
Copy link
Member Author

freezy commented Nov 24, 2019

The use case doesn't actually use VbsArray, but a locally declared array. Need to update the VbsHelper.dim() function in order to make that work. Working on it..

@neophob
Copy link
Contributor

neophob commented Nov 24, 2019

AHA, we can another error now:

Uncaught Error: ReferenceError: Cannot set 88 from undefined.
    at VbsArray.get (vbs-array.js:34)
    at VBSHelper.getOrCall (vbs-helper.js:84)
    at TimerApi.eval (tablescript.js:31)
    at TimerApi.emit (events.js:146)
    at EventProxy.fireDispID (event-proxy.js:50)
    at EventProxy.fireGroupEvent (event-proxy.js:44)
    at PlayerPhysics.updatePhysics (player-physics.js:312)
    at Player.updatePhysics (player.js:89)
    at player.worker.js:88

while line 34 looks like return target[key] !== undefined ? target[key] : new VbsUndefined(new VbsError(ReferenceError: Cannot set ${String(key)} from undefined., 9), new VbsError(ReferenceError: Cannot get ${String(key)} from undefined., 9));

@freezy
Copy link
Member Author

freezy commented Nov 25, 2019

Yes, that's expected, because error handling is actually off per default ("off" as is "crash on error"), so now we'll need to implement On Error Resume in order not to crash anymore.

You can temporarily try to set doThrow = false in the Err class.

Copy link
Contributor

@neophob neophob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

work great now!

Copy link
Contributor

@jsm174 jsm174 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the old grammar to support On Error.

In a future PR, I'd like to split Redim into two helpers. One for a normal Redim and one for a Preserve. We could also pass the dimensions in as a variable argument list instead of an array. I think this would make the transpiled code look cleaner.

@freezy freezy merged commit 257d863 into master Nov 25, 2019
@freezy freezy deleted the scripting/fake-array branch November 25, 2019 15:29
@freezy
Copy link
Member Author

freezy commented Nov 25, 2019

Thanks for the review guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants