PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/orc/lib/builtin/MakeSite.scala

https://github.com/laurenyew/cOrcS
Scala | 65 lines | 41 code | 10 blank | 14 comment | 0 complexity | 3f9f1773f8e24ee18c05a39960347779 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. //
  2. // MakeSite.scala -- Scala classes MakeSite and RunLikeSite
  3. // Project OrcScala
  4. //
  5. // $Id: MakeSite.scala 2933 2011-12-15 16:26:02Z jthywissen $
  6. //
  7. // Copyright (c) 2011 The University of Texas at Austin. All rights reserved.
  8. //
  9. // Use and redistribution of this file is governed by the license terms in
  10. // the LICENSE file found in the project's top-level directory and also found at
  11. // URL: http://orc.csres.utexas.edu/license.shtml .
  12. //
  13. package orc.lib.builtin
  14. import orc.Handle
  15. import orc.error.runtime.ArityMismatchException
  16. import orc.error.compiletime.typing.ArgumentTypecheckingException
  17. import orc.error.compiletime.typing.ExpectedType
  18. import orc.values.sites.TotalSite1
  19. import orc.values.sites.TypedSite
  20. import orc.values.sites.UntypedSite
  21. import orc.values.Format
  22. import orc.types.UnaryCallableType
  23. import orc.types.FunctionType
  24. import orc.types.Type
  25. import orc.run.extensions.InstanceEvent
  26. import orc.error.runtime.ArgumentTypeMismatchException
  27. import orc.run.extensions.InstanceEvent
  28. import orc.run.extensions.InstanceEvent
  29. import orc.run.core.Closure
  30. import orc.run.extensions.InstanceEvent
  31. // MakeSite site
  32. object MakeSite extends TotalSite1 with TypedSite {
  33. override def name = "MakeSite"
  34. def eval(arg: AnyRef) = {
  35. arg match {
  36. case c: Closure => new RunLikeSite(c)
  37. case _ => throw new ArgumentTypeMismatchException(0, "Closure", arg.getClass().getCanonicalName())
  38. }
  39. }
  40. def orcType() = new UnaryCallableType {
  41. def call(argType: Type): Type = {
  42. argType match {
  43. case f: FunctionType => f
  44. case g => throw new ArgumentTypecheckingException(0, ExpectedType("a function type"), g)
  45. }
  46. }
  47. }
  48. }
  49. // Standalone class execution
  50. class RunLikeSite(closure: Closure) extends UntypedSite {
  51. override def name = "class " + Format.formatValue(closure)
  52. def call(args: List[AnyRef], caller: Handle) {
  53. caller.notifyOrc(InstanceEvent(closure, args, caller))
  54. }
  55. }