├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── CorrelatorTest ├── CorrelatorTest.cpp ├── correlator.h ├── settings.h └── settings.xml ├── LICENSE.txt ├── README.md ├── TODO ├── examples ├── Correlator.Data.Generation │ ├── motor.babbling.replicode │ └── user.classes.replicode ├── Demo1 │ ├── initial.HLP.replicode │ ├── main.replicode │ ├── sim.devices.replicode │ ├── std.replicode │ ├── test.1.replicode │ └── user.classes.replicode ├── V1.2 │ ├── drives.replicode │ ├── hello.world.replicode │ ├── main.replicode │ ├── pong.2.replicode │ ├── pong.replicode │ ├── std.replicode │ ├── test.1.replicode │ ├── test.2.replicode │ ├── test.3.replicode │ ├── test.4.replicode │ ├── test.domain.replicode │ └── user.classes.replicode ├── helgi.replicode ├── loom-visor │ ├── rgrp.user.classes.replicode │ ├── settings.xml │ ├── std.replicode │ └── test.rgrp.1.replicode ├── rgrp.user.classes.replicode ├── std.replicode ├── test.1.replicode ├── test.10.replicode ├── test.11.replicode ├── test.12.replicode ├── test.13.replicode ├── test.14.replicode ├── test.15.replicode ├── test.16.replicode ├── test.17.replicode ├── test.18.replicode ├── test.19.replicode ├── test.2.replicode ├── test.20.replicode ├── test.21.replicode ├── test.22.replicode ├── test.23.replicode ├── test.24.replicode ├── test.25.replicode ├── test.26.replicode ├── test.3.replicode ├── test.4.replicode ├── test.5.replicode ├── test.6.replicode ├── test.7.replicode ├── test.8.replicode ├── test.9.replicode ├── test.helgi.replicode ├── test.integration.replicode ├── test.pm.var.replicode ├── test.rgrp.1.replicode ├── test.visualizer.replicode └── user.classes.replicode ├── executor ├── inifile.cpp ├── inifile.h ├── main.cpp ├── settings.h └── settings.ini ├── output_window └── main.cpp ├── r_code ├── CMakeLists.txt ├── atom.cpp ├── atom.h ├── image.cpp ├── image.h ├── image.tpl.h ├── image_impl.cpp ├── image_impl.h ├── list.h ├── object.cpp ├── object.h ├── r_code.cpp ├── r_code.h ├── replicode_defs.h ├── time_buffer.h ├── utils.cpp ├── utils.h ├── vector.cpp └── vector.h ├── r_comp ├── CMakeLists.txt ├── class.cpp ├── class.h ├── compiler.cpp ├── compiler.h ├── decompiler.cpp ├── decompiler.h ├── out_stream.h ├── preprocessor.cpp ├── preprocessor.h ├── replistruct.cpp ├── replistruct.h ├── segments.cpp ├── segments.h ├── structure_member.cpp └── structure_member.h ├── r_exec ├── CMakeLists.txt ├── _context.cpp ├── _context.h ├── ast_controller.cpp ├── ast_controller.h ├── ast_controller.tpl.h ├── auto_focus.cpp ├── auto_focus.h ├── binding_map.cpp ├── binding_map.h ├── callbacks.cpp ├── callbacks.h ├── context.cpp ├── context.h ├── cpp_programs.cpp ├── cpp_programs.h ├── cst_controller.cpp ├── cst_controller.h ├── domain.cpp ├── domain.h ├── factory.cpp ├── factory.h ├── g_monitor.cpp ├── g_monitor.h ├── group.cpp ├── group.h ├── guard_builder.cpp ├── guard_builder.h ├── hlp_context.cpp ├── hlp_context.h ├── hlp_controller.cpp ├── hlp_controller.h ├── hlp_overlay.cpp ├── hlp_overlay.h ├── init.cpp ├── init.h ├── mdl_controller.cpp ├── mdl_controller.h ├── mem.cpp ├── mem.h ├── mem.tpl.h ├── model_base.cpp ├── model_base.h ├── monitor.cpp ├── monitor.h ├── object.cpp ├── object.h ├── object.tpl.h ├── opcodes.cpp ├── opcodes.h ├── operator.cpp ├── operator.h ├── overlay.cpp ├── overlay.h ├── overlay.tpl.h ├── p_monitor.cpp ├── p_monitor.h ├── pattern_extractor.cpp ├── pattern_extractor.h ├── pgm_controller.cpp ├── pgm_controller.h ├── pgm_overlay.cpp ├── pgm_overlay.h ├── reduction_core.cpp ├── reduction_core.h ├── reduction_job.cpp ├── reduction_job.h ├── reduction_job.tpl.h ├── time_core.cpp ├── time_core.h ├── time_job.cpp ├── time_job.h ├── view.cpp └── view.h ├── replicode_common.h ├── tests ├── CMakeLists.txt └── compiler │ ├── CMakeLists.txt │ ├── drives.replicode │ ├── hello.world.replicode │ ├── hello.world.replicode.trace │ ├── main.cpp │ ├── pong.2.replicode │ ├── pong.replicode │ ├── pong.replicode.trace │ ├── std.replicode │ ├── test.1.replicode │ ├── test.1.replicode.trace │ ├── test.2.replicode │ ├── test.2.replicode.trace │ ├── test.3.replicode │ ├── test.3.replicode.trace │ ├── test.4.replicode │ ├── test.4.replicode.trace │ ├── test.domain.replicode │ └── user.classes.replicode └── usr_operators ├── CMakeLists.txt ├── Callbacks ├── callbacks.cpp └── callbacks.h ├── Correlator ├── CorrelatorCore.cpp ├── CorrelatorCore.h ├── ForwardLayer.cpp ├── ForwardLayer.h ├── LstmBlock.cpp ├── LstmBlock.h ├── LstmLayer.cpp ├── LstmLayer.h ├── LstmNetwork.cpp ├── LstmNetwork.h ├── VectorMath.h ├── correlator.cpp ├── correlator.h ├── winepi.cpp └── winepi.h ├── Operators ├── operators.cpp └── operators.h ├── TestProgram ├── test_program.cpp └── test_program.h ├── auto_focus.cpp ├── auto_focus.h ├── types.h ├── usr_operators.cpp └── usr_operators.h /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeLists.txt.user 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | before_script: 3 | - mkdir build 4 | - cd build 5 | - cmake .. 6 | script: make VERBOSE=1 7 | compiler: 8 | - clang 9 | - gcc 10 | 11 | before_install: 12 | # needed for both new gcc and libstdc++ for clang 13 | - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test 14 | 15 | # clang 3.4 16 | - if [ "$CXX" == "clang++" ]; then wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add -; fi 17 | - if [ "$CXX" == "clang++" ]; then sudo add-apt-repository -y 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise-3.6 main'; fi 18 | 19 | - sudo apt-get update -qq 20 | 21 | install: 22 | # g++4.8.1 23 | - if [ "$CXX" = "g++" ]; then sudo apt-get install -qq g++-4.8; fi 24 | - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8"; fi 25 | 26 | # clang 3.4 27 | - if [ "$CXX" == "clang++" ]; then sudo apt-get install --allow-unauthenticated clang-3.6; fi 28 | - if [ "$CXX" == "clang++" ]; then export CXX="clang++-3.6"; fi 29 | 30 | notifications: 31 | email: false 32 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(replicode) 2 | 3 | cmake_minimum_required(VERSION 2.8) 4 | find_package (Threads) 5 | 6 | include_directories(${PROJECT_SOURCE_DIR}) 7 | 8 | if(UNIX) 9 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -std=c++11 -fPIC -g") 10 | endif() 11 | 12 | option(ENABLE_SANITIZERS "Enable runtime sanitizing (for development)") 13 | if (ENABLE_SANITIZERS) 14 | message("Enabling asan and ubsan") 15 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") 17 | endif() 18 | 19 | 20 | add_subdirectory(r_code) 21 | add_subdirectory(r_comp) 22 | add_subdirectory(r_exec) 23 | add_subdirectory(usr_operators) 24 | add_subdirectory(tests) 25 | 26 | add_executable(replicode executor/main.cpp executor/inifile.cpp replicode_common.h) 27 | set_property(TARGET replicode PROPERTY CXX_STANDARD 11) 28 | set_property(TARGET replicode PROPERTY CXX_STANDARD_REQUIRED ON) 29 | 30 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 31 | configure_file(executor/settings.ini ${CMAKE_BINARY_DIR}/settings.ini COPYONLY) 32 | target_link_libraries(replicode r_exec r_comp r_code dl pthread rt) 33 | 34 | install(FILES replicode_common.h DESTINATION include) 35 | 36 | set(CMAKE_CXX_VISIBILITY_PRESET hidden) 37 | 38 | enable_testing() 39 | 40 | foreach(test_file 41 | "hello.world.replicode" 42 | "pong.replicode" 43 | "test.1.replicode" 44 | "test.2.replicode" 45 | "test.3.replicode" 46 | "test.4.replicode") 47 | add_test(NAME Compiler-${test_file} WORKING_DIRECTORY /home/sandsmark/src/replicode/tests/compiler/ COMMAND compilertest ${test_file}) 48 | endforeach() 49 | -------------------------------------------------------------------------------- /CorrelatorTest/correlator.h: -------------------------------------------------------------------------------- 1 | #ifndef correlator_h 2 | #define correlator_h 3 | 4 | #include <../../CoreLibrary/trunk/CoreLibrary/base.h> 5 | #include <../r_code/object.h> 6 | 7 | 8 | class State: 9 | public core::_Object 10 | { 11 | public: 12 | virtual void trace() = 0; 13 | }; 14 | 15 | // Set of time-invariant views. 16 | // reads as "if views then states hold". 17 | class IPGMContext: 18 | public State 19 | { 20 | public: 21 | std::vector > views; 22 | std::vector > states; 23 | 24 | void trace() 25 | { 26 | std::cout << "IPGMContext\n"; 27 | std::cout << "Views\n"; 28 | 29 | for (uint64_t i = 0; i < views.size(); ++i) { 30 | views[i]->object->trace(); 31 | } 32 | 33 | std::cout << "States\n"; 34 | 35 | for (uint64_t i = 0; i < states.size(); ++i) { 36 | states[i]->trace(); 37 | } 38 | } 39 | }; 40 | 41 | // Pattern that hold under some context. 42 | // Read as "left implies right". 43 | class Pattern: 44 | public State 45 | { 46 | public: 47 | std::vector > left; 48 | std::vector > right; 49 | 50 | void trace() 51 | { 52 | std::cout << "Pattern\n"; 53 | std::cout << "Left\n"; 54 | 55 | for (uint64_t i = 0; i < left.size(); ++i) { 56 | left[i]->object->trace(); 57 | } 58 | 59 | std::cout << "Right\n"; 60 | 61 | for (uint64_t i = 0; i < right.size(); ++i) { 62 | right[i]->object->trace(); 63 | } 64 | } 65 | }; 66 | 67 | class CorrelatorOutput 68 | { 69 | public: 70 | std::vector > contexts; 71 | 72 | void trace() 73 | { 74 | std::cout << "CorrelatorOutput\n"; 75 | 76 | for (uint64_t i = 0; i < contexts.size(); ++i) { 77 | contexts[i]->trace(); 78 | } 79 | } 80 | }; 81 | 82 | class Correlator 83 | { 84 | private: 85 | std::vector episode; 86 | public: 87 | void take_input(r_code::View *input) 88 | { 89 | episode.push_back(input->code(VIEW_OID).atom); 90 | } 91 | 92 | CorrelatorOutput *get_output() 93 | { 94 | CorrelatorOutput *c = new CorrelatorOutput(); 95 | // TODO: fill c. 96 | return c; 97 | } 98 | }; 99 | 100 | 101 | #endif -------------------------------------------------------------------------------- /CorrelatorTest/settings.h: -------------------------------------------------------------------------------- 1 | // settings.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef test_correlator_settings_h 32 | #define test_correlator_settings_h 33 | 34 | #include <../../CoreLibrary/trunk/CoreLibrary/xml_parser.h> 35 | 36 | 37 | class CorrelatorTestSettings 38 | { 39 | public: 40 | typedef enum { 41 | TS_RELATIVE = 0, 42 | TS_ABSOLUTE = 1 43 | } TSMode; 44 | TSMode decompile_timestamps; 45 | std::string usr_operator_path; 46 | std::string usr_class_path; 47 | std::string use_case_path; 48 | std::string image_name; 49 | 50 | bool load(const char *file_name) 51 | { 52 | XMLNode mainNode = XMLNode::openFileHelper(file_name, "TestConfiguration"); 53 | 54 | if (!mainNode) { 55 | std::cerr << "> Error: TestConfiguration is unreadable" << std::endl; 56 | return false; 57 | } 58 | 59 | XMLNode parameters = mainNode.getChildNode("Parameters"); 60 | 61 | if (!!parameters) { 62 | const char *_decompile_timestamps = parameters.getAttribute("decompile_timestamps"); 63 | usr_operator_path = parameters.getAttribute("usr_operator_path"); 64 | usr_class_path = parameters.getAttribute("usr_class_path"); 65 | use_case_path = parameters.getAttribute("use_case_path"); 66 | image_name = parameters.getAttribute("image_name"); 67 | 68 | if (strcmp(_decompile_timestamps, "relative") == 0) { 69 | decompile_timestamps = TS_RELATIVE; 70 | } else { 71 | decompile_timestamps = TS_ABSOLUTE; 72 | } 73 | } else { 74 | std::cerr << "> Error: Parameter section is unreadable" << std::endl; 75 | return false; 76 | } 77 | 78 | return true; 79 | } 80 | }; 81 | 82 | 83 | #endif -------------------------------------------------------------------------------- /CorrelatorTest/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 18 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Center for Analysis and Design of Intelligent Agents 2 | Reykjavik University, Menntavegur 1, 101 Reykjavik, Iceland 3 | http://cadia.ru.is 4 | Copyright(c)2012 5 | 6 | This software was developed by the above copyright holder as part of 7 | the HUMANOBS EU research project, in collaboration with the 8 | following parties: 9 | 10 | Autonomous Systems Laboratory 11 | Technical University of Madrid, Spain 12 | http://www.aslab.org/ 13 | 14 | Communicative Machines 15 | Edinburgh, United Kingdom 16 | http://www.cmlabs.com/ 17 | 18 | Istituto Dalle Molle di Studi sull'Intelligenza Artificiale 19 | University of Lugano and SUPSI, Switzerland 20 | http://www.idsia.ch/ 21 | 22 | Institute of Cognitive Sciences and Technologies 23 | Consiglio Nazionale delle Ricerche, Italy 24 | http://www.istc.cnr.it/ 25 | 26 | Dipartimento di Ingegneria Informatica 27 | University of Palermo, Italy 28 | http://roboticslab.dinfo.unipa.it/index.php/Main/HomePage 29 | 30 | 31 | --- HUMANOBS Open-Source BSD License, with CADIA Clause v 1.0 --- 32 | 33 | Redistribution and use in source and binary forms, with or without 34 | modification, is permitted provided that the following conditions 35 | are met: 36 | 37 | - Redistributions of source code must retain the above copyright 38 | and collaboration notice, this list of conditions and the 39 | following disclaimer. 40 | 41 | - Redistributions in binary form must reproduce the above copyright 42 | notice, this list of conditions and the following 43 | disclaimer in the documentation and/or other materials provided 44 | with the distribution. 45 | 46 | - Neither the name of its copyright holders nor the names of its 47 | contributors may be used to endorse or promote products 48 | derived from this software without specific prior written permission. 49 | 50 | - CADIA Clause: The license granted in and to the software under this 51 | agreement is a limited-use license. The software may not be used in 52 | furtherance of: 53 | (i) intentionally causing bodily injury or severe emotional distress 54 | to any person; 55 | (ii) invading the personal privacy or violating the human rights of 56 | any person; or 57 | (iii) committing or preparing for any act of war. 58 | 59 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 60 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 61 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 62 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 63 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 64 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 65 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 66 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 67 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 68 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 69 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | replicode 2 | ========= 3 | 4 | a constructivist programming language and runtime. 5 | 6 | to build cmake and a modern c++ compiler is required: 7 | 8 | ```bash 9 | mkdir build 10 | cd build 11 | cmake .. 12 | make 13 | ``` 14 | 15 | An optional step after building is to run the automated tests: 16 | 17 | ```bash 18 | make test 19 | ``` 20 | 21 | [![Build Status](https://travis-ci.org/sandsmark/replicode.svg?branch=travis)](https://travis-ci.org/sandsmark/replicode) 22 | [![Coverity Scan Build Status](https://scan.coverity.com/projects/3254/badge.svg)](https://scan.coverity.com/projects/3254) 23 | 24 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - CI builds for OS X (travis) 2 | - CI builds for Windows 3 | - Child class in Mem for parameters 4 | - Refactor Compiler 5 | - Call Preprocessor from compiler 6 | - New language 7 | - Implement diff for compiler test (longest common subsequence) 8 | - UI/graph view (based on replicode-visualizer from humanobs?) 9 | - Integrate with various games (TG AI competition) 10 | - More unit tests, test more individual functions (e. g. in compiler) 11 | - Clean up classes; 12 | - Remove argments from constructor, set individually 13 | -------------------------------------------------------------------------------- /examples/Correlator.Data.Generation/user.classes.replicode: -------------------------------------------------------------------------------- 1 | !load ./V1.2/std.replicode 2 | 3 | !def (std_grp _upr _sln_thr _act_thr _vis_thr _ntf_grps) (grp _upr _sln_thr _act_thr _vis_thr 1 0 1 0 0 1 0 0 1 1 1 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 _ntf_grps 1); c-salient and c-active. 4 | !def (std_rgrp _upr _sln_thr _act_thr _vis_thr) (rgrp _upr _sln_thr _act_thr _vis_thr 1 0 0 0 0 1 0 0 1 1 1 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 |[] 1); c-salient, non c-active. 5 | 6 | !class (vec3 x:nb y:nb z:nb) 7 | !class (rgb r:nb g:nb b:nb) 8 | !class (noise (_obj :)) 9 | !class (episode_end (_obj time:us)) 10 | 11 | root:(std_grp 1 0 0 0 [nil]) 12 | [] 13 | [SYNC_FRONT now 0 forever nil nil COV_OFF 0] 14 | 15 | stdin:(std_grp 1 0 0 0 |[]) 16 | [] 17 | [SYNC_FRONT now 0 forever root nil COV_OFF 0] 18 | 19 | stdout:(std_grp 1 0 0 0 |[]) 20 | [] 21 | [SYNC_FRONT now 0 forever root nil COV_OFF 0] 22 | 23 | 24 | ; ontology 25 | 26 | self:(ent 1) 27 | [] 28 | [SYNC_FRONT now 1 forever root nil] 29 | 30 | cup:(ent 1) 31 | [] 32 | [SYNC_FRONT now 1 forever root nil] 33 | 34 | hand:(ent 1) 35 | [] 36 | [SYNC_FRONT now 1 forever root nil] 37 | 38 | position:(ent 1) 39 | [] 40 | [SYNC_FRONT now 1 forever root nil] 41 | 42 | color:(ent 1) 43 | [] 44 | [SYNC_FRONT now 1 forever root nil] 45 | 46 | size:(ent 1) 47 | [] 48 | [SYNC_FRONT now 1 forever root nil] 49 | 50 | large:(ent 1) 51 | [] 52 | [SYNC_FRONT now 1 forever root nil] 53 | 54 | medium:(ent 1) 55 | [] 56 | [SYNC_FRONT now 1 forever root nil] 57 | 58 | small:(ent 1) 59 | [] 60 | [SYNC_FRONT now 1 forever root nil] 61 | 62 | hold:(ent 1) 63 | [] 64 | [SYNC_FRONT now 1 forever root nil] 65 | 66 | human:(ent 1) 67 | [] 68 | [SYNC_FRONT now 1 forever root nil] 69 | -------------------------------------------------------------------------------- /examples/Demo1/initial.HLP.replicode: -------------------------------------------------------------------------------- 1 | ; initial high-level patterns (HLP). 2 | ; abstraction is fully automatic: HLPs are built from examples. 3 | ; caveat: the provided examples will be patched. Do not refer to ontological entities here (however, ont are safe). 4 | 5 | 6 | ; self_hand_position[H P T]:[(H e hand)T,(H b self)T,(H p P)T] 7 | 8 | self_hand:(ent 1) |[] 9 | 10 | self_hand_is_a_hand:(mk.val self_hand essence hand 1) |[] 11 | f_self_hand_is_a_hand:(fact self_hand_is_a_hand 0us 1 1) |[] 12 | 13 | self_hand_belongs_to_self:(mk.val self_hand part_of self 1) |[] 14 | f_self_hand_belongs_to_self:(fact self_hand_belongs_to_self 0us 1 1) |[] 15 | 16 | self_hand_pos:(mk.val self_hand position (vec3 0 0 0) 1) |[] 17 | f_self_hand_pos:(fact self_hand_pos 0us 1 1) |[] 18 | 19 | self_hand_position:(cst [f_self_hand_is_a_hand f_self_hand_belongs_to_self f_self_hand_pos] [stdin] 0us 1) [[SYNC_FRONT now 0 forever stdin nil 1]] 20 | 21 | 22 | ; move_hand_[H Ptarget Ttarget Tinit]:[(move_hand H Ptarget Ttarget)Tinit->i_self_hand_position[H Ptarget Ttarget]] 23 | 24 | cmd_move:(cmd move_hand [self_hand (vec3 0 0 0) 100000us] 1) |[] 25 | f_cmd_move:(fact cmd_move 0us 1 1) |[] 26 | 27 | a_self_hand_pos:(icst self_hand_position [self_hand (vec3 0 0 0) 100000us] 1) |[] 28 | f_a_self_hand_pos:(fact a_self_hand_pos 100000us 1 1) |[] 29 | 30 | move_hand_:(mdl [f_cmd_move f_a_self_hand_pos] [stdin] 0us 1) [[SYNC_FRONT now 0 forever stdin nil 1]] 31 | 32 | 33 | ; same_position 34 | 35 | 36 | 37 | ; move 38 | 39 | 40 | 41 | ; link 42 | 43 | 44 | 45 | ; attach 46 | 47 | 48 | 49 | ; grab 50 | 51 | 52 | 53 | ; grab req 54 | 55 | 56 | 57 | ; move_hand_req_ 58 | 59 | 60 | -------------------------------------------------------------------------------- /examples/Demo1/main.replicode: -------------------------------------------------------------------------------- 1 | !load ../Test/Demo1/initial.HLP.replicode 2 | ; !load ../Test/Demo1/sim.devices.replicode 3 | !load ../Test/Demo1/test.1.replicode 4 | -------------------------------------------------------------------------------- /examples/Demo1/test.1.replicode: -------------------------------------------------------------------------------- 1 | ; 2 | 3 | test_match_cst:(pgm |[] |[] [] 4 | (inj [] 5 | shp:(mk.val self_right_hand position (vec3 10 20 30) 1) 6 | [SYNC_FRONT now 1 1 stdin nil] 7 | ) 8 | (inj [] 9 | (fact shp now 1 1) 10 | [SYNC_FRONT now 1 1 stdin nil] 11 | ) 12 | (inj [] 13 | (fact self_right_hand_belongs_to_self now 1 1) 14 | [SYNC_FRONT now 1 1 stdin nil] 15 | ) 16 | (inj [] 17 | (fact self_right_hand_is_a_hand now 1 1) 18 | [SYNC_FRONT now 1 1 stdin nil] 19 | ) 20 | 1) |[] 21 | 22 | i_test_match_cst:(ipgm test_match_cst |[] RUN_ONCE 600000us SILENT 1) [[SYNC_FRONT now 0 forever root nil 0]] 23 | 24 | 25 | test_match_cmd:(pgm |[] [] 26 | [] 27 | (ptn (fact (mk.goal f_cmd:(fact (cmd move_hand [: pos: deadline:] ::) ::) ::) ::) |[]) 28 | |[] 29 | |[] 30 | [] 31 | (inj [] 32 | shp:(mk.val self_right_hand position pos 1) 33 | [SYNC_FRONT deadline 1 1 stdin nil] 34 | ) 35 | (inj [] 36 | (fact shp deadline 1 1) 37 | [SYNC_FRONT deadline 1 1 stdin nil] 38 | ) 39 | (inj [] 40 | (fact self_right_hand_belongs_to_self deadline 1 1) 41 | [SYNC_FRONT deadline 1 1 stdin nil] 42 | ) 43 | (inj [] 44 | (fact self_right_hand_is_a_hand deadline 1 1) 45 | [SYNC_FRONT deadline 1 1 stdin nil] 46 | ) 47 | (inj [] 48 | f_cmd 49 | [SYNC_FRONT deadline 1 1 stdin nil] 50 | ) 51 | 1) |[] 52 | 53 | i_test_match_cmd:(ipgm test_match_cmd |[] RUN_ALWAYS 0us SILENT 1) [[SYNC_FRONT now 0 forever stdin nil 1]] 54 | 55 | 56 | test_goal_cst:(pgm |[] |[] [] 57 | (inj [] 58 | shp:(mk.val self_right_hand position (vec3 10 20 30) 1) 59 | [SYNC_FRONT now 0 1 stdin nil] 60 | ) 61 | (inj [] 62 | f_g:(fact shp (+ now 500000us) 1 1) 63 | [SYNC_FRONT now 0 1 stdin nil] 64 | ) 65 | (inj [] 66 | g:(mk.goal f_g self 1) 67 | [SYNC_FRONT now 1 1 stdin nil] 68 | ) 69 | (inj [] 70 | (fact g now 1 1) 71 | [SYNC_FRONT now 1 1 stdin nil] 72 | ) 73 | 1) |[] 74 | 75 | i_test_goal_cst:(ipgm test_goal_cst |[] RUN_ONCE 120000us SILENT 1) [[SYNC_FRONT now 0 forever root nil 1]] 76 | 77 | 78 | test_fwd_mdl:(pgm |[] |[] [] 79 | (inj [] 80 | c:(cmd move_hand [self_right_hand (vec3 10 20 30) now] 1) 81 | [SYNC_FRONT now 1 1 stdin nil] 82 | ) 83 | (inj [] 84 | (fact c now 1 1) 85 | [SYNC_FRONT now 1 1 stdin nil] 86 | ) 87 | 1) |[] 88 | 89 | i_test_fwd_mdl:(ipgm test_fwd_mdl |[] RUN_ONCE 250000us NOTIFY 1) [[SYNC_FRONT now 0 forever root nil 0]] 90 | -------------------------------------------------------------------------------- /examples/V1.2/drives.replicode: -------------------------------------------------------------------------------- 1 | ; debug 2 | 3 | 4 | ; drive injectors. 5 | 6 | init_run_pgm:(pgm |[] |[] |[] [] 7 | (inj [] 8 | f_run:(fact run t:(now) (+ t 200000us) 1 1) 9 | |[] 10 | ) 11 | (inj [] 12 | g:(goal f_run self 1) 13 | |[] 14 | ) 15 | (inj [] 16 | (fact g t t 1 1) 17 | [SYNC_ONCE t 1 1 primary nil] 18 | ) 19 | 1) |[] 20 | 21 | init_run_ipgm:(ipgm init_run_pgm |[] RUN_ONCE 200000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 drives nil 0]] 22 | 23 | success_run_pgm:(pgm |[] [] 24 | (ptn (fact (success (fact (goal (fact run after: before: ::) ::) ::) ::) ::) |[]) 25 | |[] 26 | [] 27 | (inj [] 28 | f_run:(fact run t:(now) (+ t (+ (- before after) 50000us)) 1 1) 29 | |[] 30 | ) 31 | (inj [] 32 | g:(goal f_run self 1) 33 | |[] 34 | ) 35 | (inj [] 36 | (fact g t t 1 1) 37 | [SYNC_ONCE t 1 1 primary nil] 38 | ) 39 | 1) |[] 40 | 41 | success_run_ipgm:(ipgm success_run_pgm |[] RUN_ALWAYS 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 drives nil 0]] 42 | 43 | failure_0_run_pgm:(pgm |[] [] 44 | (ptn (|fact (success (fact (goal (fact run after: before: ::) ::) ::) ::) ::) [(< 0 delta:(- (- before after) 50000us))]) 45 | |[] 46 | [] 47 | (inj [] 48 | f_run:(fact run t:(now) (+ t delta) 1 1) 49 | |[] 50 | ) 51 | (inj [] 52 | g:(goal f_run self 1) 53 | |[] 54 | ) 55 | (inj [] 56 | (fact g t t 1 1) 57 | [SYNC_ONCE t 1 1 primary nil] 58 | ) 59 | 1) |[] 60 | 61 | failure_0_run_ipgm:(ipgm failure_0_run_pgm |[] RUN_ALWAYS 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 drives nil 0]] 62 | 63 | failure_1_run_pgm:(pgm |[] [] 64 | (ptn (|fact (success (fact (goal (fact run after: before: ::) ::) ::) ::) ::) [(>= 50000us (- before after))]) 65 | |[] 66 | [] 67 | (inj [] 68 | f_run:(fact run t:(now) (+ t 50000us) 1 1) 69 | |[] 70 | ) 71 | (inj [] 72 | g:(goal f_run self 1) 73 | |[] 74 | ) 75 | (inj [] 76 | (fact g t t 1 1) 77 | [SYNC_ONCE t 1 1 primary nil] 78 | ) 79 | 1) |[] 80 | 81 | failure_1_run_ipgm:(ipgm failure_1_run_pgm |[] RUN_ALWAYS 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 drives nil 0]] 82 | -------------------------------------------------------------------------------- /examples/V1.2/hello.world.replicode: -------------------------------------------------------------------------------- 1 | ; all programs are deactivated: activate the ones according to the method you want to try. 2 | 3 | 4 | ; Method 1: locked on timer. 5 | 6 | pgm0:(pgm |[] |[] |[] [] 7 | (prb [1 "print" "hello world" |[]]) 8 | 1) |[] 9 | 10 | ipgm0:(ipgm pgm0 |[] RUN_ONCE 50000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 0]] 11 | 12 | 13 | ; Method 2: one object injected at a point in time, caught by another program. 14 | 15 | pgm1:(pgm |[] |[] |[] [] 16 | (inj [] 17 | (ent 1) 18 | [SYNC_ONCE now 1 1 stdin nil] 19 | ) 20 | 1) |[] 21 | 22 | ipgm1:(ipgm pgm1 |[] RUN_ONCE 50000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 0]] 23 | 24 | pgm2:(pgm |[] [] 25 | (ptn (ent ::) |[]) 26 | |[] [] 27 | (prb [1 "print" "hello world" |[]]) 28 | 1) |[] 29 | 30 | ipgm2:(ipgm pgm2 |[] RUN_ONCE 0us VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 0]] 31 | 32 | 33 | ; Method 3: one program that injects a new instance of itself. 34 | 35 | pgm3:(pgm |[] |[] |[] [] 36 | (inj [] 37 | (ins pgm3 |[] RUN_ONCE 50000us VOLATILE SILENT) 38 | [SYNC_ONCE now 0 forever stdin nil 1] 39 | ) 40 | (prb [1 "print" "hello world" |[]]) 41 | 1) |[] 42 | 43 | ipgm3:(ipgm pgm3 |[] RUN_ONCE 50000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 44 | 45 | -------------------------------------------------------------------------------- /examples/V1.2/main.replicode: -------------------------------------------------------------------------------- 1 | ; debug 2 | 3 | ; !load V1.2/test.1.replicode 4 | ; !load V1.2/test.2.replicode 5 | ; !load V1.2/test.3.replicode 6 | ; !load V1.2/test.4.replicode 7 | ; !load V1.2/pong.replicode 8 | !load V1.2/pong.2.replicode 9 | -------------------------------------------------------------------------------- /examples/V1.2/pong.2.replicode: -------------------------------------------------------------------------------- 1 | ; as pong, debug combinations of CTPX, GTPX and PTPX; goal-driven. 2 | 3 | ; objects. 4 | 5 | b:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 6 | ball:(ont 1) [[SYNC_ONCE now 0 forever root nil]] 7 | b_is_a_ball:(mk.val b essence ball 1) |[] 8 | f_b_is_a_ball:(fact b_is_a_ball 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 9 | 10 | red_color:(ont 1) [[SYNC_ONCE now 1 forever root nil]] 11 | blue_color:(ont 1) [[SYNC_ONCE now 1 forever root nil]] 12 | 13 | b_is_blue:(mk.val b color blue_color 1) |[] 14 | f_b_is_blue:(fact b_is_blue 0us MAX_TIME 1 1) [[SYNC_HOLD now 1 forever stdin nil]] 15 | 16 | 17 | ; top-level model and drive injectors. 18 | 19 | m_run_0:(mdl |[] [] 20 | (fact (mk.val b: position_y : :) t0: t1: ::) 21 | (fact run t0: t1: ::); drive. 22 | |[] 23 | |[] 24 | [stdin drives] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 1]] 25 | 26 | 27 | init_run_pgm:(pgm |[] |[] |[] [] 28 | (inj [] 29 | f_run:(fact run t0:(+ now 50000us) (+ t0 sampling_period) 1 1) 30 | |[] 31 | ) 32 | (inj [] 33 | g:(goal f_run self 1) 34 | |[] 35 | ) 36 | (inj [] 37 | (fact g t1:(now) t1 1 1) 38 | [SYNC_ONCE t1 1 forever primary nil] 39 | ) 40 | 1) |[] 41 | 42 | init_run_ipgm:(ipgm init_run_pgm |[] RUN_ONCE 50000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 drives nil 1]] 43 | 44 | success_run_pgm:(pgm |[] [] 45 | s:(ptn (fact (success (fact (goal (fact run after: before: ::) ::) ::) ::) ::) |[]) 46 | |[] [] 47 | (inj [] 48 | f_run:(fact run (+ after sampling_period) (+ before sampling_period) 1 1) 49 | |[] 50 | ) 51 | (inj [] 52 | g:(goal f_run self 1) 53 | |[] 54 | ) 55 | (inj [] 56 | (fact g t1:(now) t1 1 1) 57 | [SYNC_ONCE t1 1 forever primary nil] 58 | ) 59 | 1) |[] 60 | 61 | success_run_ipgm:(ipgm success_run_pgm |[] RUN_ALWAYS 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 forever drives nil 1]] 62 | 63 | failure_run_pgm:(pgm |[] [] 64 | s:(ptn (|fact (success (fact (goal (fact run after: before: ::) ::) ::) ::) ::) |[]) 65 | |[] [] 66 | (inj [] 67 | f_run:(fact run (+ after sampling_period) (+ before sampling_period) 1 1) 68 | |[] 69 | ) 70 | (inj [] 71 | g:(goal f_run self 1) 72 | |[] 73 | ) 74 | (inj [] 75 | (fact g t1:(now) t1 1 1) 76 | [SYNC_ONCE t1 1 forever primary nil] 77 | ) 78 | 1) |[] 79 | 80 | failure_run_ipgm:(ipgm failure_run_pgm |[] RUN_ALWAYS 0us VOLATILE SILENT 1) [[SYNC_ONCE now 0 forever drives nil 1]] 81 | 82 | 83 | ; input generators. 84 | 85 | start:(pgm |[] |[] |[] [] 86 | (inj [] 87 | p:(mk.val b position_y 0 1) 88 | |[] 89 | ) 90 | (inj [] 91 | (fact p after:(now) (+ after sampling_period) 1 1) 92 | [SYNC_PERIODIC now 1 1 stdin nil] 93 | ) 94 | (inj [] 95 | s:(mk.val b speed_y 0.0001 1) 96 | |[] 97 | ) 98 | (inj [] 99 | (fact s now MAX_TIME 1 1) 100 | [SYNC_HOLD now 1 forever stdin nil] 101 | ) 102 | 1) |[] 103 | 104 | istart:(ipgm start |[] RUN_ONCE sampling_period VOLATILE SILENT 1) [[SYNC_ONCE now 0 forever stdin nil 1]] 105 | 106 | pgm0:(pgm |[] [] 107 | (ptn f:(fact (mk.val b position_y py: :) after: before: ::) |[]) 108 | (ptn (fact (mk.val b speed_y sy: :) ::) |[]) 109 | |[] [] 110 | (inj [] 111 | p:(mk.val b position_y (+ py (* sy sampling_period)) 1) 112 | |[] 113 | ) 114 | (inj [] 115 | (fact p (+ after sampling_period) (+ before sampling_period) 1 1) 116 | [SYNC_PERIODIC (+ f.vw.ijt sampling_period) 1 1 stdin nil] 117 | ) 118 | 1) |[] 119 | 120 | ipgm0:(ipgm pgm0 |[] RUN_ALWAYS 20000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 forever stdin nil 1]] 121 | -------------------------------------------------------------------------------- /examples/V1.2/pong.replicode: -------------------------------------------------------------------------------- 1 | ; debug 2 | ; a ball bounces between two walls. 3 | 4 | ; objects. 5 | 6 | b:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 7 | ball:(ont 1) [[SYNC_ONCE now 0 forever root nil]] 8 | b_is_a_ball:(mk.val b essence ball 1) |[] 9 | f_b_is_a_ball:(fact b_is_a_ball 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 10 | 11 | ; w_top:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 12 | ; w_top_py:(mk.val w_top position_y 50 1) |[] 13 | ; f_w_top_py:(fact w_top_py 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 14 | 15 | ; w_bottom:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 16 | ; w_bottom_py:(mk.val w_bottom position_y 0 1) |[] 17 | ; f_w_bottom_py:(fact w_bottom_py 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 18 | 19 | 20 | ; same pos_y. 21 | 22 | s0:(cst |[] [] 23 | (fact (mk.val h: position_y py: :) t0: t1: ::) 24 | (fact (mk.val w: position_y py: :) t0: t1: ::) 25 | |[] 26 | |[] 27 | [stdin] 1) [[SYNC_ONCE now 0 forever primary nil 0]] 28 | 29 | 30 | ; input generators. 31 | 32 | start:(pgm |[] |[] |[] [] 33 | (inj [] 34 | p:(mk.val b position_y 0 1) 35 | |[] 36 | ) 37 | (inj [] 38 | (fact p after:(now) (+ after sampling_period) 1 1) 39 | [SYNC_PERIODIC now 1 1 stdin nil] 40 | ) 41 | 1) |[] 42 | 43 | istart:(ipgm start |[] RUN_ONCE sampling_period VOLATILE SILENT 1) [[SYNC_ONCE now 0 forever stdin nil 1]] 44 | 45 | pgm0:(pgm |[] [] 46 | (ptn f:(fact (mk.val b position_y py: :) after: before: ::) |[]) 47 | (ptn (fact (mk.val b speed_y sy: :) ::) |[]) 48 | |[] [] 49 | (inj [] 50 | p:(mk.val b position_y (+ py (* sy sampling_period)) 1) 51 | |[] 52 | ) 53 | (inj [] 54 | (fact p (+ after sampling_period) (+ before sampling_period) 1 1) 55 | [SYNC_PERIODIC (+ f.vw.ijt sampling_period) 1 1 stdin nil] 56 | ) 57 | 1) |[] 58 | 59 | ipgm0:(ipgm pgm0 |[] RUN_ALWAYS 20000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 forever stdin nil 1]] 60 | 61 | pgm1:(pgm |[] [] 62 | (ptn (fact (mk.val b position_y py: :) ::) [(< py 55) (> py 45)]) 63 | |[] [] 64 | (inj [] 65 | s:(mk.val b speed_y -0.0001 1) 66 | |[] 67 | ) 68 | (inj [] 69 | (fact s now MAX_TIME 1 1) 70 | [SYNC_HOLD now 1 forever stdin nil] 71 | ) 72 | 1) |[] 73 | 74 | ipgm1:(ipgm pgm1 |[] RUN_ALWAYS 0us VOLATILE SILENT 1) [[SYNC_ONCE now 0 forever stdin nil 0]] 75 | 76 | pgm2:(pgm |[] [] 77 | (ptn (fact (mk.val b position_y 0 :) ::) |[]) 78 | |[] [] 79 | (inj [] 80 | s:(mk.val b speed_y 0.0001 1) 81 | |[] 82 | ) 83 | (inj [] 84 | (fact s now MAX_TIME 1 1) 85 | [SYNC_HOLD now 1 forever stdin nil] 86 | ) 87 | 1) |[] 88 | 89 | ipgm2:(ipgm pgm2 |[] RUN_ONCE 0us VOLATILE SILENT 1) [[SYNC_ONCE now 0 forever stdin nil 1]] -------------------------------------------------------------------------------- /examples/V1.2/test.1.replicode: -------------------------------------------------------------------------------- 1 | ; debug 2 | 3 | !load V1.2/test.domain.replicode 4 | ; !load V1.2/drives.replicode 5 | 6 | 7 | s0:(cst |[] [] 8 | (fact (mk.val h: position_z z0: :) t0: t1: ::) 9 | (fact (mk.val h: essence hand :) t0: t1: ::) 10 | |[] 11 | |[] 12 | [stdin] 1) [[SYNC_ONCE now 0 forever primary nil 0]] 13 | 14 | m0:(mdl [p0: t0: t1:] [] 15 | (fact (cmd lift_hand [h: delta_z:] :) t2: t3: ::) 16 | (fact (mk.val h: position_z p1: 1) t4: t5: : 1) 17 | [] 18 | p1:(+ p0 delta_z) 19 | t4:(+ t0 sampling_period) 20 | t5:(+ t1 sampling_period) 21 | [] 22 | delta_z:(- p1 p0) 23 | [stdin] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 24 | 25 | m1:(mdl |[] [] 26 | (fact (icst s0 |[] [h: p0:] ::) t0: t1: ::) 27 | (fact (imdl m0 [p0: t0: t1:] [h: delta_z: p1: : :] : 1) t0: t2: : 1) 28 | [] 29 | t2:(+ t0 sampling_period); domain of validity of the lhs, as enforced by the input generators. 30 | [] 31 | t0:(- t2 sampling_period) 32 | [stdin] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 33 | 34 | 35 | ; top-level models. 36 | 37 | m_run_0:(mdl |[] [] 38 | (fact (mk.val self_right_hand position_z 10 :) t0: t1: ::) 39 | (fact run t2: t3: ::) 40 | |[] 41 | [] 42 | t0:(now) 43 | t1:(+ t0 100000us) 44 | [stdin drives] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 45 | 46 | 47 | ; input generators. 48 | 49 | pgm0:(pgm |[] |[] |[] [] 50 | (inj [] 51 | p:(mk.val self_right_hand position_z 10 1) 52 | |[] 53 | ) 54 | (inj [] 55 | (fact p now (+ now sampling_period) 1 1) 56 | [SYNC_PERIODIC now 1 1 stdin nil] 57 | ) 58 | 1) |[] 59 | 60 | ipgm0:(ipgm pgm0 |[] RUN_ONCE sampling_period VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 61 | 62 | pgm1:(pgm |[] |[] |[] [] 63 | (inj [] 64 | c:(cmd lift_hand [self_right_hand 2] 1) 65 | |[] 66 | ) 67 | (inj [] 68 | (fact c now 200000us 1 1) 69 | [SYNC_ONCE now 1 1 stdin nil] 70 | ) 71 | 1) |[] 72 | 73 | ipgm1:(ipgm pgm1 |[] RUN_ONCE 150000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 74 | 75 | pgm2:(pgm |[] [] 76 | (ptn (fact (cmd lift_hand [h: z:] :) t0: t1: ::) |[]) 77 | (ptn p:(fact (mk.val h: position_z old_z: :) t2: t3: ::) |[]) 78 | |[] 79 | [] 80 | (inj [] 81 | new_p:(mk.val self_right_hand position_z (+ z old_z) 1) 82 | |[] 83 | ) 84 | (inj [] 85 | (fact new_p (+ t2 sampling_period) (+ t3 sampling_period) 1 1) 86 | [SYNC_PERIODIC t3 1 1 stdin nil] 87 | ) 88 | 1) |[] 89 | 90 | ipgm2:(ipgm pgm2 |[] RUN_ONCE 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 91 | -------------------------------------------------------------------------------- /examples/V1.2/test.2.replicode: -------------------------------------------------------------------------------- 1 | ; debug 2 | 3 | !load V1.2/test.domain.replicode 4 | ; !load V1.2/drives.replicode 5 | 6 | 7 | 8 | s0:(cst |[] [] 9 | (fact (mk.val h: position_z z0: :) t0: t1: ::) 10 | (fact (mk.val h: essence hand :) t0: t1: ::) 11 | |[] 12 | |[] 13 | [stdin] 1) [[SYNC_ONCE now 0 forever primary nil 0]] 14 | 15 | m0:(mdl [p0: t0: t1:] [] 16 | (fact (cmd lift_hand [h: delta_z:] :) t2: t3: ::) 17 | (fact (mk.val h: position_z p1: 1) t4: t5: : 1) 18 | [] 19 | p1:(+ p0 delta_z) 20 | t4:(+ t0 sampling_period) 21 | t5:(+ t1 sampling_period) 22 | [] 23 | delta_z:(- p1 p0) 24 | [stdin] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 25 | 26 | m1:(mdl |[] [] 27 | (fact (icst s0 |[] [h: p0:] ::) t0: t1: ::) 28 | (fact (imdl m0 [p0: t0: t1:] [h: delta_z: p1: : :] : 1) t0: t2: : 1) 29 | [] 30 | t2:(+ t0 sampling_period); domain of validity of the lhs, as enforced by the input generators. 31 | [] 32 | t0:(- t2 sampling_period) 33 | [stdin] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 34 | 35 | 36 | ; top-level models. 37 | 38 | m_run_0:(mdl |[] [] 39 | (fact (mk.val self_right_hand attachment cube0 :) t0: t1: ::) 40 | (fact run t2: t3: ::) 41 | |[] 42 | [] 43 | t0:(now) 44 | t1:(+ t0 100000us) 45 | [stdin drives] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 46 | 47 | 48 | ; input generators. 49 | 50 | pgm0:(pgm |[] |[] |[] [] 51 | (inj [] 52 | p:(mk.val self_right_hand attachment cube0 1) 53 | |[] 54 | ) 55 | (inj [] 56 | (fact p now MAX_TIME 1 1) 57 | [SYNC_HOLD now 1 1 stdin nil] 58 | ) 59 | 1) |[] 60 | 61 | ipgm0:(ipgm pgm0 |[] RUN_ONCE sampling_period VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 62 | 63 | pgm1:(pgm |[] |[] |[] [] 64 | (inj [] 65 | c:(cmd release_hand [self_right_hand] 1) 66 | |[] 67 | ) 68 | (inj [] 69 | (fact c now (+ now 10000us) 1 1) 70 | [SYNC_ONCE now 1 1 stdin nil] 71 | ) 72 | (inj [] 73 | p:(mk.val self_right_hand attachment cube0 1) 74 | |[] 75 | ) 76 | (inj [] 77 | (|fact p now MAX_TIME 1 1) 78 | [SYNC_HOLD now 1 1 stdin nil] 79 | ) 80 | 1) |[] 81 | 82 | ipgm1:(ipgm pgm1 |[] RUN_ONCE 160000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 83 | -------------------------------------------------------------------------------- /examples/V1.2/test.3.replicode: -------------------------------------------------------------------------------- 1 | ; debug 2 | 3 | !load V1.2/test.domain.replicode 4 | ; !load V1.2/drives.replicode 5 | 6 | 7 | 8 | ; input generators. 9 | 10 | pgm0:(pgm |[] |[] |[] [] 11 | (inj [] 12 | a:(mk.val self_right_hand attachment cube0 1) 13 | |[] 14 | ) 15 | (inj [] 16 | (|fact a now MAX_TIME 1 1) 17 | [SYNC_HOLD now 1 forever stdin nil] 18 | ) 19 | (inj [] 20 | ph:(mk.val self_right_hand position_x 0 1) 21 | |[] 22 | ) 23 | (inj [] 24 | (fact ph now (+ now sampling_period) 1 1) 25 | [SYNC_PERIODIC now 1 1 stdin nil] 26 | ) 27 | (inj [] 28 | pc:(mk.val cube0 position_x 0 1) 29 | |[] 30 | ) 31 | (inj [] 32 | (fact pc now (+ now sampling_period) 1 1) 33 | [SYNC_PERIODIC now 1 1 stdin nil] 34 | ) 35 | 1) |[] 36 | 37 | ipgm0:(ipgm pgm0 |[] RUN_ONCE sampling_period VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 38 | 39 | pgm1:(pgm |[] |[] |[] [] 40 | (inj [] 41 | c:(cmd grab_hand [self_right_hand] 1) 42 | |[] 43 | ) 44 | (inj [] 45 | (fact c now (+ now 10000us) 1 1) 46 | [SYNC_ONCE now 1 1 stdin nil] 47 | ) 48 | (inj [] 49 | p:(mk.val self_right_hand attachment cube0 1) 50 | |[] 51 | ) 52 | (inj [] 53 | (fact p now MAX_TIME 1 1) 54 | [SYNC_HOLD now 1 1 stdin nil] 55 | ) 56 | 1) |[] 57 | 58 | ipgm1:(ipgm pgm1 |[] RUN_ONCE 160000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 59 | -------------------------------------------------------------------------------- /examples/V1.2/test.4.replicode: -------------------------------------------------------------------------------- 1 | ; test 1,2 and 3 together. 2 | 3 | !load V1.2/test.domain.replicode 4 | ; !load V1.2/drives.replicode 5 | 6 | 7 | ; input generators. 8 | 9 | pgm0:(pgm |[] |[] |[] [] 10 | (inj [] 11 | p:(mk.val self_right_hand position_z 10 1) 12 | |[] 13 | ) 14 | (inj [] 15 | (fact p now (+ now sampling_period) 1 1) 16 | [SYNC_PERIODIC now 1 1 stdin nil] 17 | ) 18 | 1) |[] 19 | 20 | ipgm0:(ipgm pgm0 |[] RUN_ONCE sampling_period VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 21 | 22 | pgm1:(pgm |[] |[] |[] [] 23 | (inj [] 24 | c:(cmd lift_hand [self_right_hand 2] 1) 25 | |[] 26 | ) 27 | (inj [] 28 | (fact c now 200000us 1 1) 29 | [SYNC_ONCE now 1 1 stdin nil] 30 | ) 31 | 1) |[] 32 | 33 | ipgm1:(ipgm pgm1 |[] RUN_ONCE 150000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 34 | 35 | pgm2:(pgm |[] [] 36 | (ptn (fact (cmd lift_hand [h: z:] :) t0: t1: ::) |[]) 37 | (ptn p:(fact (mk.val h: position_z old_z: :) t2: t3: ::) |[]) 38 | |[] 39 | [] 40 | (inj [] 41 | new_p:(mk.val self_right_hand position_z (+ z old_z) 1) 42 | |[] 43 | ) 44 | (inj [] 45 | (fact new_p (+ t2 sampling_period) (+ t3 sampling_period) 1 1) 46 | [SYNC_PERIODIC t3 1 1 stdin nil] 47 | ) 48 | 1) |[] 49 | 50 | ipgm2:(ipgm pgm2 |[] RUN_ONCE 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 51 | 52 | ; --------------------------------------- 53 | 54 | pgm3:(pgm |[] |[] |[] [] 55 | (inj [] 56 | a:(mk.val self_right_hand attachment cube0 1) 57 | |[] 58 | ) 59 | (inj [] 60 | (|fact a now MAX_TIME 1 1) 61 | [SYNC_HOLD now 1 forever stdin nil] 62 | ) 63 | (inj [] 64 | ph:(mk.val self_right_hand position_x 0 1) 65 | |[] 66 | ) 67 | (inj [] 68 | (fact ph now (+ now sampling_period) 1 1) 69 | [SYNC_PERIODIC now 1 1 stdin nil] 70 | ) 71 | (inj [] 72 | pc:(mk.val cube0 position_x 0 1) 73 | |[] 74 | ) 75 | (inj [] 76 | (fact pc now (+ now sampling_period) 1 1) 77 | [SYNC_PERIODIC now 1 1 stdin nil] 78 | ) 79 | 1) |[] 80 | 81 | ipgm3:(ipgm pgm3 |[] RUN_ONCE 200000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 82 | 83 | pgm4:(pgm |[] |[] |[] [] 84 | (inj [] 85 | c:(cmd grab_hand [self_right_hand] 1) 86 | |[] 87 | ) 88 | (inj [] 89 | (fact c now (+ now 10000us) 1 1) 90 | [SYNC_ONCE now 1 1 stdin nil] 91 | ) 92 | (inj [] 93 | p:(mk.val self_right_hand attachment cube0 1) 94 | |[] 95 | ) 96 | (inj [] 97 | (fact p now MAX_TIME 1 1) 98 | [SYNC_HOLD now 1 forever stdin nil] 99 | ) 100 | 1) |[] 101 | 102 | ipgm4:(ipgm pgm4 |[] RUN_ONCE 260000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 103 | 104 | ; --------------------------------------- 105 | 106 | pgm6:(pgm |[] |[] |[] [] 107 | (inj [] 108 | c:(cmd release_hand [self_right_hand] 1) 109 | |[] 110 | ) 111 | (inj [] 112 | (fact c now (+ now 10000us) 1 1) 113 | [SYNC_ONCE now 1 1 stdin nil] 114 | ) 115 | (inj [] 116 | p:(mk.val self_right_hand attachment cube0 1) 117 | |[] 118 | ) 119 | (inj [] 120 | (|fact p now MAX_TIME 1 1) 121 | [SYNC_HOLD now 1 1 stdin nil] 122 | ) 123 | 1) |[] 124 | 125 | ipgm6:(ipgm pgm6 |[] RUN_ONCE 360000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 126 | -------------------------------------------------------------------------------- /examples/V1.2/test.domain.replicode: -------------------------------------------------------------------------------- 1 | ; objects. 2 | 3 | self_right_hand:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 4 | self_right_hand_is_a_hand:(mk.val self_right_hand essence hand 1) |[] 5 | f_self_right_hand_is_a_hand:(fact self_right_hand_is_a_hand 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 6 | ; self_head:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 7 | ; self_head_is_a_head(mk.val self_head essence head 1) [[SYNC_STATE now 1 forever stdin nil]] 8 | ; f_self_head_is_a_head:(fact self_head_is_a_head 0us MAX_TIME 1 1) [[SYNC_STATE now 1 forever stdin nil]] 9 | 10 | ; programmer:(ont 1) [[SYNC_FRONT now 1 forever root nil]] 11 | 12 | ; human1:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 13 | ; (mk.val human1 essence actor 1) [[SYNC_STATE now 1 forever stdin nil]] 14 | ; human1_right_hand:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 15 | ; (mk.val human1_right_hand essence hand 1) [[SYNC_STATE now 1 forever stdin nil]] 16 | ; human1_head:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 17 | ; (mk.val human1_head essence head 1) [[SYNC_STATE now 1 forever stdin nil]] 18 | 19 | ; human2:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 20 | ; (mk.val human2 essence actor 1) [[SYNC_STATE now 1 forever stdin nil]] 21 | ; human2_right_hand:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 22 | ; (mk.val human2_right_hand essence hand 1) [[SYNC_STATE now 1 forever stdin nil]] 23 | ; human2_head:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 24 | ; (mk.val human2_head essence head 1) [[SYNC_STATE now 1 forever stdin nil]] 25 | 26 | cube0:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 27 | cube0_is_a_cube:(mk.val cube0 essence cube 1) |[] 28 | f_cube0_is_a_cube:(fact cube0_is_a_cube 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 29 | -------------------------------------------------------------------------------- /examples/helgi.replicode: -------------------------------------------------------------------------------- 1 | (Ping 2 | 0 3 | 1 4 | ) 5 | [] 6 | [SYNC_FRONT now 1 forever stdin nil] 7 | 8 | ProgPing:(pgm 9 | |[] 10 | [] 11 | [] 12 | (ptn o:(Ping v: :) |[]) 13 | |[] 14 | |[] 15 | [] 16 | (inj [(Pong now 1) [SYNC_FRONT now 1 forever stdout nil]]) 17 | 1; psln_thr 18 | ) 19 | |[] 20 | 21 | ProgPong:(pgm 22 | |[] 23 | [] 24 | [] 25 | (ptn o:(Pong v: :) |[]) 26 | |[] 27 | |[] 28 | [] 29 | (inj [(Ping now 1) [SYNC_FRONT now 1 forever stdin nil]]) 30 | 1; psln_thr 31 | ) 32 | |[] 33 | 34 | iProgPing:(ipgm 35 | ProgPing; 36 | |[]; args 37 | RUN_ALWAYS; run 38 | 0us; tsc 39 | NOTIFY; nfr 40 | 1; psln_thr 41 | ) 42 | 43 | [] 44 | [SYNC_FRONT now 1 forever stdin nil 1] 45 | 46 | iProgPong:(ipgm 47 | ProgPong; 48 | |[]; args 49 | RUN_ALWAYS; run 50 | 0us; tsc 51 | NOTIFY; nfr 52 | 1; psln_thr 53 | ) 54 | 55 | [] 56 | [SYNC_FRONT now 1 forever stdout nil 1] 57 | 58 | -------------------------------------------------------------------------------- /examples/loom-visor/rgrp.user.classes.replicode: -------------------------------------------------------------------------------- 1 | !load Replicode/std.replicode 2 | 3 | !def (std_grp _upr _sln_thr _act_thr _vis_thr _ntf_grps) (grp _upr _sln_thr _act_thr _vis_thr 1 0 1 0 0 1 0 0 1 1 1 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 _ntf_grps 1); c-salient and c-active. 4 | !def (std_rgrp _upr _sln_thr _act_thr _vis_thr) (rgrp _upr _sln_thr _act_thr _vis_thr 1 0 0 0 0 1 0 0 1 1 1 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 |[] 1); c-salient, non c-active. 5 | 6 | !class (vec3 x:nb y:nb z:nb) 7 | !class (rgb r:nb g:nb b:nb) 8 | 9 | root:(std_grp 1 0 0 0 [nil]) 10 | [] 11 | [SYNC_FRONT now 0 forever nil nil COV_OFF 0] 12 | 13 | stdin:(std_grp 1 0 0 0 |[]) 14 | [] 15 | [SYNC_FRONT now 0 forever root nil COV_OFF 0] 16 | 17 | stdout:(std_grp 1 0 0 0 |[]) 18 | [] 19 | [SYNC_FRONT now 0 forever root nil COV_OFF 0] 20 | 21 | 22 | ; ontology 23 | 24 | self:(ent 1) 25 | [] 26 | [SYNC_FRONT now 1 forever root nil] 27 | 28 | cup:(ent 1) 29 | [] 30 | [SYNC_FRONT now 1 forever root nil] 31 | 32 | hand:(ent 1) 33 | [] 34 | [SYNC_FRONT now 1 forever root nil] 35 | 36 | position:(ent 1) 37 | [] 38 | [SYNC_FRONT now 1 forever root nil] 39 | 40 | color:(ent 1) 41 | [] 42 | [SYNC_FRONT now 1 forever root nil] 43 | 44 | size:(ent 1) 45 | [] 46 | [SYNC_FRONT now 1 forever root nil] 47 | 48 | large:(ent 1) 49 | [] 50 | [SYNC_FRONT now 1 forever root nil] 51 | 52 | medium:(ent 1) 53 | [] 54 | [SYNC_FRONT now 1 forever root nil] 55 | 56 | small:(ent 1) 57 | [] 58 | [SYNC_FRONT now 1 forever root nil] 59 | 60 | hold:(ent 1) 61 | [] 62 | [SYNC_FRONT now 1 forever root nil] 63 | -------------------------------------------------------------------------------- /examples/loom-visor/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 27 | 28 | 29 | 30 | 53 | -------------------------------------------------------------------------------- /examples/rgrp.user.classes.replicode: -------------------------------------------------------------------------------- 1 | !load ../Test/std.replicode 2 | 3 | !def (std_grp _upr _sln_thr _act_thr _vis_thr _ntf_grps) (grp _upr _sln_thr _act_thr _vis_thr 1 0 1 0 0 1 0 0 1 1 1 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 _ntf_grps 1); c-salient and c-active. 4 | !def (std_rgrp _upr _sln_thr _act_thr _vis_thr) (rgrp _upr _sln_thr _act_thr _vis_thr 1 0 0 0 0 1 0 0 1 1 1 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 |[] 1); c-salient, non c-active. 5 | 6 | !class (vec3 x:nb y:nb z:nb) 7 | !class (rgb r:nb g:nb b:nb) 8 | 9 | root:(std_grp 1 0 0 0 [nil]) 10 | [] 11 | [SYNC_FRONT now 0 forever nil nil COV_OFF 0] 12 | 13 | stdin:(std_grp 1 0 0 0 |[]) 14 | [] 15 | [SYNC_FRONT now 0 forever root nil COV_OFF 0] 16 | 17 | stdout:(std_grp 1 0 0 0 |[]) 18 | [] 19 | [SYNC_FRONT now 0 forever root nil COV_OFF 0] 20 | 21 | 22 | ; ontology 23 | 24 | self:(ent 1) 25 | [] 26 | [SYNC_FRONT now 1 forever root nil] 27 | 28 | cup:(ent 1) 29 | [] 30 | [SYNC_FRONT now 1 forever root nil] 31 | 32 | hand:(ent 1) 33 | [] 34 | [SYNC_FRONT now 1 forever root nil] 35 | 36 | position:(ent 1) 37 | [] 38 | [SYNC_FRONT now 1 forever root nil] 39 | 40 | color:(ent 1) 41 | [] 42 | [SYNC_FRONT now 1 forever root nil] 43 | 44 | size:(ent 1) 45 | [] 46 | [SYNC_FRONT now 1 forever root nil] 47 | 48 | large:(ent 1) 49 | [] 50 | [SYNC_FRONT now 1 forever root nil] 51 | 52 | medium:(ent 1) 53 | [] 54 | [SYNC_FRONT now 1 forever root nil] 55 | 56 | small:(ent 1) 57 | [] 58 | [SYNC_FRONT now 1 forever root nil] 59 | 60 | hold:(ent 1) 61 | [] 62 | [SYNC_FRONT now 1 forever root nil] 63 | -------------------------------------------------------------------------------- /examples/test.1.replicode: -------------------------------------------------------------------------------- 1 | ;using tpl args for matching and production 2 | 3 | s1:(str "qwerty" 1) 4 | [] 5 | [SYNC_FRONT now 1 forever root nil] 6 | 7 | P1:(pgm 8 | [] 9 | (ptn tgv:(tagged_v vec: s:) |[]) 10 | [] 11 | [] 12 | (ptn (str tgv.string ::) |[]) 13 | |[] 14 | |[] 15 | [] 16 | (inj [(mk.val self position tgv.vector 1) [SYNC_FRONT now 1 forever root nil]]) 17 | (inj [(mk.val self position (vec3 tgv.vector.x vec.y 256) 1) [SYNC_FRONT now 1 forever root nil]]) 18 | 1 19 | ) 20 | |[] 21 | 22 | iP1:(ipgm P1 [(tagged_v (vec3 1 2 3) "qwerty")] RUN_ALWAYS 0us NOTIFY 1) 23 | [] 24 | [SYNC_FRONT now 1 forever root nil 1] 25 | -------------------------------------------------------------------------------- /examples/test.10.replicode: -------------------------------------------------------------------------------- 1 | ;hello world. 2 | ;pgm with no input will fire each time the tsc expires. 3 | 4 | hw:(pgm 5 | |[] 6 | |[] 7 | [] 8 | (inj [] 9 | (str "Hello World" 1) 10 | [SYNC_FRONT now 1 forever root nil] 11 | ) 12 | (set [this.vw.act 0]); deactivate the ipgm so that the pgm runs only once. 13 | 1 14 | ) 15 | |[] 16 | 17 | 18 | ihw:(ipgm 19 | hw; code 20 | |[]; args 21 | RUN_ALWAYS; run 22 | 100000us 23 | NOTIFY 24 | 1 25 | ) 26 | [] 27 | [SYNC_FRONT now 1 forever root nil 1] 28 | -------------------------------------------------------------------------------- /examples/test.11.replicode: -------------------------------------------------------------------------------- 1 | ;heart beat 2 | ;primitive: inject new object regularly. 3 | ;see test.15.replicode for a subtler version. 4 | 5 | hb:(pgm 6 | |[] 7 | |[] 8 | [] 9 | (inj [] 10 | (string "beep" now 1) 11 | [SYNC_FRONT now 1 forever root nil] 12 | ) 13 | 1; propagation saliency threshold 14 | ) 15 | |[] 16 | 17 | 18 | ihb:(ipgm 19 | hb; code 20 | |[]; args 21 | RUN_ALWAYS; run 22 | 200000us; time scope 23 | NOTIFY; notify reduction flag 24 | 1; propagation saliency threshold 25 | ) 26 | [] 27 | [SYNC_FRONT now 1 forever root nil 1] 28 | -------------------------------------------------------------------------------- /examples/test.12.replicode: -------------------------------------------------------------------------------- 1 | ;ping pong 2 | 3 | ;view = [sync:bl ijt:us sln:nb res:us grp:grp org:] 4 | 5 | table:(grp 6 | 1; upr 7 | 0.5; sln_thr 8 | 0.4; act_thr 9 | 0; vis_thr 10 | 1; c_sln 11 | 0; c_sln_thr 12 | 1; c_act 13 | 0; c_act_thr 14 | 0; dcy_per 15 | 0; dcy_tgt 16 | 1; dcy_prd 17 | 0; dcy_auto 18 | 1; sln_chg_thr 19 | 1; sln_chg_prd 20 | 1; act_chg_thr 21 | 1; act_chg_prd 22 | 0; avg_sln 23 | 0; high_sln 24 | 0; low_sln 25 | 0; avg_act 26 | 0; high_act 27 | 0; low_act 28 | 1; high_sln_thr 29 | 0; low_sln_thr 30 | 1; sln_ntf_prd 31 | 1; high_act_thr 32 | 0; low_act_thr 33 | 1; act_ntf_prd 34 | 0; ntf_new 35 | 0; low_res_thr 36 | [nil]; ntf_grp 37 | 1; psln_thr 38 | ) 39 | [] 40 | [SYNC_FRONT now 1 forever root nil COV_OFF 0] 41 | 42 | serve:(pgm 43 | |[] 44 | |[] 45 | [] 46 | (inj [] 47 | (string "ping" now 1) 48 | [SYNC_FRONT now 1 1 table nil] 49 | ) 50 | (mod [this.vw.res -1]) 51 | 1 52 | ) 53 | |[] 54 | 55 | iserve:(ipgm 56 | serve; code 57 | |[]; args 58 | RUN_ALWAYS 59 | 80000us 60 | NOTIFY 61 | 1; propagation saliency threshold 62 | ) 63 | [] 64 | [SYNC_FRONT now 1 10 table nil 1] 65 | 66 | 67 | player1:(pgm 68 | |[] 69 | [] 70 | [] 71 | (ptn ball:(string "ping" ::) |[]) 72 | |[] 73 | |[] 74 | [] 75 | (inj [] 76 | (string "pong" now 1) 77 | [SYNC_FRONT now 1 1 table nil] 78 | ) 79 | 1; propagation saliency threshold 80 | ) 81 | |[] 82 | 83 | iplayer1:(ipgm 84 | player1; code 85 | |[]; args 86 | RUN_ALWAYS 87 | 0us; time scope 88 | SILENT; notify reduction flag 89 | 1; propagation saliency threshold 90 | ) 91 | [] 92 | [SYNC_FRONT now 1 forever table nil 1] 93 | 94 | 95 | player2:(pgm 96 | |[] 97 | [] 98 | [] 99 | (ptn ball:(string "pong" ::) |[]) 100 | |[] 101 | |[] 102 | [] 103 | (inj [] 104 | (string "ping" now 1) 105 | [SYNC_FRONT now 1 1 table nil] 106 | ) 107 | 1; propagation saliency threshold 108 | ) 109 | |[] 110 | 111 | iplayer2:(ipgm 112 | player2; code 113 | |[]; args 114 | RUN_ALWAYS 115 | 0us; time scope 116 | SILENT; notify reduction flag 117 | 1; propagation saliency threshold 118 | ) 119 | [] 120 | [SYNC_FRONT now 1 forever table nil 1] 121 | -------------------------------------------------------------------------------- /examples/test.13.replicode: -------------------------------------------------------------------------------- 1 | ;matching on strings 2 | 3 | s1:(str "qwerty" 1) 4 | [] 5 | [SYNC_FRONT now 1 forever root nil] 6 | 7 | P1:(pgm 8 | |[] 9 | [] 10 | [] 11 | (ptn s:(str "qwerty" ::) |[]) 12 | |[] 13 | |[] 14 | [] 15 | (inj [(mk.val self position (vec3 1 2 3) 1) [SYNC_FRONT now 1 forever root nil]]) 16 | 1 17 | ) 18 | |[] 19 | 20 | iP1:(ipgm P1 |[] RUN_ALWAYS 0us NOTIFY 1) 21 | [] 22 | [SYNC_FRONT now 1 forever root nil 1] 23 | 24 | P2:(pgm 25 | |[] 26 | [] 27 | [] 28 | (ptn s:(str ::) [(= s.s "qwerty")]) 29 | |[] 30 | |[] 31 | [] 32 | (inj [(mk.val self position (vec3 4 5 6) 1) [SYNC_FRONT now 1 forever root nil]]) 33 | 1 34 | ) 35 | |[] 36 | 37 | iP2:(ipgm P2 |[] RUN_ALWAYS 0us NOTIFY 1) 38 | [] 39 | [SYNC_FRONT now 1 forever root nil 1] 40 | 41 | P3:(pgm 42 | |[] 43 | [] 44 | [] 45 | (ptn s:(str x: ::) [(= x "qwerty")]) 46 | |[] 47 | |[] 48 | [] 49 | (inj [(mk.val self position (vec3 7 8 9) 1) [SYNC_FRONT now 1 forever root nil]]) 50 | 1 51 | ) 52 | |[] 53 | 54 | iP3:(ipgm P3 |[] RUN_ALWAYS 0us NOTIFY 1) 55 | [] 56 | [SYNC_FRONT now 1 forever root nil 1] 57 | -------------------------------------------------------------------------------- /examples/test.14.replicode: -------------------------------------------------------------------------------- 1 | ; simple number sequence generation. 2 | 3 | _start:(pgm 4 | |[] 5 | |[] 6 | [] 7 | (inj [] 8 | (counter 0 1) 9 | [SYNC_FRONT now 1 1 root nil] 10 | ) 11 | (mod [this.vw.res (+ 1 (* -2 this.vw.res))]); N.B.: at each upr, res is decremented by the group. 12 | 1 13 | ) 14 | |[] 15 | 16 | i_start:(ipgm 17 | _start; code 18 | |[]; args 19 | RUN_ONCE 20 | 80000us 21 | NOTIFY 22 | 1; propagation saliency threshold 23 | ) 24 | [] 25 | [SYNC_FRONT now 0 10 root nil 1] 26 | 27 | count:(pgm 28 | |[] 29 | [] 30 | [] 31 | (ptn c:(counter ::) |[]) 32 | |[] 33 | |[] 34 | [] 35 | (inj [(counter (+ 1 c.value) 1) [SYNC_FRONT now 1 1 root nil]]) 36 | 1 37 | ) 38 | |[] 39 | 40 | icount:(ipgm count |[] RUN_ALWAYS 0us SILENT 1) 41 | [] 42 | [SYNC_FRONT now 0 forever root nil 1] 43 | -------------------------------------------------------------------------------- /examples/test.15.replicode: -------------------------------------------------------------------------------- 1 | ;heart beat. 2 | ;inject the same object ("beep") regularly with vw.sln=1. 3 | ;have the target group apply a decay on the sln of its members 4 | ;so that the new view on "beep" will gain saliency. 5 | ;to check: a pgm that catches the "beep". 6 | ;use of dcy_auto to restart decay automatically after dcy_prd expires. 7 | 8 | target_grp:(grp 9 | 1; upr 10 | 0.9; sln_thr 11 | 0.4; act_thr 12 | 0; vis_thr 13 | 1; c_sln 14 | 0; c_sln_thr 15 | 1; c_act 16 | 0; c_act_thr 17 | -1; dcy_per (decay percentage) 18 | 0; dcy_tgt (decay target): 0=member's sln, 1=group's sln_thr 19 | 1; dcy_prd (decay period) as a multiple of upr 20 | 1; dcy_auto (restart). 1=on, 0=off. 21 | 1; sln_chg_thr 22 | 1; sln_chg_prd 23 | 1; act_chg_thr 24 | 1; act_chg_prd 25 | 0; avg_sln 26 | 0; high_sln 27 | 0; low_sln 28 | 0; avg_act 29 | 0; high_act 30 | 0; low_act 31 | 1; high_sln_thr 32 | 0; low_sln_thr 33 | 1; sln_ntf_prd 34 | 1; high_act_thr 35 | 0; low_act_thr 36 | 1; act_ntf_prd 37 | 0; ntf_new 38 | 0; low_res_thr 39 | [nil]; ntf_grp 40 | 1; psln_thr 41 | ) 42 | [] 43 | [SYNC_FRONT now 0 forever root nil COV_OFF 0] 44 | 45 | hb:(pgm 46 | |[] 47 | |[] 48 | [] 49 | (inj [] 50 | (str "beep" 1) 51 | [SYNC_FRONT now 1 forever target_grp nil] 52 | ) 53 | 1; propagation saliency threshold 54 | ) 55 | |[] 56 | 57 | ihb:(ipgm hb |[] RUN_ALWAYS 200000us SILENT 1) 58 | [] 59 | [SYNC_FRONT now 1 forever target_grp nil 1] 60 | 61 | monitor:(pgm 62 | |[] 63 | [] 64 | [] 65 | (ptn (str "beep" ::) |[]) 66 | |[] 67 | |[] 68 | [] 69 | (inj [(str "caught beep" 1) [SYNC_FRONT now 1 forever target_grp nil]]) 70 | 1 71 | ) 72 | |[] 73 | 74 | imonitor:(ipgm monitor |[] RUN_ALWAYS 0us NOTIFY 1) 75 | [] 76 | [SYNC_FRONT now 1 forever target_grp nil 1] 77 | -------------------------------------------------------------------------------- /examples/test.16.replicode: -------------------------------------------------------------------------------- 1 | ;dynamic generation of a program 2 | ;case 1 3 | ;the generated program is input-less and 4 | ;does not depend on any value from the generating program. 5 | 6 | _start:(pgm 7 | |[] 8 | |[] 9 | |[] 10 | [] 11 | (inj [] 12 | p:(pgm 13 | |[] 14 | |[] 15 | |[] 16 | [] 17 | (inj [] 18 | (mk.val self position (vec3 1 2 3) 1) 19 | [SYNC_FRONT now 1 forever root nil 1 1 1 1] 20 | |[] 21 | ) 22 | (mod [this.vw.act -1]) 23 | 1 24 | ) 25 | [SYNC_FRONT now 1 forever root nil] 26 | ) 27 | (inj [] 28 | (ins p |[] RUN_ALWAYS 50000us NOTIFY) 29 | [SYNC_FRONT now 1 forever root nil 1] 30 | ) 31 | 1 32 | ) 33 | |[] 34 | 35 | i_start:(ipgm _start |[] RUN_ONCE 90000us NOTIFY 1) 36 | [] 37 | [SYNC_FRONT now 1 1 root nil 1] 38 | -------------------------------------------------------------------------------- /examples/test.17.replicode: -------------------------------------------------------------------------------- 1 | ; dynamic generation of a program 2 | ; case 2 3 | ; the generated program has one input and 4 | ; does not depend on any value from the generating program. 5 | 6 | _start:(pgm 7 | |[] 8 | |[] 9 | [] 10 | (inj [] 11 | p:(pgm 12 | |[] 13 | [] 14 | [] 15 | (ptn e:(ent ::) |[]) 16 | |[] 17 | |[] 18 | [] 19 | (inj [] 20 | (mk.val e position (vec3 1 2 3) 1) 21 | [SYNC_FRONT (\ now) 1 forever root nil] 22 | ) 23 | (mod [e.vw.sln -1]) 24 | 1 25 | ) 26 | [SYNC_FRONT now 1 forever root nil] 27 | ) 28 | (inj [] 29 | (ins p |[] RUN_ALWAYS 0us NOTIFY) 30 | [SYNC_FRONT now 1 forever root nil 1] 31 | ) 32 | 1 33 | ) 34 | |[] 35 | 36 | i_start:(ipgm _start |[] RUN_ONCE 90000us NOTIFY 1) 37 | [] 38 | [SYNC_FRONT now 1 1 root nil 1] 39 | -------------------------------------------------------------------------------- /examples/test.18.replicode: -------------------------------------------------------------------------------- 1 | ;dynamic generation of a program 2 | ;case 3 3 | ;the generated program is input-less and 4 | ;depends on some tpl arg value from the generating program. 5 | 6 | _start:(pgm 7 | [] 8 | (ptn v:(vec3 ::) |[]) 9 | |[] 10 | [] 11 | (inj [] 12 | p:(pgm 13 | |[] 14 | |[] 15 | [] 16 | (inj [] 17 | (mk.val self position v 1) 18 | [SYNC_FRONT (\ (+ now v.z)) 1 forever root nil] 19 | ) 20 | 1 21 | ) 22 | [SYNC_FRONT now 1 forever root nil] 23 | ) 24 | (inj [] 25 | (ins p |[] RUN_ALWAYS 50000us NOTIFY) 26 | [SYNC_FRONT now 1 forever root nil 1] 27 | ) 28 | 1 29 | ) 30 | |[] 31 | 32 | i_start:(ipgm _start [(vec3 1 2 3000)] RUN_ONCE 90000us NOTIFY 1) 33 | [] 34 | [SYNC_FRONT now 1 1 root nil 1] 35 | -------------------------------------------------------------------------------- /examples/test.19.replicode: -------------------------------------------------------------------------------- 1 | ;dynamic generation of a program 2 | ;case 4 3 | ;the generated program is input-less and 4 | ;depends on some value from the generating program. 5 | 6 | (mk.val self position (vec3 4 5 6) 1) 7 | [] 8 | [SYNC_FRONT now 1 forever root nil] 9 | 10 | _start:(pgm 11 | [] 12 | (ptn v1:(vec3 ::) |[]) 13 | [] 14 | [] 15 | (ptn m:(mk.val self position v2: ::) |[]) 16 | |[] 17 | |[] 18 | [] 19 | (inj [] 20 | p:(pgm 21 | |[] 22 | |[] 23 | [] 24 | (inj [] 25 | (mk.val self position (+ v1 v2) 1) 26 | [SYNC_FRONT (\ now) 1 forever root nil] 27 | ) 28 | 1 29 | ) 30 | [SYNC_FRONT now 1 forever root nil] 31 | ) 32 | (inj [] 33 | (ins p |[] RUN_ALWAYS 50000us NOTIFY) 34 | [SYNC_FRONT now 1 forever root nil 1] 35 | ) 36 | 1 37 | ) 38 | |[] 39 | 40 | i_start:(ipgm _start [(vec3 1 2 3)] RUN_ONCE 0us NOTIFY 1) 41 | [] 42 | [SYNC_FRONT now 1 1 root nil 1] 43 | -------------------------------------------------------------------------------- /examples/test.2.replicode: -------------------------------------------------------------------------------- 1 | ;creating a group 2 | ;injecting an object in that group 3 | ;setting the sln and act of the ipgm 4 | 5 | P1:(pgm 6 | []; tpl 7 | (ptn tgv1:(tagged_v v: :) |[]) 8 | (ptn tgv2:(tagged_v ::) |[]) 9 | |[]; input 10 | []; productions 11 | (inj [] 12 | g:(grp 13 | 1; upr 14 | 0.4; sln_thr 15 | 0.2; act_thr 16 | 0; vis_thr 17 | 1; c_sln 18 | 0; c_sln_thr 19 | 1; c_act 20 | 0; c_act_thr 21 | 0; dcy_per 22 | 0; dcy_tgt 23 | 1; dcy_prd 24 | 0; dcy_auto 25 | 1; sln_chg_thr 26 | 1; sln_chg_prd 27 | 1; act_chg_thr 28 | 1; act_chg_prd 29 | 0; avg_sln 30 | 0; high_sln 31 | 0; low_sln 32 | 0; avg_act 33 | 0; high_act 34 | 0; low_act 35 | 1; high_sln_thr 36 | 0; low_sln_thr 37 | 1; sln_ntf_prd 38 | 1; high_act_thr 39 | 0; low_act_thr 40 | 1; act_ntf_prd 41 | 0; ntf_new 42 | 0; low_res_thr 43 | [nil]; ntf_grps 44 | 1; psln_thr 45 | ) 46 | [SYNC_FRONT now 1 forever root nil COV_OFF 0] 47 | ) 48 | (inj [(mk.val self position (- (vec3 v.x v.y v.z) tgv2.vector) 0) [SYNC_FRONT now 1 forever g nil]]) 49 | (mod [this.vw.sln (+ g.sln_thr 0.1)]) 50 | (set [this.vw.act (- g.act_thr 0.1)]) 51 | 0; psln_thr 52 | ) 53 | 54 | |[] 55 | 56 | iP1:(ipgm 57 | P1; code 58 | []; args 59 | (tagged_v (vec3 1 2 3) "vector 123") 60 | (tagged_v (vec3 3 4 5) "vector 345") 61 | RUN_ALWAYS 62 | 50000us; tsc 63 | NOTIFY; nfr 64 | 1; psln_thr 65 | ) 66 | 67 | [] 68 | [SYNC_FRONT now 0.2 forever root nil 1] 69 | -------------------------------------------------------------------------------- /examples/test.20.replicode: -------------------------------------------------------------------------------- 1 | ;dynamic generation of a program 2 | ;case 5 3 | ;the generated program has one input and 4 | ;depends on some value from the generating program. 5 | ;highly recursive: _start generates instances of p that 6 | ;in turn generate inputs for _start, thus 7 | ;generating more instances of p. 8 | 9 | (mk.val self position (vec3 1 1 1) 1) 10 | [] 11 | [SYNC_FRONT now 1 forever root nil] 12 | 13 | _start:(pgm 14 | |[] 15 | [] 16 | [] 17 | (ptn (mk.val self position v1#vec3: ::) |[]) 18 | |[] 19 | |[] 20 | [] 21 | (inj [] 22 | p:(pgm 23 | |[] 24 | [] 25 | [] 26 | (ptn (mk.val e: position v2:(vec3 x: y: z:) ::) [(\ (= e self))]) 27 | |[] 28 | |[] 29 | [] 30 | (inj [] 31 | (mk.val self position (vec3 v1.y 10 (\ (+ z 1))) 1) 32 | [SYNC_FRONT (\ now) 1 forever root nil] 33 | ) 34 | 1 35 | ) 36 | [SYNC_FRONT now 0 forever root nil] 37 | ) 38 | (inj [] 39 | (ins p |[] RUN_ALWAYS 0us NOTIFY) 40 | [SYNC_FRONT now 0 forever root nil 1] 41 | ) 42 | 1 43 | ) 44 | |[] 45 | 46 | i_start:(ipgm _start |[] RUN_ALWAYS 0us NOTIFY 1) 47 | [] 48 | [SYNC_FRONT now 0 forever root nil 1] 49 | -------------------------------------------------------------------------------- /examples/test.21.replicode: -------------------------------------------------------------------------------- 1 | ;dynamic generation of a program 2 | ;case 6 3 | ;the generated program has one input and 4 | ;tpl args that depend on some value 5 | ;from the generating program. 6 | ;similar to test.20.replicode except that p now gets tpl args. 7 | 8 | (mk.val self position (vec3 1 1 1) 1) 9 | [] 10 | [SYNC_STATE now 1 forever root nil] 11 | 12 | _start:(pgm 13 | |[] 14 | [] 15 | [] 16 | (ptn m:(mk.val self position v1: ::) |[]) 17 | |[] 18 | |[] 19 | [] 20 | (inj [] 21 | p:(pgm 22 | [] 23 | (ptn v2:(vec3 ::) |[]) 24 | [] 25 | [] 26 | (ptn m:(mk.val self position v3: ::) |[]) 27 | |[] 28 | |[] 29 | [] 30 | (inj [] 31 | (mk.val self position (\ (+ v2 v3)) 1) 32 | [SYNC_FRONT (\ now) 1 forever root nil] 33 | ) 34 | 1 35 | ) 36 | [SYNC_FRONT now 1 forever root nil] 37 | ) 38 | (inj [] 39 | (ins p [v1] RUN_ALWAYS 50000us SILENT) 40 | [SYNC_FRONT now 1 forever root nil 1] 41 | ) 42 | 1 43 | ) 44 | |[] 45 | 46 | i_start:(ipgm _start |[] RUN_ALWAYS 0us NOTIFY 1) 47 | [] 48 | [SYNC_FRONT now 1 1 root nil 1] 49 | -------------------------------------------------------------------------------- /examples/test.22.replicode: -------------------------------------------------------------------------------- 1 | ;dynamic generation of a program 2 | ;case 7 3 | ;similar to test.20.repliocde. 4 | ;here the generated program controls its instantiated program and 5 | ;controls its own input. 6 | 7 | (mk.val self position (vec3 1 1 1) 1) 8 | [] 9 | [SYNC_STATE now 1 forever root nil] 10 | 11 | _start:(pgm 12 | |[] 13 | [] 14 | [] 15 | (ptn (mk.val self position v1#vec3: ::) |[]) 16 | |[] 17 | |[] 18 | [] 19 | (inj [] 20 | p:(pgm 21 | |[] 22 | [] 23 | [] 24 | (ptn m:(mk.val self position : ::) |[]) 25 | |[] 26 | |[] 27 | [] 28 | (mod [this.vw.act -1]); this points to p. 29 | (mod [m.vw.sln -1]) 30 | 1 31 | ) 32 | [SYNC_FRONT now 1 forever root nil] 33 | ) 34 | (inj [] 35 | (ins p |[] RUN_ALWAYS 0us SILENT) 36 | [SYNC_FRONT now 1 forever root nil 1] 37 | ) 38 | 1 39 | ) 40 | |[] 41 | 42 | i_start:(ipgm _start |[] RUN_ALWAYS 0us SILENT 1) 43 | [] 44 | [SYNC_FRONT now 1 forever root nil 1] 45 | -------------------------------------------------------------------------------- /examples/test.23.replicode: -------------------------------------------------------------------------------- 1 | ;inject a marker M on object O (dummy) at now+dt. 2 | ;at now+t, t in.vw.res 2) 29 | (< in.psln_thr 1) 30 | v#view:(fvw in root) 31 | (red in.mks [] 32 | (ptn m: [mkv#view:(fvw m root) (> mkv.sln 0)]) 33 | [m] 34 | |[] 35 | ) 36 | ) 37 | (ptn pos:(ent psln:) [(= psln 1)]) 38 | |[] 39 | [] 40 | (= v.res pos.vw.res) 41 | []; productions 42 | (inj [(mk.val in pos vec 0) [SYNC_FRONT now v.sln forever stdout nil]]) 43 | (inj [(mk.val in pos (vec3 6 7 8) 0) [SYNC_FRONT now in.vw.sln forever stdout nil]]) 44 | (inj [in [SYNC_FRONT now 0.25 forever stdout nil]]) 45 | (mod [in.vw.sln -0.2]) 46 | (mod [this.vw.sln -0.4]) 47 | 0; psln_thr 48 | ) 49 | |[] 50 | 51 | iP1:(ipgm 52 | P1; code 53 | []; args 54 | (tagged_v (vec3 1 2 3) "vector 123") 55 | RUN_ALWAYS; run 56 | 4000000us; tsc 57 | NOTIFY; nfr 58 | 0; psln_thr 59 | ) 60 | [] 61 | [SYNC_FRONT now 0.5 forever root nil 1] 62 | -------------------------------------------------------------------------------- /examples/test.4.replicode: -------------------------------------------------------------------------------- 1 | ;demonstrates deep pattern-matching, i.e. 2 | ;specifying the skeleton of a pattern at 3 | ;arbitrary levels of structure embedding. 4 | 5 | dummy:(ent 1) 6 | [] 7 | [SYNC_FRONT now 1 forever root nil] 8 | 9 | (mk.val self position (vec3 1 1 1) 1) 10 | [] 11 | [SYNC_FRONT now 1 forever root nil] 12 | 13 | _start:(pgm 14 | [] 15 | (ptn v1:(vec3 : y: ::) |[]) 16 | [] 17 | [] 18 | (ptn (mk.val self position v2:(vec3 x: y2: ::) ::) |[]) 19 | |[] 20 | [] 21 | (= (- y 1) y2) 22 | [] 23 | (inj [] 24 | (mk.val dummy position (vec3 (+ v1.x x) y v2.z) 1) 25 | [SYNC_FRONT now 1 forever root nil] 26 | ) 27 | 1 28 | ) 29 | |[] 30 | 31 | i_start:(ipgm _start [(vec3 2 2 2)] RUN_ALWAYS 0us NOTIFY 1) 32 | [] 33 | [SYNC_FRONT now 1 1 root nil 1] 34 | -------------------------------------------------------------------------------- /examples/test.5.replicode: -------------------------------------------------------------------------------- 1 | ;demonstrates the use of red as productions 2 | 3 | mk.val1:(mk.val 4 | self 5 | position 6 | (vec3 0 0 0) 7 | 0 8 | ) 9 | [] 10 | [SYNC_FRONT now 0.2 forever root nil] 11 | 12 | mk.tag1:(mk.tag 13 | self 14 | "tag on self" 15 | 1 16 | ) 17 | [] 18 | [SYNC_FRONT now 0.1 forever root nil] 19 | 20 | P1:(pgm 21 | []; tpl 22 | (ptn tgv:(tagged_v vec: :) |[]) 23 | []; input 24 | [] 25 | (ptn in:(ent ::) [] 26 | (> in.vw.res 2) 27 | (< in.psln_thr 1) 28 | ) 29 | (ptn pos:(ent psln:) [(= psln 1)]) 30 | |[] 31 | [] 32 | v#view:(fvw in root) 33 | (= v.res pos.vw.res) 34 | (red in.mks [] 35 | (ptn m: [mkv#view:(fvw m root) (> mkv.sln 0)]) 36 | [] 37 | (inj [m [SYNC_FRONT now mkv.sln forever stdout nil]]) 38 | (mod [mkv.sln -0.7]) 39 | |[] 40 | ) 41 | 0; psln_thr 42 | ) 43 | |[] 44 | 45 | iP1:(ipgm 46 | P1; code 47 | []; args 48 | (tagged_v (vec3 1 2 3) "vector 123") 49 | RUN_ALWAYS; run 50 | 4000000us; tsc 51 | NOTIFY; nfr 52 | 0; psln_thr 53 | ) 54 | [] 55 | [SYNC_FRONT now 0 forever root nil 1] 56 | -------------------------------------------------------------------------------- /examples/test.6.replicode: -------------------------------------------------------------------------------- 1 | ;demonstrates the use of red as productions 2 | ;demonstrates the use of type resolution ("cast") 3 | 4 | mk.val1:(mk.val 5 | self 6 | position 7 | (vec3 0 0 0) 8 | 0 9 | ) 10 | [] 11 | [SYNC_FRONT now 0.2 forever root nil] 12 | 13 | mk.tag1:(mk.tag 14 | self 15 | "tag on self" 16 | 1 17 | ) 18 | [] 19 | [SYNC_FRONT now 0.1 forever root nil] 20 | 21 | P1:(pgm 22 | []; tpl 23 | (ptn tgv:(tagged_v vec: :) |[]) 24 | []; input 25 | [] 26 | (|ptn in:(ent ::) [] 27 | (> in.vw.res 2) 28 | (= in.psln_thr 1) 29 | ) 30 | (ptn pos:(ent psln:) [(= psln 1)]) 31 | |[] 32 | [] 33 | v#view:(fvw in root) 34 | (= v.res pos.vw.res) 35 | (red in.mks [] 36 | (ptn m: [mkv#view:(fvw m root) (> mkv.sln 0)]) 37 | [] 38 | (inj [m [SYNC_FRONT now mkv.sln forever stdout nil]]) 39 | (mod [mkv.sln -0.7]) 40 | |[] 41 | ) 42 | 0; psln_thr 43 | ) 44 | |[] 45 | 46 | iP1:(ipgm 47 | P1; code 48 | []; args 49 | (tagged_v (vec3 1 2 3) "vector 123") 50 | RUN_ALWAYS; run 51 | 4000000us; tsc 52 | NOTIFY; nfr 53 | 0; psln_thr 54 | ) 55 | [] 56 | [SYNC_FRONT now 0 forever root nil 1] 57 | -------------------------------------------------------------------------------- /examples/test.7.replicode: -------------------------------------------------------------------------------- 1 | P1:(|pgm 2 | []; tpl 3 | (ptn tgv:(tagged_v vec: :) |[]) 4 | []; input 5 | [] 6 | (ptn in:(ent ::) [] 7 | (> in.vw.res 2) 8 | (= in.psln_thr 1) 9 | ) 10 | |[] 11 | |[] 12 | [] 13 | (inj [(ent 1) [SYNC_FRONT now 1 forever stdout nil]]) 14 | 1; psln_thr 15 | ) 16 | |[] 17 | 18 | iP1:(ipgm 19 | P1; code 20 | []; args 21 | (tagged_v (vec3 1 2 3) "vector 123") 22 | RUN_ALWAYS; run 23 | 100000us; tsc 24 | NOTIFY; nfr 25 | 1; psln_thr 26 | ) 27 | [] 28 | [SYNC_FRONT now 0 forever root nil 1] 29 | -------------------------------------------------------------------------------- /examples/test.8.replicode: -------------------------------------------------------------------------------- 1 | ;anti-program used in conjunction with regular programs and notifications 2 | 3 | P1:(|pgm 4 | []; tpl 5 | (ptn tgv:(tagged_v vec: :) |[]) 6 | []; input 7 | [] 8 | (ptn in:(ent ::) [] 9 | (> in.vw.res 2) 10 | (= in.psln_thr 1) 11 | ) 12 | |[] 13 | |[] 14 | [] 15 | (inj [(ent 1) [SYNC_FRONT now 1 forever root nil]]) 16 | 1; psln_thr 17 | ) 18 | |[] 19 | 20 | iP1:(ipgm 21 | P1; code 22 | []; args 23 | (tagged_v (vec3 1 2 3) "vector 123") 24 | RUN_ALWAYS; run 25 | 200000us; tsc 26 | NOTIFY; nfr 27 | 1; psln_thr 28 | ) 29 | [] 30 | [SYNC_FRONT now 0 forever root nil 1] 31 | 32 | P2:(pgm 33 | |[] 34 | [] 35 | [] 36 | (ptn in:(ent ::) |[]) 37 | (ptn mk_rdx:(mk.|rdx ::) |[]) 38 | |[] 39 | |[] 40 | [] 41 | (inj [(mk.val mk_rdx position (vec3 1 2 3) 1) [SYNC_FRONT now 1 5 stdout nil]]) 42 | 1; psln_thr 43 | ) 44 | |[] 45 | 46 | iP2:(ipgm P2 |[] RUN_ALWAYS 0us NOTIFY 1) 47 | [] 48 | [SYNC_FRONT now 0 40 root nil 1] 49 | -------------------------------------------------------------------------------- /examples/test.9.replicode: -------------------------------------------------------------------------------- 1 | P0:(pgm 2 | |[] 3 | [] 4 | [] 5 | (ptn in:(ent ::) |[]) 6 | (ptn mk_rdx:(mk.|rdx ::) |[]) 7 | |[] 8 | |[] 9 | [] 10 | (inj [(mk.val mk_rdx position (vec3 1 2 3) 1) [SYNC_FRONT now 1 5 stdout nil]]) 11 | 1; psln_thr 12 | ) 13 | |[] 14 | 15 | P1:(|pgm 16 | []; tpl 17 | (ptn tgv:(tagged_v vec: :) |[]) 18 | []; input 19 | [] 20 | (ptn in:(ent ::) [] 21 | (> in.vw.res 2) 22 | (= in.psln_thr 1) 23 | ) 24 | |[] 25 | |[] 26 | [] 27 | (inj [(ent 1) [SYNC_FRONT now 1 10 root nil]]) 28 | (inj [(ins P0 |[] RUN_ALWAYS 0us NOTIFY) [SYNC_FRONT now 0 40 root nil 1]]) 29 | (set [this.vw.act 0]) 30 | 1; psln_thr 31 | ) 32 | |[] 33 | 34 | iP1:(ipgm 35 | P1; code 36 | []; args 37 | (tagged_v (vec3 1 2 3) "vector 123") 38 | RUN_ALWAYS; run 39 | 200000us; tsc 40 | NOTIFY; nfr 41 | 1; psln_thr 42 | ) 43 | [] 44 | [SYNC_FRONT now 0 forever root nil 1] 45 | -------------------------------------------------------------------------------- /examples/test.helgi.replicode: -------------------------------------------------------------------------------- 1 | ; This basic examples has one program that regularly injects object to the root group and another program 2 | ; that catches those objects and injects them to the stdout group 3 | 4 | ; An anti-program that regularly injects objects into the root group 5 | Prog0:(pgm 6 | |[]; tpl 7 | |[]; input 8 | [] 9 | (inj [(mk.val self position (vec3 1 2 3) 0) [now 1 forever root nil]]) 10 | 500000s; tsc 11 | 1; nfr 12 | 1; psln_thr 13 | ) 14 | |[] 15 | 16 | ; A program to catch objects produced by Prog0 and inject them to the stdout group 17 | Prog1:(pgm 18 | |[] 19 | [] 20 | [] 21 | (ptn m:(mk.val ::) |[]) 22 | |[] 23 | |[] 24 | [] 25 | (inj [m [now 1 forever stdout nil]]) 26 | 0us; tsc 27 | 1; nfr 28 | 1; psln_thr 29 | ) 30 | |[] 31 | 32 | ; Instansiate Prog0 33 | iProg0:(ipgm 34 | Prog0; code 35 | |[]; args 36 | 1; psln_thr 37 | ) 38 | [] 39 | [now 1 forever root nil 1] 40 | 41 | ; Instansiate Prog1 42 | iProg1:(ipgm 43 | Prog1; code 44 | |[]; args 45 | 1; psln_thr 46 | ) 47 | [] 48 | [now 1 forever root nil 1] 49 | -------------------------------------------------------------------------------- /examples/test.integration.replicode: -------------------------------------------------------------------------------- 1 | P1:(pgm 2 | []; tpl 3 | (ptn ref_val:(mk.val : position ::) |[]); no views can be passed with an object as a tpl arg. 4 | (ptn ref_t: |[]); put view data here, one by one (not in a set, as ptn 1st member must be anything but a set). 5 | []; input 6 | []; inputs 7 | (ptn m:(mk.val ref_val.object position value: [: ijt: ::] ::) [] 8 | (> ijt ref_t) 9 | (<> value ref_val.value) 10 | v#view:(fvw m stdin) 11 | ) 12 | |[]; timing 13 | |[]; guards 14 | []; prods 15 | (inj [(mk.last_known m |[] |[] |[] 0) [|nb now 1 4 nil nil]]); builds L. 16 | (inj [(ins P1 [m ijt]) [|nb now 1 forever stdin nil]]); instantiates P1 with m as actual template arguments. 17 | (set [this.vw.res 0]); kills the original ipgm. 18 | (mod [v.sln -0.5]); just for quick testing; shall not be there! 19 | 1000000us; tsc 20 | 0; nfr 21 | |[]; view 22 | |[]; mks 23 | |[]; vws 24 | 0; psln_thr 25 | ) 26 | 27 | |[] 28 | 29 | P2:(pgm 30 | []; tpl 31 | (ptn ref_b:(ent ::) |[]) 32 | []; input 33 | []; inputs 34 | (ptn m:(mk.val o: position : [: ijt: ::] ::) [] 35 | (<> o ref_b)] 36 | |[]; timings 37 | |[]; guards 38 | []; productions 39 | (inj [(ins P1 [m ijt]) [|nb now 1 4 stdin nil]]) 40 | (inj [(ins P2 [m.object]) [|nb now 1 4 stdin nil]]) 41 | 1000000us; tsc 42 | 0; nfr 43 | |[]; view 44 | |[]; mks 45 | |[]; vws 46 | 0; psln_thr 47 | ) 48 | 49 | |[] 50 | 51 | iP2:(ipgm 52 | P2; code 53 | [nil]; args 54 | |[]; view 55 | |[]; mks 56 | |[]; vws 57 | 0; psln_thr 58 | ) 59 | 60 | [] 61 | [now 1 3 stdin nil 1] 62 | 63 | P3:(pgm 64 | |[] 65 | [] 66 | [] 67 | (ptn l:(mk.last_known ::) |[]) 68 | |[] 69 | |[] 70 | [] 71 | (eje [l l.vw 0]) 72 | 100000us 73 | 0 74 | |[] 75 | |[] 76 | |[] 77 | 0 78 | ) 79 | 80 | |[] 81 | 82 | iP3:(ipgm 83 | P3 84 | |[] 85 | |[] 86 | |[] 87 | |[] 88 | 0 89 | ) 90 | 91 | [] 92 | [now 1 forever stdin nil 1] 93 | 94 | P4:(pgm 95 | |[] 96 | [] 97 | [] 98 | (ptn m:(mk.val : position v:(vec3 ::) ::) |[]) 99 | |[] 100 | |[] 101 | [] 102 | (inj [(mk.val m.object position (vec3 (+ v.x 1) v.y v.z) |[] |[] |[] 0) [(+ m.vw.ijt 1000000us) m.vw.sln m.vw.res m.vw.grp m.vw.org] 0]) 103 | 100000us 104 | 0 105 | |[] 106 | |[] 107 | |[] 108 | 0 109 | ) 110 | 111 | |[] 112 | 113 | iP4:(ipgm 114 | P4 115 | |[] 116 | |[] 117 | |[] 118 | |[] 119 | 0 120 | ) 121 | 122 | [] 123 | [now 1 forever stdin nil 1] 124 | 125 | O1:(mk.val 126 | self 127 | position 128 | (vec3 3 3 3) 129 | |[] 130 | |[] 131 | |[] 132 | 0 133 | ) 134 | 135 | [] 136 | [now 1 5 stdin nil] 137 | 138 | Tag:(mk.tag 139 | self 140 | "a test string" 141 | |[] 142 | |[] 143 | |[] 144 | 0 145 | ) 146 | 147 | [] 148 | [now 1 5 stdin nil] 149 | -------------------------------------------------------------------------------- /examples/test.pm.var.replicode: -------------------------------------------------------------------------------- 1 | ; pattern-matching on variables. 2 | 3 | 4 | variable:(var 0 1) 5 | [] 6 | [SYNC_FRONT now 1 forever root nil] 7 | 8 | v_hold_cup:(mk.val variable hold cup 1) 9 | [] 10 | [SYNC_FRONT now 1 forever root nil] 11 | 12 | 13 | prb0:(pgm |[] 14 | [] 15 | [] 16 | (ptn m:(mk.val hand hold ::) |[]) 17 | |[] 18 | |[] 19 | [] 20 | (prb [1 "print" "got variable" [m.obj]]) 21 | 1) 22 | |[] 23 | 24 | i_prb0:(ipgm prb0 |[] RUN_ALWAYS 0us NOTIFY 1) 25 | [] 26 | [SYNC_FRONT now 0 forever root nil 0] 27 | 28 | 29 | f:(fact v_hold_cup 0us 1 1) 30 | [] 31 | [SYNC_FRONT now 1 forever root nil] 32 | 33 | 34 | prb1:(pgm |[] 35 | [] 36 | [] 37 | (ptn (fact m:(mk.val hand hold ::) ::) |[]) 38 | |[] 39 | |[] 40 | [] 41 | (prb [1 "print" "got variable" [m.obj]]) 42 | 1) 43 | |[] 44 | 45 | i_prb1:(ipgm prb1 |[] RUN_ALWAYS 0us NOTIFY 1) 46 | [] 47 | [SYNC_FRONT now 0 forever root nil 0] 48 | 49 | 50 | g:(mk.goal f nil 1) 51 | [] 52 | [SYNC_FRONT now 1 forever root nil] 53 | 54 | 55 | prb2:(pgm |[] 56 | [] 57 | [] 58 | (ptn (mk.goal (fact m:(mk.val hand hold what: ::) when: ::) ::) |[]) 59 | |[] 60 | |[] 61 | [] 62 | (prb [2 "print" "got variable" [m m.val]]) 63 | (inj [] 64 | _mk:(mk.val hand hold what 1) 65 | [SYNC_FRONT now 1 forever stdin nil] 66 | ) 67 | (inj [] 68 | (fact _mk when 1 1) 69 | [SYNC_FRONT now 1 forever stdin nil] 70 | ) 71 | 1) 72 | |[] 73 | 74 | i_prb2:(ipgm prb2 |[] RUN_ALWAYS 0us NOTIFY 1) 75 | [] 76 | [SYNC_FRONT now 0 forever root nil 1] 77 | 78 | 79 | ; -------------------------------------------- 80 | 81 | var_pos:(mk.val variable position (vec3 2 2 2) 1) 82 | [] 83 | [SYNC_FRONT now 1 forever root nil] 84 | 85 | f_var_pos:(fact var_pos 0us 1 1) 86 | [] 87 | [SYNC_FRONT now 1 forever root nil] 88 | 89 | g_var_pos:(mk.goal f_var_pos nil 1) 90 | [] 91 | [SYNC_FRONT now 1 forever root nil] 92 | 93 | prb3:(pgm |[] 94 | [] 95 | [] 96 | (ptn (mk.goal (fact m:(mk.val hand position ::) ::) ::) |[]) 97 | |[] 98 | |[] 99 | [] 100 | (prb [1 "print" "got variable" [m]]) 101 | 1) 102 | |[] 103 | 104 | i_prb3:(ipgm prb3 |[] RUN_ALWAYS 0us NOTIFY 1) 105 | [] 106 | [SYNC_FRONT now 0 forever root nil 0] 107 | -------------------------------------------------------------------------------- /examples/user.classes.replicode: -------------------------------------------------------------------------------- 1 | !load ./V1.2/std.replicode 2 | 3 | !class (vec3 x:nb y:nb z:nb) 4 | !class (mk.tag (_obj {object: tag:st})) 5 | 6 | !class (tagged_v vector:vec3 string:st) 7 | 8 | !class (string (_obj {s:st id:us})) 9 | !class (str (_obj s:st)) 10 | !class (counter (_obj value:nb)) 11 | !class (Ping (_obj {object:})) 12 | !class (Pong (_obj {object:})) 13 | 14 | !dfn (sample_io_start :nb) 15 | !dfn (sample_io_stop) 16 | 17 | root:(grp 18 | 1; upr 19 | 0.5; sln_thr 20 | 0.4; act_thr 21 | 0; vis_thr 22 | 1; c_sln 23 | 0; c_sln_thr 24 | 1; c_act 25 | 0; c_act_thr 26 | 0; dcy_per 27 | 0; dcy_tgt 28 | 1; dcy_prd 29 | 0; dcy_auto 30 | 1; sln_chg_thr 31 | 1; sln_chg_prd 32 | 1; act_chg_thr 33 | 1; act_chg_prd 34 | 0; avg_sln 35 | 0; high_sln 36 | 0; low_sln 37 | 0; avg_act 38 | 0; high_act 39 | 0; low_act 40 | 1; high_sln_thr 41 | 0; low_sln_thr 42 | 1; sln_ntf_prd 43 | 1; high_act_thr 44 | 0; low_act_thr 45 | 1; act_ntf_prd 46 | 0; ntf_new 47 | 0; low_res_thr 48 | [nil]; ntf_grps 49 | 1; psln_thr 50 | )[[SYNC_ONCE now 0 forever nil nil COV_OFF 0]] 51 | 52 | g1:(grp 53 | 1; upr 54 | 1; sln_thr 55 | 0; act-thr 56 | 0; vis_thr 57 | 1; c_sln 58 | 0; c_sln_thr 59 | 1; c_act 60 | 0; c_act_thr 61 | -0.2; dcy_per 62 | 0; dcy_tgt 63 | 0; dcy_prd 64 | 0; dcy_auto 65 | 1; sln_chg_thr 66 | 2; sln_chg_prd 67 | 1; act_chg_thr 68 | 1; act_chg_prd 69 | 0; avg_sln 70 | 0; high_sln 71 | 0; low_sln 72 | 0; avg_act 73 | 0; high_act 74 | 0; low_act 75 | 1; high_sln_thr 76 | 0; low_sln_thr 77 | 1; sln_ntf_prd 78 | 1; high_act_thr 79 | 0; low_act_thr 80 | 1; act_ntf_prd 81 | 0; ntf_new 82 | 0; low_res_thr 83 | [nil]; ntf_grps 84 | 1; psln_thr 85 | ) 86 | [] 87 | [SYNC_ONCE now 0 forever root nil COV_OFF 0] 88 | 89 | stdin:(grp 90 | 1; upr 91 | 0; sln_thr 92 | 0; act_thr 93 | 0; vis_thr 94 | 1; c_sln 95 | 0; c_sln_thr 96 | 1; c_act 97 | 0; c_act_thr 98 | 0; dcy_per 99 | 1; dcy_tgt 100 | 0; dcy_prd 101 | 0; dcy_auto 102 | 1; sln_chg_thr 103 | 1; sln_chg_prd 104 | 1; act_chg_thr 105 | 1; act_chg_prd 106 | 0; avg_sln 107 | 0; high_sln 108 | 0; low_sln 109 | 0; avg_act 110 | 0; high_act 111 | 0; low_act 112 | 1; high_sln_thr 113 | 0; low_sln_thr 114 | 1; sln_ntf_prd 115 | 1; high_act_thr 116 | 0; low_act_thr 117 | 1; act_ntf_prd 118 | 0; ntf_new 119 | 0; low_res_thr 120 | [root]; ntf_grps 121 | 1; psln_thr 122 | ) 123 | [] 124 | [SYNC_ONCE now 0 forever root nil COV_OFF 0] 125 | [SYNC_ONCE now 0 forever g1 nil COV_ON 1]; last 2 members: cov and vis. 126 | 127 | stdout:(grp 128 | 1; upr 129 | 0; sln_thr 130 | 0; act_thr 131 | 0; vis_thr 132 | 1; c_sln 133 | 0; c_sln_thr 134 | 1; c_act 135 | 0; c_act_thr 136 | 0; dcy_per 137 | 0; dcy_tgt 138 | 1; dcy_prd 139 | 0; dcy_auto 140 | 1; sln_chg_thr 141 | 1; sln_chg_prd 142 | 1; act_chg_thr 143 | 1; act_chg_prd 144 | 0; avg_sln 145 | 0; high_sln 146 | 0; low_sln 147 | 0; avg_act 148 | 0; high_act 149 | 0; low_act 150 | 1; high_sln_thr 151 | 0; low_sln_thr 152 | 1; sln_ntf_prd 153 | 1; high_act_thr 154 | 0; low_act_thr 155 | 1; act_ntf_prd 156 | 0; ntf_new 157 | 0; low_res_thr 158 | [nil]; ntf_grps 159 | 1; psln_thr 160 | ) 161 | [] 162 | [SYNC_ONCE now 0 forever root nil COV_OFF 0] 163 | 164 | self:(ent 165 | 0.95; psln_thr 166 | ) 167 | [] 168 | [SYNC_ONCE now 0.6 forever root nil] 169 | 170 | position:(ent 171 | 1; psln_thr 172 | ) 173 | [] 174 | [SYNC_ONCE now 1 forever root nil] 175 | -------------------------------------------------------------------------------- /executor/inifile.h: -------------------------------------------------------------------------------- 1 | #ifndef INIFILE_H 2 | #define INIFILE_H 3 | 4 | #include // for uint64_t 5 | #include // for string 6 | #include // for unordered_map 7 | 8 | namespace utils 9 | { 10 | 11 | class IniFile 12 | { 13 | public: 14 | bool readFile(std::string filename); 15 | 16 | 17 | std::string getString(const std::string group, const std::string name, std::string defaultVal); 18 | uint64_t getInt(const std::string group, const std::string name, uint64_t defaultVal); 19 | double getDouble(const std::string group, const std::string name, double defaultVal); 20 | int getBool(const std::string group, const std::string name, bool defaultVal); 21 | 22 | private: 23 | bool hasInt(const std::string group, const std::string name); 24 | bool hasDouble(const std::string group, const std::string name); 25 | bool hasBool(const std::string group, const std::string name); 26 | bool hasString(const std::string group, const std::string name); 27 | 28 | std::unordered_map> m_values; 29 | }; 30 | 31 | } //namespace utils 32 | 33 | #endif // INIFILE_H 34 | -------------------------------------------------------------------------------- /executor/settings.ini: -------------------------------------------------------------------------------- 1 | [Load] 2 | usr_operator_path=../build/usr_operators/libusr_operators.so 3 | usr_class_path=./V1.2/user.classes.replicode 4 | source_file_name=./V1.2/test.2.replicode 5 | 6 | [Init] 7 | base_period=50000 // in us 8 | reduction_core_count=6 // number of threads processing reduction jobs 9 | time_core_count=2 // number of threads processing update jobs 10 | 11 | [System] 12 | mdl_inertia_sr_thr=0.9 // in [0,1] 13 | mdl_inertia_cnt_thr=6 // in instance count 14 | tpx_dsr_thr=0.1 // in [0,1] 15 | min_sim_time_horizon=0 // in us 16 | max_sim_time_horizon=0 // in us 17 | sim_time_horizon=0.3 // [0,1] percentage of (before-now) allocated to simulation 18 | tpx_time_horizon=500000 // in us 19 | perf_sampling_period=250000 //in us 20 | float_tolerance=0.00001 // [0,1] 21 | time_tolerance=10000 // in us 22 | primary_thz=3600000 // timehorizon after which states/models that did not match are pushed down to secondary group (models) or sent to oblivion (states), in seconds 23 | secondary_thz=7200000 // time after which states/models that did not match are sent to oblivion, in seconds 24 | 25 | [Debug] 26 | debug=yes 27 | debug_windows=1 // number of debugging windows to open 28 | trace_levels=CC // ORed values (numbers indicate the location from right to left): 0:cst inputs, 1: cst outputs, 2: mdl inputs, 3: mdl outputs, 4 prediction monitoring, 5: goal monitoring, 6: model revision, 7:mdl/cst injections. ex: 3 means cst inputs and cst outputs, ignore others. 29 | 30 | [Resilience] 31 | ntf_mk_resilience=1 // in upr (i. e. relative to the ntf group) 32 | goal_pred_success_resilience=1000 // in upr (i. e. relative to the ntf group) 33 | 34 | [Objects] 35 | get_objects=yes 36 | decompile_objects=yes 37 | decompile_to_file=no 38 | decompilation_file_path=../Test/decompiled.replicode 39 | ignore_named_objects=yes 40 | write_objects=no 41 | objects_path=../Test/objects.replicode.image 42 | test_objects=no 43 | 44 | [Run] 45 | run_time=10080 // in ms 46 | probe_level=2 // set to max level to probe, 0 means no probe will be executed 47 | 48 | [Models] 49 | get_models=yes // the image will contain all valid objects after the mem shuts down 50 | decompile_models=yes 51 | ignore_named_models=yes // if objects supplied by the initial seedcode/developer should be decompiled 52 | write_models=no 53 | models_path=../Test/models.replicode.image 54 | test_models=no // if models should be read back and decompiled 55 | -------------------------------------------------------------------------------- /output_window/main.cpp: -------------------------------------------------------------------------------- 1 | // main.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "../../CoreLibrary/trunk/CoreLibrary/utils.h" 32 | 33 | 34 | using namespace core; 35 | 36 | int64_t main(int argc, char **argv) 37 | { 38 | HANDLE pipe_read = (HANDLE)atoi(argv[1]); 39 | uint64_t read; 40 | char buffer[1024]; 41 | bool r; 42 | 43 | while (1) { 44 | r = ReadFile(pipe_read, buffer, 1024, &read, NULL); 45 | 46 | if (!r || read == 0) { 47 | break; 48 | } 49 | 50 | std::string s(buffer); 51 | s = s.substr(0, read); 52 | std::string stop("close_output_window"); 53 | size_t found = s.rfind(stop); 54 | 55 | if (found != std::string::npos) { 56 | break; 57 | } 58 | 59 | std::cout << s; 60 | } 61 | 62 | std::cout << "> press a key to exit\n"; 63 | getchar(); 64 | return 0; 65 | } -------------------------------------------------------------------------------- /r_code/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(r_code_SRC 2 | atom.cpp 3 | image.cpp 4 | image_impl.cpp 5 | object.cpp 6 | r_code.cpp 7 | utils.cpp 8 | vector.cpp 9 | ) 10 | set(r_code_HDR 11 | atom.h 12 | image.h 13 | image.tpl.h 14 | image_impl.h 15 | list.h 16 | object.h 17 | r_code.h 18 | replicode_defs.h 19 | time_buffer.h 20 | utils.h 21 | vector.h 22 | ) 23 | 24 | add_library(r_code SHARED ${r_code_SRC} ${r_code_HDR}) 25 | set_property(TARGET r_code PROPERTY CXX_STANDARD 11) 26 | set_property(TARGET r_code PROPERTY CXX_STANDARD_REQUIRED ON) 27 | install(TARGETS r_code DESTINATION lib) 28 | install(FILES ${r_code_HDR} DESTINATION include/r_code) 29 | -------------------------------------------------------------------------------- /r_code/image.cpp: -------------------------------------------------------------------------------- 1 | // image.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "image.h" 32 | 33 | 34 | namespace r_code 35 | { 36 | 37 | size_t GetStringSize(const std::string &s) 38 | { 39 | size_t length = s.length() + 1; // +1 for null termination 40 | 41 | if (length % 4) { 42 | return length / 4 + 2; // +1 for the length, +1 for alignment 43 | } 44 | 45 | return length / 4 + 1; // +1 for the length 46 | } 47 | 48 | void WriteString(uint32_t *data, const std::string &string) 49 | { 50 | data[0] = GetStringSize(string) - 1; 51 | char *content = (char *)(data + 1); 52 | 53 | for (uint64_t i = 0; i < string.length(); ++i) { 54 | content[i] = string[i]; 55 | } 56 | 57 | content[string.length()] = '\0'; 58 | } 59 | 60 | std::string ReadString(uint32_t *data) 61 | { 62 | std::string ret; 63 | char *content = (char *)(data + 1); 64 | 65 | for (size_t i = 0; content[i] != 0; ++i) { 66 | ret += content[i]; 67 | } 68 | 69 | return ret; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /r_code/image_impl.cpp: -------------------------------------------------------------------------------- 1 | // image_impl.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "image_impl.h" 32 | 33 | #include // for ImageImpl 34 | 35 | 36 | namespace r_code 37 | { 38 | 39 | void *ImageImpl::operator new(size_t s, uint64_t data_size) 40 | { 41 | return ::operator new(s); 42 | } 43 | 44 | void ImageImpl::operator delete(void *o) 45 | { 46 | ::operator delete(o); 47 | } 48 | 49 | ImageImpl::ImageImpl(uint64_t timestamp, size_t map_size, size_t code_size, size_t names_size) : 50 | _data(new uint32_t[map_size + code_size + names_size]), 51 | _timestamp(timestamp), 52 | _map_size(map_size), 53 | _code_size(code_size), 54 | _names_size(names_size) 55 | { 56 | } 57 | 58 | ImageImpl::~ImageImpl() 59 | { 60 | delete[] _data; 61 | } 62 | 63 | uint64_t ImageImpl::timestamp() const 64 | { 65 | return _timestamp; 66 | } 67 | 68 | size_t ImageImpl::map_size() const 69 | { 70 | return _map_size; 71 | } 72 | 73 | size_t ImageImpl::code_size() const 74 | { 75 | return _code_size; 76 | } 77 | 78 | size_t ImageImpl::names_size() const 79 | { 80 | return _names_size; 81 | } 82 | 83 | uint32_t *ImageImpl::data() const 84 | { 85 | return _data; 86 | } 87 | 88 | uint32_t &ImageImpl::data(size_t i) 89 | { 90 | return _data[i]; 91 | } 92 | 93 | uint32_t &ImageImpl::data(size_t i) const 94 | { 95 | return _data[i]; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /r_code/image_impl.h: -------------------------------------------------------------------------------- 1 | // image_impl.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef image_impl_h 32 | #define image_impl_h 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | namespace r_code 40 | { 41 | 42 | class REPLICODE_EXPORT ImageImpl 43 | { 44 | private: 45 | /// [object map|code segment|object names] 46 | uint32_t *_data; 47 | 48 | uint64_t _timestamp; 49 | size_t _map_size; 50 | size_t _code_size; 51 | size_t _names_size; 52 | protected: 53 | uint64_t timestamp() const; 54 | size_t map_size() const; 55 | size_t code_size() const; 56 | size_t names_size() const; 57 | uint32_t *data() const; 58 | uint32_t &data(size_t i); 59 | uint32_t &data(size_t i) const; 60 | public: 61 | void *operator new(size_t, uint64_t data_size); 62 | void operator delete(void *o); 63 | ImageImpl(uint64_t timestamp, size_t map_size, size_t code_size, size_t names_size); 64 | ~ImageImpl(); 65 | }; 66 | } 67 | 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /r_code/r_code.cpp: -------------------------------------------------------------------------------- 1 | // r_code.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "r_code.h" 32 | 33 | #include // for debug, DebugStream 34 | 35 | void Init() 36 | { 37 | debug("r_code") << "r_code library loaded"; 38 | } 39 | -------------------------------------------------------------------------------- /r_code/r_code.h: -------------------------------------------------------------------------------- 1 | // r_code.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef r_code_h 32 | #define r_code_h 33 | 34 | 35 | #include // for REPLICODE_EXPORT 36 | 37 | extern "C" { 38 | void REPLICODE_EXPORT Init(); 39 | } 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /r_code/vector.cpp: -------------------------------------------------------------------------------- 1 | // vector.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "vector.h" 32 | 33 | 34 | namespace r_code 35 | { 36 | 37 | } -------------------------------------------------------------------------------- /r_code/vector.h: -------------------------------------------------------------------------------- 1 | // vector.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef r_code_vector_h 32 | #define r_code_vector_h 33 | 34 | #include 35 | #include 36 | 37 | namespace r_code 38 | { 39 | 40 | /// Auto-resizing vector 41 | template class vector 42 | { 43 | public: 44 | vector() {} 45 | ~vector() { } 46 | size_t size() const 47 | { 48 | return m_vector.size(); 49 | } 50 | T &operator [](size_t i) 51 | { 52 | if (i >= size()) { 53 | m_vector.resize(i + 1); 54 | } 55 | 56 | return m_vector.at(i); 57 | } 58 | const T &operator [](size_t i) const 59 | { 60 | return m_vector[i]; 61 | } 62 | void push_back(T t) 63 | { 64 | m_vector.push_back(t); 65 | } 66 | std::vector *as_std() 67 | { 68 | return &m_vector; 69 | } 70 | 71 | typedef typename std::vector::iterator iterator; 72 | typedef typename std::vector::const_iterator const_iterator; 73 | iterator begin() 74 | { 75 | return m_vector.begin(); 76 | } 77 | const_iterator begin() const 78 | { 79 | return m_vector.begin(); 80 | } 81 | const_iterator cbegin() const 82 | { 83 | return m_vector.cbegin(); 84 | } 85 | iterator end() 86 | { 87 | return m_vector.end(); 88 | } 89 | const_iterator end() const 90 | { 91 | return m_vector.end(); 92 | } 93 | const_iterator cend() const 94 | { 95 | return m_vector.cend(); 96 | } 97 | 98 | private: 99 | std::vector m_vector; 100 | }; 101 | 102 | } 103 | 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /r_comp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(r_comp_SRC 2 | class.cpp 3 | replistruct.cpp 4 | compiler.cpp 5 | decompiler.cpp 6 | preprocessor.cpp 7 | segments.cpp 8 | structure_member.cpp 9 | ) 10 | set(r_comp_HDR 11 | class.h 12 | compiler.h 13 | decompiler.h 14 | out_stream.h 15 | preprocessor.h 16 | replistruct.h 17 | segments.h 18 | structure_member.h 19 | ) 20 | 21 | 22 | add_library(r_comp SHARED ${r_comp_SRC} ${r_comp_HDR}) 23 | set_property(TARGET r_comp PROPERTY CXX_STANDARD 11) 24 | set_property(TARGET r_comp PROPERTY CXX_STANDARD_REQUIRED ON) 25 | install(TARGETS r_comp DESTINATION lib) 26 | install(FILES ${r_comp_HDR} DESTINATION include/r_comp) 27 | -------------------------------------------------------------------------------- /r_comp/class.h: -------------------------------------------------------------------------------- 1 | // class.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef class_h 32 | #define class_h 33 | 34 | #include // for Atom 35 | #include // for ::ANY, ReturnType, etc 36 | #include // for size_t 37 | #include // for uint16_t, uint32_t, uint64_t 38 | #include // for string 39 | #include // for vector 40 | 41 | namespace r_comp { 42 | class Metadata; 43 | } // namespace r_comp 44 | 45 | namespace r_comp 46 | { 47 | 48 | class Class 49 | { 50 | private: 51 | bool has_offset() const; 52 | public: 53 | static const char *Expression; 54 | static const char *Type; 55 | 56 | Class(ReturnType t = ANY); 57 | Class(r_code::Atom atom, 58 | std::string str_opcode, 59 | std::vector r, 60 | ReturnType t = ANY); 61 | bool is_pattern(Metadata *metadata) const; 62 | bool is_fact(Metadata *metadata) const; 63 | bool get_member_index(Metadata *metadata, std::string &name, uint16_t &index, Class *&p) const; 64 | std::string get_member_name(uint64_t index); // for decompilation 65 | ReturnType get_member_type(const uint16_t index); 66 | Class *get_member_class(Metadata *metadata, const std::string &name); 67 | r_code::Atom atom; 68 | std::string str_opcode; // unused for anything but objects, markers and operators. 69 | std::vector things_to_read; 70 | ReturnType type; // ANY for non-operators. 71 | StructureMember::Iteration use_as; 72 | 73 | void write(uint32_t *storage); 74 | void read(uint32_t *storage); 75 | size_t get_size() const; 76 | }; 77 | } 78 | 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /r_comp/preprocessor.h: -------------------------------------------------------------------------------- 1 | // preprocessor.h 2 | // 3 | // Author: Thor List, Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Thor List, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Thor List or Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef preprocessor_h 32 | #define preprocessor_h 33 | 34 | #include // for ReturnType 35 | #include 36 | #include // for NULL 37 | #include // for uint16_t 38 | #include // for list 39 | #include // for string 40 | #include // for unordered_map 41 | #include // for vector 42 | 43 | #include // for REPLICODE_EXPORT 44 | 45 | namespace r_comp { 46 | class Metadata; 47 | class RepliStruct; 48 | } // namespace r_comp 49 | 50 | namespace r_comp 51 | { 52 | class REPLICODE_EXPORT Preprocessor 53 | { 54 | public: 55 | RepliStruct::Ptr root; 56 | 57 | Preprocessor(); 58 | ~Preprocessor(); 59 | RepliStruct::Ptr process(const char *file, // if an ifstream, stream must be open. 60 | std::string &error, // set when function fails, e.g. returns false. 61 | Metadata *metadata = NULL); // process will fill class_image, or use the exiting one if NULL. 62 | 63 | private: 64 | enum ClassType { 65 | T_CLASS = 0, 66 | T_SYS_CLASS = 1, 67 | T_SET = 2 68 | }; 69 | 70 | void instantiateClass(RepliStruct::Ptr tpl_class, std::vector &tpl_args, std::string &instantiated_class_name); 71 | bool isSet(std::string className); 72 | bool isTemplateClass(RepliStruct::Ptr replistruct); 73 | void getMember(std::vector &members, RepliStruct::Ptr m, std::list &tpl_args, bool instantiate); 74 | void getMembers(RepliStruct::Ptr s, std::vector &members, std::list &tpl_args, bool instantiate); 75 | ReturnType getReturnType(RepliStruct::Ptr s); 76 | void initialize(Metadata *metadata); // init definition_segment 77 | 78 | Metadata *m_metadata; 79 | uint16_t m_classOpcode; // shared with sys_classes 80 | std::unordered_map m_templateClasses; 81 | }; 82 | } 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /r_comp/replistruct.h: -------------------------------------------------------------------------------- 1 | #ifndef REPLISTRUCT_H 2 | #define REPLISTRUCT_H 3 | 4 | #include // for uint64_t, int64_t 5 | #include // for ostream, istream 6 | #include // for list 7 | #include // for string, basic_string, allocator 8 | #include // for unordered_map 9 | #include // for vector 10 | #include 11 | 12 | namespace r_comp 13 | { 14 | 15 | class RepliCondition; 16 | class RepliMacro; 17 | 18 | class RepliStruct 19 | { 20 | public: 21 | typedef std::shared_ptr Ptr; 22 | static std::unordered_map> s_macros; 23 | static std::unordered_map s_counters; 24 | static std::list s_conditions; 25 | static uint64_t GlobalLine; 26 | static std::string GlobalFilename; 27 | static void cleanup(); 28 | 29 | enum Type {Root, Structure, Set, Atom, Directive, Condition, Development}; 30 | Type type; 31 | std::string cmd; 32 | std::string tail; 33 | std::string label; 34 | std::string error; 35 | std::string fileName; 36 | uint64_t line; 37 | std::vector> args; 38 | RepliStruct *parent; 39 | 40 | RepliStruct(r_comp::RepliStruct::Type type); 41 | ~RepliStruct(); 42 | 43 | void reset(); // remove rags that are objects. 44 | 45 | uint64_t getIndent(std::istream *stream); 46 | int64_t parse(std::istream *stream, uint64_t &curIndent, uint64_t &prevIndent, int64_t paramExpect = 0); 47 | bool parseDirective(std::istream *stream, uint64_t &curIndent, uint64_t &prevIndent); 48 | int64_t process(); 49 | 50 | RepliStruct::Ptr findAtom(const std::string &name); 51 | RepliStruct::Ptr loadReplicodeFile(const std::string &filename); 52 | 53 | RepliStruct::Ptr clone() const; 54 | std::string print() const; 55 | std::string printError() const; 56 | 57 | friend std::ostream& operator<<(std::ostream &os, const RepliStruct &structure); 58 | friend std::ostream& operator<<(std::ostream &os, RepliStruct::Ptr structure); 59 | private: 60 | RepliStruct(const RepliStruct &) = delete; 61 | RepliStruct() = delete; 62 | }; 63 | 64 | class RepliMacro 65 | { 66 | public: 67 | typedef std::shared_ptr Ptr; 68 | std::string name; 69 | RepliStruct::Ptr src; 70 | RepliStruct::Ptr dest; 71 | std::string error; 72 | 73 | RepliMacro(const std::string &name, RepliStruct::Ptr src, RepliStruct::Ptr dest); 74 | ~RepliMacro(); 75 | 76 | uint64_t argCount(); 77 | RepliStruct::Ptr expandMacro(RepliStruct *oldStruct); 78 | }; 79 | 80 | class RepliCondition 81 | { 82 | public: 83 | std::string name; 84 | bool reversed; 85 | 86 | RepliCondition(const std::string &name, bool reversed); 87 | ~RepliCondition(); 88 | bool reverse(); 89 | bool isActive(std::unordered_map &RepliMacros, std::unordered_map &Counters); 90 | }; 91 | 92 | 93 | } 94 | 95 | #endif//REPLISTRUCT_H 96 | -------------------------------------------------------------------------------- /r_exec/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(r_exec_SRC 2 | _context.cpp 3 | ast_controller.cpp 4 | auto_focus.cpp 5 | binding_map.cpp 6 | callbacks.cpp 7 | context.cpp 8 | cpp_programs.cpp 9 | cst_controller.cpp 10 | domain.cpp 11 | factory.cpp 12 | g_monitor.cpp 13 | group.cpp 14 | guard_builder.cpp 15 | hlp_context.cpp 16 | hlp_controller.cpp 17 | hlp_overlay.cpp 18 | init.cpp 19 | mdl_controller.cpp 20 | mem.cpp 21 | model_base.cpp 22 | monitor.cpp 23 | object.cpp 24 | opcodes.cpp 25 | operator.cpp 26 | overlay.cpp 27 | p_monitor.cpp 28 | pattern_extractor.cpp 29 | pgm_controller.cpp 30 | pgm_overlay.cpp 31 | reduction_core.cpp 32 | reduction_job.cpp 33 | time_core.cpp 34 | time_job.cpp 35 | view.cpp 36 | ) 37 | set(r_exec_HDR 38 | _context.h 39 | ast_controller.h 40 | ast_controller.tpl.h 41 | auto_focus.h 42 | binding_map.h 43 | callbacks.h 44 | context.h 45 | cpp_programs.h 46 | cst_controller.h 47 | domain.h 48 | factory.h 49 | g_monitor.h 50 | group.h 51 | guard_builder.h 52 | hlp_context.h 53 | hlp_controller.h 54 | hlp_overlay.h 55 | init.h 56 | mdl_controller.h 57 | mem.h 58 | mem.tpl.h 59 | model_base.h 60 | monitor.h 61 | object.h 62 | object.tpl.h 63 | opcodes.h 64 | operator.h 65 | overlay.h 66 | overlay.tpl.h 67 | p_monitor.h 68 | pattern_extractor.h 69 | pgm_controller.h 70 | pgm_overlay.h 71 | reduction_core.h 72 | reduction_job.h 73 | reduction_job.tpl.h 74 | time_core.h 75 | time_job.h 76 | view.h 77 | ) 78 | 79 | add_library(r_exec SHARED ${r_exec_SRC} ${r_exec_HDR}) 80 | target_link_libraries(r_exec ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) 81 | set_property(TARGET r_exec PROPERTY CXX_STANDARD 11) 82 | set_property(TARGET r_exec PROPERTY CXX_STANDARD_REQUIRED ON) 83 | install(TARGETS r_exec DESTINATION lib) 84 | install(FILES ${r_exec_HDR} DESTINATION include/r_exec) 85 | -------------------------------------------------------------------------------- /r_exec/callbacks.cpp: -------------------------------------------------------------------------------- 1 | // callbacks.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "callbacks.h" 32 | 33 | #include // for Callbacks, Callbacks::Callback 34 | #include // for pair 35 | 36 | namespace r_exec 37 | { 38 | 39 | std::unordered_map Callbacks::_Callbacks; 40 | 41 | void Callbacks::Register(const std::string &callback_name, Callback callback) 42 | { 43 | _Callbacks[callback_name] = callback; 44 | } 45 | 46 | Callbacks::Callback Callbacks::Get(std::string &callback_name) 47 | { 48 | std::unordered_map::const_iterator it = _Callbacks.find(callback_name); 49 | 50 | if (it != _Callbacks.end()) { 51 | return it->second; 52 | } 53 | 54 | return nullptr; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /r_exec/callbacks.h: -------------------------------------------------------------------------------- 1 | // callbacks.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef callbacks_h 32 | #define callbacks_h 33 | 34 | #include // for uint64_t, uint8_t 35 | #include // for string 36 | #include // for unordered_map 37 | 38 | #include // for REPLICODE_EXPORT 39 | 40 | namespace r_code { 41 | class Code; 42 | } // namespace r_code 43 | 44 | namespace r_exec 45 | { 46 | 47 | class REPLICODE_EXPORT Callbacks 48 | { 49 | public: 50 | typedef bool (*Callback)(uint64_t, bool, const char *, uint8_t, r_code::Code **); 51 | private: 52 | static std::unordered_map _Callbacks; 53 | public: 54 | static void Register(const std::string &callback_name, Callback callback); 55 | static Callback Get(std::string &callback_name); 56 | }; 57 | } 58 | 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /r_exec/cpp_programs.cpp: -------------------------------------------------------------------------------- 1 | // cpp_programs.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "cpp_programs.h" 32 | 33 | #include // for CPPPrograms, CPPPrograms::Program 34 | #include // for operator<<, basic_ostream, cerr, etc 35 | #include // for pair 36 | 37 | namespace r_code { 38 | class View; 39 | } // namespace r_code 40 | namespace r_exec { 41 | class Controller; 42 | } // namespace r_exec 43 | 44 | 45 | namespace r_exec 46 | { 47 | 48 | std::unordered_map CPPPrograms::Programs; 49 | 50 | void CPPPrograms::Register(std::string &pgm_name, Program pgm) 51 | { 52 | Programs[pgm_name] = pgm; 53 | } 54 | 55 | CPPPrograms::Program CPPPrograms::Get(std::string &pgm_name) 56 | { 57 | std::unordered_map::const_iterator it = Programs.find(pgm_name); 58 | 59 | if (it != Programs.end()) { 60 | return it->second; 61 | } 62 | 63 | return nullptr; 64 | } 65 | 66 | Controller *CPPPrograms::New(std::string &pgm_name, r_code::View *view) 67 | { 68 | CPPPrograms::Program pgm = Get(pgm_name); 69 | 70 | if (pgm != nullptr) { 71 | return pgm(view); 72 | } else { 73 | std::cerr << "c++ program '" << pgm_name << "' could not be found\n"; 74 | return nullptr; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /r_exec/cpp_programs.h: -------------------------------------------------------------------------------- 1 | // cpp_programs.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef cpp_programs_h 32 | #define cpp_programs_h 33 | 34 | #include // for string 35 | #include // for unordered_map 36 | 37 | #include // for REPLICODE_EXPORT 38 | 39 | namespace r_code { 40 | class View; 41 | } // namespace r_code 42 | namespace r_exec { 43 | class Controller; 44 | } // namespace r_exec 45 | 46 | namespace r_exec 47 | { 48 | 49 | class REPLICODE_EXPORT CPPPrograms 50 | { 51 | public: 52 | typedef Controller *(*Program)(r_code::View *); 53 | private: 54 | static std::unordered_map Programs; 55 | public: 56 | static void Register(std::string &pgm_name, Program pgm); 57 | static Program Get(std::string &pgm_name); 58 | static Controller *New(std::string &pgm_name, r_code::View *view); 59 | }; 60 | } 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /r_exec/hlp_overlay.h: -------------------------------------------------------------------------------- 1 | // hlp_overlay.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef hlp_overlay_h 32 | #define hlp_overlay_h 33 | 34 | 35 | #include // for list 36 | #include // for HLPBindingMap 37 | #include // for Overlay 38 | #include // for uint16_t 39 | 40 | #include // for P 41 | 42 | namespace r_code { 43 | class Atom; 44 | class Code; 45 | } // namespace r_code 46 | namespace r_exec { 47 | class _Fact; 48 | } // namespace r_exec 49 | 50 | namespace r_exec 51 | { 52 | 53 | // HLP: high-level patterns. 54 | class HLPOverlay: 55 | public Overlay 56 | { 57 | friend class HLPContext; 58 | protected: 59 | P bindings; 60 | 61 | r_code::list > patterns; 62 | 63 | bool evaluate_guards(uint16_t guard_set_iptr_index); 64 | bool evaluate_fwd_guards(); 65 | bool evaluate(uint16_t index); 66 | 67 | bool check_fwd_timings(); 68 | 69 | bool scan_bwd_guards(); 70 | bool scan_location(uint16_t index); 71 | bool scan_variable(uint16_t index); 72 | 73 | void store_evidence(_Fact *evidence, bool prediction, bool simulation); // stores both actual and non-simulated predicted evidences. 74 | 75 | HLPOverlay(Controller *c, HLPBindingMap *bindings); 76 | public: 77 | static bool EvaluateBWDGuards(Controller *c, HLPBindingMap *bindings); // updates the bindings. 78 | static bool CheckFWDTimings(Controller *c, HLPBindingMap *bindings); // updates the bindings. 79 | static bool ScanBWDGuards(Controller *c, HLPBindingMap *bindings); // does not update the bindings. 80 | 81 | HLPOverlay(Controller *c, const HLPBindingMap *bindings, bool load_code); 82 | virtual ~HLPOverlay(); 83 | 84 | HLPBindingMap *get_bindings() const 85 | { 86 | return bindings; 87 | } 88 | 89 | Atom *get_value_code(uint16_t id) const; 90 | uint16_t get_value_code_size(uint16_t id) const; 91 | 92 | Code *get_unpacked_object() const; 93 | 94 | bool evaluate_bwd_guards(); 95 | }; 96 | } 97 | 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /r_exec/monitor.cpp: -------------------------------------------------------------------------------- 1 | // monitor.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | 32 | #include // for BindingMap 33 | #include // for Fact 34 | #include // for MDLController 35 | #include // for Monitor 36 | 37 | #include // for P, _Object 38 | 39 | namespace r_exec 40 | { 41 | 42 | Monitor::Monitor(MDLController *controller, 43 | BindingMap *bindings, 44 | Fact *target): _Object(), controller(controller) 45 | { 46 | this->bindings = bindings; 47 | this->target = target; 48 | } 49 | 50 | bool Monitor::is_alive() const 51 | { 52 | return !controller->is_invalidated() && controller->is_activated() && !target->is_invalidated(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /r_exec/monitor.h: -------------------------------------------------------------------------------- 1 | // monitor.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef monitor_h 32 | #define monitor_h 33 | 34 | 35 | #include // for P, _Object 36 | 37 | namespace r_exec { 38 | class BindingMap; 39 | class Fact; 40 | class _Fact; 41 | } // namespace r_exec 42 | 43 | namespace r_exec 44 | { 45 | 46 | class MDLController; 47 | 48 | class Monitor: 49 | public core::_Object 50 | { 51 | protected: 52 | core::P bindings; 53 | core::P target; // f->g or f->p. 54 | 55 | MDLController *controller; 56 | 57 | Monitor(MDLController *controller, 58 | BindingMap *bindings, 59 | Fact *target); // fact. 60 | public: 61 | bool is_alive() const; 62 | virtual bool reduce(_Fact *input) = 0; 63 | }; 64 | } 65 | 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /r_exec/object.cpp: -------------------------------------------------------------------------------- 1 | // object.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "object.h" 32 | 33 | #include // for Atom, Atom::::MARKER 34 | 35 | 36 | namespace r_exec 37 | { 38 | 39 | bool IsNotification(r_code::Code *object) 40 | { 41 | switch (object->code(0).getDescriptor()) { 42 | case r_code::Atom::MARKER: 43 | return object->code(0).asOpcode() == Opcodes::MkActChg || 44 | object->code(0).asOpcode() == Opcodes::MkHighAct || 45 | object->code(0).asOpcode() == Opcodes::MkHighSln || 46 | object->code(0).asOpcode() == Opcodes::MkLowAct || 47 | object->code(0).asOpcode() == Opcodes::MkLowRes || 48 | object->code(0).asOpcode() == Opcodes::MkLowSln || 49 | object->code(0).asOpcode() == Opcodes::MkNew || 50 | object->code(0).asOpcode() == Opcodes::MkRdx || 51 | object->code(0).asOpcode() == Opcodes::MkSlnChg; 52 | 53 | default: 54 | return false; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /r_exec/opcodes.cpp: -------------------------------------------------------------------------------- 1 | // opcodes.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "opcodes.h" 32 | 33 | #include // for Opcodes 34 | 35 | 36 | namespace r_exec 37 | { 38 | 39 | uint16_t Opcodes::View; 40 | uint16_t Opcodes::PgmView; 41 | uint16_t Opcodes::GrpView; 42 | 43 | uint16_t Opcodes::Ent; 44 | uint16_t Opcodes::Ont; 45 | uint16_t Opcodes::MkVal; 46 | 47 | uint16_t Opcodes::Grp; 48 | 49 | uint16_t Opcodes::Ptn; 50 | uint16_t Opcodes::AntiPtn; 51 | 52 | uint16_t Opcodes::IPgm; 53 | uint16_t Opcodes::ICppPgm; 54 | 55 | uint16_t Opcodes::Pgm; 56 | uint16_t Opcodes::AntiPgm; 57 | 58 | uint16_t Opcodes::ICmd; 59 | uint16_t Opcodes::Cmd; 60 | 61 | uint16_t Opcodes::Fact; 62 | uint16_t Opcodes::AntiFact; 63 | 64 | uint16_t Opcodes::Cst; 65 | uint16_t Opcodes::Mdl; 66 | 67 | uint16_t Opcodes::ICst; 68 | uint16_t Opcodes::IMdl; 69 | 70 | uint16_t Opcodes::Pred; 71 | uint16_t Opcodes::Goal; 72 | 73 | uint16_t Opcodes::Success; 74 | 75 | uint16_t Opcodes::MkGrpPair; 76 | 77 | uint16_t Opcodes::MkRdx; 78 | uint16_t Opcodes::Perf; 79 | 80 | uint16_t Opcodes::MkNew; 81 | 82 | uint16_t Opcodes::MkLowRes; 83 | uint16_t Opcodes::MkLowSln; 84 | uint16_t Opcodes::MkHighSln; 85 | uint16_t Opcodes::MkLowAct; 86 | uint16_t Opcodes::MkHighAct; 87 | uint16_t Opcodes::MkSlnChg; 88 | uint16_t Opcodes::MkActChg; 89 | 90 | uint16_t Opcodes::Inject; 91 | uint16_t Opcodes::Eject; 92 | uint16_t Opcodes::Mod; 93 | uint16_t Opcodes::Set; 94 | uint16_t Opcodes::NewClass; 95 | uint16_t Opcodes::DelClass; 96 | uint16_t Opcodes::LDC; 97 | uint16_t Opcodes::Swap; 98 | uint16_t Opcodes::Prb; 99 | uint16_t Opcodes::Stop; 100 | 101 | uint16_t Opcodes::Add; 102 | uint16_t Opcodes::Sub; 103 | uint16_t Opcodes::Mul; 104 | uint16_t Opcodes::Div; 105 | } 106 | -------------------------------------------------------------------------------- /r_exec/opcodes.h: -------------------------------------------------------------------------------- 1 | // opcodes.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef opcodes_h 32 | #define opcodes_h 33 | 34 | #include 35 | 36 | #include 37 | 38 | namespace r_exec 39 | { 40 | 41 | // Opcodes are initialized by Init(). 42 | class REPLICODE_EXPORT Opcodes 43 | { 44 | public: 45 | static uint16_t View; 46 | static uint16_t PgmView; 47 | static uint16_t GrpView; 48 | 49 | static uint16_t Ent; 50 | static uint16_t Ont; 51 | static uint16_t MkVal; 52 | 53 | static uint16_t Grp; 54 | 55 | static uint16_t Ptn; 56 | static uint16_t AntiPtn; 57 | 58 | static uint16_t IPgm; 59 | static uint16_t ICppPgm; 60 | 61 | static uint16_t Pgm; 62 | static uint16_t AntiPgm; 63 | 64 | static uint16_t ICmd; 65 | static uint16_t Cmd; 66 | 67 | static uint16_t Fact; 68 | static uint16_t AntiFact; 69 | 70 | static uint16_t Mdl; 71 | static uint16_t Cst; 72 | 73 | static uint16_t ICst; 74 | static uint16_t IMdl; 75 | 76 | static uint16_t Pred; 77 | static uint16_t Goal; 78 | 79 | static uint16_t Success; 80 | 81 | static uint16_t MkGrpPair; 82 | 83 | static uint16_t MkRdx; 84 | static uint16_t Perf; 85 | 86 | static uint16_t MkNew; 87 | 88 | static uint16_t MkLowRes; 89 | static uint16_t MkLowSln; 90 | static uint16_t MkHighSln; 91 | static uint16_t MkLowAct; 92 | static uint16_t MkHighAct; 93 | static uint16_t MkSlnChg; 94 | static uint16_t MkActChg; 95 | 96 | static uint16_t Inject; 97 | static uint16_t Eject; 98 | static uint16_t Mod; 99 | static uint16_t Set; 100 | static uint16_t NewClass; 101 | static uint16_t DelClass; 102 | static uint16_t LDC; 103 | static uint16_t Swap; 104 | static uint16_t Prb; 105 | static uint16_t Stop; 106 | 107 | static uint16_t Add; 108 | static uint16_t Sub; 109 | static uint16_t Mul; 110 | static uint16_t Div; 111 | }; 112 | } 113 | 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /r_exec/overlay.tpl.h: -------------------------------------------------------------------------------- 1 | // overlay.tpl.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include 32 | 33 | namespace r_exec 34 | { 35 | // TODO nuke this 36 | template void Controller::__take_input(r_exec::View *input) // utility: to be called by sub-classes. 37 | { 38 | ReductionJob *j = new ReductionJob(input/*_view*/, (C *)this); 39 | _Mem::Get()->pushReductionJob(j); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /r_exec/p_monitor.h: -------------------------------------------------------------------------------- 1 | // p_monitor.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef p_monitor_h 32 | #define p_monitor_h 33 | 34 | 35 | #include // for Monitor 36 | #include // for uint64_t 37 | 38 | namespace r_exec { 39 | class BindingMap; 40 | class Fact; 41 | class _Fact; 42 | } // namespace r_exec 43 | 44 | namespace r_exec 45 | { 46 | 47 | class MDLController; 48 | 49 | class PMonitor: 50 | public Monitor 51 | { 52 | private: 53 | bool rate_failures; 54 | _Fact *prediction_target; // f1 as in f0->pred->f1->object. 55 | public: 56 | PMonitor(MDLController *controller, 57 | BindingMap *bindings, 58 | Fact *prediction, // f0->pred->f1->object. 59 | bool rate_failures); 60 | ~PMonitor(); 61 | 62 | bool reduce(_Fact *input); 63 | void update(uint64_t &next_target); 64 | }; 65 | } 66 | 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /r_exec/reduction_core.cpp: -------------------------------------------------------------------------------- 1 | // reduction_core.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "reduction_core.h" 32 | 33 | #include // for Now 34 | #include // for _Mem 35 | #include // for _ReductionJob 36 | 37 | 38 | namespace r_exec 39 | { 40 | 41 | void runReductionCore() 42 | { 43 | bool run = true; 44 | 45 | while (run) { 46 | _ReductionJob *job = _Mem::Get()->popReductionJob(); 47 | 48 | if (job == nullptr) { 49 | break; 50 | } 51 | 52 | run = job->update(Now()); 53 | delete job; 54 | } 55 | } 56 | 57 | } // namespace r_exec 58 | -------------------------------------------------------------------------------- /r_exec/reduction_core.h: -------------------------------------------------------------------------------- 1 | // reduction_core.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef reduction_core_h 32 | #define reduction_core_h 33 | 34 | namespace r_exec 35 | { 36 | // Pop a job and reduce - may create overlays from exisitng ones. 37 | // Injects new productions in the mem - may create 1st level overlays. 38 | // For each job: 39 | // - reduce. 40 | // - notify. 41 | // - inject new rdx jobs if salient prods. 42 | // - inject new update jobs if prod=grp. 43 | // - inject new signaling jobs if prod=|pgm or prod=pgm with no inputs. 44 | void runReductionCore(); 45 | } 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /r_exec/reduction_job.cpp: -------------------------------------------------------------------------------- 1 | // reduction_job.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "reduction_job.h" 32 | 33 | #include // for _Mem 34 | #include // for BatchReductionJob, ReductionJob, etc 35 | 36 | 37 | namespace r_exec 38 | { 39 | 40 | _ReductionJob::_ReductionJob(): _Object() 41 | { 42 | } 43 | 44 | //////////////////////////////////////////////////////////// 45 | 46 | bool ShutdownReductionCore::update(uint64_t now) 47 | { 48 | return false; 49 | } 50 | 51 | //////////////////////////////////////////////////////////// 52 | 53 | bool AsyncInjectionJob::update(uint64_t now) 54 | { 55 | _Mem::Get()->inject(input); 56 | return true; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /r_exec/reduction_job.h: -------------------------------------------------------------------------------- 1 | // reduction_job.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef reduction_job_h 32 | #define reduction_job_h 33 | 34 | 35 | #include // for View 36 | #include // for uint64_t 37 | 38 | #include // for P, _Object 39 | #include // for REPLICODE_EXPORT 40 | 41 | namespace r_exec 42 | { 43 | 44 | class REPLICODE_EXPORT _ReductionJob: 45 | public _Object 46 | { 47 | protected: 48 | _ReductionJob(); 49 | public: 50 | uint64_t ijt; // time of injection of the job in the pipe. 51 | virtual bool update(uint64_t now) = 0; // return false to shutdown the reduction core. 52 | virtual void debug() {} 53 | }; 54 | 55 | template class ReductionJob: 56 | public _ReductionJob 57 | { 58 | public: 59 | P input; 60 | P<_P> processor; 61 | ReductionJob(View *input, _P *processor): _ReductionJob(), input(input), processor(processor) {} 62 | bool update(uint64_t now); 63 | void debug() 64 | { 65 | processor->debug(input); 66 | } 67 | }; 68 | 69 | template class BatchReductionJob: 70 | public _ReductionJob 71 | { 72 | public: 73 | P<_P> processor; // the controller that will process the job. 74 | P trigger; // the event that triggered the job. 75 | P controller; // the controller that produced the job. 76 | BatchReductionJob(_P *processor, T *trigger, C *controller): _ReductionJob(), processor(processor), trigger(trigger), controller(controller) {} 77 | bool update(uint64_t now); 78 | }; 79 | 80 | class REPLICODE_EXPORT ShutdownReductionCore: 81 | public _ReductionJob 82 | { 83 | public: 84 | bool update(uint64_t now); 85 | }; 86 | 87 | class REPLICODE_EXPORT AsyncInjectionJob: 88 | public _ReductionJob 89 | { 90 | public: 91 | P input; 92 | AsyncInjectionJob(View *input): _ReductionJob(), input(input) {} 93 | bool update(uint64_t now); 94 | }; 95 | } 96 | 97 | #include 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /r_exec/reduction_job.tpl.h: -------------------------------------------------------------------------------- 1 | #include "mem.h" 2 | 3 | namespace r_exec 4 | { 5 | 6 | template bool ReductionJob<_P>::update(uint64_t now) 7 | { 8 | _Mem::Get()->register_reduction_job_latency(now - ijt); 9 | processor->reduce(input); 10 | return true; 11 | } 12 | template bool BatchReductionJob<_P, T, C>::update(uint64_t now) 13 | { 14 | _Mem::Get()->register_reduction_job_latency(now - ijt); 15 | processor->reduce_batch(trigger, controller); 16 | return true; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /r_exec/time_core.h: -------------------------------------------------------------------------------- 1 | // time_core.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef time_core_h 32 | #define time_core_h 33 | 34 | namespace r_exec 35 | { 36 | void runTimeCore(); 37 | } 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(compiler) 2 | -------------------------------------------------------------------------------- /tests/compiler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(compilertest main.cpp) 2 | target_link_libraries(compilertest r_code r_comp r_exec) 3 | set_property(TARGET compilertest PROPERTY CXX_STANDARD 11) 4 | set_property(TARGET compilertest PROPERTY CXX_STANDARD_REQUIRED ON) 5 | 6 | -------------------------------------------------------------------------------- /tests/compiler/drives.replicode: -------------------------------------------------------------------------------- 1 | ; debug 2 | 3 | 4 | ; drive injectors. 5 | 6 | init_run_pgm:(pgm |[] |[] |[] [] 7 | (inj [] 8 | f_run:(fact run t:(now) (+ t 200000us) 1 1) 9 | |[] 10 | ) 11 | (inj [] 12 | g:(goal f_run self 1) 13 | |[] 14 | ) 15 | (inj [] 16 | (fact g t t 1 1) 17 | [SYNC_ONCE t 1 1 primary nil] 18 | ) 19 | 1) |[] 20 | 21 | init_run_ipgm:(ipgm init_run_pgm |[] RUN_ONCE 200000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 drives nil 0]] 22 | 23 | success_run_pgm:(pgm |[] [] 24 | (ptn (fact (success (fact (goal (fact run after: before: ::) ::) ::) ::) ::) |[]) 25 | |[] 26 | [] 27 | (inj [] 28 | f_run:(fact run t:(now) (+ t (+ (- before after) 50000us)) 1 1) 29 | |[] 30 | ) 31 | (inj [] 32 | g:(goal f_run self 1) 33 | |[] 34 | ) 35 | (inj [] 36 | (fact g t t 1 1) 37 | [SYNC_ONCE t 1 1 primary nil] 38 | ) 39 | 1) |[] 40 | 41 | success_run_ipgm:(ipgm success_run_pgm |[] RUN_ALWAYS 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 drives nil 0]] 42 | 43 | failure_0_run_pgm:(pgm |[] [] 44 | (ptn (|fact (success (fact (goal (fact run after: before: ::) ::) ::) ::) ::) [(< 0 delta:(- (- before after) 50000us))]) 45 | |[] 46 | [] 47 | (inj [] 48 | f_run:(fact run t:(now) (+ t delta) 1 1) 49 | |[] 50 | ) 51 | (inj [] 52 | g:(goal f_run self 1) 53 | |[] 54 | ) 55 | (inj [] 56 | (fact g t t 1 1) 57 | [SYNC_ONCE t 1 1 primary nil] 58 | ) 59 | 1) |[] 60 | 61 | failure_0_run_ipgm:(ipgm failure_0_run_pgm |[] RUN_ALWAYS 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 drives nil 0]] 62 | 63 | failure_1_run_pgm:(pgm |[] [] 64 | (ptn (|fact (success (fact (goal (fact run after: before: ::) ::) ::) ::) ::) [(>= 50000us (- before after))]) 65 | |[] 66 | [] 67 | (inj [] 68 | f_run:(fact run t:(now) (+ t 50000us) 1 1) 69 | |[] 70 | ) 71 | (inj [] 72 | g:(goal f_run self 1) 73 | |[] 74 | ) 75 | (inj [] 76 | (fact g t t 1 1) 77 | [SYNC_ONCE t 1 1 primary nil] 78 | ) 79 | 1) |[] 80 | 81 | failure_1_run_ipgm:(ipgm failure_1_run_pgm |[] RUN_ALWAYS 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 drives nil 0]] 82 | -------------------------------------------------------------------------------- /tests/compiler/hello.world.replicode: -------------------------------------------------------------------------------- 1 | ; all programs are deactivated: activate the ones according to the method you want to try. 2 | 3 | 4 | ; Method 1: locked on timer. 5 | 6 | pgm0:(pgm |[] |[] |[] [] 7 | (prb [1 "print" "hello world" |[]]) 8 | 1) |[] 9 | 10 | ipgm0:(ipgm pgm0 |[] RUN_ONCE 50000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 0]] 11 | 12 | 13 | ; Method 2: one object injected at a point in time, caught by another program. 14 | 15 | pgm1:(pgm |[] |[] |[] [] 16 | (inj [] 17 | (ent 1) 18 | [SYNC_ONCE now 1 1 stdin nil] 19 | ) 20 | 1) |[] 21 | 22 | ipgm1:(ipgm pgm1 |[] RUN_ONCE 50000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 0]] 23 | 24 | pgm2:(pgm |[] [] 25 | (ptn (ent ::) |[]) 26 | |[] [] 27 | (prb [1 "print" "hello world" |[]]) 28 | 1) |[] 29 | 30 | ipgm2:(ipgm pgm2 |[] RUN_ONCE 0us VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 0]] 31 | 32 | 33 | ; Method 3: one program that injects a new instance of itself. 34 | 35 | pgm3:(pgm |[] |[] |[] [] 36 | (inj [] 37 | (ins pgm3 |[] RUN_ONCE 50000us VOLATILE SILENT) 38 | [SYNC_ONCE now 0 forever stdin nil 1] 39 | ) 40 | (prb [1 "print" "hello world" |[]]) 41 | 1) |[] 42 | 43 | ipgm3:(ipgm pgm3 |[] RUN_ONCE 50000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 44 | 45 | -------------------------------------------------------------------------------- /tests/compiler/pong.2.replicode: -------------------------------------------------------------------------------- 1 | ; as pong, debug combinations of CTPX, GTPX and PTPX; goal-driven. 2 | 3 | ; objects. 4 | 5 | b:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 6 | ball:(ont 1) [[SYNC_ONCE now 0 forever root nil]] 7 | b_is_a_ball:(mk.val b essence ball 1) |[] 8 | f_b_is_a_ball:(fact b_is_a_ball 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 9 | 10 | red_color:(ont 1) [[SYNC_ONCE now 1 forever root nil]] 11 | blue_color:(ont 1) [[SYNC_ONCE now 1 forever root nil]] 12 | 13 | b_is_blue:(mk.val b color blue_color 1) |[] 14 | f_b_is_blue:(fact b_is_blue 0us MAX_TIME 1 1) [[SYNC_HOLD now 1 forever stdin nil]] 15 | 16 | 17 | ; top-level model and drive injectors. 18 | 19 | m_run_0:(mdl |[] [] 20 | (fact (mk.val b: position_y : :) t0: t1: ::) 21 | (fact run t0: t1: ::); drive. 22 | |[] 23 | |[] 24 | [stdin drives] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 1]] 25 | 26 | 27 | init_run_pgm:(pgm |[] |[] |[] [] 28 | (inj [] 29 | f_run:(fact run t0:(+ now 50000us) (+ t0 sampling_period) 1 1) 30 | |[] 31 | ) 32 | (inj [] 33 | g:(goal f_run self 1) 34 | |[] 35 | ) 36 | (inj [] 37 | (fact g t1:(now) t1 1 1) 38 | [SYNC_ONCE t1 1 forever primary nil] 39 | ) 40 | 1) |[] 41 | 42 | init_run_ipgm:(ipgm init_run_pgm |[] RUN_ONCE 50000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 drives nil 1]] 43 | 44 | success_run_pgm:(pgm |[] [] 45 | s:(ptn (fact (success (fact (goal (fact run after: before: ::) ::) ::) ::) ::) |[]) 46 | |[] [] 47 | (inj [] 48 | f_run:(fact run (+ after sampling_period) (+ before sampling_period) 1 1) 49 | |[] 50 | ) 51 | (inj [] 52 | g:(goal f_run self 1) 53 | |[] 54 | ) 55 | (inj [] 56 | (fact g t1:(now) t1 1 1) 57 | [SYNC_ONCE t1 1 forever primary nil] 58 | ) 59 | 1) |[] 60 | 61 | success_run_ipgm:(ipgm success_run_pgm |[] RUN_ALWAYS 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 forever drives nil 1]] 62 | 63 | failure_run_pgm:(pgm |[] [] 64 | s:(ptn (|fact (success (fact (goal (fact run after: before: ::) ::) ::) ::) ::) |[]) 65 | |[] [] 66 | (inj [] 67 | f_run:(fact run (+ after sampling_period) (+ before sampling_period) 1 1) 68 | |[] 69 | ) 70 | (inj [] 71 | g:(goal f_run self 1) 72 | |[] 73 | ) 74 | (inj [] 75 | (fact g t1:(now) t1 1 1) 76 | [SYNC_ONCE t1 1 forever primary nil] 77 | ) 78 | 1) |[] 79 | 80 | failure_run_ipgm:(ipgm failure_run_pgm |[] RUN_ALWAYS 0us VOLATILE SILENT 1) [[SYNC_ONCE now 0 forever drives nil 1]] 81 | 82 | 83 | ; input generators. 84 | 85 | start:(pgm |[] |[] |[] [] 86 | (inj [] 87 | p:(mk.val b position_y 0 1) 88 | |[] 89 | ) 90 | (inj [] 91 | (fact p after:(now) (+ after sampling_period) 1 1) 92 | [SYNC_PERIODIC now 1 1 stdin nil] 93 | ) 94 | (inj [] 95 | s:(mk.val b speed_y 0.0001 1) 96 | |[] 97 | ) 98 | (inj [] 99 | (fact s now MAX_TIME 1 1) 100 | [SYNC_HOLD now 1 forever stdin nil] 101 | ) 102 | 1) |[] 103 | 104 | istart:(ipgm start |[] RUN_ONCE sampling_period VOLATILE SILENT 1) [[SYNC_ONCE now 0 forever stdin nil 1]] 105 | 106 | pgm0:(pgm |[] [] 107 | (ptn f:(fact (mk.val b position_y py: :) after: before: ::) |[]) 108 | (ptn (fact (mk.val b speed_y sy: :) ::) |[]) 109 | |[] [] 110 | (inj [] 111 | p:(mk.val b position_y (+ py (* sy sampling_period)) 1) 112 | |[] 113 | ) 114 | (inj [] 115 | (fact p (+ after sampling_period) (+ before sampling_period) 1 1) 116 | [SYNC_PERIODIC (+ f.vw.ijt sampling_period) 1 1 stdin nil] 117 | ) 118 | 1) |[] 119 | 120 | ipgm0:(ipgm pgm0 |[] RUN_ALWAYS 20000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 forever stdin nil 1]] 121 | -------------------------------------------------------------------------------- /tests/compiler/pong.replicode: -------------------------------------------------------------------------------- 1 | ; debug 2 | ; a ball bounces between two walls. 3 | 4 | ; objects. 5 | 6 | b:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 7 | ball:(ont 1) [[SYNC_ONCE now 0 forever root nil]] 8 | b_is_a_ball:(mk.val b essence ball 1) |[] 9 | f_b_is_a_ball:(fact b_is_a_ball 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 10 | 11 | ; w_top:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 12 | ; w_top_py:(mk.val w_top position_y 50 1) |[] 13 | ; f_w_top_py:(fact w_top_py 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 14 | 15 | ; w_bottom:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 16 | ; w_bottom_py:(mk.val w_bottom position_y 0 1) |[] 17 | ; f_w_bottom_py:(fact w_bottom_py 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 18 | 19 | 20 | ; same pos_y. 21 | 22 | s0:(cst |[] [] 23 | (fact (mk.val h: position_y py: :) t0: t1: ::) 24 | (fact (mk.val w: position_y py: :) t0: t1: ::) 25 | |[] 26 | |[] 27 | [stdin] 1) [[SYNC_ONCE now 0 forever primary nil 0]] 28 | 29 | 30 | ; input generators. 31 | 32 | start:(pgm |[] |[] |[] [] 33 | (inj [] 34 | p:(mk.val b position_y 0 1) 35 | |[] 36 | ) 37 | (inj [] 38 | (fact p after:(now) (+ after sampling_period) 1 1) 39 | [SYNC_PERIODIC now 1 1 stdin nil] 40 | ) 41 | 1) |[] 42 | 43 | istart:(ipgm start |[] RUN_ONCE sampling_period VOLATILE SILENT 1) [[SYNC_ONCE now 0 forever stdin nil 1]] 44 | 45 | pgm0:(pgm |[] [] 46 | (ptn f:(fact (mk.val b position_y py: :) after: before: ::) |[]) 47 | (ptn (fact (mk.val b speed_y sy: :) ::) |[]) 48 | |[] [] 49 | (inj [] 50 | p:(mk.val b position_y (+ py (* sy sampling_period)) 1) 51 | |[] 52 | ) 53 | (inj [] 54 | (fact p (+ after sampling_period) (+ before sampling_period) 1 1) 55 | [SYNC_PERIODIC (+ f.vw.ijt sampling_period) 1 1 stdin nil] 56 | ) 57 | 1) |[] 58 | 59 | ipgm0:(ipgm pgm0 |[] RUN_ALWAYS 20000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 forever stdin nil 1]] 60 | 61 | pgm1:(pgm |[] [] 62 | (ptn (fact (mk.val b position_y py: :) ::) [(< py 55) (> py 45)]) 63 | |[] [] 64 | (inj [] 65 | s:(mk.val b speed_y -0.0001 1) 66 | |[] 67 | ) 68 | (inj [] 69 | (fact s now MAX_TIME 1 1) 70 | [SYNC_HOLD now 1 forever stdin nil] 71 | ) 72 | 1) |[] 73 | 74 | ipgm1:(ipgm pgm1 |[] RUN_ALWAYS 0us VOLATILE SILENT 1) [[SYNC_ONCE now 0 forever stdin nil 0]] 75 | 76 | pgm2:(pgm |[] [] 77 | (ptn (fact (mk.val b position_y 0 :) ::) |[]) 78 | |[] [] 79 | (inj [] 80 | s:(mk.val b speed_y 0.0001 1) 81 | |[] 82 | ) 83 | (inj [] 84 | (fact s now MAX_TIME 1 1) 85 | [SYNC_HOLD now 1 forever stdin nil] 86 | ) 87 | 1) |[] 88 | 89 | ipgm2:(ipgm pgm2 |[] RUN_ONCE 0us VOLATILE SILENT 1) [[SYNC_ONCE now 0 forever stdin nil 1]] 90 | -------------------------------------------------------------------------------- /tests/compiler/test.1.replicode: -------------------------------------------------------------------------------- 1 | ; debug 2 | 3 | !load test.domain.replicode 4 | ; !load c:/work/Replicode/Test/V1.2/drives.replicode 5 | 6 | 7 | s0:(cst |[] [] 8 | (fact (mk.val h: position_z z0: :) t0: t1: ::) 9 | (fact (mk.val h: essence hand :) t0: t1: ::) 10 | |[] 11 | |[] 12 | [stdin] 1) [[SYNC_ONCE now 0 forever primary nil 0]] 13 | 14 | m0:(mdl [p0: t0: t1:] [] 15 | (fact (cmd lift_hand [h: delta_z:] :) t2: t3: ::) 16 | (fact (mk.val h: position_z p1: 1) t4: t5: : 1) 17 | [] 18 | p1:(+ p0 delta_z) 19 | t4:(+ t0 sampling_period) 20 | t5:(+ t1 sampling_period) 21 | [] 22 | delta_z:(- p1 p0) 23 | [stdin] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 24 | 25 | m1:(mdl |[] [] 26 | (fact (icst s0 |[] [h: p0:] ::) t0: t1: ::) 27 | (fact (imdl m0 [p0: t0: t1:] [h: delta_z: p1: : :] : 1) t0: t2: : 1) 28 | [] 29 | t2:(+ t0 sampling_period); domain of validity of the lhs, as enforced by the input generators. 30 | [] 31 | t0:(- t2 sampling_period) 32 | [stdin] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 33 | 34 | 35 | ; top-level models. 36 | 37 | m_run_0:(mdl |[] [] 38 | (fact (mk.val self_right_hand position_z 10 :) t0: t1: ::) 39 | (fact run t2: t3: ::) 40 | |[] 41 | [] 42 | t0:(now) 43 | t1:(+ t0 100000us) 44 | [stdin drives] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 45 | 46 | 47 | ; input generators. 48 | 49 | pgm0:(pgm |[] |[] |[] [] 50 | (inj [] 51 | p:(mk.val self_right_hand position_z 10 1) 52 | |[] 53 | ) 54 | (inj [] 55 | (fact p now (+ now sampling_period) 1 1) 56 | [SYNC_PERIODIC now 1 1 stdin nil] 57 | ) 58 | 1) |[] 59 | 60 | ipgm0:(ipgm pgm0 |[] RUN_ONCE sampling_period VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 61 | 62 | pgm1:(pgm |[] |[] |[] [] 63 | (inj [] 64 | c:(cmd lift_hand [self_right_hand 2] 1) 65 | |[] 66 | ) 67 | (inj [] 68 | (fact c now 200000us 1 1) 69 | [SYNC_ONCE now 1 1 stdin nil] 70 | ) 71 | 1) |[] 72 | 73 | ipgm1:(ipgm pgm1 |[] RUN_ONCE 150000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 74 | 75 | pgm2:(pgm |[] [] 76 | (ptn (fact (cmd lift_hand [h: z:] :) t0: t1: ::) |[]) 77 | (ptn p:(fact (mk.val h: position_z old_z: :) t2: t3: ::) |[]) 78 | |[] 79 | [] 80 | (inj [] 81 | new_p:(mk.val self_right_hand position_z (+ z old_z) 1) 82 | |[] 83 | ) 84 | (inj [] 85 | (fact new_p (+ t2 sampling_period) (+ t3 sampling_period) 1 1) 86 | [SYNC_PERIODIC t3 1 1 stdin nil] 87 | ) 88 | 1) |[] 89 | 90 | ipgm2:(ipgm pgm2 |[] RUN_ONCE 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 91 | -------------------------------------------------------------------------------- /tests/compiler/test.2.replicode: -------------------------------------------------------------------------------- 1 | ; debug 2 | 3 | !load test.domain.replicode 4 | ; !load c:/work/Replicode/Test/V1.2/drives.replicode 5 | 6 | 7 | 8 | s0:(cst |[] [] 9 | (fact (mk.val h: position_z z0: :) t0: t1: ::) 10 | (fact (mk.val h: essence hand :) t0: t1: ::) 11 | |[] 12 | |[] 13 | [stdin] 1) [[SYNC_ONCE now 0 forever primary nil 0]] 14 | 15 | m0:(mdl [p0: t0: t1:] [] 16 | (fact (cmd lift_hand [h: delta_z:] :) t2: t3: ::) 17 | (fact (mk.val h: position_z p1: 1) t4: t5: : 1) 18 | [] 19 | p1:(+ p0 delta_z) 20 | t4:(+ t0 sampling_period) 21 | t5:(+ t1 sampling_period) 22 | [] 23 | delta_z:(- p1 p0) 24 | [stdin] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 25 | 26 | m1:(mdl |[] [] 27 | (fact (icst s0 |[] [h: p0:] ::) t0: t1: ::) 28 | (fact (imdl m0 [p0: t0: t1:] [h: delta_z: p1: : :] : 1) t0: t2: : 1) 29 | [] 30 | t2:(+ t0 sampling_period); domain of validity of the lhs, as enforced by the input generators. 31 | [] 32 | t0:(- t2 sampling_period) 33 | [stdin] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 34 | 35 | 36 | ; top-level models. 37 | 38 | m_run_0:(mdl |[] [] 39 | (fact (mk.val self_right_hand attachment cube0 :) t0: t1: ::) 40 | (fact run t2: t3: ::) 41 | |[] 42 | [] 43 | t0:(now) 44 | t1:(+ t0 100000us) 45 | [stdin drives] 1 1 1 0 1) [[SYNC_ONCE now 0 forever primary nil 0]] 46 | 47 | 48 | ; input generators. 49 | 50 | pgm0:(pgm |[] |[] |[] [] 51 | (inj [] 52 | p:(mk.val self_right_hand attachment cube0 1) 53 | |[] 54 | ) 55 | (inj [] 56 | (fact p now MAX_TIME 1 1) 57 | [SYNC_HOLD now 1 1 stdin nil] 58 | ) 59 | 1) |[] 60 | 61 | ipgm0:(ipgm pgm0 |[] RUN_ONCE sampling_period VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 62 | 63 | pgm1:(pgm |[] |[] |[] [] 64 | (inj [] 65 | c:(cmd release_hand [self_right_hand] 1) 66 | |[] 67 | ) 68 | (inj [] 69 | (fact c now (+ now 10000us) 1 1) 70 | [SYNC_ONCE now 1 1 stdin nil] 71 | ) 72 | (inj [] 73 | p:(mk.val self_right_hand attachment cube0 1) 74 | |[] 75 | ) 76 | (inj [] 77 | (|fact p now MAX_TIME 1 1) 78 | [SYNC_HOLD now 1 1 stdin nil] 79 | ) 80 | 1) |[] 81 | 82 | ipgm1:(ipgm pgm1 |[] RUN_ONCE 160000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 83 | -------------------------------------------------------------------------------- /tests/compiler/test.3.replicode: -------------------------------------------------------------------------------- 1 | ; debug 2 | 3 | !load test.domain.replicode 4 | ; !load c:/work/Replicode/Test/V1.2/drives.replicode 5 | 6 | 7 | 8 | ; input generators. 9 | 10 | pgm0:(pgm |[] |[] |[] [] 11 | (inj [] 12 | a:(mk.val self_right_hand attachment cube0 1) 13 | |[] 14 | ) 15 | (inj [] 16 | (|fact a now MAX_TIME 1 1) 17 | [SYNC_HOLD now 1 forever stdin nil] 18 | ) 19 | (inj [] 20 | ph:(mk.val self_right_hand position_x 0 1) 21 | |[] 22 | ) 23 | (inj [] 24 | (fact ph now (+ now sampling_period) 1 1) 25 | [SYNC_PERIODIC now 1 1 stdin nil] 26 | ) 27 | (inj [] 28 | pc:(mk.val cube0 position_x 0 1) 29 | |[] 30 | ) 31 | (inj [] 32 | (fact pc now (+ now sampling_period) 1 1) 33 | [SYNC_PERIODIC now 1 1 stdin nil] 34 | ) 35 | 1) |[] 36 | 37 | ipgm0:(ipgm pgm0 |[] RUN_ONCE sampling_period VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 38 | 39 | pgm1:(pgm |[] |[] |[] [] 40 | (inj [] 41 | c:(cmd grab_hand [self_right_hand] 1) 42 | |[] 43 | ) 44 | (inj [] 45 | (fact c now (+ now 10000us) 1 1) 46 | [SYNC_ONCE now 1 1 stdin nil] 47 | ) 48 | (inj [] 49 | p:(mk.val self_right_hand attachment cube0 1) 50 | |[] 51 | ) 52 | (inj [] 53 | (fact p now MAX_TIME 1 1) 54 | [SYNC_HOLD now 1 1 stdin nil] 55 | ) 56 | 1) |[] 57 | 58 | ipgm1:(ipgm pgm1 |[] RUN_ONCE 160000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 59 | -------------------------------------------------------------------------------- /tests/compiler/test.4.replicode: -------------------------------------------------------------------------------- 1 | ; test 1,2 and 3 together. 2 | 3 | !load test.domain.replicode 4 | ; !load c:/work/Replicode/Test/V1.2/drives.replicode 5 | 6 | 7 | ; input generators. 8 | 9 | pgm0:(pgm |[] |[] |[] [] 10 | (inj [] 11 | p:(mk.val self_right_hand position_z 10 1) 12 | |[] 13 | ) 14 | (inj [] 15 | (fact p now (+ now sampling_period) 1 1) 16 | [SYNC_PERIODIC now 1 1 stdin nil] 17 | ) 18 | 1) |[] 19 | 20 | ipgm0:(ipgm pgm0 |[] RUN_ONCE sampling_period VOLATILE SILENT 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 21 | 22 | pgm1:(pgm |[] |[] |[] [] 23 | (inj [] 24 | c:(cmd lift_hand [self_right_hand 2] 1) 25 | |[] 26 | ) 27 | (inj [] 28 | (fact c now 200000us 1 1) 29 | [SYNC_ONCE now 1 1 stdin nil] 30 | ) 31 | 1) |[] 32 | 33 | ipgm1:(ipgm pgm1 |[] RUN_ONCE 150000us VOLATILE SILENT 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 34 | 35 | pgm2:(pgm |[] [] 36 | (ptn (fact (cmd lift_hand [h: z:] :) t0: t1: ::) |[]) 37 | (ptn p:(fact (mk.val h: position_z old_z: :) t2: t3: ::) |[]) 38 | |[] 39 | [] 40 | (inj [] 41 | new_p:(mk.val self_right_hand position_z (+ z old_z) 1) 42 | |[] 43 | ) 44 | (inj [] 45 | (fact new_p (+ t2 sampling_period) (+ t3 sampling_period) 1 1) 46 | [SYNC_PERIODIC t3 1 1 stdin nil] 47 | ) 48 | 1) |[] 49 | 50 | ipgm2:(ipgm pgm2 |[] RUN_ONCE 0us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 51 | 52 | ; --------------------------------------- 53 | 54 | pgm3:(pgm |[] |[] |[] [] 55 | (inj [] 56 | a:(mk.val self_right_hand attachment cube0 1) 57 | |[] 58 | ) 59 | (inj [] 60 | (|fact a now MAX_TIME 1 1) 61 | [SYNC_HOLD now 1 forever stdin nil] 62 | ) 63 | (inj [] 64 | ph:(mk.val self_right_hand position_x 0 1) 65 | |[] 66 | ) 67 | (inj [] 68 | (fact ph now (+ now sampling_period) 1 1) 69 | [SYNC_PERIODIC now 1 1 stdin nil] 70 | ) 71 | (inj [] 72 | pc:(mk.val cube0 position_x 0 1) 73 | |[] 74 | ) 75 | (inj [] 76 | (fact pc now (+ now sampling_period) 1 1) 77 | [SYNC_PERIODIC now 1 1 stdin nil] 78 | ) 79 | 1) |[] 80 | 81 | ipgm3:(ipgm pgm3 |[] RUN_ONCE 200000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 1 stdin nil 1]] 82 | 83 | pgm4:(pgm |[] |[] |[] [] 84 | (inj [] 85 | c:(cmd grab_hand [self_right_hand] 1) 86 | |[] 87 | ) 88 | (inj [] 89 | (fact c now (+ now 10000us) 1 1) 90 | [SYNC_ONCE now 1 1 stdin nil] 91 | ) 92 | (inj [] 93 | p:(mk.val self_right_hand attachment cube0 1) 94 | |[] 95 | ) 96 | (inj [] 97 | (fact p now MAX_TIME 1 1) 98 | [SYNC_HOLD now 1 forever stdin nil] 99 | ) 100 | 1) |[] 101 | 102 | ipgm4:(ipgm pgm4 |[] RUN_ONCE 260000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 103 | 104 | ; --------------------------------------- 105 | 106 | pgm6:(pgm |[] |[] |[] [] 107 | (inj [] 108 | c:(cmd release_hand [self_right_hand] 1) 109 | |[] 110 | ) 111 | (inj [] 112 | (fact c now (+ now 10000us) 1 1) 113 | [SYNC_ONCE now 1 1 stdin nil] 114 | ) 115 | (inj [] 116 | p:(mk.val self_right_hand attachment cube0 1) 117 | |[] 118 | ) 119 | (inj [] 120 | (|fact p now MAX_TIME 1 1) 121 | [SYNC_HOLD now 1 1 stdin nil] 122 | ) 123 | 1) |[] 124 | 125 | ipgm6:(ipgm pgm6 |[] RUN_ONCE 360000us VOLATILE NOTIFY 1) [[SYNC_ONCE now 0 2 stdin nil 1]] 126 | -------------------------------------------------------------------------------- /tests/compiler/test.domain.replicode: -------------------------------------------------------------------------------- 1 | ; objects. 2 | 3 | self_right_hand:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 4 | self_right_hand_is_a_hand:(mk.val self_right_hand essence hand 1) |[] 5 | f_self_right_hand_is_a_hand:(fact self_right_hand_is_a_hand 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 6 | ; self_head:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 7 | ; self_head_is_a_head(mk.val self_head essence head 1) [[SYNC_STATE now 1 forever stdin nil]] 8 | ; f_self_head_is_a_head:(fact self_head_is_a_head 0us MAX_TIME 1 1) [[SYNC_STATE now 1 forever stdin nil]] 9 | 10 | ; programmer:(ont 1) [[SYNC_FRONT now 1 forever root nil]] 11 | 12 | ; human1:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 13 | ; (mk.val human1 essence actor 1) [[SYNC_STATE now 1 forever stdin nil]] 14 | ; human1_right_hand:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 15 | ; (mk.val human1_right_hand essence hand 1) [[SYNC_STATE now 1 forever stdin nil]] 16 | ; human1_head:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 17 | ; (mk.val human1_head essence head 1) [[SYNC_STATE now 1 forever stdin nil]] 18 | 19 | ; human2:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 20 | ; (mk.val human2 essence actor 1) [[SYNC_STATE now 1 forever stdin nil]] 21 | ; human2_right_hand:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 22 | ; (mk.val human2_right_hand essence hand 1) [[SYNC_STATE now 1 forever stdin nil]] 23 | ; human2_head:(ent 1) [[SYNC_FRONT now 1 forever root nil]] 24 | ; (mk.val human2_head essence head 1) [[SYNC_STATE now 1 forever stdin nil]] 25 | 26 | cube0:(ent 1) [[SYNC_ONCE now 1 forever root nil]] 27 | cube0_is_a_cube:(mk.val cube0 essence cube 1) |[] 28 | f_cube0_is_a_cube:(fact cube0_is_a_cube 0us MAX_TIME 1 1) [[SYNC_AXIOM now 1 forever stdin nil]] 29 | -------------------------------------------------------------------------------- /usr_operators/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(usr_operators_SRC 2 | auto_focus.cpp 3 | usr_operators.cpp 4 | Callbacks/callbacks.cpp 5 | Operators/operators.cpp 6 | TestProgram/test_program.cpp 7 | ) 8 | 9 | add_library(usr_operators SHARED ${usr_operators_SRC}) 10 | target_link_libraries(usr_operators r_exec) 11 | set_property(TARGET usr_operators PROPERTY CXX_STANDARD 11) 12 | set_property(TARGET usr_operators PROPERTY CXX_STANDARD_REQUIRED ON) 13 | -------------------------------------------------------------------------------- /usr_operators/Callbacks/callbacks.cpp: -------------------------------------------------------------------------------- 1 | // callbacks.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "callbacks.h" 32 | 33 | #include // for Code 34 | #include // for operator<<, basic_ostream, cout, etc 35 | #include // for char_traits, operator<< 36 | 37 | #include // for DebugStream 38 | 39 | 40 | bool print(uint64_t t, bool suspended, const char *msg, uint8_t object_count, r_code::Code **objects) // return true to resume the executive (applies when called from a suspend call, i.e. suspended==true). 41 | { 42 | std::cout << DebugStream::timestamp(t) << ": " << msg << std::endl; 43 | 44 | for (uint8_t i = 0; i < object_count; ++i) { 45 | objects[i]->trace(); 46 | } 47 | 48 | return true; 49 | } 50 | -------------------------------------------------------------------------------- /usr_operators/Callbacks/callbacks.h: -------------------------------------------------------------------------------- 1 | // callbacks.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef callbacks_h 32 | #define callbacks_h 33 | 34 | 35 | #include // for uint64_t, uint8_t 36 | 37 | #include // for REPLICODE_EXPORT 38 | 39 | namespace r_code { 40 | class Code; 41 | } // namespace r_code 42 | 43 | extern "C" { 44 | bool REPLICODE_EXPORT print(uint64_t t, bool suspended, const char *msg, uint8_t object_count, r_code::Code **objects); 45 | } 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /usr_operators/Correlator/CorrelatorCore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CorrelatorCore.h 3 | * 4 | * Created on: Nov 15, 2010 5 | * Author: koutnij 6 | */ 7 | 8 | #ifndef CORRELATORCORE_H_ 9 | #define CORRELATORCORE_H_ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "CorrelatorCore.h" 18 | #include "LstmLayer.h" 19 | #include "ForwardLayer.h" 20 | #include "LstmNetwork.h" 21 | #include "VectorMath.h" 22 | 23 | class CorrelatorCore 24 | { 25 | public: 26 | std::vector< std::vector > inputSequenceBuffer; 27 | std::vector< std::vector > lstmStateBuffer; 28 | std::vector outputLayerStateBuffer; 29 | std::vector > trainingSequenceBuffer; 30 | std::vector > inputLayerErrorBuffer; 31 | std::vector > outputErrorBuffer; 32 | 33 | std::vector< std::vector > inputSequenceBufferSnapshot; 34 | std::vector< std::vector > lstmStateBufferSnapshot; 35 | std::vector outputLayerStateBufferSnapshot; 36 | std::vector > trainingSequenceBufferSnapshot; 37 | std::vector > inputLayerErrorBufferSnapshot; 38 | std::vector > outputErrorBufferSnapshot; 39 | 40 | int nCells, nBlocks, nInputs, nOutputs; 41 | int buffersLength; 42 | 43 | LstmNetwork* lstmNetwork; 44 | 45 | CorrelatorCore(); 46 | 47 | //int nCells=1,nBlocks=2,nInputs=3,nOutputs=3,nX=10,dimX=3; 48 | void initializeOneStepPrediction(int nC, int nB, std::vector >& dataSequence); 49 | void appendBuffers(std::vector >& dataSequence); 50 | void forwardPass(); 51 | void backwardPass(); 52 | double trainingEpoch(double learningRate, double momentum); 53 | void snapshot(int t1, int t2); 54 | void getJacobian(int t1, int t2, std::vector >& jacobian); 55 | void readMatrix(std::vector >& mat, int lineLength); 56 | ~CorrelatorCore(); 57 | }; 58 | 59 | #endif /* CORRELATORCORE_H_ */ 60 | -------------------------------------------------------------------------------- /usr_operators/Correlator/ForwardLayer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ForwardLayer.h 3 | * 4 | * Created on: Oct 27, 2010 5 | * Author: koutnij 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #ifndef FORWARDLAYER_H_ 12 | #define FORWARDLAYER_H_ 13 | 14 | struct ForwardLayerState { 15 | // current cell states 16 | std::vector ak; // neuron excitations 17 | std::vector bk; // neuron activations 18 | std::vector ek; // errors 19 | std::vector dk; // deltas 20 | }; 21 | 22 | class ForwardLayer 23 | { 24 | public: 25 | ForwardLayer(int nCells, int nOutputs, int nBlocks); 26 | void forwardPassStep(int t, std::vector& state, std::vector& b); 27 | // backwardPassStep(time, state, training vector) 28 | void backwardPassStep(int t, std::vector& state, std::vector& b, std::vector >& er); 29 | void setwK(std::vector >& newwK); 30 | void setConstantWeights(double w); 31 | void setRandomWeights(double halfRange); 32 | void updateWeights(double eta, double alpha); 33 | void resetDerivs(); 34 | 35 | void printWeights(); 36 | void getSerializedWeights(std::vector & w); 37 | void getSerializedDerivs(std::vector & w); 38 | void updateOutputError(std::vector& state, std::vector >& tr, std::vector >& er); 39 | ~ForwardLayer(); 40 | 41 | std::vector > wK; 42 | std::vector > wKd; // weight derivatives, updated through the backward pass 43 | std::vector > wKm; // weights after the previous training episode - for momentum 44 | 45 | std::vector biasK; // bias vector, biases are treated separately 46 | std::vector biasKd; 47 | std::vector biasKm; 48 | private: 49 | 50 | }; 51 | 52 | inline double fnO(double x) 53 | { 54 | return 1 / (1 + exp(-x)); 55 | //return x; 56 | } 57 | 58 | inline double fnOd(double x) 59 | { 60 | double ex = exp(x); 61 | return ex / ((1 + ex) * (1 + ex)); 62 | //return 1.; 63 | } 64 | 65 | #endif /* FORWARDLAYER_H_ */ 66 | -------------------------------------------------------------------------------- /usr_operators/Correlator/LstmLayer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LstmLayer.h 3 | * 4 | * Created on: Oct 27, 2010 5 | * Author: koutnij 6 | */ 7 | #include 8 | #include 9 | 10 | #include "LstmBlock.h" 11 | 12 | #ifndef LSTMLAYER_H_ 13 | #define LSTMLAYER_H_ 14 | 15 | class LstmLayer 16 | { 17 | 18 | public: 19 | LstmLayer(int nCells, int nInputs, int nOutputs, int nBlocks); 20 | void forwardPassStep(int t, std::vector >& state, std::vector >& x); 21 | void backwardPassStep(int t, std::vector >& state, std::vector< std::vector >& wK, 22 | std::vector& dk, std::vector >& x); 23 | void getBlockOutputs(int t, std::vector >& state, std::vector& b); 24 | void updateWeights(double eta, double alpha); 25 | void setConstantWeights(double w); 26 | void setRandomWeights(double halfRange); 27 | 28 | void resetDerivs(); 29 | 30 | void printWeights(); 31 | 32 | ~LstmLayer(); 33 | 34 | std::vector lstmBlock; // lstm blocks 35 | private: 36 | 37 | }; 38 | 39 | #endif /* LSTMLAYER_H_ */ 40 | -------------------------------------------------------------------------------- /usr_operators/Correlator/LstmNetwork.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LstmNetwork.h 3 | * 4 | * Created on: Oct 27, 2010 5 | * Author: koutnij 6 | */ 7 | 8 | #include 9 | 10 | #include "LstmBlock.h" 11 | #include "LstmLayer.h" 12 | #include "ForwardLayer.h" 13 | 14 | #ifndef LSTMNETWORK_H_ 15 | #define LSTMNETWORK_H_ 16 | 17 | class LstmNetwork 18 | { 19 | public: 20 | LstmNetwork(int nCells, int nInputs, int nOutputs, int nBlocks); 21 | void forwardPassStep(int t, std::vector >& lstmLayerState, 22 | std::vector& outputLayerState, std::vector >& x); 23 | void forwardPass(int t1, int t2, 24 | std::vector >& lstmLayerState, 25 | std::vector& outputLayerState, std::vector >& x); 26 | void backwardPassStep(int t, std::vector >& lstmLayerState, 27 | std::vector& outputLayerState, std::vector >& er, 28 | std::vector >& inputErrorBuffer, std::vector >& x); 29 | void backwardPass(int t1, int t2, 30 | std::vector >& lstmLayerState, 31 | std::vector& outputLayerState, std::vector >& er, 32 | std::vector >& inputErrorBuffer, std::vector >& x); 33 | void updateWeights(double eta, double alpha); 34 | void resetDerivs(); 35 | void setConstantWeights(double w); 36 | void setRandomWeights(double halfRange); 37 | 38 | void printWeights(); 39 | void printSerializedWeights(int lineLength); 40 | void printSerializedDerivs(int lineLength); 41 | void setSerializedWeights(std::vector& w); 42 | 43 | ~LstmNetwork(); 44 | 45 | LstmLayer* lstmLayer; 46 | ForwardLayer* outputLayer; 47 | 48 | private: 49 | 50 | }; 51 | 52 | #endif /* LSTMNETWORK_H_ */ 53 | -------------------------------------------------------------------------------- /usr_operators/Operators/operators.h: -------------------------------------------------------------------------------- 1 | // operators.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef operators_h 32 | #define operators_h 33 | 34 | #include // for Context 35 | #include // for uint16_t 36 | 37 | #include // for REPLICODE_EXPORT 38 | 39 | namespace r_comp { 40 | class Metadata; 41 | } // namespace r_comp 42 | 43 | extern "C" { 44 | bool REPLICODE_EXPORT add(const r_exec::Context &context, uint16_t &index); 45 | bool REPLICODE_EXPORT sub(const r_exec::Context &context, uint16_t &index); 46 | bool REPLICODE_EXPORT mul(const r_exec::Context &context, uint16_t &index); 47 | bool REPLICODE_EXPORT dis(const r_exec::Context &context, uint16_t &index); 48 | } 49 | 50 | class Operators 51 | { 52 | public: 53 | static void Init(r_comp::Metadata *metadata); 54 | }; 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /usr_operators/TestProgram/test_program.cpp: -------------------------------------------------------------------------------- 1 | // test_program.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "test_program.h" 32 | 33 | #include // for Atom 34 | #include // for Code 35 | #include // for ICPP_PGM_ARGS 36 | #include // for Controller 37 | #include // for uint16_t 38 | #include // for operator<<, basic_ostream, etc 39 | 40 | namespace r_exec { 41 | class View; 42 | } // namespace r_exec 43 | 44 | 45 | // Sample c++ user-defined program. 46 | class TestController: 47 | public r_exec::Controller 48 | { 49 | private: 50 | float arg1; 51 | bool arg2; 52 | public: 53 | TestController(r_code::View *icpp_pgm_view): r_exec::Controller(icpp_pgm_view) 54 | { 55 | // Load arguments here: one float and one Boolean. 56 | uint16_t arg_set_index = getObject()->code(ICPP_PGM_ARGS).asIndex(); 57 | uint16_t arg_count = getObject()->code(arg_set_index).getAtomCount(); 58 | 59 | if (arg_count != 2) { 60 | std::cerr << "test_program error: expected 2 arguments, got " << arg_count << std::endl; 61 | return; 62 | } 63 | 64 | arg1 = getObject()->code(arg_set_index + 1).asFloat(); 65 | arg2 = getObject()->code(arg_set_index + 2).asBoolean(); 66 | } 67 | 68 | ~TestController() 69 | { 70 | } 71 | 72 | Code *get_core_object() const override 73 | { 74 | return getObject()->get_reference(0); 75 | } 76 | 77 | void take_input(r_exec::View *input) override 78 | { 79 | // Inputs are all types of objects - salient or that have become salient depending on their view's sync member. 80 | // Manual filtering may be needed instead of pattern-matching. 81 | //input->object->trace(); 82 | } 83 | }; 84 | 85 | //////////////////////////////////////////////////////////////////////////////// 86 | 87 | r_exec::Controller *test_program(r_code::View *view) 88 | { 89 | return new TestController(view); 90 | } 91 | -------------------------------------------------------------------------------- /usr_operators/TestProgram/test_program.h: -------------------------------------------------------------------------------- 1 | // test_program.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef test_program_h 32 | #define test_program_h 33 | 34 | 35 | #include // for REPLICODE_EXPORT 36 | 37 | namespace r_code { 38 | class View; 39 | } // namespace r_code 40 | namespace r_exec { 41 | class Controller; 42 | } // namespace r_exec 43 | 44 | extern "C" { 45 | r_exec::Controller REPLICODE_EXPORT *test_program(r_code::View *view); 46 | } 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /usr_operators/auto_focus.cpp: -------------------------------------------------------------------------------- 1 | // auto_focus.cpp 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include "auto_focus.h" 32 | 33 | #include // for AutoFocusController 34 | 35 | namespace r_code { 36 | class View; 37 | } // namespace r_code 38 | namespace r_exec { 39 | class Controller; 40 | } // namespace r_exec 41 | 42 | 43 | r_exec::Controller *auto_focus(r_code::View *view) 44 | { 45 | return new r_exec::AutoFocusController(view); 46 | } 47 | -------------------------------------------------------------------------------- /usr_operators/auto_focus.h: -------------------------------------------------------------------------------- 1 | // auto_focus.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef auto_focus_proxy_h 32 | #define auto_focus_proxy_h 33 | 34 | 35 | #include // for REPLICODE_EXPORT 36 | 37 | namespace r_code { 38 | class View; 39 | } // namespace r_code 40 | namespace r_exec { 41 | class Controller; 42 | } // namespace r_exec 43 | 44 | extern "C" { 45 | r_exec::Controller REPLICODE_EXPORT *auto_focus(r_code::View *view); 46 | } 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /usr_operators/types.h: -------------------------------------------------------------------------------- 1 | // types.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef usr_operators_types_h 32 | #define usr_operators_types_h 33 | 34 | #include "../r_exec/operator.h" 35 | 36 | typedef bool (*Operator)(const r_exec::Context &, uint16_t &); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /usr_operators/usr_operators.h: -------------------------------------------------------------------------------- 1 | // usr_operators.h 2 | // 3 | // Author: Eric Nivel 4 | // 5 | // BSD license: 6 | // Copyright (c) 2010, Eric Nivel 7 | // All rights reserved. 8 | // Redistribution and use in source and binary forms, with or without 9 | // modification, are permitted provided that the following conditions are met: 10 | // 11 | // - Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // - Redistributions in binary form must reproduce the above copyright 14 | // notice, this list of conditions and the following disclaimer in the 15 | // documentation and/or other materials provided with the distribution. 16 | // - Neither the name of Eric Nivel nor the 17 | // names of their contributors may be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 21 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #ifndef usr_operators_h 32 | #define usr_operators_h 33 | 34 | 35 | #include // for uint16_t 36 | 37 | #include // for REPLICODE_EXPORT 38 | 39 | namespace r_comp { 40 | class Metadata; 41 | } // namespace r_comp 42 | 43 | extern "C" { 44 | void REPLICODE_EXPORT Init(r_comp::Metadata *metadata); // The metadata contains the opcodes 45 | 46 | // Operators ////////////////////////////////////////////////////////////////////////////// 47 | 48 | uint16_t REPLICODE_EXPORT GetOperatorCount(); 49 | void REPLICODE_EXPORT GetOperatorName(char *op_name, int op_index); 50 | 51 | // CPP Programs ////////////////////////////////////////////////////////////////////////////// 52 | 53 | uint16_t REPLICODE_EXPORT GetProgramCount(); 54 | void REPLICODE_EXPORT GetProgramName(char *pgm_name); 55 | 56 | // Callbacks ////////////////////////////////////////////////////////////////////////////// 57 | 58 | uint16_t REPLICODE_EXPORT GetCallbackCount(); 59 | void REPLICODE_EXPORT GetCallbackName(char *callback_name); 60 | } 61 | 62 | 63 | #endif 64 | --------------------------------------------------------------------------------