Skip to content

Commit

Permalink
[WIP] Huge numbers (#472)
Browse files Browse the repository at this point in the history
* Create test_huge_number.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in b91775b according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #472

* Update test_huge_number.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in bf8f6a3 according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #472

* Update test_huge_number.py

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.lex

Signed-off-by: Ian Hunter <[email protected]>

* Update vec.h

Signed-off-by: Ian Hunter <[email protected]>

* Update roll_parameters.h

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update vec.h

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update string_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update string_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update mocking.h

Signed-off-by: Ian Hunter <[email protected]>

* Update mocking.c

Signed-off-by: Ian Hunter <[email protected]>

* Update array_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update array_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.c

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.h

Signed-off-by: Ian Hunter <[email protected]>

* Update dice_frontend.c

Signed-off-by: Ian Hunter <[email protected]>

* Update dice_core.h

Signed-off-by: Ian Hunter <[email protected]>

* Update dice_core.c

Signed-off-by: Ian Hunter <[email protected]>

* Update vec.h

Signed-off-by: Ian Hunter <[email protected]>

* Update dice_frontend.c

Signed-off-by: Ian Hunter <[email protected]>

* Update vec.h

Signed-off-by: Ian Hunter <[email protected]>

* Update vec.h

Signed-off-by: Ian Hunter <[email protected]>

* Update dice_frontend.c

Signed-off-by: Ian Hunter <[email protected]>

* Update dice_frontend.c

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.lex

Signed-off-by: Ian Hunter <[email protected]>

* Update shared_header.h

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update array_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update array_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update dice_frontend.h

Signed-off-by: Ian Hunter <[email protected]>

* Update dice_frontend.c

Signed-off-by: Ian Hunter <[email protected]>

* Update roll_parameters.h

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update macros.c

Signed-off-by: Ian Hunter <[email protected]>

* Update conditionals.c

Signed-off-by: Ian Hunter <[email protected]>

* Update conditionals.h

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update conditionals.c

Signed-off-by: Ian Hunter <[email protected]>

* Update vector_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update conditionals.c

Signed-off-by: Ian Hunter <[email protected]>

* Update conditionals.h

Signed-off-by: Ian Hunter <[email protected]>

* replace pcg-basic with pcg-c

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update test_OS.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update test_core.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update test_language_bindings.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update test_packages.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update test_OS.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.c

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.c

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update test_language_bindings.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.c

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update lint_codeQL.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.c

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update test_OS.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update test_huge_number.py

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* Update test_troika.py

Signed-off-by: Ian Hunter <[email protected]>

* Update target.mk

Signed-off-by: Ian Hunter <[email protected]>

* remove union to another PR

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update conditionals.c

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice_core.c

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update __init__.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in 7365bee according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #472

* Update __init__.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in 346fe6d according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #472

* Update test_huge_number.py

Signed-off-by: Ian Hunter <[email protected]>

* Update test_huge_number.py

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update src/grammar/rolls/dice_core.c

Signed-off-by: Ian Hunter <[email protected]>

* Update src/grammar/rolls/dice_core.c

Signed-off-by: Ian Hunter <[email protected]>

* Update test_huge_number.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in 85e22cf according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #472

* Update test_huge_number.py

Signed-off-by: Ian Hunter <[email protected]>

* Update __init__.py

Signed-off-by: Ian Hunter <[email protected]>

* style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Yapf

This commit fixes the style issues introduced in 598b67c according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: #472

* Update randomness.c

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.c

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.h

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.c

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.c

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.h

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.c

Signed-off-by: Ian Hunter <[email protected]>

* Update randomness.h

Signed-off-by: Ian Hunter <[email protected]>

* Update test_huge_number.py

Signed-off-by: Ian Hunter <[email protected]>

---------

Signed-off-by: Ian Hunter <[email protected]>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Ian Hunter <[email protected]>
  • Loading branch information
3 people authored Mar 29, 2024
1 parent 6f7d9ae commit b5949f1
Show file tree
Hide file tree
Showing 41 changed files with 683 additions and 497 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/lint_codeQL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: true

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test_OS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
with:
python-version: '3.x'
- uses: actions/checkout@v3
with:
submodules: true
- name: Install dependencies
run: |
python -m pip install -r reqs/requirements.txt
Expand Down Expand Up @@ -49,6 +51,8 @@ jobs:
python3.10-venv

- uses: actions/checkout@v3
with:
submodules: true
- name: test
shell: wsl-bash {0}
run: |
Expand All @@ -59,6 +63,8 @@ jobs:
runs-on: macos-12
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Build
run: make all
- name: Test
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v3
with:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/test_language_bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: make
run: |
make cpp
Expand All @@ -49,6 +51,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: prereqs
# https://linuxize.com/post/how-to-install-mono-on-ubuntu-20-04/
run: |
Expand All @@ -68,6 +72,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: go install
run: sudo apt install golang-go
- name: make go
Expand All @@ -80,6 +86,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: dep install
run: |
sudo apt update
Expand All @@ -98,6 +106,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: java dependencies
run: |
sudo apt-get update
Expand All @@ -113,6 +123,8 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1
with:
Expand Down Expand Up @@ -149,6 +161,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: julia install
run: |
wget https://julialang-s3.julialang.org/bin/linux/x64/1.8/julia-1.8.2-linux-x86_64.tar.gz
Expand All @@ -158,12 +172,15 @@ jobs:
- name: make julia
run: |
PATH="$PATH:$PWD/julia-1.8.2/bin" make julia
test_lua:
name: "Test: Lua"
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: lua install
run: |
sudo apt install luajit
Expand All @@ -176,6 +193,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: perl install
run: |
sudo apt install perl
Expand All @@ -190,6 +209,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: r-lib/actions/setup-r@v2
- name: make r
run: make r
Expand All @@ -199,6 +220,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: ruby install
run: |
sudo apt install ruby-full
Expand All @@ -210,6 +233,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -226,6 +251,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Setup Rust
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v3
with:
Expand Down Expand Up @@ -50,6 +52,8 @@ jobs:
runs-on: macos-12
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Build
run: make all
- name: Test
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/grammar/external/pcg-c"]
path = src/grammar/external/pcg-c
url = https://github.com/imneme/pcg-c.git
34 changes: 21 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
CODEDIRS=./src/grammar ./src/grammar/rolls ./src/grammar/util ./src/grammar/operations ./src/grammar/external
INCDIRS=./src/grammar
INCDIRS=./src/grammar ./src/grammar/external/pcg-c/include

CC=cc
PCG_SRC=./src/grammar/external/pcg-c/src

$(info CC is $(CC))

ifeq ($(CC),g++)
STANDARD= -std=c++11
else ifeq ($(CC),clang++)
STANDARD= -std=c++11
else ifeq ($(filter $(CC),gcc cc),gcc cc)
STANDARD= -std=c99
else
STANDARD= -std=c99
endif
Expand All @@ -25,8 +29,8 @@ ifneq ($(shell uname -s), Darwin)
OPT := $(OPT) -Wl,-z,nodlopen -Wl,-z,noexecstack \
-Wl,-z,relro
endif
# -ffast-math # Problematic for Python

# -ffast-math # Problematic for Python

# YACC/LEX fails for the following, so disabled:
# -Wswitch-default -Wstrict-overflow=5
Expand Down Expand Up @@ -91,16 +95,16 @@ ifeq ($(LEX_FALLBACK), 1)
LEXER:=lex
else
#$(shell echo USING FLEX)
LEXER:=flex -f -Ca -Ce -Cr
LEXER:=flex -f -Ca -Ce -Cr
endif

# add flags and the include paths
DEFS=-DUSE_SECURE_RANDOM=${USE_SECURE_RANDOM} -DJUST_YACC=${YACC_FALLBACK} -DUSE_CLT=${USE_CLT}

CFLAGS=$(foreach D,$(INCDIRS),-I$(D)) $(OPT) $(DEFS)
CFLAGS=$(foreach D,$(INCDIRS),-I$(D)) $(OPT) $(DEFS)

# add flags to build for shared library and add include paths
SHAREDCFLAGS=-fPIC -c $(foreach D,$(INCDIRS),-I$(D)) $(ARC4RANDOM) $(DEFS)
SHAREDCFLAGS=-fPIC -c $(foreach D,$(INCDIRS),-I$(D)) $(ARC4RANDOM) $(DEFS)

# generate list of c files and remove y.tab.c from src/grammar directory
CFILES=$(foreach D,$(CODEDIRS),$(wildcard $(D)/*.c)) build/lex.yy.c build/y.tab.c
Expand All @@ -127,7 +131,7 @@ install: all
yacc:
mkdir -p build
$(foreach BD,$(CFILE_SUBDIRS),mkdir -p build/$(BD))
$(PARSER) -d src/grammar/dice.yacc $(PARSER_DEBUG)
$(PARSER) -d src/grammar/dice.yacc $(PARSER_DEBUG)
mv y.tab.c build/y.tab.c
mv y.tab.h build/y.tab.h
mv y.output build/y.output | true # Only present with verbose
Expand All @@ -136,29 +140,33 @@ lex:
mv lex.yy.c build/lex.yy.c

# Executable
compile:
compile: pcg
# FLEX creates warning when run with -f
# MacOS creates warnings for signs.
$(CC) $(CFLAGS) $(CFILES) $(ARC4RANDOM) \
-Wno-error=implicit-function-declaration \
-Wno-sign-conversion -Wno-sign-compare -lm \
-Wno-implicit-int-conversion
-Wno-implicit-int-conversion -lpcg_random -L$(PCG_SRC) \
-Wno-undef -Wno-conversion # For pcg-c

# PCG Submodule
pcg:
make -C src/grammar/external/pcg-c all

# Shared Lib
shared: $(OBJECTS)
$(CC) -shared -o build/dice.so $^ $(ARC4RANDOM) -lm
$(CC) -shared -o build/dice.so $^ $(ARC4RANDOM) -lm -lpcg_random -L$(PCG_SRC)
cp build/dice.so build/libdice.so
# Linux
mv ./a.out build/dice | true
# Windows
mv ./a.exe build/dice | true

# hardcode for lex and yacc files
build/y.tab.o:
build/y.tab.o:
$(CC) $(SHAREDCFLAGS) -c build/y.tab.c -o $@
build/lex.yy.o:
$(CC) $(SHAREDCFLAGS) -c build/lex.yy.c -o $@
$(CC) $(SHAREDCFLAGS) -c build/lex.yy.c -o $@

# Wildcard everything else
build/*/%.o:src/grammar/*/%.c
Expand Down
2 changes: 1 addition & 1 deletion src/R/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

r: clean yacc lex compile $(OBJECTS)
mkdir -p build/r/
$(CC) -shared -o build/r/dice.so $(OBJECTS) $(ARC4RANDOM) -lR
$(CC) -shared -o build/r/dice.so $(OBJECTS) $(ARC4RANDOM) -lR -lpcg_random -L$(PCG_SRC)
Rscript src/R/main.r
6 changes: 3 additions & 3 deletions src/grammar/constructs/roll_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include "constructs/dice_enums.h"

typedef struct roll_params {
unsigned int number_of_dice;
unsigned int die_sides;
unsigned long long number_of_dice;
unsigned long long die_sides;
EXPLOSION_TYPE explode;
char** symbol_pool;
int start_value;
long long start_value;
DIE_TYPE dtype;
} roll_params;

Expand Down
6 changes: 4 additions & 2 deletions src/grammar/constructs/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

typedef struct vec {
DIE_TYPE dtype;

union { // Vectors can only contain one dice type
int* content;
long long* content;
char** symbols;
} storage;
unsigned int length;
unsigned long long length;

roll_params source;
bool has_source;
} vec;
Expand Down
Loading

0 comments on commit b5949f1

Please sign in to comment.