Skip to content

Commit

Permalink
Добавил нумерацию версий для релизов и вывод описания синтаксиса в REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
rsashka committed Jun 24, 2022
1 parent 1ac104a commit e8e53b0
Show file tree
Hide file tree
Showing 15 changed files with 259 additions and 44 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ contrib/*
**/DartConfiguration.tcl
Makefile

core/syntax_help.cpp
core/version.*
docs/syntax.txt


# Binaries
*.7z
*.dmg
Expand Down Expand Up @@ -328,4 +333,4 @@ dmypy.json
.pytype/

# Cython debug symbols
cython_debug/
cython_debug/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "contrib/libffi"]
path = contrib/libffi
url = https://github.com/libffi/libffi.git
[submodule "contrib/text2cpp"]
path = contrib/text2cpp
url = https://github.com/lostjared/text2cpp.git
2 changes: 1 addition & 1 deletion contrib/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ cd libffi
./configure --prefix=`pwd`/output
make
make install
cd ..
cd ..
1 change: 1 addition & 0 deletions contrib/text2cpp
Submodule text2cpp added at 51940c
82 changes: 82 additions & 0 deletions core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,94 @@ CP=cp
CCADMIN=CCadmin


VERSION_MAJOR=0
VERSION_MINOR=1
VERSION_PATCH=0
VERSION_HEADER="version.h"
VERSION_FILE="version.c"


GIT_TAG_VERSION=$(shell git describe --abbrev=0 --tags)
GIT_SHORT_HASH=$(shell git rev-parse --short HEAD)
GIT_SOURCE_ID=$(GIT_TAG_VERSION)-$(GIT_SHORT_HASH)
DATE_BUILD=$(shell date +'%y.%m.%d %H:%M:%S')

# build
build: .build-post

.build-pre:
# Add your pre 'build' code here...

@if [ ! -d "temp" ]; then \
@mkdir temp; \
fi
pandoc -t plain ../docs/syntax.md > ../docs/syntax.txt
../contrib/text2cpp/output/bin/text2cpp ../docs/syntax.txt syntax_help.cpp newlang_syntax_help c


@if [ "$(GIT_TAG_VERSION)" != "v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)" ]; then \
echo "Git TAG $(GIT_TAG_VERSION) differ version v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)"; \
exit 1; \
fi
@if [ -z $(GIT_SHORT_HASH) ]; then \
echo Undefined version for build; \
exit 1; \
fi
@if [ -f $(VERSION_HEADER) ]; then \
rm $(VERSION_HEADER); \
fi

@echo "/** @file $(VERSION_HEADER)" > $(VERSION_HEADER)
@echo "* Auto generate file for identification current build" >> $(VERSION_HEADER)
@echo "* Date build $(DATE_BUILD)" >> $(VERSION_HEADER)
@echo "*/" >> $(VERSION_HEADER)
@echo "" >> $(VERSION_HEADER)

@echo "#include <stdint.h>" >> $(VERSION_HEADER)

@echo "extern const uint8_t VERSION_MAJOR;" >> $(VERSION_HEADER)
@echo "extern const uint8_t VERSION_MINOR;" >> $(VERSION_HEADER)
@echo "extern const uint8_t VERSION_PATCH;" >> $(VERSION_HEADER)
@echo "extern const uint16_t VERSION_BUILD;" >> $(VERSION_HEADER)
@echo "" >> $(VERSION_HEADER)

@echo "#define VERSION ($(VERSION_MAJOR) << 4 | $(VERSION_MINOR))" >> $(VERSION_HEADER)
@echo "#define VERSION_GIT_SOURCE \"$(GIT_SOURCE_ID)\"" >> $(VERSION_HEADER)
@echo "#define VERSION_DATE_BUILD_STR \"$(DATE_BUILD)\"" >> $(VERSION_HEADER)
@echo "#define VERSION_SOURCE_FULL_ID \"$(GIT_SOURCE_ID) $(DATE_BUILD)\"" >> $(VERSION_HEADER)
@echo "" >> $(VERSION_HEADER)

@echo "extern const char * GIT_SOURCE;" >> $(VERSION_HEADER)
@echo "extern const char * DATE_BUILD_STR;" >> $(VERSION_HEADER)
@echo "extern const char * SOURCE_FULL_ID; " >> $(VERSION_HEADER)
@echo "" >> $(VERSION_HEADER)

@if [ -f $(VERSION_FILE) ]; then \
rm $(VERSION_FILE); \
fi

@echo "/** @file $(VERSION_FILE)" > $(VERSION_FILE)
@echo "* Auto generate file for identification current build" >> $(VERSION_FILE)
@echo "* Date build $(DATE_BUILD)" >> $(VERSION_FILE)
@echo "*/" >> $(VERSION_FILE)
@echo "" >> $(VERSION_FILE)

