Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I think this is a better way to handle these
- Loading branch information
Stevan Little
committed
Feb 12, 2013
1 parent
3bd6929
commit 4e3fd2a
Showing
15 changed files
with
277 additions
and
64 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
package org.moe.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Any | ||
*/ | ||
object AnyClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val anyClass = r.getCoreClassFor("Any").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Any") | ||
) | ||
|
||
} | ||
|
||
} |
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.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Array | ||
*/ | ||
object ArrayClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val arrayClass = r.getCoreClassFor("Array").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Array") | ||
) | ||
|
||
} | ||
|
||
} |
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.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Bool | ||
*/ | ||
object BoolClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val boolClass = r.getCoreClassFor("Bool").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Bool") | ||
) | ||
|
||
} | ||
|
||
} |
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,24 @@ | ||
package org.moe.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Class | ||
*/ | ||
object ClassClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val classClass = r.getCoreClassFor("Class").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Class") | ||
) | ||
|
||
// constructor | ||
classClass.addMethod( | ||
new MoeMethod( | ||
"new", | ||
{ (invocant, _) => invocant.asInstanceOf[MoeClass].newInstance } | ||
) | ||
) | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/scala/org/moe/runtime/builtins/ExceptionClass.scala
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.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Exception | ||
*/ | ||
object ExceptionClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val exceptionClass = r.getCoreClassFor("Exception").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Exception") | ||
) | ||
|
||
} | ||
|
||
} |
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.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Hash | ||
*/ | ||
object HashClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val hashClass = r.getCoreClassFor("Hash").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Hash") | ||
) | ||
|
||
} | ||
|
||
} |
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,33 @@ | ||
package org.moe.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Int | ||
*/ | ||
object IntClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val intClass = r.getCoreClassFor("Int").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Int") | ||
) | ||
|
||
// arithmetic | ||
|
||
intClass.addMethod( | ||
new MoeMethod( | ||
"+", | ||
{ (lhs, args) => | ||
val rhs = args(0) | ||
val i = lhs.asInstanceOf[MoeIntObject] | ||
rhs match { | ||
case rhs_i: MoeIntObject => r.NativeObjects.getInt(i.getNativeValue + rhs_i.getNativeValue) | ||
case rhs_n: MoeFloatObject => r.NativeObjects.getFloat(i.getNativeValue.toDouble + rhs_n.getNativeValue) | ||
case _ => throw new MoeErrors.UnexpectedType(rhs.toString) | ||
} | ||
} | ||
) | ||
) | ||
} | ||
|
||
} |
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,31 @@ | ||
package org.moe.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Num | ||
*/ | ||
object NumClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val numClass = r.getCoreClassFor("Num").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Num") | ||
) | ||
|
||
numClass.addMethod( | ||
new MoeMethod( | ||
"+", | ||
{ (lhs, args) => | ||
val rhs = args(0) | ||
val n = lhs.asInstanceOf[MoeFloatObject] | ||
rhs match { | ||
case rhs_n: MoeFloatObject => r.NativeObjects.getFloat(n.getNativeValue + rhs_n.getNativeValue) | ||
case rhs_i: MoeIntObject => r.NativeObjects.getFloat(n.getNativeValue + rhs_i.getNativeValue.toDouble) | ||
case _ => throw new MoeErrors.UnexpectedType(rhs.toString) | ||
} | ||
} | ||
) | ||
) | ||
} | ||
|
||
} |
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.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Object | ||
*/ | ||
object ObjectClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val objectClass = r.getCoreClassFor("Object").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Object") | ||
) | ||
|
||
} | ||
|
||
} |
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.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Pair | ||
*/ | ||
object PairClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val pairClass = r.getCoreClassFor("Pair").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.moe.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Scalar | ||
*/ | ||
object ScalarClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val scalarClass = r.getCoreClassFor("Scalar").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Scalar") | ||
) | ||
|
||
} | ||
|
||
} |
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.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Str | ||
*/ | ||
object StrClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val strClass = r.getCoreClassFor("Str").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Str") | ||
) | ||
|
||
} | ||
|
||
} |
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.runtime.builtins | ||
|
||
import org.moe.runtime._ | ||
|
||
/** | ||
* setup class Undef | ||
*/ | ||
object UndefClass { | ||
|
||
def apply(r: MoeRuntime): Unit = { | ||
val undefClass = r.getCoreClassFor("Undef").getOrElse( | ||
throw new MoeErrors.MoeStartupError("Could not find class Undef") | ||
) | ||
|
||
} | ||
|
||
} |