Module: dummy-environment Synopsis: Dummy Environment Author: Andy Armstrong Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND /// The dummy project define class () end class ; define class () end class ; define class () end class ; define method make-dummy (class :: subclass(), #rest args, #key, #all-keys) => (object :: ) apply(make, class, proxy: #"dummy", args) end method make-dummy; define method make-dummy (class :: subclass(), #rest args, #key, #all-keys) => (object :: ) apply(make, class, application-object-proxy: #"dummy", args) end method make-dummy; define method make-dummy (class :: subclass(), #rest args, #key, #all-keys) => (object :: ) apply(make, class, compiler-object-proxy: #"dummy", args) end method make-dummy; define method make-dummy (class :: subclass(), #rest args, #key, #all-keys) => (object :: ) apply(make, class, application-object-proxy: #"dummy", compiler-object-proxy: #"dummy", args) end method make-dummy; /// Define all of the objects in this fake system define constant $othello-project = make-dummy(, name: "othello"); define constant $dylan-project = make-dummy(, name: "dylan"); define constant $othello-application = make(, project: $othello-project, filename: "othello.exe"); define constant $othello-database = make(, project: $othello-project, name: "othello.pdb"); define constant $othello-library = make-dummy(, name: "othello"); define constant $othello-module = make-dummy(); define constant $othello-module-name = make-dummy(, name: "othello"); define constant $othello-dylan-module-name = make-dummy(, name: "dylan"); define constant $dylan-library = make-dummy(, name: "dylan"); define constant $dylan-module = make-dummy(); define constant $dylan-module-name = make-dummy(, name: "dylan"); define constant $object-class = make-dummy(); define constant $class-class = make-dummy(); define constant $function-class = make-dummy(); define constant $othello-game-class = make-dummy(); define constant $play-othello-function = make-dummy(); define constant $play-othello-method = make-dummy(); define constant $object-name = make-dummy(); define constant $class-name = make-dummy(); define constant $othello-object-name = make-dummy(); define constant $othello-class-name = make-dummy(); define constant $othello-game-name = make-dummy(); define constant $play-othello-name = make-dummy(); define constant $othello-thread = make-dummy(, name: "othello"); /// Project modeling define sideways method find-project (name :: ) => (project :: false-or()) if (as-lowercase(name) = "othello") let project = $othello-project; project-compiler-database(project) := $othello-database; project end end method find-project; define method get-environment-object-primitive-name (project :: , object :: ) => (name :: ) "Othello" end method get-environment-object-primitive-name; define method project-library (project :: ) => (library :: ) select (project) $othello-project => $othello-library; $dylan-project => $dylan-library; end end method project-library; define method project-used-projects (project :: ) => (projects :: ) if (project == $othello-project) vector($dylan-project) end end method project-used-projects; define method project-sources (project :: ) => (sources :: ) vector("library.dylan", "module.dylan", "game.dylan", "algorithms.dylan", "board.dylan") end method project-sources; define method project-directory (project :: ) => (directory :: ) "c:/dylan/othello" end method project-directory; define method project-source-location (project :: , source :: ) => (location :: ) let directory = project-directory(project); as(, format-to-string("%s/%s.dylan", directory, source)); end method project-source-location; define method compile-project (project :: , #key progress-callback, error-handler, save-databases?, process-subprojects?) => () #f end method compile-project; define method recompile-project (project :: , #key progress-callback, error-handler, save-databases?, process-subprojects?) => () #f end method recompile-project; define method link-project (project :: , #key progress-callback, error-handler, process-subprojects?) => () #f end method link-project; //---*** A hack, but a useful one for now! define method edit-project-source (project :: , source :: , #key line) => () #f end method edit-project-source; define method environment-object-source (project :: , object :: ) => (source :: ) "define fake-macro foo ()" " //--- Do something!" " #f" "end fake-macro foo;" end method environment-object-source; /// Library modeling define method library-project (database :: , library :: ) => (project :: false-or()) if (library == $othello-library) $othello-project end end method library-project; define method do-namespace-names (function :: , database :: , library :: , #key client, imported? = #t) => () select (library) $othello-library => function($othello-module-name); if (imported?) function($othello-dylan-module-name) end; $dylan-library => function($dylan-module-name); end end method do-namespace-names; /// Module modeling define method module-library (database :: , module :: ) => (library :: ) ignore(database); select (module) $dylan-module => $dylan-library; $othello-module => $othello-library; end end method module-library; define method find-module (database :: , name :: , #key library) => (module :: false-or()) ignore(library, database); select (as-lowercase(name) by \=) "othello" => $othello-module; "dylan" => $dylan-module; end end method find-module; define method do-namespace-names (function :: , database :: , module :: , #key client, imported? = #t) => () select (module) $othello-module => function($othello-game-name); function($play-othello-name); if (imported?) function($othello-class-name); function($othello-object-name); end; $dylan-module => function($class-name); function($object-name); end end method do-namespace-names; define method do-used-definitions (function :: , database :: , module :: , #key modules, libraries, client) => () ignore(modules, libraries, client); if (module = $othello-module) function($dylan-module) end end method do-used-definitions; /// Name objects define method environment-object-name (database :: , object :: , namespace :: ) => (name :: ) select (namespace) $othello-module => select (object) $object-class => $othello-object-name; $class-class => $othello-class-name; $othello-game-class => $othello-game-name; $play-othello-function => $play-othello-name; otherwise => #f; end; $dylan-module => select (object) $object-class => $object-name; $class-class => $class-name; otherwise => #f; end; end end method environment-object-name; define method name-value (project :: , name :: ) => (value :: ) select (name) $othello-game-name => $othello-game-class; $play-othello-name => $play-othello-function; $object-name, $othello-object-name => $object-class; $class-name, $othello-class-name => $class-class; $othello-module-name => $othello-module; end end method name-value; define method name-value (project :: , name :: ) => (module :: ) select (name) $othello-module-name => $othello-module; $othello-dylan-module-name => $othello-module; $dylan-module-name => $dylan-module; end end method name-value; define method name-namespace (database :: , name :: ) => (library :: ) select (name) $othello-module-name => $othello-library; $othello-dylan-module-name => $othello-library; $dylan-module-name => $dylan-library; end end method name-namespace; define method name-namespace (database :: , name :: ) => (library :: ) select (name) $othello-game-name => $othello-module; $play-othello-name => $othello-module; $othello-object-name => $othello-module; $othello-class-name => $othello-module; $object-name => $dylan-module; $class-name => $dylan-module; end end method name-namespace; define method environment-object-home-name (database :: , object :: ) => (name :: false-or()) select (object) $othello-module => $othello-module-name; $dylan-module => $dylan-module-name; $othello-game-class => $othello-game-name; $play-othello-function => $play-othello-name; $object-class => $object-name; $class-class => $class-name; otherwise => #f; end end method environment-object-home-name; //---*** Do we really need this as well as environment-object-display-name? define method get-environment-object-primitive-name (database :: , name :: ) => (name :: false-or()) select (name) $object-name => ""; $class-name => ""; $othello-object-name => "dylan/"; $othello-class-name => "dylan/"; $othello-game-name => ""; $play-othello-name => "play-othello"; end end method get-environment-object-primitive-name; define method name-type (project :: , name :: ) => (type :: ) select (name) $play-othello-name => $function-class; otherwise => $class-class; end end method name-type; /// Class objects define method application-object-class (project :: , object :: ) => (class :: false-or()) #f end method application-object-class; define method do-direct-subclasses (function :: , project :: , class :: , #key client) => () if (class == $object-class) do(function, vector($class-class, $function-class, $othello-game-class)) end end method do-direct-subclasses; define method do-direct-superclasses (function :: , project :: , class :: , #key client) => () if (class ~= $object-class) function($object-class) end end method do-direct-superclasses; define method do-direct-methods (function :: , project :: , class :: , #key client) => () #f end method do-direct-methods; define method do-direct-slots (function :: , project :: , class :: , #key client) => () #f end method do-direct-slots; define method do-all-superclasses (function :: , project :: , class :: , #key client) => () #f end method do-all-superclasses; define method do-all-slots (function :: , project :: , class :: , #key client) => () #f end method do-all-slots; define method do-init-keywords (function :: , project :: , class :: , #key client) => () #f end method do-init-keywords; /// Function objects define method function-parameters (project :: , function :: ) => (required :: , rest :: false-or(), keys :: , next :: false-or(), values :: , rest-value :: false-or()) values(#(), #f, #(), #f, #(), #f) end method function-parameters; define method do-generic-function-methods (function :: , project :: , generic-function :: , #key client) => () function($play-othello-method) end method do-generic-function-methods; define method method-specializers (database :: , object :: ) => (specializers :: ) #() end method method-specializers; define method method-generic-function (database :: , object :: ) => (function :: ) $play-othello-function end method method-generic-function; /// Compiler warning objects define method do-compiler-warnings (function :: , project :: , object :: , #key client) => () #f end method do-compiler-warnings; /// Project execution define constant $dummy-thread = make(, application-object-proxy: #f); define method project-valid-code? (project :: , code :: , #key module) => (valid :: , reason :: ) let object = project-execute-code(project, code, $dummy-thread, module: module); if (object) values(#t, "") else values(#f, "Dummy code execution can only evaluate variables!") end end method project-valid-code?; define method project-execute-code (project :: , code :: , thread :: , #key module, stack-frame) => (results :: , success? :: ) ignore(module, thread, stack-frame); let object = select (code by \=) ";" => $object-class; ";" => $class-class; ";" => $function-class; ";" => $othello-game-class; "play-othello;" => $play-othello-function; otherwise => #f; end; if (object) values(vector(object), #t) else values(#[], #f) end end method project-execute-code; define method project-bind-variable (project :: , variable-name :: , object :: , #key module) => (success? :: ) //---*** Just do nothing! #t end method project-bind-variable; /// Some default methods to stop things crashing //--- A default method doing nothing define method do-used-definitions (function :: , database :: , definition :: , #key modules, libraries, client) => () ignore(modules, libraries, client); #f end method do-used-definitions; define method composite-object-contents (application :: , object :: , #key inherited? = #t) => (names :: , values :: ) values(vector("application"), vector(application)) end method composite-object-contents; /// Applications define method update-application (project :: , #key progress-callback) => () let sources = project-sources(project); let name = environment-object-primitive-name(project, project); let progress-range = 2 * size(sources); let i = 0; for (source in sources) let filename = format-to-string("file %s.dylan", source); progress-callback(i, progress-range, label: format-to-string("Compiling %s", source)); i := i + 1; progress-callback(i, progress-range, label: format-to-string("Loading %s", source)); i := i + 1; end; progress-callback(progress-range, progress-range, label: format-to-string("Updated %s", name)) end method update-application; define method application-threads (application :: , #key client) => (threads :: ) vector($othello-thread) end method application-threads; define method run-application (project :: , #key debug?, filename, arguments) => (application :: ) project-application(project) := $othello-application; application-state($othello-application) := if (debug?) #"stopped" else #"running" end; $othello-application end method run-application; define method continue-application (project :: ) => () application-state($othello-application) := #"running"; end method continue-application; define method stop-application (project :: ) => () application-state($othello-application) := #"stopped"; end method stop-application; define method close-application (project :: ) => () project-application(project) := #f; application-state($othello-application) := #"closed"; end method close-application;