/src/orc/lib/builtin/MakeSite.scala
Scala | 65 lines | 41 code | 10 blank | 14 comment | 0 complexity | 3f9f1773f8e24ee18c05a39960347779 MD5 | raw file
Possible License(s): BSD-3-Clause
- //
- // MakeSite.scala -- Scala classes MakeSite and RunLikeSite
- // Project OrcScala
- //
- // $Id: MakeSite.scala 2933 2011-12-15 16:26:02Z jthywissen $
- //
- // Copyright (c) 2011 The University of Texas at Austin. All rights reserved.
- //
- // Use and redistribution of this file is governed by the license terms in
- // the LICENSE file found in the project's top-level directory and also found at
- // URL: http://orc.csres.utexas.edu/license.shtml .
- //
- package orc.lib.builtin
- import orc.Handle
- import orc.error.runtime.ArityMismatchException
- import orc.error.compiletime.typing.ArgumentTypecheckingException
- import orc.error.compiletime.typing.ExpectedType
- import orc.values.sites.TotalSite1
- import orc.values.sites.TypedSite
- import orc.values.sites.UntypedSite
- import orc.values.Format
- import orc.types.UnaryCallableType
- import orc.types.FunctionType
- import orc.types.Type
- import orc.run.extensions.InstanceEvent
- import orc.error.runtime.ArgumentTypeMismatchException
- import orc.run.extensions.InstanceEvent
- import orc.run.extensions.InstanceEvent
- import orc.run.core.Closure
- import orc.run.extensions.InstanceEvent
- // MakeSite site
- object MakeSite extends TotalSite1 with TypedSite {
- override def name = "MakeSite"
- def eval(arg: AnyRef) = {
- arg match {
- case c: Closure => new RunLikeSite(c)
- case _ => throw new ArgumentTypeMismatchException(0, "Closure", arg.getClass().getCanonicalName())
- }
- }
- def orcType() = new UnaryCallableType {
- def call(argType: Type): Type = {
- argType match {
- case f: FunctionType => f
- case g => throw new ArgumentTypecheckingException(0, ExpectedType("a function type"), g)
- }
- }
- }
- }
- // Standalone class execution
- class RunLikeSite(closure: Closure) extends UntypedSite {
- override def name = "class " + Format.formatValue(closure)
- def call(args: List[AnyRef], caller: Handle) {
- caller.notifyOrc(InstanceEvent(closure, args, caller))
- }
- }