forked from MoeOrganization/moe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stevan Little
committed
Dec 31, 2012
0 parents
commit 3b7caf2
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.moe | ||
|
||
object Moe { | ||
|
||
val VERSION = 0.01; | ||
val AUTHORITY = "cpan:STEVAN"; | ||
|
||
object Errors { | ||
class ValueNotFound ( msg : String ) extends Exception( msg ) | ||
class UninitializedValue ( msg : String ) extends Exception( msg ) | ||
} | ||
|
||
def main ( args: Array[String] ): Unit = { | ||
println( "Hello World" ) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package org.moe.runtime | ||
|
||
trait Container {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.moe.runtime | ||
|
||
import scala.collection.mutable.HashMap | ||
|
||
import org.moe.Moe.Errors | ||
|
||
class Environment { | ||
|
||
object Markers { | ||
val Package = "__PACKAGE__"; | ||
val Class = "__CLASS__"; | ||
val Invocant = "__SELF__"; | ||
} | ||
|
||
val pad = new HashMap[String,Container](); | ||
|
||
var parent : Environment = _; | ||
|
||
def this ( p : Environment ) { | ||
this() | ||
parent = p | ||
} | ||
|
||
def getCurrentPackage (): Container = getLocal( Markers.Package ) | ||
def getCurrentClass (): Container = getLocal( Markers.Class ) | ||
def getCurrentInvocant (): Container = getLocal( Markers.Invocant ) | ||
|
||
def setCurrentPackage ( p : Container ): Unit = pad.put( Markers.Package, p ) | ||
def setCurrentClass ( c : Container ): Unit = pad.put( Markers.Class, c ) | ||
def setCurrentInvocant ( i : Container ): Unit = pad.put( Markers.Invocant, i ) | ||
|
||
def getParent (): Environment = parent | ||
def isRoot (): Boolean = parent == null | ||
|
||
def get ( name : String ): Container = { | ||
if ( pad.contains( name ) ) return pad( name ) | ||
if ( !isRoot ) return parent.get( name ) | ||
throw new Errors.ValueNotFound( name ); | ||
} | ||
|
||
def has ( name : String ): Boolean = { | ||
if ( pad.contains( name ) ) return true | ||
if ( !isRoot ) return parent.has( name ) | ||
false; | ||
} | ||
|
||
def create ( name : String, value : Container ): Unit = pad.put( name, value ) | ||
|
||
def set ( name : String, value : Container ): Unit = { | ||
if ( !has( name ) ) throw new Errors.UninitializedValue( name ) | ||
|
||
if ( pad.contains( name ) ) { | ||
pad.put( name, value ) | ||
} else { | ||
var current : Environment = parent | ||
while ( current != null ) { | ||
if ( current.hasLocal( name ) ) { | ||
current.setLocal( name, value ) | ||
return; | ||
} | ||
else { | ||
current = current.getParent | ||
} | ||
} | ||
throw new Errors.UninitializedValue( name ) | ||
} | ||
} | ||
|
||
private def getLocal ( name : String ): Container = pad( name ) | ||
private def hasLocal ( name : String ): Boolean = pad.contains( name ) | ||
private def setLocal ( name : String, value : Container ): Unit = pad.put( name, value ) | ||
|
||
} | ||
|
||
|