@echo "#include <stdint.h>" >> $(VERSION_FILE)
@echo "#include <core/version.h>" >> $(VERSION_FILE)
@echo "" >> $(VERSION_FILE)

@echo "const uint8_t VERSION_MAJOR=$(VERSION_MAJOR);" >> $(VERSION_FILE)
@echo "const uint8_t VERSION_MINOR=$(VERSION_MINOR);" >> $(VERSION_FILE)
@echo "const uint8_t VERSION_PATCH=$(VERSION_PATCH);" >> $(VERSION_FILE)
@echo "" >> $(VERSION_FILE)

@echo "const char * GIT_SOURCE = VERSION_GIT_SOURCE;" >> $(VERSION_FILE)
@echo "const char * DATE_BUILD_STR = VERSION_DATE_BUILD_STR;" >> $(VERSION_FILE)
@echo "const char * SOURCE_FULL_ID = VERSION_SOURCE_FULL_ID;" >> $(VERSION_FILE)
@echo "" >> $(VERSION_FILE)

@echo Mark version $(GIT_SOURCE_ID) $(DATE_BUILD)


.build-post: .build-impl
# Add your post 'build' code here...
Expand Down
44 changes: 25 additions & 19 deletions core/builtin.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "pch.h"

#include <core/syntax_help.cpp>

#include <core/builtin.h>
#include <core/newlang.h>

