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
1 parent
91a2cb2
commit 39b819d
Showing
6 changed files
with
130 additions
and
23 deletions.
There are no files selected for viewing
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 @@ | ||
target/ |
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
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
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,47 @@ | ||
package org.moe.runtime | ||
|
||
import scala.collection.mutable.HashMap | ||
|
||
import org.moe.Moe.Errors | ||
|
||
class MoeClass ( | ||
private val name : String, | ||
private val version : String, | ||
private val authority : String | ||
) { | ||
|
||
private var superclass : MoeClass = _ | ||
|
||
private val methods = new HashMap[String,MoeMethod]() | ||
|
||
def getName (): String = name | ||
def getVersion (): String = version | ||
def getAuthority (): String = authority | ||
|
||
def getSuperclass (): MoeClass = superclass | ||
def hasSuperclass (): Boolean = superclass != null | ||
def setSuperclass ( s : MoeClass ): Unit = superclass = s | ||
|
||
def getMethod ( name : String ): MoeMethod = { | ||
if ( hasMethod( name ) ) return methods( name ) | ||
if ( hasSuperclass ) return superclass.getMethod( name ) | ||
throw new Errors.MethodNotFound( name ) | ||
} | ||
|
||
def hasMethod ( name : String ): Boolean = { | ||
if ( methods.contains( name ) ) return true | ||
if ( hasSuperclass ) return superclass.hasMethod( name ) | ||
false | ||
} | ||
|
||
override def toString (): String = { | ||
var out = "{ " + name | ||
out += " " + version | ||
out += " " + authority | ||
if (hasSuperclass) { | ||
out += " #extends " + superclass.toString() | ||
} | ||
out += " }" | ||
out | ||
} | ||
} |
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,14 @@ | ||
package org.moe.runtime | ||
|
||
import org.moe.Moe.Errors | ||
|
||
class MoeMethod ( | ||
private val name : String | ||
) { | ||
|
||
def getName (): String = name | ||
|
||
def call ( reciever : MoeObject, args : List[MoeObject] ): MoeObject = { | ||
throw new Errors.UndefinedMethod( name ) | ||
} | ||
} |
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,38 @@ | ||
package org.moe.runtime | ||
|
||
import org.moe.Moe.Errors | ||
|
||
import scala.collection.mutable.HashMap | ||
|
||
class MoeObject { | ||
|
||
private val id : Integer = System.identityHashCode( this ) | ||
private val data = new HashMap[String,MoeObject]() | ||
|
||
private var klass : MoeClass = _ | ||
|
||
def this ( k : MoeClass ) = { | ||
this() | ||
klass = k | ||
} | ||
|
||
def getID (): Integer = id | ||
def getAssociatedClass (): MoeClass = klass | ||
|
||
def setAssocaitedClass ( k : MoeClass ): Unit = klass = k | ||
|
||
def hasValue ( name : String ): Boolean = data.contains( name ) | ||
def getValue ( name : String ): MoeObject = { | ||
if ( !hasValue( name ) ) throw new Errors.InstanceValueNotFound( name ) | ||
data( name ) | ||
} | ||
|
||
def setValue ( name : String, value : MoeObject ): Unit = data.put( name, value ) | ||
|
||
def callMethod ( method : String, args : List[MoeObject] ): MoeObject = { | ||
if ( klass == null ) throw new Errors.MissingClass( toString ) | ||
klass.getMethod( method ).call( this, args ) | ||
} | ||
|
||
override def toString (): String = "{ #instance(" + id + ") " + klass.toString() + " }" | ||
} |