Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes from portability branch #221

Open
wants to merge 94 commits into
base: cpp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
ecd9daf
Update: removal of network-related code to not depend on POSIX networ…
patham9 Sep 9, 2022
46dd91e
Merge branch 'master' into portability
patham9 Sep 12, 2022
64cf60c
Merge branch 'cpp' into portability
patham9 Sep 27, 2022
428d0e4
Update: update from cpp branch
patham9 Nov 3, 2022
5647fcc
Update: portability improvements
patham9 Nov 3, 2022
0f51738
Update: removal of unistd include
patham9 Nov 3, 2022
cdfcb66
Merge branch 'cpp' into portability
patham9 Nov 4, 2022
1182d08
Update: build scripts separated
patham9 Nov 4, 2022
70d6943
Update: increased stack size for ReactOS build
patham9 Nov 4, 2022
0ca1ea1
Merge branch 'cpp' into portability
patham9 Nov 23, 2022
919521d
Merge branch 'cpp' into portability
patham9 Nov 23, 2022
8d00400
Merge branch 'cpp' into portability
patham9 Dec 9, 2022
3e0606a
Update: build_ipad.sh: Ipad build script using wasm
patham9 Dec 13, 2022
7079ee4
Merge branch 'cpp' into portability
patham9 Jun 13, 2023
e6d2207
Merge branch 'cpp' into portability
patham9 Jul 31, 2023
4d8e3d6
Merge branch 'cpp' into portability
patham9 Sep 21, 2023
8fc0fcd
Update: merge conflict resolved
patham9 Nov 9, 2023
d693beb
Update: for browser build, always run shell
patham9 Nov 12, 2023
37d32c7
Update: build script for browser
patham9 Nov 12, 2023
cfddd29
Update: stack size needs to be greater to not cause issues with emscr…
patham9 Nov 13, 2023
c3b4268
Update: added Shell.html which accepts URL args
patham9 Nov 13, 2023
6021152
Update: get rid of the convoluted emscripten shell, replace with sane…
patham9 Nov 13, 2023
305c8a0
Update: log to console and skip POSIX clear
patham9 Nov 13, 2023
1829670
Update: support animated examples
patham9 Nov 13, 2023
de16848
Update: replace ansi escapes as suggested by ChatGPT
patham9 Nov 13, 2023
ffa60ef
Update: title update:
patham9 Nov 13, 2023
e1e8578
Update: export relevant functions so they can be used by the browser
patham9 Nov 15, 2023
a696cbb
Update: export the shell init and input instead so commands are also …
patham9 Nov 15, 2023
ce3860c
Update: export the shell init and input instead so commands are also …
patham9 Nov 15, 2023
fd80a78
Update: interactive shell
patham9 Nov 15, 2023
e5e2f3b
Update: also main exported
patham9 Nov 15, 2023
b174c2b
Update: also main exported
patham9 Nov 15, 2023
c1cd356
Update: browser GUI added
patham9 Nov 15, 2023
e10c6a3
Update: avoid scroll to top, this is expensive for the browser
patham9 Nov 15, 2023
c4c8a76
Update: do not print stdout
patham9 Nov 15, 2023
a00421b
Update: only 20 textrows
patham9 Nov 15, 2023
e543a46
Update: export malloc too
patham9 Nov 15, 2023
d875030
Update: GUI fix
patham9 Nov 15, 2023
6d57c1c
Merge branch 'cpp' into portability
patham9 Nov 16, 2023
e1e951c
Update: merged cpp branch
patham9 Dec 5, 2023
2a2ff9a
Merge branch 'cpp' into portability
patham9 Dec 6, 2023
479a7d3
Merge branch 'cpp' into portability
patham9 Dec 6, 2023
d2159ed
Merge branch 'cpp' into portability
patham9 Dec 7, 2023
30ab968
Merge branch 'cpp' into portability
patham9 Dec 7, 2023
71fef8c
Merge branch 'cpp' into portability
patham9 Dec 8, 2023
0400136
Merge branch 'cpp' into portability
patham9 Dec 8, 2023
4a26340
Merge branch 'cpp' into portability
patham9 Dec 8, 2023
119d4a9
Merge branch 'cpp' into portability
patham9 Dec 8, 2023
a9b659d
Merge branch 'cpp' into portability
patham9 Dec 9, 2023
95ae461
Merge branch 'cpp' into portability
patham9 Dec 9, 2023
45ef665
Merge branch 'cpp' into portability
patham9 Dec 10, 2023
0bbab70
Merge branch 'cpp' into portability
patham9 Dec 10, 2023
310fcb0
Merge branch 'cpp' into portability
patham9 Jan 14, 2024
402130c
Merge branch 'cpp' into portability
patham9 Jan 14, 2024
502065c
Merge branch 'cpp' into portability
patham9 Jan 14, 2024
c1363a0
Update: added the missing introduction of variables for functional eq…
patham9 Jan 16, 2024
20f74be
Merge branch 'cpp' into portability
patham9 Jun 25, 2024
ead97e2
Merge branch 'cpp' into portability
patham9 Jul 16, 2024
c6c64b8
Merge branch 'cpp' into portability
patham9 Aug 13, 2024
000b42b
Merge branch 'cpp' into portability
patham9 Aug 15, 2024
f225d64
Merge branch 'cpp' into portability
patham9 Aug 23, 2024
7fbc64d
Merge branch 'cpp' into portability
patham9 Aug 27, 2024
2d2e7f7
Merge branch 'cpp' into portability
patham9 Aug 30, 2024
bb94d2d
Merge branch 'cpp' into portability
patham9 Aug 30, 2024
6ca8e08
Merge branch 'cpp' into portability
patham9 Aug 30, 2024
2fa4d68
Merge branch 'cpp' into portability
patham9 Sep 5, 2024
ce79633
Update: comparative relations from discrete spaces compatible with co…
patham9 Sep 5, 2024
d2b8fb2
Merge branch 'cpp' into portability
patham9 Sep 5, 2024
cb08a89
Merge branch 'cpp' into portability
patham9 Sep 6, 2024
0a2c200
Merge branch 'cpp' into portability
patham9 Sep 16, 2024
ede6494
Merge branch 'cpp' into portability
patham9 Sep 17, 2024
8686578
Merge branch 'cpp' into portability
patham9 Sep 17, 2024
f961dfb
Update: conflict fix
patham9 Sep 18, 2024
479c626
Merge branch 'cpp' into portability
patham9 Sep 19, 2024
e33c032
Update: build script update:
patham9 Sep 20, 2024
7a7a306
Merge branch 'cpp' into portability
patham9 Sep 20, 2024
06c3fc6
Merge branch 'cpp' into portability
patham9 Sep 21, 2024
e48fbf7
Merge branch 'cpp' into portability
patham9 Sep 25, 2024
8ed37c4
Merge branch 'cpp' into portability
patham9 Sep 27, 2024
b9e5938
Merge branch 'cpp' into portability
patham9 Sep 28, 2024
0150939
Create: Added build. cmd for compilation on Windows
ARCJ137442 Sep 29, 2024
d84caed
Update: build.cmd: now delete `.\NAR.exe` not `.\NAR`
ARCJ137442 Sep 29, 2024
b12bcb4
Merge branch 'cpp' into portability
patham9 Oct 1, 2024
3522b44
Merge branch 'cpp' into portability
patham9 Oct 3, 2024
8fcd7a1
Merge branch 'cpp' into portability
patham9 Oct 9, 2024
c2f90eb
Merge branch 'cpp' into portability
patham9 Oct 14, 2024
8ac316a
Merge branch 'cpp' into portability
patham9 Oct 14, 2024
f78c7bd
Merge branch 'cpp' into portability
patham9 Oct 14, 2024
623bbef
Merge branch 'cpp' into portability
patham9 Oct 15, 2024
1b0098f
Merge branch 'cpp' into portability
patham9 Oct 16, 2024
8c21aef
Merge branch 'cpp' into portability
patham9 Oct 16, 2024
7fe6ae7
Merge branch 'cpp' into portability
patham9 Oct 16, 2024
7c1e964
Merge branch 'cpp' into portability
patham9 Oct 16, 2024
88fdc8b
Merge pull request #285 from ARCJ137442/feature-compilation-on-Windows
patham9 Jan 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions GUI.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<title>OpenNARS for Applications: Shell</title>
</head>
<body>
<textarea style="width: 100%" rows=10 id="input"></textarea>
<button onclick="handleClick()">Send</button>
<textarea style="width: 100%" rows=20 id="output"></textarea>
<script>
var input = document.getElementById('input');
var output = document.getElementById('output');
function print(text)
{
output.value += text + "\n";
output.scrollTop = output.scrollHeight; // focus on bottom
}
var Module = {
arguments: ['nothing'],
'print': function(text) { print(text) },
'printErr': function(text) { print(text) },
};
</script>
<script src="NAR.js"></script>
<script>
function NAR_AddInput(narsese)
{
charptr = stringToNewUTF8(narsese)
Module._Shell_ProcessInput(charptr);
Module._free(charptr);
}
function NAR_INIT()
{
Module._Shell_NARInit();
}
initialized = false;
function handleClick()
{
if(!initialized)
{
initialized = true;
NAR_INIT()
}
var inputs = input.value.split("\n");
var i=0;
while(i<inputs.length)
{
console.log(inputs[i]);
if(inputs[i] != "")
{
NAR_AddInput(inputs[i]+"\n");
}
i++;
}
input.value = "";
}
</script>
</body>
</html>
52 changes: 52 additions & 0 deletions Shell.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html>
<head>
<title>OpenNARS for Applications</title>
</head>
<body>
<textarea id="output" rows="30" style="width: 100%"></textarea>
<script>
//the prior textarea element where the final output will show up
var element = document.getElementById('output');
var writeindex = 0;
var readindex = -1;
var framearray = [];
var frame = ""
function outputProcess(text)
{
if(text.includes("\033[1;1H\033[2J"))
{
framearray[writeindex++] = frame;
frame = "";
}
text = text.replace("\033[1;1H\033[2J","")
const ansiEscape = /\x1B\[\d+(;\d+)*m/g;
text = text.replace(ansiEscape, '');
console.log(text);
frame += text + "\n";
element.value += text + "\n";
readindex = 0;
}
//which parameter to pass to ONA
function getParams()
{
if(window.location.search == "")
{
return [];
}
return window.location.search.substring(1).split("&");
}
var Module = {
arguments: getParams(),
'print': function(text) { outputProcess(text); },
'printErr': function(text) { outputProcess(text) },
};
var interval = setInterval(function(){
if(readindex != -1 && readindex < framearray.length){
element.value = framearray[readindex++];
}
}, 50)
</script>
<script src="NAR.js"></script>
</body>
</html>
57 changes: 57 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@echo off
setlocal enabledelayedexpansion

:: delete NAR and src\RuleTable.c
del .\NAR.exe
del .\src\RuleTable.c

:: setup error handling
set ERRORLEVEL=0

:: get all .c file path
for /r "src" %%f in (*.c) do (
set "Str=!Str! %%f"
)

:: print all .c file path and notify user the compilation is started
echo !Str!
echo Compilation started:

:: setup compiler parameters of gcc
set BaseFlags=-flto -g -pthread -lpthread -D_POSIX_C_SOURCE=199506L -pedantic -std=c99 -g3 -O3 !Str! -lm -oNAR

:: mute the output of compiler warnings
set NoWarn=-Wno-unknown-pragmas -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-variable -Wno-strict-prototypes -Wno-implicit-function-declaration -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast

:: 1st stage compilation
gcc %* -DSTAGE=1 -Wall -Wextra -Wformat-security %NoWarn% %BaseFlags%

:: check if compilation was successful
if %ERRORLEVEL% neq 0 (
echo Error during first stage compilation.
goto :eof
)

:: notify user that 1st stage is done, and start generating RuleTable.c
echo First stage done, generating RuleTable.c now, and finishing compilation.

:: generate RuleTable.c uses 1st stage binary
call NAR.exe NAL_GenerateRuleTable > src\RuleTable.c

:: try second stage compilation with SSE flag
gcc %* -mfpmath=sse -msse2 -DSTAGE=2 %NoWarn% %BaseFlags% src\RuleTable.c
if %ERRORLEVEL% equ 0 (
echo Done.
) else (
echo Error with SSE, hence compiling without SSE:
:: if error, try compilation without SSE:
gcc %* -DSTAGE=2 %NoWarn% %BaseFlags% src\RuleTable.c
if %ERRORLEVEL% equ 0 (
echo Done.
) else (
echo Compilation failed.
)
)

:end
endlocal
10 changes: 5 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
rm NAR
rm src/RuleTable.c
set -e
Str=`ls src/*.c src/NetworkNAR/*.c | xargs`
Str=`ls src/*.c | xargs`
echo $Str
echo "Compilation started:"
BaseFlags="-flto -g -pthread -lpthread -D_POSIX_C_SOURCE=199506L -std=c++17 -g3 -O3 $Str -lm -oNAR"
NoWarn="-Wno-unknown-pragmas -Wno-tautological-compare -Wno-dollar-in-identifier-extension -Wno-unused-parameter -Wno-unused-variable -Wno-write-strings -Wno-missing-field-initializers -Wno-narrowing -Wno-strict-prototypes -Wno-c++20-compat -Wno-missing-braces"
g++ $@ -DSTAGE=1 -Wall -Wextra -Wformat-security $NoWarn $BaseFlags
BaseFlags="-flto -g -D_POSIX_C_SOURCE=199506L -pedantic -std=c99 -g3 -O3 $Str -lm -oNAR"
NoWarn="-Wno-unknown-pragmas -Wno-tautological-compare -Wno-dollar-in-identifier-extension -Wno-unused-parameter -Wno-unused-variable -Wno-strict-prototypes"
gcc $@ -DSTAGE=1 -Wall -Wextra -Wformat-security $NoWarn $BaseFlags
echo "First stage done, generating RuleTable.c now, and finishing compilation."
./NAR NAL_GenerateRuleTable > ./src/RuleTable.c
g++ $@ -mfpmath=sse -msse2 -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c || (echo "Error with SSE, hence compiling without SSE:" && g++ $@ -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c)
gcc $@ -mfpmath=sse -msse2 -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c || (echo "Error with SSE, hence compiling without SSE:" && gcc $@ -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c)
echo "Done."
9 changes: 9 additions & 0 deletions build_ReactOS.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set Str=src/Cycle.c src/Decision.c src/Event.c src/Globals.c src/HashTable.c src/Inference.c src/InvertedAtomIndex.c src/main.c src/Memory.c src/NAL.c src/NAR.c src/Narsese.c src/PriorityQueue.c src/Shell.c src/Stack.c src/Stamp.c src/Stats.c src/Table.c src/Term.c src/Truth.c src/Usage.c src/Variable.c
echo %Str%
echo "Compilation started:"
set NoWarn=-Wno-unknown-pragmas -Wno-tautological-compare -Wno-dollar-in-identifier-extension -Wno-unused-parameter -Wno-unused-variable -Wno-write-strings -Wno-missing-field-initializers -Wno-narrowing
C:/tcc/tcc -DSTAGE=1 -Wall -Wextra -Wformat-security %NoWarn% %Str% -oNAR.exe
echo "First stage done, generating RuleTable.c now, and finishing compilation."
NAR NAL_GenerateRuleTable > src/RuleTable.c
C:/tcc/tcc -Wl,--stack,4194304 -DSTAGE=2 %Str% src/RuleTable.c -oNAR.exe
echo "Done."
17 changes: 17 additions & 0 deletions build_browser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
rm NAR
rm src/RuleTable.c
set -e
Str=`ls src/*.c | xargs`
echo $Str
echo "Compilation started:"
BaseFlags="-g -D_POSIX_C_SOURCE=199506L -pedantic -std=c99 -g3 -O3 $Str -lm -oNAR"
NoWarn="-Wno-unknown-pragmas -Wno-tautological-compare -Wno-dollar-in-identifier-extension -Wno-unused-parameter -Wno-unused-variable -Wno-strict-prototypes"
gcc $@ -DSTAGE=1 -Wall -Wextra -Wformat-security $NoWarn $BaseFlags
echo "First stage done, generating RuleTable.c now, and finishing compilation."
./NAR NAL_GenerateRuleTable > ./src/RuleTable.c
export WASI_SDK_PATH=/home/tc/wasi-sdk
CC="${WASI_SDK_PATH}/bin/clang --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot"
BaseFlags="-g -D_POSIX_C_SOURCE=199506L -pedantic -std=c99 -g3 -O3 $Str -lm -oNAR.html"
emcc $@ -sEXPORTED_FUNCTIONS=_malloc,_main,_Shell_NARInit,_Shell_ProcessInput,_free -sEXPORTED_RUNTIME_METHODS=stringToNewUTF8 -sSTACK_SIZE=10485760 -DSTAGE=2 $NoWarn $BaseFlags -s TOTAL_MEMORY=900mb src/RuleTable.c
echo "Done."
14 changes: 14 additions & 0 deletions build_cpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
rm NAR
rm src/RuleTable.c
set -e
Str=`ls src/*.c src/NetworkNAR/*.c | xargs`
echo $Str
echo "Compilation started:"
BaseFlags="-flto -g -pthread -lpthread -D_POSIX_C_SOURCE=199506L -std=c++17 -g3 -O3 $Str -lm -oNAR"
NoWarn="-Wno-unknown-pragmas -Wno-tautological-compare -Wno-dollar-in-identifier-extension -Wno-unused-parameter -Wno-unused-variable -Wno-write-strings -Wno-missing-field-initializers -Wno-narrowing -Wno-strict-prototypes -Wno-c++20-compat -Wno-missing-braces"
g++ $@ -DSTAGE=1 -Wall -Wextra -Wformat-security $NoWarn $BaseFlags
echo "First stage done, generating RuleTable.c now, and finishing compilation."
./NAR NAL_GenerateRuleTable > ./src/RuleTable.c
g++ $@ -mfpmath=sse -msse2 -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c || (echo "Error with SSE, hence compiling without SSE:" && g++ $@ -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c)
echo "Done."
17 changes: 17 additions & 0 deletions build_ipad.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
rm NAR
rm src/RuleTable.c
set -e
Str=`ls src/*.c | xargs`
echo $Str
echo "Compilation started:"
BaseFlags="-g -D_POSIX_C_SOURCE=199506L -pedantic -std=c99 -g3 -O3 $Str -lm -oNAR"
NoWarn="-Wno-unknown-pragmas -Wno-tautological-compare -Wno-dollar-in-identifier-extension -Wno-unused-parameter -Wno-unused-variable -Wno-strict-prototypes"
gcc $@ -DSTAGE=1 -Wall -Wextra -Wformat-security $NoWarn $BaseFlags
echo "First stage done, generating RuleTable.c now, and finishing compilation."
./NAR NAL_GenerateRuleTable > ./src/RuleTable.c
export WASI_SDK_PATH=/home/tc/wasi-sdk
CC="${WASI_SDK_PATH}/bin/clang --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot"
BaseFlags="-g -D_POSIX_C_SOURCE=199506L -pedantic -std=c99 -g3 -O3 $Str -lm -oNAR.wasm"
/home/tc/wasi-sdk/build/install/opt/bin/clang $@ -DSTAGE=2 $NoWarn $BaseFlags src/RuleTable.c
echo "Done."
1 change: 0 additions & 1 deletion src/Cycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,6 @@ void Cycle_RelativeForgetting(long currentTime)

void Cycle_Perform(long currentTime)
{
Metric_send("NARNode.Cycle", 1);
//1a. Retrieve BELIEF_EVENT_SELECTIONS events from cyclings events priority queue (which includes both input and derivations)
Cycle_PopEvents(selectedBeliefs, selectedBeliefsPriority, &beliefsSelectedCnt, &cycling_belief_events, BELIEF_EVENT_SELECTIONS);
//2a. Process incoming belief events from FIFO, building implications utilizing input sequences
Expand Down
1 change: 0 additions & 1 deletion src/Cycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "RuleTable.h"
#include "Variable.h"
#include "Stats.h"
#include "./NetworkNAR/Metric.h"

//Methods//
//-------//
Expand Down
5 changes: 5 additions & 0 deletions src/Globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ void mysrand(unsigned int seed)
{
next = seed;
}

double mylog2(double n)
{
return log(n) / log(2);
}
7 changes: 6 additions & 1 deletion src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
//////////////
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <ctype.h>
#include <math.h>

//Macros//
//////////
Expand Down Expand Up @@ -73,5 +74,9 @@ void mysrand(unsigned int seed);
//Stringification macro:
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
double mylog2(double n);
#ifndef log2
#define log2 mylog2
#endif

#endif
53 changes: 0 additions & 53 deletions src/NetworkNAR/Metric.c

This file was deleted.

Loading