Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add in named params (also rename MoeNamedParameter to MoePositionalPa…
…rameter cause that is a better name) then add the support for named parameters to the parser and the runtime (and add some tests too)
- Loading branch information
Stevan Little
committed
Mar 30, 2013
1 parent
37412d0
commit 60bf7dd
Showing
22 changed files
with
188 additions
and
93 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
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
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package org.moe.runtime | ||
|
||
sealed abstract class MoeParameter(private val name: String) extends MoeObject { | ||
def getName = name | ||
def getName = name | ||
def getKeyName = name.drop(1) | ||
} | ||
|
||
case class MoeNamedParameter (val n: String) extends MoeParameter(n) | ||
case class MoeOptionalParameter (val n: String) extends MoeParameter(n) | ||
case class MoeSlurpyParameter (val n: String) extends MoeParameter(n) | ||
case class MoePositionalParameter (val n: String) extends MoeParameter(n) | ||
case class MoeOptionalParameter (val n: String) extends MoeParameter(n) | ||
case class MoeSlurpyParameter (val n: String) extends MoeParameter(n) | ||
case class MoeNamedParameter (val n: String) extends MoeParameter(n) |
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 |
---|---|---|
@@ -1,25 +1,58 @@ | ||
package org.moe.runtime | ||
|
||
import scala.collection.mutable.{HashMap,Map} | ||
|
||
import org.moe.runtime.nativeobjects.MoePairObject | ||
|
||
class MoeSignature( | ||
private val params: List[MoeParameter] = List() | ||
) extends MoeObject { | ||
|
||
lazy val arity = params.length | ||
lazy val namedParameterMap: Map[String,MoeParameter] = Map( | ||
params.filter(_ match { | ||
case (x: MoeNamedParameter) => true | ||
case _ => false | ||
}).map( | ||
p => p.getKeyName -> p | ||
):_* | ||
) | ||
|
||
def getParams = params | ||
def getArity = params.length | ||
|
||
def bindArgsToEnv (args: MoeArguments, env: MoeEnvironment) = { | ||
for (i <- 0.until(getArity)) { | ||
|
||
val r = env.getCurrentRuntime.get | ||
|
||
var extra: List[MoeObject] = List() | ||
|
||
for (i <- 0.until(arity)) { | ||
params(i) match { | ||
case MoeNamedParameter(name) => env.create(name, args.getArgAt(i).get) | ||
case MoePositionalParameter(name) => env.create(name, args.getArgAt(i).get) | ||
case MoeOptionalParameter(name) => args.getArgAt(i) match { | ||
case Some(a) => env.create(name, a) | ||
case None => env.create(name, env.getCurrentRuntime.get.NativeObjects.getUndef) | ||
case None => env.create(name, r.NativeObjects.getUndef) | ||
} | ||
case MoeSlurpyParameter(name) => env.create( | ||
case MoeSlurpyParameter(name) => env.create( | ||
name, | ||
env.getCurrentRuntime.get.NativeObjects.getArray(args.slurpArgsAt(i):_*) | ||
r.NativeObjects.getArray(args.slurpArgsAt(i):_*) | ||
) | ||
case _ => extra = args.getArgAt(i).get :: extra | ||
} | ||
} | ||
|
||
for (arg <- extra) { | ||
arg match { | ||
case (a: MoePairObject) => { | ||
val k = a.key(r).unboxToString.get | ||
val p = namedParameterMap.get(k).getOrElse( | ||
throw new MoeErrors.MoeProblems("Could not find matching key for " + k) | ||
) | ||
env.create(p.getName, a.value(r)) | ||
} | ||
case _ => throw new MoeErrors.MoeProblems("extra argument was not a pair") | ||
} | ||
} | ||
|
||
} | ||
} |
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
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
Oops, something went wrong.