JSCompiler subclass: #EJSCompiler instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'EJavascript'! !EJSCompiler methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 22:12'! compile ::= {#when :c :s} => [{'(('. self currentContext. ' jsAt: #''__sched__'') invokeScriptOn: '. '[[true] whileTrue: [[Processor activeProcess suspend. '. c. '] whileFalse. '. s. '. Processor activeProcess suspend]] selector: #value arguments: #())'}] | ! ! JSDeclVisitor subclass: #EJSDeclVisitor instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'EJavascript'! !EJSDeclVisitor methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 22:01'! decls ::= {#when :c :s} => [{#when. c. s}] | ! ! JSObject subclass: #EJSObject instanceVariableNames: '' classVariableNames: 'EGlobal PlayerProto' poolDictionaries: '' category: 'EJavascript'! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! EJSObject class instanceVariableNames: ''! !EJSObject class methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 23:20'! example1 " EJSObject example1 " EJSObject eval: ' x = 0 when (x % 5 == 0) print("5 "); when (x % 19 == 0) print("19 "); when (true) x = x + 1; '! ! !EJSObject class methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 23:21'! example2 " EJSObject example2 " | global playfield morph | global := self global. playfield := global jsAt: #'__container__'. morph := Morph new. playfield addMorph: morph. morph center: playfield center. global jsAt: #this put: morph assuredPlayer. self eval: ' when (true) this.turn(5); when (true) this.forward(5); ' withGlobal: global.! ! !EJSObject class methodsFor: 'as yet unclassified' stamp: 'aw 9/1/2007 00:18'! example3 " EJSObject example3 " | global playfield rocket joystick | global := self global. playfield := global jsAt: #'__container__'. rocket := Morph new center: playfield center; yourself. joystick := JoystickMorph new. playfield addMorph: rocket. playfield addMorph: joystick. rocket center: playfield center. global jsAt: #rocket put: rocket assuredPlayer; jsAt: #joystick put: joystick assuredPlayer. self eval: ' vel = 0 when (true) rocket.turn(joystick.leftRight() / 5); when (joystick.upDown() > 4) vel = vel + 1.1; when (true) { vel = vel - 1 rocket.y(rocket.y() + vel) } when (rocket.y() < 0) { rocket.y(0) vel = -vel * 0.9 } ' withGlobal: global.! ! !EJSObject class methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 23:07'! global | playfield | playfield := EJSPlayfield new openInWorld. ^ super global makeSandbox jsAt: #'__container__' put: playfield; jsAt: #'__sched__' put: playfield scheduler; jsAt: #print put: (self functionWithEnv: Global args: #(x) body: [:ctxt | Transcript show: ((ctxt jsAt: #x) jsSend: #toString withArguments: #()) ]); yourself! ! !EJSObject class methodsFor: 'as yet unclassified' stamp: 'aw 9/1/2007 00:18'! initialize " EJSObject initialize " PlayerProto _ JSObject objectProto makeChild jsAt: #forward put: (self functionWithEnv: Global args: #(x) body: [:ctxt | (ctxt jsAt: #this) forward: (ctxt jsAt: #x)]); jsAt: #turn put: (self functionWithEnv: Global args: #(x) body: [:ctxt | (ctxt jsAt: #this) turn: (ctxt jsAt: #x)]); jsAt: #x put: (self functionWithEnv: Global args: #() body: [:ctxt | (ctxt jsAt: #this) getX]); jsAt: #y put: (self functionWithEnv: Global args: #() body: [:ctxt | | args | args := ctxt jsAt: #arguments. args ifEmpty: [(ctxt jsAt: #this) getY] ifNotEmpty: [(ctxt jsAt: #this) setY: args first] ]); jsAt: #heading put: (self functionWithEnv: Global args: #() body: [:ctxt | (ctxt jsAt: #this) getHeading]); jsAt: #upDown put: (self functionWithEnv: Global args: #() body: [:ctxt | (ctxt jsAt: #this) getUpDown]); jsAt: #leftRight put: (self functionWithEnv: Global args: #() body: [:ctxt | (ctxt jsAt: #this) getLeftRight]); yourself.! ! !EJSObject class methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 22:16'! parser ^ EJSParser! ! !EJSObject class methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 23:24'! playerProto ^ PlayerProto! ! JSParser subclass: #EJSParser instanceVariableNames: '' classVariableNames: 'EKeywords' poolDictionaries: '' category: 'EJavascript'! !EJSParser methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 22:42'! compiler ^ EJSCompiler! ! !EJSParser methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 22:43'! declVisitor ^ EJSDeclVisitor! ! !EJSParser methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 22:00'! expr ::= | :c :s => [{#when. c. s}]! ! !EJSParser methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 22:29'! keywords ^ EKeywords! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! EJSParser class instanceVariableNames: ''! !EJSParser class methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 22:29'! initialize " EJSParser initialize " EKeywords := Keywords copy. EKeywords add: #when.! ! PasteUpMorph subclass: #EJSPlayfield instanceVariableNames: 'scheduler slider' classVariableNames: '' poolDictionaries: '' category: 'EJavascript'! !EJSPlayfield methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 22:59'! initialize super initialize. scheduler _ EtoysScriptScheduler new. self extent: 400@300. slider _ SimpleSliderMorph new. slider maxVal: 10.0. slider minVal: 0.0. slider setNumericValue: 1.0. self addMorph: slider. slider position: 380@0. ! ! !EJSPlayfield methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 22:59'! scheduler ^ scheduler! ! !EJSPlayfield methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 23:00'! step scheduler scale: slider getScaledValue. scheduler step ! ! !EJSPlayfield methodsFor: 'as yet unclassified' stamp: 'aw 8/31/2007 23:00'! stepTime ^ 0! ! !Player methodsFor: '*EJavascript' stamp: 'aw 8/31/2007 23:26'! jsAt: key ^ EJSObject playerProto jsAt: key! ! !Player methodsFor: '*EJavascript' stamp: 'aw 8/31/2007 23:26'! jsAt: key put: val ^ EJSObject playerProto jsAt: key put: val! ! EJSParser initialize! EJSObject initialize!