Expand All @@ -11,99 +13,103 @@ using namespace newlang;
namespace newlang {

NEWLANG_TRANSPARENT(min) {
if(in.size() < 2) {
if (in.size() < 2) {
LOG_RUNTIME("Empty argument list parameter!");
}
ObjPtr out = in.at(1).second;
for (size_t i = 2; i < in.size(); i++) {
if(*in.at(i).second < out) {
if (*in.at(i).second < out) {
out = in.at(i).second;
}
}
return out;
}

NEWLANG_TRANSPARENT(max) {
if(in.size() < 2) {
if (in.size() < 2) {
LOG_RUNTIME("Empty argument list parameter!");
}
ObjPtr out = in.at(1).second;
for (size_t i = 2; i < in.size(); i++) {
if(*in.at(i).second > out) {
if (*in.at(i).second > out) {
out = in.at(i).second;
}
}
return out;
}

NEWLANG_FUNCTION(clone) {
if(in.size() != 2) {
if (in.size() != 2) {
LOG_RUNTIME("Bad argument count parameter!");
}
return in[1]->Clone(nullptr);
}

NEWLANG_FUNCTION(const_) {
if(in.size() != 2) {
if (in.size() != 2) {
LOG_RUNTIME("Bad argument count parameter!");
}
return in[1]->MakeConst();
}

NEWLANG_FUNCTION(mutable_) {
if(in.size() != 2) {
if (in.size() != 2) {
LOG_RUNTIME("Bad argument count parameter!");
}
return in[1]->MakeMutable();
}

NEWLANG_FUNCTION(import) {
if(!ctx) {
if (!ctx) {
LOG_RUNTIME("No access to context!");
}
return ctx->CreateNative(in.at(1).second->GetValueAsString().c_str(),
in["module"]->GetValueAsString().c_str(), in["lazzy"]->GetValueAsBoolean());
}

NEWLANG_FUNCTION(eval) {
if(!ctx) {
if (!ctx) {
LOG_RUNTIME("No access to context!");
}
return ctx->ExecStr(in.at(1).second->GetValueAsString().c_str());
}

NEWLANG_FUNCTION(exec) {
if(!ctx) {
if (!ctx) {
LOG_RUNTIME("No access to context!");
}
return ctx->ExecFile(in.at(1).second->GetValueAsString().c_str());
}

NEWLANG_TRANSPARENT(help) {

std::string help_str;
for (int i = 0; i < newlang_syntax_help_size; i++) {
help_str.append(newlang_syntax_help_arr[i]);
help_str.append("\n\r");
}
return Obj::CreateString(help_str);
}


#undef NEWLANG_FUNCTION
#undef NEWLANG_TRANSPARENT

}






bool BuiltInTorchDirect::CheckDirect(CompileInfo &ci, TermPtr &term, std::string &output) {

if(term->size() == 0 && m_tensor_noarg.find(term->getText()) != m_tensor_noarg.end()) {
if (term->size() == 0 && m_tensor_noarg.find(term->getText()) != m_tensor_noarg.end()) {
output += "->asTensor_()." + term->getText() + "(), " + output;

return true;
} else if(term->size() == 1) {
} else if (term->size() == 1) {

if((*term)[0]->IsScalar() && m_tensor_scalar.find(term->getText()) != m_tensor_scalar.end()) {
if ((*term)[0]->IsScalar() && m_tensor_scalar.find(term->getText()) != m_tensor_scalar.end()) {
output += "->asTensor_()." + term->getText() + "(" + (*term)[0]->getText() + "), " + output;
return true;

} else if((*term)[0]->getTermID() == TermID::TERM) {
} else if ((*term)[0]->getTermID() == TermID::TERM) {
std::string temp;
NewLang::GetImpl(ci, (*term)[0], temp);
output += "->asTensor_()." + term->getText() + "(" + temp + "->asTensor_()), " + output;
Expand Down
1 change: 1 addition & 0 deletions core/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ FUNC_DIRECT(newlang_print, print_);
FUNC_DIRECT(newlang_eval, eval);
FUNC_DIRECT(newlang_exec, exec);

FUNC_TRANSPARENT(newlang_help, help);
/*
*
*
Expand Down
5 changes: 3 additions & 2 deletions core/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ Context::Context(RuntimePtr global) {
Context::m_funcs["max"] = CreateBuiltin("max(arg, ...)", (void *) &max, ObjType::TRANSPARENT);
Context::m_funcs["макс"] = Context::m_funcs["max"];

Context::m_funcs["import"] =
CreateBuiltin("import(arg, module='', lazzy=0)", (void *) &import, ObjType::FUNCTION);
Context::m_funcs["import"] = CreateBuiltin("import(arg, module='', lazzy=0)", (void *) &import, ObjType::FUNCTION);

Context::m_funcs["eval"] = CreateBuiltin("eval(string:String)", (void *) &eval, ObjType::FUNCTION);
Context::m_funcs["exec"] = CreateBuiltin("exec(filename:String)", (void *) &exec, ObjType::FUNCTION);
Context::m_funcs["help"] = CreateBuiltin("help(...)", (void *) &help, ObjType::TRANSPARENT);

}

Expand Down Expand Up @@ -167,6 +167,7 @@ ObjPtr Context::CreateBuiltin(const char *prototype, void *func, ObjType type) {
Obj::CreateFunc(this, proto->Left(), type,
proto->Left()->getName().empty() ? proto->Left()->getText() : proto->Left()->getName());
obj->m_func_ptr = func;
obj->m_var_is_init = true;

return obj;
}
Expand Down
20 changes: 19 additions & 1 deletion core/nbproject/Makefile-Debug.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ OBJECTFILES= \
${OBJECTDIR}/object.o \
${OBJECTDIR}/parser.o \
${OBJECTDIR}/parser.yy.o \
${OBJECTDIR}/syntax_help.o \
${OBJECTDIR}/term.o \
${OBJECTDIR}/test/alg_test.o \
${OBJECTDIR}/test/eval_test.o \
Expand All @@ -54,7 +55,8 @@ OBJECTFILES= \
${OBJECTDIR}/test/nlc_test.o \
${OBJECTDIR}/test/object_test.o \
${OBJECTDIR}/test/parser_test.o \
${OBJECTDIR}/variable.o
${OBJECTDIR}/variable.o \
${OBJECTDIR}/version.o


# C Compiler Flags
Expand Down Expand Up @@ -87,6 +89,11 @@ ${OBJECTDIR}/_ext/e16507f5/logger.o: ../contrib/logger/logger.cpp
${RM} "$@.d"
$(COMPILE.cc) -g -DDEBUG -DLOG_LEVEL_NORMAL=LOG_LEVEL_DEBUG -DPDC_WIDE -I.. -I../contrib/googletest/googletest -I../contrib/googletest/googletest/include -I../contrib/Lyra/include -I../contrib/libtorch/include/torch/csrc/api/include -I../contrib/libtorch/include -I../contrib/tensorboard_logger/include -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/_ext/e16507f5/logger.o ../contrib/logger/logger.cpp

temp/syntax.temp.txt: ../docs/syntax.md ../docs/syntax.md
${MKDIR} -p temp
@echo Выполнение шага пользовательского сборки
mkdir temp || pandoc -t plain ../docs/syntax.md > temp/syntax.temp.txt

${OBJECTDIR}/builtin.o: builtin.cpp parser.h parser.yy.h pch.h.gch location.hh
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
Expand Down Expand Up @@ -178,6 +185,11 @@ pch.h.gch: pch.h
@echo Выполнение шага пользовательского сборки
g++ -o pch.h.gch -c pch.h -g -I.. -I../contrib/libtorch/include/torch/csrc/api/include -I../contrib/libtorch/include --no-gnu-unique -Wno-trigraphs -Winvalid-pch -Werror=return-type -g -DDEBUG -DLOG_LEVEL_NORMAL=LOG_LEVEL_DEBUG -DPDC_WIDE -I../contrib/googletest/googletest -I../contrib/googletest/googletest/include -I../contrib/Lyra/include -I../contrib/libtorch/include/torch/csrc/api/include -I../contrib/libtorch/include -I.. -I../contrib/tensorboard_logger/include -I/usr/lib/llvm-13/include -std=c++17

${OBJECTDIR}/syntax_help.o: syntax_help.cpp
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
$(COMPILE.cc) -g -DDEBUG -DLOG_LEVEL_NORMAL=LOG_LEVEL_DEBUG -DPDC_WIDE -I.. -I../contrib/googletest/googletest -I../contrib/googletest/googletest/include -I../contrib/Lyra/include -I../contrib/libtorch/include/torch/csrc/api/include -I../contrib/libtorch/include -I../contrib/tensorboard_logger/include -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/syntax_help.o syntax_help.cpp

${OBJECTDIR}/term.o: term.cpp parser.h parser.yy.h pch.h.gch location.hh
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
Expand Down Expand Up @@ -240,6 +252,11 @@ ${OBJECTDIR}/variable.o: variable.cpp pch.h.gch
@echo Выполнение шага пользовательского сборки


${OBJECTDIR}/version.o: version.c
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
$(COMPILE.c) -g -s -DDEBUG -DLOG_LEVEL_NORMAL=LOG_LEVEL_DUMP -I../contrib/googletest/googletest -I../contrib/googletest/googletest/include -I.. -std=c11 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/version.o version.c

: warning_pop.h parser.yy.cpp location.hh
@echo Выполнение шага пользовательского сборки

Expand All @@ -254,6 +271,7 @@ ${OBJECTDIR}/variable.o: variable.cpp pch.h.gch
# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
${RM} -r ${CND_BUILDDIR}/${CND_CONF}
${RM} temp/syntax.temp.txt
${RM}
${RM}
${RM}
Expand Down
14 changes: 13 additions & 1 deletion core/nbproject/Makefile-GCOV.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ OBJECTFILES= \
${OBJECTDIR}/object.o \
${OBJECTDIR}/parser.o \
${OBJECTDIR}/parser.yy.o \
${OBJECTDIR}/syntax_help.o \
${OBJECTDIR}/term.o \
${OBJECTDIR}/test/alg_test.o \
${OBJECTDIR}/test/eval_test.o \
Expand All @@ -56,7 +57,8 @@ OBJECTFILES= \
${OBJECTDIR}/test/nlc_test.o \
${OBJECTDIR}/test/object_test.o \
${OBJECTDIR}/test/parser_test.o \
${OBJECTDIR}/variable.o
${OBJECTDIR}/variable.o \
${OBJECTDIR}/version.o


# C Compiler Flags
Expand Down Expand Up @@ -163,6 +165,11 @@ ${OBJECTDIR}/parser.yy.o: parser.yy.cpp parser.y
@echo Выполнение шага пользовательского сборки


${OBJECTDIR}/syntax_help.o: syntax_help.cpp
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
$(COMPILE.cc) -g -DDEBUG -DLOG_LEVEL_NORMAL=LOG_LEVEL_DEBUG -DPDC_WIDE -DUNITTEST -I.. -I../contrib/googletest/googletest -I../contrib/googletest/googletest/include -I../contrib/Tensorflow/bazel-bin/tensorflow/include -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/syntax_help.o syntax_help.cpp

${OBJECTDIR}/term.o: term.cpp
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
Expand Down Expand Up @@ -217,6 +224,11 @@ ${OBJECTDIR}/variable.o: variable.cpp
${RM} "$@.d"
$(COMPILE.cc) -g -DDEBUG -DLOG_LEVEL_NORMAL=LOG_LEVEL_DEBUG -DPDC_WIDE -DUNITTEST -I.. -I../contrib/googletest/googletest -I../contrib/googletest/googletest/include -I../contrib/Tensorflow/bazel-bin/tensorflow/include -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/variable.o variable.cpp

${OBJECTDIR}/version.o: version.c
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
$(COMPILE.c) -g -s -DDEBUG -DLOG_LEVEL_NORMAL=LOG_LEVEL_DUMP -DUNITTEST -I.. -I../contrib/googletest/googletest -I../contrib/googletest/googletest/include -std=c11 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/version.o version.c

: warning_pop.h parser.yy.cpp location.hh
@echo Выполнение шага пользовательского сборки

Expand Down
Loading

0 comments on commit e8e53b0

Please sign in to comment.