GithubHelp home page GithubHelp logo

bthink-bgu / bpjs Goto Github PK

View Code? Open in Web Editor NEW
36.0 36.0 8.0 6.02 MB

Environment for running behavioral programs written in JavaScript.

License: MIT License

Java 86.41% JavaScript 13.59%
behavioral-programming engine

bpjs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bpjs's Issues

Refactor: BSyncStatement should not have a BThread

Thus it could also be immutable.

Where it is required, we can probably move to a Map<b-thread id, BSS>. The b-thread id is currently a String, which we might want to revisit too.

Another option - use Set<BThreadSyncSnapshot> instead of the map.

Split the .jars to to FAT and normal

this is to allow

  • easy to run executable jar, that users can d/l form GitHub
  • a sane jar to include in builds.

General direction: Use a profile to make the FAT jar using shade plugin. Use default build for the normal .jar.

Automatic event conversion

In BThreadJSProxy, we can allow a shorthand where users pass just the name of the event and we generate the event for it. So the following lines of code are equivalent:

bsync({request:"A"});
bsync({request:bp.Event("A")});

Can also consider allowing a to-stringed integer. Other objects there should result in IllegalArgumentException.

TicTacToeVerMaim does not work

Crashes with message:

Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "UseSimulatedPlayer" is not defined. (BPJSTicTacToe.js#12)
	at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4142)
	at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4120)
	at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:4210)
	at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1952)
	at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1891)
	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1558)
	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:815)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:109)
	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:399)
	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3452)
	at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:120)
	at org.mozilla.javascript.Context.evaluateString(Context.java:1244)
	at il.ac.bgu.cs.bp.bpjs.model.BProgram.evaluate(BProgram.java:209)
	... 6 more

Crash when de-serializing a BThreadSyncSnapshot with a scope that holds a Java object

see discussion here:

https://groups.google.com/forum/#!topic/mozilla-rhino/_FpS27B_01k

Workaround:
store relevant fields of the objects in JS vars (e.g. get the last event's name rather than storing it as-is).

Possible solution pointer:
Implement a state serializer that uses Rhino's ScriptableObjectOutputStream. This solution was implemented by the Spring folks when faced with a similar problem:
https://sourceforge.net/p/rhinoinspring/code/HEAD/tree/trunk/rhinoInSpring/src/java/org/szegedi/spring/web/jsflow/support/FlowStateSerializer.java#l240

Refactor: BThreadJsProxy

a. Not sure if this is needed at all. Currently its only use is setInterruptHandler, which might be replaceable using ThreadLocals at the BPEngineTasks, or even by cancelling this option, and passing the handler at the bp.sync site.
b. If we keep it, and since it has no state of its own, it should be pointless to keep it around when not running. Ideally, we'll create a proxy and a scope just before running the b-thread, and let the GC have it when the b-thread hits its next bp.sync.

Better system for reporting warnings to the programmer

At the moment, when a programmer is doing "weird" stuff (e.g. block an event while requesting it), BPjs prints a message to stderr. This works, but a better way would be to report a warning to a listener. This will allow IDEs or embedded runtimes (such as web servers) to report the errors to the user.

Also, need to think on maybe creating/using a logging framework for this.

Escape scoping issue: Allow parameters to the b-thread entry point.

As we can't use closures in BPjs, we need another mechanism to pass data from parent syntactical scopes to their descendants. An option:

var x=...
var y=...
bp.regBT( "child", function(a,b){...}, x,y)
// or
bp.regBT( "child", function(a,b){...}, [x,y] )

Where on invocation of the child, a<-x and b<-y.

Usable way of importing and exporting objects between JS and the Java listeners

Consider the following BThread:
bp.registerBThread("Test", function() {
bp.sync({ waitFor:[ bp.Event('Click', {row: 0, col: 0}) ] });
});

It is easy to request this event from JS, however it is impossible to request it from external event. The reason is that the data of the event created in JS is converted to a Rhino object.

Another related issue is that data objects in JS has a string representation, however in Java they are [object Object] - which makes it very hard to debug.

@potashkeren


@michbarsinai Editing after talking with @eggsterino:

We need a way for:

  1. importing external objects as if they were created JS (e.g. parsing JSON on the Java side and then putting it into objects in JS). This should allow objects created in Java to be the same as those created in JS.
  2. Reading objects created in JavaScript as Java objects.

Note that these objects are not necessarily JSON-like, so we can allow complex objects as keys, as long as they have a working equals method. Further translation to/from JSON is another story, but should be considered as part of this issue as well.

Support fork

Minimal:

if ( bp.fork() ) {
   doChild();
} else {
   doParent();
}

Better `equals` method between event sets

Equals should be done at the semantic set level, as much as possible.

e.g:

  • None and empty array should be same (this could be handled during event set conversion)
  • an event and an array containing only it should be the same (this could be handled during event set conversion)
  • two arrays containing the same events, even in different order, should be the same.

Note the delicate interplay with hashCode on this - we might need to implement our own BProgramSyncSnapshot sets.

Executors are not being shutdown when setting daemon mode to false

I use BPjs program when running an external framework (robocode). I set daemon mode to false when completing the run (battle), but I still get log prints on threads that are still running:
Waiting for robot il.ac.bgu.cs.bp.bpjsrobot.BPjsRobot* to stop thread ForkJoinPool-1-worker-1
Waiting for robot il.ac.bgu.cs.bp.bpjsrobot.BPjsRobot* to stop thread ForkJoinPool-1-worker-2
Waiting for robot il.ac.bgu.cs.bp.bpjsrobot.BPjsRobot* to stop thread ForkJoinPool-1-worker-3
Waiting for robot il.ac.bgu.cs.bp.bpjsrobot.BPjsRobot* to stop thread ForkJoinPool-1-worker-4
Waiting for robot il.ac.bgu.cs.bp.bpjsrobot.BPjsRobot* to stop thread ForkJoinPool-1-worker-5
Waiting for robot il.ac.bgu.cs.bp.bpjsrobot.BPjsRobot* to stop thread ForkJoinPool-1-worker-6
Waiting for robot il.ac.bgu.cs.bp.bpjsrobot.BPjsRobot* to stop thread ForkJoinPool-1-worker-7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.