Fix bug with classes, use slim exclusively, add package private data and change rehaul cmake configs
This commit is contained in:
321
.clang-format
Normal file
321
.clang-format
Normal file
@@ -0,0 +1,321 @@
|
||||
---
|
||||
Language: Cpp
|
||||
AlignAfterOpenBracket: true
|
||||
AccessModifierOffset: -2
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: true
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveShortCaseStatements:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCaseArrows: false
|
||||
AlignCaseColons: false
|
||||
AlignConsecutiveTableGenBreakingDAGArgColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveTableGenCondOperatorColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveTableGenDefinitionColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments:
|
||||
AlignPPAndNotPP: true
|
||||
Kind: Always
|
||||
OverEmptyLines: 0
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowBreakBeforeNoexceptSpecifier: Never
|
||||
AllowBreakBeforeQtProperty: false
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseExpressionOnASingleLine: true
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCompoundRequirementOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortNamespacesOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BinPackArguments: true
|
||||
BinPackLongBracedList: true
|
||||
BinPackParameters: BinPack
|
||||
BitFieldColonSpacing: Both
|
||||
BracedInitializerIndentWidth: -1
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterExternBlock: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakAdjacentStringLiterals: true
|
||||
BreakAfterAttributes: Leave
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakAfterOpenBracketBracedList: false
|
||||
BreakAfterOpenBracketFunction: false
|
||||
BreakAfterOpenBracketIf: false
|
||||
BreakAfterOpenBracketLoop: false
|
||||
BreakAfterOpenBracketSwitch: false
|
||||
BreakAfterReturnType: None
|
||||
BreakArrays: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeCloseBracketBracedList: false
|
||||
BreakBeforeCloseBracketFunction: false
|
||||
BreakBeforeCloseBracketIf: false
|
||||
BreakBeforeCloseBracketLoop: false
|
||||
BreakBeforeCloseBracketSwitch: false
|
||||
BreakBeforeConceptDeclarations: Always
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInlineASMColon: OnlyMultiline
|
||||
BreakBeforeTemplateCloser: false
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakBinaryOperations: Never
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakFunctionDefinitionParameters: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakStringLiterals: true
|
||||
BreakTemplateDeclarations: MultiLine
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: AlignFirstComment
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
EnumTrailingComma: Leave
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IfMacros:
|
||||
- KJ_IF_MAYBE
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseBlocks: false
|
||||
IndentCaseLabels: false
|
||||
IndentExportBlock: true
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentRequiresClause: true
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertBraces: false
|
||||
InsertNewlineAtEOF: false
|
||||
InsertTrailingCommas: None
|
||||
IntegerLiteralSeparator:
|
||||
Binary: 0
|
||||
BinaryMinDigitsInsert: 0
|
||||
BinaryMaxDigitsRemove: 0
|
||||
Decimal: 0
|
||||
DecimalMinDigitsInsert: 0
|
||||
DecimalMaxDigitsRemove: 0
|
||||
Hex: 0
|
||||
HexMinDigitsInsert: 0
|
||||
HexMaxDigitsRemove: 0
|
||||
BinaryMinDigits: 0
|
||||
DecimalMinDigits: 0
|
||||
HexMinDigits: 0
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLines:
|
||||
AtEndOfFile: false
|
||||
AtStartOfBlock: true
|
||||
AtStartOfFile: true
|
||||
KeepFormFeed: false
|
||||
LambdaBodyIndentation: Signature
|
||||
LineEnding: DeriveLF
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MainIncludeChar: Quote
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
NumericLiteralCase:
|
||||
ExponentLetter: Leave
|
||||
HexDigit: Leave
|
||||
Prefix: Leave
|
||||
Suffix: Leave
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
OneLineFormatOffRegex: ''
|
||||
PackConstructorInitializers: BinPack
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakBeforeMemberAccess: 150
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakOpenParenthesis: 0
|
||||
PenaltyBreakScopeResolution: 500
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
PPIndentWidth: -1
|
||||
QualifierAlignment: Leave
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: Always
|
||||
RemoveBracesLLVM: false
|
||||
RemoveEmptyLinesInUnwrappedLines: false
|
||||
RemoveParentheses: Leave
|
||||
RemoveSemicolon: false
|
||||
RequiresClausePosition: OwnLine
|
||||
RequiresExpressionIndentation: OuterScope
|
||||
SeparateDefinitionBlocks: Leave
|
||||
ShortNamespaceLines: 1
|
||||
SkipMacroDefinitionBody: false
|
||||
SortIncludes:
|
||||
Enabled: true
|
||||
IgnoreCase: false
|
||||
IgnoreExtension: false
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: LexicographicNumeric
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterOperatorKeyword: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeJsonColon: false
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: true
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterIfMacros: true
|
||||
AfterNot: false
|
||||
AfterOverloadedOperator: false
|
||||
AfterPlacementOperator: true
|
||||
AfterRequiresInClause: false
|
||||
AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBraces: Never
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: Never
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParens: Never
|
||||
SpacesInParensOptions:
|
||||
ExceptDoubleParentheses: false
|
||||
InCStyleCasts: false
|
||||
InConditionalStatements: false
|
||||
InEmptyParentheses: false
|
||||
Other: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TableGenBreakInsideDAGArg: DontBreak
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
VerilogBreakBetweenInstancePorts: true
|
||||
WhitespaceSensitiveMacros:
|
||||
- BOOST_PP_STRINGIZE
|
||||
- CF_SWIFT_NAME
|
||||
- NS_SWIFT_NAME
|
||||
- PP_STRINGIZE
|
||||
- STRINGIZE
|
||||
WrapNamespaceBodyWithEmptyLines: Leave
|
||||
...
|
||||
|
||||
@@ -29,7 +29,6 @@ jobs:
|
||||
- run: chown build:build /home/build/PKGBUILD
|
||||
- run: chown build:build /home/build/build-arch.sh
|
||||
- run: su build -c /home/build/build-arch.sh
|
||||
- run: env -C Packaging/Slim bash build.sh
|
||||
- uses: akkuman/gitea-release-action@v1
|
||||
env:
|
||||
NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
|
||||
@@ -39,9 +38,20 @@ jobs:
|
||||
artifacts/**
|
||||
|
||||
update-tap:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: global-container-mingw
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: |
|
||||
mkdir -p artifacts
|
||||
env -C Packaging/Windows bash build.sh
|
||||
- uses: akkuman/gitea-release-action@v1
|
||||
env:
|
||||
NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
|
||||
with:
|
||||
prerelease: true
|
||||
files: |-
|
||||
artifacts/**
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Log in to registry
|
||||
|
||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -88,7 +88,8 @@
|
||||
"clangd.fallbackFlags": [
|
||||
"-I${workspaceFolder}/include",
|
||||
"-I/home/mike/tmp-crosslang/usr/local/include/"
|
||||
]
|
||||
],
|
||||
"editor.formatOnSave": true
|
||||
|
||||
|
||||
}
|
||||
186
CMakeLists.txt
186
CMakeLists.txt
@@ -1,188 +1,34 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include(cmake/version.cmake)
|
||||
include(cmake/options.cmake)
|
||||
|
||||
project(TessesCrossLang VERSION ${CROSSLANG_MAJOR_VERSION}.${CROSSLANG_MINOR_VERSION}.${CROSSLANG_PATCH_VERSION})
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
|
||||
|
||||
if(CROSSLANG_CUSTOM_CONSOLE)
|
||||
set(CROSSLANG_ENABLE_BINARIES OFF)
|
||||
set(CROSSLANG_ENABLE_SHARED OFF)
|
||||
endif()
|
||||
|
||||
|
||||
if(CROSSLANG_FETCHCONTENT)
|
||||
|
||||
set(TESSESFRAMEWORK_ENABLE_EXAMPLES OFF)
|
||||
set(TESSESFRAMEWORK_ENABLE_APPS OFF)
|
||||
|
||||
if(NOT TESSESFRAMEWORK_ENABLE_SHARED)
|
||||
set(CROSSLANG_ENABLE_SHARED OFF)
|
||||
endif()
|
||||
if(NOT TESSESFRAMEWORK_ENABLE_STATIC)
|
||||
set(CROSSLANG_ENABLE_STATIC OFF)
|
||||
endif()
|
||||
if(NOT TESSESFRAMEWORK_ENABLE_RPATH)
|
||||
set(CROSSLANG_ENABLE_RPATH OFF)
|
||||
endif()
|
||||
|
||||
#set(CROSSLANG_ENABLE_SHARED OFF)
|
||||
#set(TESSESFRAMEWORK_ENABLE_SHARED OFF)
|
||||
#set(CROSSLANG_SHARED_EXECUTABLES OFF)
|
||||
include(GNUInstallDirs)
|
||||
include(CheckLibraryExists)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
TessesFramework
|
||||
GIT_REPOSITORY https://git.tesses.org/tesses50/tessesframework.git
|
||||
)
|
||||
FetchContent_MakeAvailable(TessesFramework)
|
||||
list(APPEND TessesCrossLangLibs ${TessesFrameworkTargets})
|
||||
else()
|
||||
find_package(TessesFramework REQUIRED)
|
||||
endif()
|
||||
|
||||
include(cmake/sources.cmake)
|
||||
include(cmake/options.cmake)
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
if(CROSSLANG_ENABLE_FFI)
|
||||
find_package(PkgConfig)
|
||||
endif()
|
||||
include(cmake/linkdeps.cmake)
|
||||
if(CROSSLANG_ENABLE_FFI AND CROSSLANG_ENABLE_SHARED)
|
||||
pkg_check_modules(LIBFFI REQUIRED IMPORTED_TARGET libffi)
|
||||
endif()
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/CrossLangVersion.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/CrossLangVersion.h"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CrossLangVersion.h)
|
||||
|
||||
|
||||
|
||||
include(cmake/findtf.cmake)
|
||||
include(cmake/sources.cmake)
|
||||
|
||||
if(CROSSLANG_OFFLINE_SHELL_PACKAGE STREQUAL "")
|
||||
|
||||
include(cmake/cpack.cmake)
|
||||
if(CROSSLANG_STATIC)
|
||||
include(cmake/staticlib.cmake)
|
||||
else()
|
||||
install(FILES ${CROSSLANG_OFFLINE_SHELL_PACKAGE} DESTINATION share/Tesses/CrossLang)
|
||||
include(cmake/sharedlib.cmake)
|
||||
endif()
|
||||
|
||||
if(MINGW)
|
||||
list(APPEND CROSSLANG_WIN32_EXE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/winicon.rc")
|
||||
if(MINGW)
|
||||
ENABLE_LANGUAGE(RC)
|
||||
endif(MINGW)
|
||||
endif()
|
||||
include(cmake/install-dev.cmake)
|
||||
|
||||
include(cmake/app.cmake)
|
||||
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
if(CROSSLANG_ENABLE_STATIC)
|
||||
|
||||
add_library(crosslang_static STATIC ${CROSSLANG_SOURCE})
|
||||
CROSSLANG_LINK_DEPS(crosslang_static)
|
||||
if(CROSSLANG_FETCHCONTENT)
|
||||
|
||||
target_link_libraries(crosslang_static PUBLIC tessesframework)
|
||||
else()
|
||||
target_link_libraries(crosslang_static PUBLIC TessesFramework::tessesframework)
|
||||
endif()
|
||||
|
||||
list(APPEND TessesCrossLangLibs crosslang_static)
|
||||
endif()
|
||||
|
||||
|
||||
if(CROSSLANG_ENABLE_SHARED)
|
||||
add_library(crosslang_shared SHARED ${CROSSLANG_SOURCE})
|
||||
CROSSLANG_LINK_DEPS(crosslang_shared)
|
||||
if(CROSSLANG_FETCHCONTENT)
|
||||
target_link_libraries(crosslang_shared PUBLIC tessesframework_shared)
|
||||
else()
|
||||
target_link_libraries(crosslang_shared PUBLIC TessesFramework::tessesframework_shared)
|
||||
endif()
|
||||
list(APPEND TessesCrossLangLibs crosslang_shared)
|
||||
endif()
|
||||
|
||||
|
||||
if(CROSSLANG_ENABLE_SUPERSLIM)
|
||||
include(cmake/slim.cmake)
|
||||
else()
|
||||
include(cmake/shared.cmake)
|
||||
|
||||
|
||||
|
||||
if(CROSSLANG_ENABLE_BINARIES)
|
||||
if(CROSSLANG_ENABLE_SHARED AND CROSSLANG_SHARED_EXECUTABLES)
|
||||
include(cmake/shared_exec.cmake)
|
||||
elseif(CROSSLANG_ENABLE_STATIC)
|
||||
include(cmake/static_exec.cmake)
|
||||
else()
|
||||
include(cmake/exec.cmake)
|
||||
endif()
|
||||
|
||||
install(TARGETS crossc DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
install(TARGETS crossvm DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
install(TARGETS crossint DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
install(TARGETS crossdump DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
install(TARGETS crosslang DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
install(TARGETS crossarchiveextract DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
install(TARGETS crossarchivecreate DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
install(TARGETS crossasm DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
install(TARGETS crossdisasm DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
install(TARGETS crossmerge DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
if(NOT WIN32)
|
||||
install(TARGETS crossthumbnailer DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/crossvm-binfmt.conf.in "${CMAKE_CURRENT_BINARY_DIR}/crossvm-binfmt.conf"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/binfmt.d)
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/crossvm-binfmt.conf"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/binfmt.d)
|
||||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/crosslang.xml"
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/mime/packages)
|
||||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/crosslang.png"
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons)
|
||||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/crosslang.thumbnailer"
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/thumbnailers)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
include(InstallRequiredSystemLibraries)
|
||||
set(CPACK_PACKAGE_CONTACT "Mike Nolan <tesses@tesses.net>")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR "${TessesCrossLang_VERSION_MAJOR}")
|
||||
set(CPACK_PACKAGE_VERSION_MINOR "${TessesCrossLang_VERSION_MINOR}")
|
||||
|
||||
set(CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS
|
||||
"!include \\\"FileFunc.nsh\\\"\n!include \\\"${CMAKE_CURRENT_SOURCE_DIR}/FileAssociation.nsh\\\"")
|
||||
|
||||
|
||||
# Create association on install
|
||||
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
|
||||
"\\\${RegisterExtension} '$INSTDIR\\\\bin\\\\crossvm.exe' '.crvm' 'CrossLang Executable'\n\
|
||||
\\\${RefreshShellIcons}")
|
||||
|
||||
# Remove association on uninstall
|
||||
|
||||
|
||||
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
|
||||
"\\\${RegisterExtension} '$INSTDIR\\\\bin\\\\crossint.exe' '.tcross' 'CrossLang Script'\n\
|
||||
\\\${RefreshShellIcons}\n\
|
||||
\\\${UnRegisterExtension} '.crvm' 'CrossLang Executable'\n\
|
||||
\\\${RefreshShellIcons}")
|
||||
|
||||
# Remove association on uninstall
|
||||
set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
|
||||
"\\\${UnRegisterExtension} '.tcross' 'CrossLang Script'\n\
|
||||
\\\${RefreshShellIcons}\n\
|
||||
\\\${UnRegisterExtension} '.crvm' 'CrossLang Executable'\n\
|
||||
\\\${RefreshShellIcons}")
|
||||
|
||||
set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/winicon.ico")
|
||||
set(CPACK_NSIS_MODIFY_PATH ON)
|
||||
set(CPACK_PACKAGE_VENDOR "Tesses")
|
||||
set(CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$DESKTOP\\\\CrossLang Interperter.lnk' '$INSTDIR\\\\bin\\\\crossint.exe'")
|
||||
set(CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\CrossLang Interperter.lnk' '$INSTDIR\\\\bin\\\\crossint.exe'")
|
||||
|
||||
|
||||
include(CPack)
|
||||
if(CROSSLANG_INSTALL_DEVELOPMENT)
|
||||
add_subdirectory(pkgconfig)
|
||||
endif()
|
||||
endif()
|
||||
@@ -6,7 +6,7 @@ RUN apk add --no-cache cmake g++ make git
|
||||
COPY ./ /src
|
||||
|
||||
|
||||
RUN cd /src && mkdir build && cd build && cmake -S .. -B . -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_ENABLE_APPS=ON -DCMAKE_BUILD_TYPE=Release ; make -j`nproc` && make install DESTDIR=/out
|
||||
RUN cd /src && mkdir build && cd build && cmake -S .. -B . -DTESSESFRAMEWORK_STATIC=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_ENABLE_APPS=ON -DCMAKE_BUILD_TYPE=Release ; make -j`nproc` && make install DESTDIR=/out
|
||||
|
||||
FROM alpine:latest
|
||||
RUN apk update
|
||||
@@ -14,4 +14,4 @@ RUN apk add --no-cache libstdc++
|
||||
COPY --from=build /out/usr /usr
|
||||
|
||||
ENV CROSSLANG_CONTAINER=1
|
||||
ENTRYPOINT ["/usr/local/bin/crossint"]
|
||||
ENTRYPOINT ["/usr/local/bin/crosslang","int"]
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# Maintainer: Mike Nolan <tesses@tesses.net>
|
||||
pkgname=crosslang # '-bzr', '-git', '-hg' or '-svn'
|
||||
pkgver=0.0.5
|
||||
pkgver=0.0.6
|
||||
pkgrel=1
|
||||
pkgdesc=""
|
||||
arch=('x86_64' 'powerpc')
|
||||
url="https://git.tesses.org/tesses50/crosslang"
|
||||
license=('GPLv3')
|
||||
groups=()
|
||||
depends=('mbedtls' 'tessesframework=0.0.3')
|
||||
depends=('mbedtls' 'tessesframework=0.0.4')
|
||||
makedepends=('git' 'cmake' 'make' 'base-devel' 'wget') # 'bzr', 'git', 'mercurial' or 'subversion'
|
||||
install=
|
||||
source=('crosslang::git+https://git.tesses.org/tesses50/crosslang')
|
||||
|
||||
@@ -7,7 +7,7 @@ git clone --depth 1 https://git.tesses.org/tesses50/zig-cross builds/zig-cross
|
||||
for tripple in x86_64-linux-musl x86-linux-musl aarch64-linux-musl arm-linux-musleabi riscv64-linux-musl powerpc-linux-musleabihf; do
|
||||
export BUILDDIR=builds/$tripple
|
||||
mkdir -p $BUILDDIR
|
||||
cmake -S ../.. -B $BUILDDIR --toolchain $PWD/builds/zig-cross/$tripple\.cmake -DCMAKE_BUILD_TYPE=Release -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_ENABLE_SHARED=OFF -DTESSESFRAMEWORK_ENABLE_STATIC=ON -DCROSSLANG_ENABLE_SUPERSLIM=ON -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++ -static -Wl,--strip-all" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -GNinja
|
||||
cmake -S ../.. -B $BUILDDIR --toolchain $PWD/builds/zig-cross/$tripple\.cmake -DCMAKE_BUILD_TYPE=Release -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -D -DTESSESFRAMEWORK_STATIC=ON -DCROSSLANG_ENABLE_SUPERSLIM=ON -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++ -static -Wl,--strip-all" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -GNinja
|
||||
cmake --build $BUILDDIR || exit 1
|
||||
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
||||
mv $BUILDDIR/out/bin/crosslang ../../artifacts/crosslang-slim-$tripple
|
||||
@@ -16,7 +16,7 @@ done
|
||||
for tripple in x86_64-windows-gnu x86-windows-gnu aarch64-windows-gnu; do
|
||||
export BUILDDIR=builds/$tripple
|
||||
mkdir -p $BUILDDIR
|
||||
cmake -S ../.. -B $BUILDDIR --toolchain $PWD/builds/zig-cross/$tripple\.cmake -DCMAKE_BUILD_TYPE=Release -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_ENABLE_SHARED=OFF -DTESSESFRAMEWORK_ENABLE_STATIC=ON -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++ -static -Wl,--strip-all" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCROSSLANG_ENABLE_SUPERSLIM=ON -GNinja
|
||||
cmake -S ../.. -B $BUILDDIR --toolchain $PWD/builds/zig-cross/$tripple\.cmake -DCMAKE_BUILD_TYPE=Release -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -D -DTESSESFRAMEWORK_STATIC=ON -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++ -static -Wl,--strip-all" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCROSSLANG_ENABLE_SUPERSLIM=ON -GNinja
|
||||
cmake --build $BUILDDIR || exit 1
|
||||
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
||||
|
||||
@@ -26,7 +26,7 @@ done
|
||||
for tripple in x86_64-macos-none aarch64-macos-none; do
|
||||
export BUILDDIR=builds/$tripple
|
||||
mkdir -p $BUILDDIR
|
||||
cmake -S ../.. -B $BUILDDIR --toolchain $PWD/builds/zig-cross/$tripple\.cmake -DCMAKE_BUILD_TYPE=Release -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_ENABLE_SHARED=OFF -DTESSESFRAMEWORK_ENABLE_STATIC=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCROSSLANG_ENABLE_SUPERSLIM=ON -GNinja -DCMAKE_EXE_LINKER_FLAGS="-Wl,--strip-all"
|
||||
cmake -S ../.. -B $BUILDDIR --toolchain $PWD/builds/zig-cross/$tripple\.cmake -DCMAKE_BUILD_TYPE=Release -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -D -DTESSESFRAMEWORK_STATIC=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCROSSLANG_ENABLE_SUPERSLIM=ON -GNinja -DCMAKE_EXE_LINKER_FLAGS="-Wl,--strip-all"
|
||||
cmake --build $BUILDDIR || exit 1
|
||||
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
||||
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
#!/bin/bash
|
||||
cmake -S ../.. -B build-x86 -DCMAKE_TOOLCHAIN_FILE=`pwd`/WindowsToolchains/x86.cmake -DTESSESFRAMEWORK_FETCHCONTENT=ON -DTESSESFRAMEWORK_ENABLE_APPS=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_ENABLE_STATIC=ON -DTESSESFRAMEWORK_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=tmp-x86 -DCMAKE_BUILD_TYPE=Release
|
||||
mkdir -p ../../artifacts
|
||||
cmake -S ../.. -B build-x86 -DCMAKE_TOOLCHAIN_FILE=`pwd`/WindowsToolchains/x86.cmake -DTESSESFRAMEWORK_FETCHCONTENT=ON -DTESSESFRAMEWORK_ENABLE_APPS=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_STATIC=ON -DCMAKE_INSTALL_PREFIX=tmp-x86 -DCMAKE_BUILD_TYPE=Release
|
||||
cd build-x86
|
||||
make -j`nproc`
|
||||
cpack -G NSIS
|
||||
cpack -G ZIP
|
||||
mv TessesCrossLang-*-win32.exe ../../../artifacts/crosslang-win32.exe
|
||||
mv TessesCrossLang-*-win32.zip ../../../artifacts/crosslang-win32.zip
|
||||
mv TessesCrossLang-*-win32.exe ../../../artifacts/crosslang-win32-setup.exe
|
||||
mv crosslang.exe ../../../artifacts/crosslang-win32-portable.exe
|
||||
cd ..
|
||||
cmake -S ../.. -B build-x64 -DCMAKE_TOOLCHAIN_FILE=`pwd`/WindowsToolchains/x64.cmake -DTESSESFRAMEWORK_FETCHCONTENT=ON -DTESSESFRAMEWORK_ENABLE_APPS=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_ENABLE_STATIC=ON -DTESSESFRAMEWORK_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=tmp-x64 -DCMAKE_BUILD_TYPE=Release
|
||||
cmake -S ../.. -B build-x64 -DCMAKE_TOOLCHAIN_FILE=`pwd`/WindowsToolchains/x64.cmake -DTESSESFRAMEWORK_FETCHCONTENT=ON -DTESSESFRAMEWORK_ENABLE_APPS=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_STATIC=ON -DCMAKE_INSTALL_PREFIX=tmp-x64 -DCMAKE_BUILD_TYPE=Release
|
||||
cd build-x64
|
||||
make -j`nproc`
|
||||
cpack -G NSIS
|
||||
cpack -G ZIP
|
||||
mv TessesCrossLang-*-win64.exe ../../../artifacts/crosslang-win64.exe
|
||||
mv TessesCrossLang-*-win64.zip ../../../artifacts/crosslang-win64.zip
|
||||
mv TessesCrossLang-*-win64.exe ../../../artifacts/crosslang-win64-setup.exe
|
||||
mv crosslang.exe ../../../artifacts/crosslang-win64-portable.exe
|
||||
|
||||
@@ -47,7 +47,7 @@ sudo make install
|
||||
|
||||
## Build with shared libs only (self contained dependencies)
|
||||
```bash
|
||||
cmake -S ../.. -B . -DTESSESFRAMEWORK_ENABLE_STATIC=OFF -DTESSESFRAMEWORK_ENABLE_SHARED=ON
|
||||
cmake -S ../.. -B .
|
||||
make -j`nproc`
|
||||
sudo make install
|
||||
```
|
||||
|
||||
280
build-dvd.tcross
280
build-dvd.tcross
@@ -1,280 +0,0 @@
|
||||
var cpus = [
|
||||
{
|
||||
uname = "ppc",
|
||||
name = "powerpc",
|
||||
compiler = "powerpc-linux-musl-cross",
|
||||
cc = "powerpc-linux-musl-gcc",
|
||||
cxx = "powerpc-linux-musl-g++",
|
||||
flags = "-static-libgcc -static-libstdc++ -static"
|
||||
},
|
||||
{
|
||||
uname = "ppc64",
|
||||
name = "powerpc64",
|
||||
compiler = "powerpc64-linux-musl-cross",
|
||||
cc = "powerpc64-linux-musl-gcc",
|
||||
cxx = "powerpc64-linux-musl-g++",
|
||||
flags = "-static-libgcc -static-libstdc++ -static"
|
||||
},
|
||||
{
|
||||
uname = "x86_64",
|
||||
name = "x86_64",
|
||||
compiler = "x86_64-linux-musl-cross",
|
||||
cc = "x86_64-linux-musl-gcc",
|
||||
cxx = "x86_64-linux-musl-g++",
|
||||
flags = "-static-libgcc -static-libstdc++ -static"
|
||||
},
|
||||
{
|
||||
uname="i686",
|
||||
name = "i686",
|
||||
compiler = "i686-linux-musl-cross",
|
||||
cc = "i686-linux-musl-gcc",
|
||||
cxx = "i686-linux-musl-g++",
|
||||
flags = "-static-libgcc -static-libstdc++ -static"
|
||||
},
|
||||
{
|
||||
uname = "aarch64",
|
||||
name = "aarch64",
|
||||
compiler = "aarch64-linux-musl-cross",
|
||||
cc = "aarch64-linux-musl-gcc",
|
||||
cxx = "aarch64-linux-musl-g++",
|
||||
flags = "-static-libgcc -static-libstdc++ -static"
|
||||
},
|
||||
{
|
||||
uname = "arm",
|
||||
name = "arm",
|
||||
compiler = "arm-linux-musleabi-cross",
|
||||
cc = "arm-linux-musleabi-gcc",
|
||||
cxx = "arm-linux-musleabi-g++",
|
||||
flags = "-static-libgcc -static-libstdc++ -static"
|
||||
},
|
||||
{
|
||||
uname = "armv7l",
|
||||
name = "armv7l",
|
||||
compiler = "arm-linux-musleabihf-cross",
|
||||
cc = "arm-linux-musleabihf-gcc",
|
||||
cxx = "arm-linux-musleabihf-g++",
|
||||
flags = "-static-libgcc -static-libstdc++ -static"
|
||||
},
|
||||
{
|
||||
uname = "mips",
|
||||
name = "mips",
|
||||
compiler = "mips-linux-musl-cross",
|
||||
cc = "mips-linux-musl-gcc",
|
||||
cxx = "mips-linux-musl-g++",
|
||||
flags = "-static-libgcc -static-libstdc++ -static"
|
||||
},
|
||||
{
|
||||
uname = "mips64",
|
||||
name = "mips64",
|
||||
compiler = "mips64-linux-musl-cross",
|
||||
cc = "mips64-linux-musl-gcc",
|
||||
cxx = "mips64-linux-musl-g++",
|
||||
flags = "-static-libgcc -static-libstdc++ -static"
|
||||
},
|
||||
{
|
||||
uname = "riscv32",
|
||||
name = "riscv32",
|
||||
compiler = "riscv32-linux-musl-cross",
|
||||
cc = "riscv32-linux-musl-gcc",
|
||||
cxx = "riscv32-linux-musl-g++",
|
||||
flags = "-static-libgcc -static-libstdc++ -static"
|
||||
},
|
||||
{
|
||||
uname = "riscv64",
|
||||
name = "riscv64",
|
||||
compiler = "riscv64-linux-musl-cross",
|
||||
cc = "riscv64-linux-musl-gcc",
|
||||
cxx = "riscv64-linux-musl-g++",
|
||||
flags = "-static-libgcc -static-libstdc++ -static"
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
var mbedversion="mbedtls-2.28.9";
|
||||
func main(args)
|
||||
{
|
||||
var working = FS.CurrentPath / "Working";
|
||||
|
||||
|
||||
FS.Local.CreateDirectory(working / "Toolchains");
|
||||
FS.Local.CreateDirectory(working / "CMakeToolchains");
|
||||
FS.Local.CreateDirectory(working / "Source");
|
||||
FS.Local.CreateDirectory(working / "DvdFiles" / "Linux");
|
||||
FS.Local.CreateDirectory(working / "DvdFiles" / "Common");
|
||||
FS.Local.CreateDirectory(working / "Output");
|
||||
var install = "#!/bin/bash
|
||||
export CPU=`uname -m`
|
||||
|
||||
";
|
||||
var file = $"cd {working / \"Source\"}
|
||||
if [ ! -d \"{mbedversion}\" ]; then
|
||||
wget -O ../DvdFiles/crosslang-license.txt https://downloads.tesses.net/gpl-3.0.txt
|
||||
cp ../DvdFiles/crosslang-license.txt ../Output/crosslang-license.txt
|
||||
wget -O {mbedversion}.tar.bz2 https://downloads.tesses.net/cache/libraries/source/{mbedversion}.tar.bz2
|
||||
tar xf {mbedversion}.tar.bz2
|
||||
rm {mbedversion}.tar.bz2
|
||||
fi
|
||||
git clone --depth=1 https://git.tesses.org/tesses50/tessesframework
|
||||
git clone --depth=1 https://git.tesses.org/tesses50/crosslang
|
||||
zip -r \"{working / \"DvdFiles\" / \"crosslang-source.zip\"}\" ./*
|
||||
cp ../DvdFiles/crosslang-source.zip ../Output/crosslang-source.zip
|
||||
wget -O \"{working / \"DvdFiles\" / \"Common\" / \"ShellPackage.crvm\"}\" https://redirect.tesses.net/crosslang-shell
|
||||
";
|
||||
var w32_toolchain = $"
|
||||
set(CMAKE_C_COMPILER \"/usr/bin/i686-w64-mingw32-gcc\")
|
||||
set(CMAKE_CXX_COMPILER \"/usr/bin/i686-w64-mingw32-g++\")
|
||||
set(CMAKE_C_FLAGS \"-static-libgcc -static-libstdc++ -static\")
|
||||
set(CMAKE_CXX_FLAGS \"-static-libgcc -static-libstdc++ -static\")
|
||||
set(CMAKE_EXE_LINKER_FLAGS \"-static-libgcc -static-libstdc++ -static\")
|
||||
|
||||
set(CMAKE_SYSROOT \"{working}/Sysroot/windows\")
|
||||
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR i686)
|
||||
";
|
||||
FS.Local.CreateDirectory(working / "Build" / "windows");
|
||||
FS.Local.CreateDirectory(working / "Sysroot" / "windows");
|
||||
FS.WriteAllText(FS.Local,working / "CMakeToolchains" / "windows.cmake", w32_toolchain);
|
||||
file += $"#windows
|
||||
cd \"{working / \"Build\" / \"windows\"}\"
|
||||
mkdir -p mbedtls
|
||||
cd mbedtls
|
||||
cmake -S \"{working / \"Source\" / mbedversion}\" -B . -DCMAKE_TOOLCHAIN_FILE=\"{working / \"CMakeToolchains\" / \"windows\"}.cmake\" -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF
|
||||
make -j16
|
||||
make install DESTDIR=\"{working / \"Sysroot\" / \"windows\"}\"
|
||||
cd ..
|
||||
mkdir -p tesses-framework
|
||||
cd tesses-framework
|
||||
cmake -S \"{working / \"Source\" / \"tesses-framework\"}\" -DMBEDTLS_DIR=\"{working / \"Sysroot\" / \"windows\"/\"usr\"/\"local\"}\" -B . -DCMAKE_TOOLCHAIN_FILE=\"{working / \"CMakeToolchains\" / \"windows\"}.cmake\" -DTESSESFRAMEWORK_ENABLE_SHARED=OFF -DTESSESFRAMEWORK_ENABLE_APPS=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF
|
||||
make -j16
|
||||
make install DESTDIR=\"{working / \"Sysroot\" / \"windows\"}\"
|
||||
cd ..
|
||||
mkdir -p crosslang
|
||||
cd crosslang
|
||||
cmake -S \"{working / \"Source\" / \"crosslang\"}\" -B . -DCMAKE_TOOLCHAIN_FILE=\"{working / \"CMakeToolchains\" / \"windows\"}.cmake\" -DCROSSLANG_ENABLE_SHARED=OFF -DCROSSLANG_FETCHCONTENT=OFF -DCROSSLANG_SHARED_EXECUTABLES=OFF
|
||||
make -j16
|
||||
cpack -G NSIS
|
||||
cpack -G ZIP
|
||||
cp TessesCrossLang-*-win32.exe \"{working/\"DvdFiles\"/\"setup.exe\"}\"
|
||||
cp TessesCrossLang-*-win32.zip \"{working/\"DvdFiles\"/\"crosslang-win32.zip\"}\"
|
||||
cp TessesCrossLang-*-win32.exe \"{working/\"Output\"/\"crosslang-win32.exe\"}\"
|
||||
cp TessesCrossLang-*-win32.zip \"{working/\"Output\"/\"crosslang-win32.zip\"}\"
|
||||
";
|
||||
each(var item : cpus)
|
||||
{
|
||||
FS.Local.CreateDirectory(working / "Build" / item.name);
|
||||
FS.Local.CreateDirectory(working / "Sysroot" / item.name);
|
||||
|
||||
var toolchain = $"
|
||||
set(CMAKE_C_COMPILER \"{working}/Toolchains/{item.compiler}/bin/{item.cc}\")
|
||||
set(CMAKE_CXX_COMPILER \"{working}/Toolchains/{item.compiler}/bin/{item.cxx}\")
|
||||
set(CMAKE_C_FLAGS \"{item.flags}\")
|
||||
set(CMAKE_CXX_FLAGS \"{item.flags}\")
|
||||
set(CMAKE_EXE_LINKER_FLAGS \"{item.flags}\")
|
||||
|
||||
set(CMAKE_SYSROOT \"{working}/Sysroot/{item.name}\")
|
||||
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR powerpc)
|
||||
";
|
||||
if(item.name == "riscv32" || item.name == "riscv64")
|
||||
{
|
||||
toolchain += "set(CMAKE_POSITION_INDEPENDENT_CODE ON)\n";
|
||||
}
|
||||
FS.WriteAllText(FS.Local,working / "CMakeToolchains" / $"{item.name}.cmake", toolchain);
|
||||
var tar = working / "Output" / $"crosslang-{item.name}.tar.gz";
|
||||
var dvdDir = working / "DvdFiles" / "Linux" / item.name;
|
||||
file += $"#{item.name}
|
||||
cd \"{working / \"Toolchains\"}\"
|
||||
if [ ! -d \"{item.compiler}\" ]; then
|
||||
|
||||
wget -O {item.compiler}.tgz https://downloads.tesses.net/cache/compilers/{item.compiler}.tgz
|
||||
tar xzf {item.compiler}.tgz
|
||||
rm {item.compiler}.tgz
|
||||
fi
|
||||
cd \"{working / \"Build\" / item.name}\"
|
||||
mkdir -p mbedtls
|
||||
cd mbedtls
|
||||
cmake -S \"{working / \"Source\" / mbedversion}\" -B . -DCMAKE_TOOLCHAIN_FILE=\"{working / \"CMakeToolchains\" / item.name}.cmake\" -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF
|
||||
make -j16
|
||||
make install DESTDIR=\"{working / \"Sysroot\" / item.name}\"
|
||||
cd ..
|
||||
mkdir -p tesses-framework
|
||||
cd tesses-framework
|
||||
cmake -S \"{working / \"Source\" / \"tesses-framework\"}\" -DMBEDTLS_DIR=\"{working / \"Sysroot\" / item.name/\"usr\"/\"local\"}\" -B . -DCMAKE_TOOLCHAIN_FILE=\"{working / \"CMakeToolchains\" / item.name}.cmake\" -DTESSESFRAMEWORK_ENABLE_SHARED=OFF -DTESSESFRAMEWORK_ENABLE_APPS=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF
|
||||
make -j16
|
||||
make install DESTDIR=\"{working / \"Sysroot\" / item.name}\"
|
||||
cd ..
|
||||
mkdir -p crosslang
|
||||
cd crosslang
|
||||
cmake -S \"{working / \"Source\" / \"crosslang\"}\" -B . -DCMAKE_TOOLCHAIN_FILE=\"{working / \"CMakeToolchains\" / item.name}.cmake\" -DCROSSLANG_ENABLE_SHARED=OFF -DCROSSLANG_FETCHCONTENT=OFF -DCROSSLANG_SHARED_EXECUTABLES=OFF
|
||||
make -j16
|
||||
make install DESTDIR=\"{working / \"Sysroot\" / item.name}\"
|
||||
cd \"{working/\"Sysroot\"/item.name/\"usr\"/\"local\"}\"
|
||||
tar czf \"{tar}\" bin share lib/binfmt.d
|
||||
mv bin \"{dvdDir}\"
|
||||
";
|
||||
install += $"
|
||||
if [[ \"$CPU\" == \"{item.uname}\" ]]; then
|
||||
install -D -m 755 -o root ./Linux/{item.name}/crossarchivecreate /usr/local/bin/crossarchivecreate
|
||||
install -D -m 755 -o root ./Linux/{item.name}/crossarchiveextract /usr/local/bin/crossarchiveextract
|
||||
install -D -m 755 -o root ./Linux/{item.name}/crossc /usr/local/bin/crossc
|
||||
install -D -m 755 -o root ./Linux/{item.name}/crossdump /usr/local/bin/crossdump
|
||||
install -D -m 755 -o root ./Linux/{item.name}/crossint /usr/local/bin/crossint
|
||||
install -D -m 755 -o root ./Linux/{item.name}/crosslang /usr/local/bin/crosslang
|
||||
install -D -m 755 -o root ./Linux/{item.name}/crossthumbnailer /usr/local/bin/crossthumbnailer
|
||||
install -D -m 755 -o root ./Linux/{item.name}/crossvm /usr/local/bin/crossvm
|
||||
install -D -m 644 -o root ./Linux/crosslang.thumbnailer /usr/local/share/thumbnailers/crosslang.thumbnailer
|
||||
install -D -m 644 -o root ./Linux/crosslang.xml /usr/local/share/mime/crosslang.xml
|
||||
install -D -m 644 -o root ./Linux/crossvm-binfmt.conf /usr/local/lib/binfmt.d/crossvm-binfmt.conf
|
||||
install -D -m 644 -o root ./Linux/crosslang.png /usr/local/share/icons/crosslang.png
|
||||
install -D -m 644 -o root ./Common/ShellPackage.crvm /usr/local/share/Tesses/CrossLang/Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm
|
||||
|
||||
|
||||
fi
|
||||
";
|
||||
}
|
||||
|
||||
file += $"
|
||||
cd \"{working.GetParent()}\"
|
||||
cd \"{working}\"
|
||||
chmod 755 DvdFiles/install.sh
|
||||
cp Source/crosslang/crosslang.png DvdFiles/Linux/crosslang.png
|
||||
cp Source/crosslang/winicon.ico DvdFiles/cross.ico
|
||||
cd DvdFiles
|
||||
xorriso -outdev ../Output/crosslang.iso -add *
|
||||
";
|
||||
|
||||
|
||||
FS.WriteAllText(FS.Local,"script.sh", file);
|
||||
FS.WriteAllText(FS.Local,./"Working"/"DvdFiles"/"install.sh", install);
|
||||
FS.WriteAllText(FS.Local,./"Working"/"DvdFiles"/"Linux"/"crossvm-binfmt.conf",":CrossVM:M::TCROSSVM::/usr/local/bin/crossvm:\n");
|
||||
FS.WriteAllText(FS.Local,./"Working"/"DvdFiles"/"Linux"/"crosslang.thumbnailer","[Thumbnailer Entry]
|
||||
TryExec=crossthumbnailer
|
||||
Exec=crossthumbnailer %i %o
|
||||
MimeType=application/crvm;
|
||||
");
|
||||
FS.WriteAllText(FS.Local,"Working"/"DvdFiles"/"ReadmeWindows.txt", "When installing make sure to enable path\nRun ShellInstaller.bat from each user (if offline)");
|
||||
|
||||
FS.WriteAllText(FS.Local,"Working"/"DvdFiles"/"ShellInstaller.bat", "@echo off\r\ncrossarchiveextract Common\\ShellPackage.crvm %APPDATA%\\Tesses\\CrossLang");
|
||||
FS.WriteAllText(FS.Local,./"Working"/"DvdFiles"/"autorun.inf","[autorun]\r\nicon=cross.ico\r\nopen=setup.exe\r\nlabel=CrossLang");
|
||||
FS.WriteAllText(FS.Local,./"Working"/"DvdFiles"/"Linux"/"crosslang.xml","<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">
|
||||
<mime-type type=\"application/crvm\">
|
||||
<sub-class-of type=\"application/octet-stream\"/>
|
||||
<comment>CrossLang Executable</comment>
|
||||
<comment xml:lang=\"en\">CrossLang Executable</comment>
|
||||
<glob pattern=\"*.crvm\"/>
|
||||
<icon name=\"crosslang\"/>
|
||||
</mime-type>
|
||||
<mime-type type=\"text/tcross\">
|
||||
<sub-class-of type=\"text/plain\"/>
|
||||
<comment>CrossLang Source</comment>
|
||||
<comment xml:lang=\"en\">CrossLang Source</comment>
|
||||
<glob pattern=\"*.tcross\"/>
|
||||
<icon name=\"crosslang\"/>
|
||||
</mime-type>
|
||||
</mime-info>"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
## 0.0.6
|
||||
Fix bug with classes, use slim exclusively, add package private data and change rehaul cmake configs
|
||||
|
||||
## 0.0.5
|
||||
Fix crosslang Stat, StatVFS for custom crosslang filesystems and add queryable
|
||||
|
||||
|
||||
25
cmake/app.cmake
Normal file
25
cmake/app.cmake
Normal file
@@ -0,0 +1,25 @@
|
||||
if(CROSSLANG_ENABLE_BINARIES)
|
||||
if(MINGW)
|
||||
list(APPEND CROSSLANG_WIN32_EXE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/winicon.rc")
|
||||
if(MINGW)
|
||||
ENABLE_LANGUAGE(RC)
|
||||
endif(MINGW)
|
||||
endif()
|
||||
add_executable(crosslang_app src/programs/slim.cpp "${CROSSLANG_WIN32_EXE_SRC}")
|
||||
target_link_libraries(crosslang_app PUBLIC crosslang)
|
||||
set_target_properties(crosslang_app PROPERTIES OUTPUT_NAME crosslang)
|
||||
install(TARGETS crosslang_app DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
endif()
|
||||
|
||||
if(NOT WIN32 AND NOT APPLE)
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/crossvm-binfmt.conf.in "${CMAKE_CURRENT_BINARY_DIR}/crossvm-binfmt.conf"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/binfmt.d)
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/crossvm-binfmt.conf"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/binfmt.d)
|
||||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/crosslang.xml"
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/mime/packages)
|
||||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/crosslang.png"
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons)
|
||||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/crosslang.thumbnailer"
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/thumbnailers)
|
||||
endif()
|
||||
39
cmake/cpack.cmake
Normal file
39
cmake/cpack.cmake
Normal file
@@ -0,0 +1,39 @@
|
||||
include(InstallRequiredSystemLibraries)
|
||||
set(CPACK_PACKAGE_CONTACT "Mike Nolan <tesses@tesses.net>")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR "${TessesCrossLang_VERSION_MAJOR}")
|
||||
set(CPACK_PACKAGE_VERSION_MINOR "${TessesCrossLang_VERSION_MINOR}")
|
||||
|
||||
set(CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS
|
||||
"!include \\\"FileFunc.nsh\\\"\n!include \\\"${CMAKE_CURRENT_SOURCE_DIR}/FileAssociation.nsh\\\"")
|
||||
|
||||
|
||||
# Create association on install
|
||||
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
|
||||
"\\\${RegisterExtension} '$INSTDIR\\\\bin\\\\crossvm.exe' '.crvm' 'CrossLang Executable'\n\
|
||||
\\\${RefreshShellIcons}")
|
||||
|
||||
# Remove association on uninstall
|
||||
|
||||
|
||||
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
|
||||
"\\\${RegisterExtension} '$INSTDIR\\\\bin\\\\crosslang.exe int' '.tcross' 'CrossLang Script'\n\
|
||||
\\\${RefreshShellIcons}\n\
|
||||
\\\${UnRegisterExtension} '.crvm' 'CrossLang Executable'\n\
|
||||
\\\${RefreshShellIcons}")
|
||||
|
||||
# Remove association on uninstall
|
||||
set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
|
||||
"\\\${UnRegisterExtension} '.tcross' 'CrossLang Script'\n\
|
||||
\\\${RefreshShellIcons}\n\
|
||||
\\\${UnRegisterExtension} '.crvm' 'CrossLang Executable'\n\
|
||||
\\\${RefreshShellIcons}")
|
||||
|
||||
set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/winicon.ico")
|
||||
set(CPACK_NSIS_MODIFY_PATH ON)
|
||||
set(CPACK_PACKAGE_VENDOR "Tesses")
|
||||
set(CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$DESKTOP\\\\CrossLang Interperter.lnk' '$INSTDIR\\\\bin\\\\crossint.exe'")
|
||||
set(CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\CrossLang Interperter.lnk' '$INSTDIR\\\\bin\\\\crossint.exe'")
|
||||
|
||||
|
||||
include(CPack)
|
||||
@@ -1,57 +0,0 @@
|
||||
add_executable(crossc src/programs/crosslangcompiler.cpp ${CROSSLANG_SOURCE} ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossvm src/programs/crosslangvm.cpp ${CROSSLANG_SOURCE} ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossint src/programs/crosslanginterperter.cpp ${CROSSLANG_SOURCE} ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossdump src/programs/crosslangdump.cpp ${CROSSLANG_SOURCE} ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crosslang src/programs/crosslang.cpp ${CROSSLANG_SOURCE} ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossarchiveextract src/programs/crossarchiveextract.cpp ${CROSSLANG_SOURCE} ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossarchivecreate src/programs/crossarchivecreate.cpp ${CROSSLANG_SOURCE} ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossasm src/crossasmcli.cpp ${CROSSLANG_SOURCE} ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossdisasm src/crossdisasmcli.cpp ${CROSSLANG_SOURCE} ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossmerge src/crossmergecli.cpp ${CROSSLANG_SOURCE} ${CROSSLANG_WIN32_EXE_SRC})
|
||||
|
||||
if(NOT WIN32)
|
||||
add_executable(crossthumbnailer src/crossthumbnailer.cpp ${CROSSLANG_SOURCE} ${CROSSLANG_WIN32_EXE_SRC})
|
||||
endif()
|
||||
CROSSLANG_LINK_DEPS(crossc)
|
||||
CROSSLANG_LINK_DEPS(crossvm)
|
||||
CROSSLANG_LINK_DEPS(crossint)
|
||||
CROSSLANG_LINK_DEPS(crosslang)
|
||||
CROSSLANG_LINK_DEPS(crossdump)
|
||||
CROSSLANG_LINK_DEPS(crossarchiveextract)
|
||||
CROSSLANG_LINK_DEPS(crossarchivecreate)
|
||||
CROSSLANG_LINK_DEPS(crossmerge)
|
||||
CROSSLANG_LINK_DEPS(crossdisasm)
|
||||
CROSSLANG_LINK_DEPS(crossasm)
|
||||
|
||||
if(NOT WIN32)
|
||||
CROSSLANG_LINK_DEPS(crossthumbnailer)
|
||||
endif()
|
||||
if(CROSSLANG_FETCHCONTENT)
|
||||
target_link_libraries(crossc PUBLIC tessesframework)
|
||||
target_link_libraries(crossvm PUBLIC tessesframework)
|
||||
target_link_libraries(crossint PUBLIC tessesframework)
|
||||
target_link_libraries(crosslang PUBLIC tessesframework)
|
||||
target_link_libraries(crossdump PUBLIC tessesframework)
|
||||
target_link_libraries(crossarchiveextract PUBLIC tessesframework)
|
||||
target_link_libraries(crossarchivecreate PUBLIC tessesframework)
|
||||
target_link_libraries(crossasm PUBLIC tessesframework)
|
||||
target_link_libraries(crossdisasm PUBLIC tessesframework)
|
||||
target_link_libraries(crossmerge PUBLIC tessesframework)
|
||||
if(NOT WIN32)
|
||||
target_link_libraries(crossthumbnailer PUBLIC tessesframework)
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(crossc PUBLIC TessesFramework::tessesframework)
|
||||
target_link_libraries(crossvm PUBLIC TessesFramework::tessesframework)
|
||||
target_link_libraries(crossint PUBLIC TessesFramework::tessesframework)
|
||||
target_link_libraries(crosslang PUBLIC TessesFramework::tessesframework)
|
||||
target_link_libraries(crossdump PUBLIC TessesFramework::tessesframework)
|
||||
target_link_libraries(crossarchiveextract PUBLIC TessesFramework::tessesframework)
|
||||
target_link_libraries(crossarchivecreate PUBLIC TessesFramework::tessesframework)
|
||||
target_link_libraries(crossasm PUBLIC TessesFramework::tessesframework)
|
||||
target_link_libraries(crossdisasm PUBLIC TessesFramework::tessesframework)
|
||||
target_link_libraries(crossmerge PUBLIC TessesFramework::tessesframework)
|
||||
if(NOT WIN32)
|
||||
target_link_libraries(crossthumbnailer PUBLIC TessesFramework::tessesframework)
|
||||
endif()
|
||||
endif()
|
||||
14
cmake/findtf.cmake
Normal file
14
cmake/findtf.cmake
Normal file
@@ -0,0 +1,14 @@
|
||||
if(CROSSLANG_FETCHCONTENT)
|
||||
|
||||
|
||||
set(CROSSLANG_STATIC ${TESSESFRAMEWORK_STATIC} CACHE INTERNAL "For CrossLang" FORCE)
|
||||
FetchContent_Declare(
|
||||
TessesFramework
|
||||
GIT_REPOSITORY https://git.tesses.org/tesses50/tessesframework.git
|
||||
GIT_TAG 25d67053ccebf209f50e6928fad8827164eb4c28
|
||||
)
|
||||
set(TESSESFRAMEWORK_ENABLE_EXAMPLES OFF)
|
||||
FetchContent_MakeAvailable(TessesFramework)
|
||||
else()
|
||||
find_package(TessesFramework REQUIRED)
|
||||
endif()
|
||||
38
cmake/helpers.cmake
Normal file
38
cmake/helpers.cmake
Normal file
@@ -0,0 +1,38 @@
|
||||
if(CROSSLANG_ENABLE_FFI)
|
||||
if(NOT CROSSLANG_STATIC)
|
||||
pkg_check_modules(LIBFFI REQUIRED IMPORTED_TARGET libffi)
|
||||
target_compile_definitions(crosslang PUBLIC CROSSLANG_ENABLE_FFI)
|
||||
target_link_libraries(crosslang PUBLIC PkgConfig::LIBFFI)
|
||||
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CROSSLANG_CUSTOM_CONSOLE)
|
||||
target_compile_definitions(crosslang PRIVATE CROSSLANG_CUSTOM_CONSOLE)
|
||||
|
||||
endif()
|
||||
|
||||
if(CROSSLANG_STATIC)
|
||||
target_compile_definitions(crosslang PRIVATE CROSSLANG_STATIC)
|
||||
|
||||
endif()
|
||||
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/CrossLangVersion.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/CrossLangVersion.h"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CrossLangVersion.h)
|
||||
|
||||
target_include_directories(crosslang
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
target_include_directories(crosslang
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
|
||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
||||
target_link_libraries(crosslang PUBLIC tessesframework)
|
||||
else()
|
||||
target_link_libraries(crosslang PUBLIC TessesFramework::tessesframework)
|
||||
endif()
|
||||
@@ -1,34 +1,28 @@
|
||||
if(CROSSLANG_INSTALL_DEVELOPMENT)
|
||||
install(TARGETS ${TessesCrossLangLibs}
|
||||
EXPORT TessesCrossLangTargets
|
||||
install(TARGETS ${CrossLangLibs}
|
||||
EXPORT CrossLangTargets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
install(FILES include/CrossLang.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/CrossLangVersion.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
install(EXPORT TessesCrossLangTargets
|
||||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/CrossLang.hpp" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/CrossLangVersion.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
|
||||
install(EXPORT CrossLangTargets
|
||||
FILE TessesCrossLangTargets.cmake
|
||||
NAMESPACE TessesCrossLang::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesCrossLang
|
||||
)
|
||||
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/TessesCrossLangConfig.cmake"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesCrossLang)
|
||||
|
||||
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TessesCrossLangConfig.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesCrossLang)
|
||||
else()
|
||||
|
||||
if(CROSSLANG_ENABLE_SHARED)
|
||||
install(TARGETS crosslang_shared
|
||||
EXPORT TessesCrossLangTargets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
endif()
|
||||
endif()
|
||||
@@ -1,62 +0,0 @@
|
||||
function(CROSSLANG_LINK_DEPS CROSSLANG_TARGET_NAME)
|
||||
target_include_directories(${CROSSLANG_TARGET_NAME}
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
if(CROSSLANG_ENABLE_FFI AND CROSSLANG_ENABLE_SHARED)
|
||||
|
||||
target_compile_definitions(${CROSSLANG_TARGET_NAME} PUBLIC CROSSLANG_ENABLE_FFI)
|
||||
target_link_libraries(${CROSSLANG_TARGET_NAME} PUBLIC PkgConfig::LIBFFI)
|
||||
|
||||
endif()
|
||||
if(CROSSLANG_ENABLE_SUPERSLIM)
|
||||
|
||||
target_compile_definitions(${CROSSLANG_TARGET_NAME} PUBLIC CROSSLANG_ENABLE_SUPERSLIM)
|
||||
endif()
|
||||
if(CROSSLANG_ENABLE_TIME)
|
||||
target_compile_definitions(${CROSSLANG_TARGET_NAME} PUBLIC CROSSLANG_ENABLE_TIME)
|
||||
endif()
|
||||
if(CROSSLANG_ENABLE_CONFIG_ENVVAR)
|
||||
target_compile_definitions(${CROSSLANG_TARGET_NAME} PUBLIC CROSSLANG_ENABLE_CONFIG_ENVVAR)
|
||||
endif()
|
||||
if(CROSSLANG_ENABLE_PROCESS)
|
||||
target_compile_definitions(${CROSSLANG_TARGET_NAME} PUBLIC CROSSLANG_ENABLE_PROCESS)
|
||||
endif()
|
||||
if(CROSSLANG_ENABLE_THREADING)
|
||||
target_compile_definitions(${CROSSLANG_TARGET_NAME} PUBLIC CROSSLANG_ENABLE_THREADING)
|
||||
endif()
|
||||
if(CROSSLANG_ENABLE_TERMIOS)
|
||||
target_compile_definitions(${CROSSLANG_TARGET_NAME} PUBLIC CROSSLANG_ENABLE_TERMIOS)
|
||||
endif()
|
||||
|
||||
if(CROSSLANG_ENABLE_SQLITE)
|
||||
target_compile_definitions(${CROSSLANG_TARGET_NAME} PUBLIC CROSSLANG_ENABLE_SQLITE)
|
||||
endif()
|
||||
|
||||
if(CROSSLANG_CUSTOM_CONSOLE)
|
||||
target_compile_definitions(${CROSSLANG_TARGET_NAME} PUBLIC CROSSLANG_CUSTOM_CONSOLE)
|
||||
endif()
|
||||
if(CROSSLANG_ENABLE_PLATFORM_FOLDERS)
|
||||
target_compile_definitions(${CROSSLANG_TARGET_NAME} PUBLIC CROSSLANG_ENABLE_PLATFORM_FOLDERS)
|
||||
endif()
|
||||
if(CROSSLANG_ENABLE_SHARED)
|
||||
target_compile_definitions(${CROSSLANG_TARGET_NAME} PUBLIC CROSSLANG_ENABLE_SHARED)
|
||||
|
||||
endif()
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoGameCube")
|
||||
target_link_libraries(${CROSSLANG_TARGET_NAME} PUBLIC fat)
|
||||
endif()
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii")
|
||||
target_link_libraries(${CROSSLANG_TARGET_NAME} PUBLIC wiisocket)
|
||||
endif()
|
||||
if(CROSSLANG_ENABLE_SHARED AND NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows"))
|
||||
target_link_libraries(${CROSSLANG_TARGET_NAME} PUBLIC dl)
|
||||
endif()
|
||||
target_include_directories(${CROSSLANG_TARGET_NAME}
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
|
||||
endfunction()
|
||||
@@ -1,18 +1,7 @@
|
||||
option(CROSSLANG_ENABLE_STATIC "Enable Tesses CrossLang static libraries" ON)
|
||||
option(CROSSLANG_ENABLE_SHARED "Enable Tesses CrossLang shared libraries" ON)
|
||||
option(CROSSLANG_ENABLE_BINARIES "Enable Tesses CrossLang binaries" ON)
|
||||
option(CROSSLANG_INSTALL_DEVELOPMENT "Enable Tesses CrossLang development files" ON)
|
||||
option(CROSSLANG_ENABLE_THREADING "Enable Tesses CrossLang threading" ON)
|
||||
option(CROSSLANG_ENABLE_TERMIOS "Enable termios (For changing terminal options)" ON)
|
||||
option(CROSSLANG_SHARED_EXECUTABLES "Link with libcrosslang_shared" ON)
|
||||
option(CROSSLANG_FETCHCONTENT "Use fetchcontent" ON)
|
||||
option(CROSSLANG_ENABLE_CONFIG_ENVVAR "Allow setting config directory via the environment variable CROSSLANG_CONFIG" ON)
|
||||
option(CROSSLANG_ENABLE_FFI "Enable libffi" OFF)
|
||||
option(CROSSLANG_ENABLE_RPATH "Enable RPATH" ON)
|
||||
option(CROSSLANG_ENABLE_SUPERSLIM "Enable crosslang superslim, one binary" OFF)
|
||||
|
||||
option(CROSSLANG_CUSTOM_CONSOLE "Enable custom Console" OFF)
|
||||
|
||||
|
||||
|
||||
set(CROSSLANG_OFFLINE_SHELL_PACKAGE "" CACHE FILEPATH "Path to the shell package generated from https://git.tesses.org/crosslangextras")
|
||||
option(CROSSLANG_STATIC "Build with static libraries instead of shared" OFF)
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
if(CROSSLANG_ENABLE_RPATH)
|
||||
set(CMAKE_MACOSX_RPATH 1)
|
||||
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
|
||||
if (APPLE)
|
||||
set(CMAKE_INSTALL_RPATH "@executable_path/../${CMAKE_INSTALL_LIBDIR}")
|
||||
else()
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
|
||||
endif()
|
||||
endif()
|
||||
add_executable(crossmerge src/crossmergecli.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossasm src/crossasmcli.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossdisasm src/crossdisasmcli.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
|
||||
add_executable(crossc src/programs/crosslangcompiler.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossvm src/programs/crosslangvm.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossint src/programs/crosslanginterperter.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossdump src/programs/crosslangdump.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crosslang src/programs/crosslang.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossarchiveextract src/programs/crossarchiveextract.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossarchivecreate src/programs/crossarchivecreate.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
if(NOT WIN32)
|
||||
add_executable(crossthumbnailer src/crossthumbnailer.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
endif()
|
||||
target_link_libraries(crossc PUBLIC crosslang_shared)
|
||||
target_link_libraries(crossvm PUBLIC crosslang_shared)
|
||||
target_link_libraries(crossint PUBLIC crosslang_shared)
|
||||
target_link_libraries(crossdump PUBLIC crosslang_shared)
|
||||
target_link_libraries(crosslang PUBLIC crosslang_shared)
|
||||
target_link_libraries(crossarchiveextract PUBLIC crosslang_shared)
|
||||
target_link_libraries(crossarchivecreate PUBLIC crosslang_shared)
|
||||
target_link_libraries(crossasm PUBLIC crosslang_shared)
|
||||
target_link_libraries(crossdisasm PUBLIC crosslang_shared)
|
||||
target_link_libraries(crossmerge PUBLIC crosslang_shared)
|
||||
|
||||
if(NOT WIN32)
|
||||
target_link_libraries(crossthumbnailer PUBLIC crosslang_shared)
|
||||
endif()
|
||||
20
cmake/sharedlib.cmake
Normal file
20
cmake/sharedlib.cmake
Normal file
@@ -0,0 +1,20 @@
|
||||
if(TESSESFRAMEWORK_ENABLE_RPATH)
|
||||
set(CMAKE_MACOSX_RPATH 1)
|
||||
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
|
||||
|
||||
if (APPLE)
|
||||
set(CMAKE_INSTALL_RPATH "@executable_path/../${CMAKE_INSTALL_LIBDIR}")
|
||||
else()
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
|
||||
endif()
|
||||
endif()
|
||||
add_library(crosslang SHARED ${CROSSLANG_SOURCE})
|
||||
set_target_properties(crosslang PROPERTIES
|
||||
VERSION ${CROSSLANG_MAJOR_VERSION}.${CROSSLANG_MINOR_VERSION}.${CROSSLANG_PATCH_VERSION}
|
||||
SOVERSION ${CROSSLANG_MAJOR_VERSION}
|
||||
)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/helpers.cmake)
|
||||
|
||||
|
||||
|
||||
list(APPEND CrossLangLibs crosslang)
|
||||
@@ -1,21 +0,0 @@
|
||||
|
||||
add_executable(crosslang WIN32 src/programs/slim.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
|
||||
if(CROSSLANG_ENABLE_STATIC)
|
||||
|
||||
target_link_libraries(crosslang PUBLIC crosslang_static)
|
||||
elseif(CROSSLANG_ENABLE_SHARED)
|
||||
target_link_libraries(crosslang PUBLIC crosslang_shared)
|
||||
endif()
|
||||
|
||||
if(CROSSLANG_ENABLE_SHARED)
|
||||
|
||||
install(TARGETS crosslang_shared
|
||||
EXPORT TessesCrossLangTargets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
install(TARGETS crosslang DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
@@ -9,9 +9,6 @@ src/vm/bc/invokemethod.cpp
|
||||
src/vm/bc/executemethod2.cpp
|
||||
src/vm/bc/invoketwo.cpp
|
||||
src/vm/bc/tobool.cpp
|
||||
src/assembler/asm.cpp
|
||||
src/assembler/disasm.cpp
|
||||
src/assembler/merge.cpp
|
||||
src/compiler/codegen.cpp
|
||||
src/compiler/lexer.cpp
|
||||
src/compiler/parser.cpp
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
add_executable(crossc src/programs/crosslangcompiler.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossvm src/programs/crosslangvm.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossint src/programs/crosslanginterperter.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossdump src/programs/crosslangdump.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crosslang src/programs/crosslang.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossarchiveextract src/programs/crossarchiveextract.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossarchivecreate src/programs/crossarchivecreate.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossasm src/crossasmcli.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossdisasm src/crossdisasmcli.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
add_executable(crossmerge src/crossmergecli.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
|
||||
if(NOT WIN32)
|
||||
add_executable(crossthumbnailer src/crossthumbnailer.cpp ${CROSSLANG_WIN32_EXE_SRC})
|
||||
endif()
|
||||
target_link_libraries(crossc PUBLIC crosslang_static)
|
||||
target_link_libraries(crossvm PUBLIC crosslang_static)
|
||||
target_link_libraries(crossint PUBLIC crosslang_static)
|
||||
target_link_libraries(crossdump PUBLIC crosslang_static)
|
||||
target_link_libraries(crosslang PUBLIC crosslang_static)
|
||||
target_link_libraries(crossarchiveextract PUBLIC crosslang_static)
|
||||
target_link_libraries(crossarchivecreate PUBLIC crosslang_static)
|
||||
target_link_libraries(crossmerge PUBLIC crosslang_static)
|
||||
target_link_libraries(crossasm PUBLIC crosslang_static)
|
||||
target_link_libraries(crossdisasm PUBLIC crosslang_static)
|
||||
|
||||
if(NOT WIN32)
|
||||
target_link_libraries(crossthumbnailer PUBLIC crosslang_static)
|
||||
endif()
|
||||
6
cmake/staticlib.cmake
Normal file
6
cmake/staticlib.cmake
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
add_library(crosslang STATIC ${CROSSLANG_SOURCE})
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/helpers.cmake)
|
||||
|
||||
list(APPEND CrossLangLibs crosslang)
|
||||
@@ -1,3 +1,3 @@
|
||||
set(CROSSLANG_MAJOR_VERSION 0)
|
||||
set(CROSSLANG_MINOR_VERSION 0)
|
||||
set(CROSSLANG_PATCH_VERSION 5)
|
||||
set(CROSSLANG_PATCH_VERSION 6)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[Thumbnailer Entry]
|
||||
TryExec=crossthumbnailer
|
||||
Exec=crossthumbnailer %i %o
|
||||
TryExec=crosslang
|
||||
Exec=crosslang thumbnailer %i %o
|
||||
MimeType=application/crvm;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -10,16 +10,8 @@ else()
|
||||
set(PKGCONFIG_DEPS "")
|
||||
endif()
|
||||
|
||||
if(CROSSLANG_ENABLE_STATIC)
|
||||
configure_file(crosslang_static.pc.in crosslang_static.pc @ONLY)
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/crosslang_static.pc
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
endif()
|
||||
|
||||
if(CROSSLANG_ENABLE_SHARED)
|
||||
configure_file(crosslang.pc.in crosslang.pc @ONLY)
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/crosslang.pc
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
endif()
|
||||
@@ -11,4 +11,4 @@ Version: @PROJECT_VERSION@
|
||||
Requires: tessesframework
|
||||
|
||||
Cflags: -I"${includedir}"
|
||||
Libs: -L"${libdir}" -lcrosslang_shared
|
||||
Libs: -L"${libdir}" -lcrosslang
|
||||
@@ -1,14 +0,0 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
includedir=@PKGCONFIG_INCLUDEDIR@
|
||||
libdir=@PKGCONFIG_LIBDIR@
|
||||
|
||||
Name: @PROJECT_NAME@
|
||||
Description: @PKGCONFIG_PROJECT_DESCRIPTION@
|
||||
URL: @PKGCONFIG_PROJECT_HOMEPAGE_URL@
|
||||
Version: @PROJECT_VERSION@
|
||||
|
||||
@PKGCONFIG_DEPS@
|
||||
Requires: tessesframework_static
|
||||
|
||||
Cflags: -I"${includedir}"
|
||||
Libs: -L"${libdir}" -lcrosslang_static
|
||||
598
src/archive.cpp
598
src/archive.cpp
@@ -1,324 +1,306 @@
|
||||
#include "CrossLang.hpp"
|
||||
#include <iostream>
|
||||
namespace Tesses::CrossLang
|
||||
{
|
||||
|
||||
void CrossArchiveCreate(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,std::shared_ptr<Tesses::Framework::Streams::Stream> strm,std::string name, TVMVersion version, std::string info, std::string icon)
|
||||
{
|
||||
std::vector<std::string> ignored_files;
|
||||
std::string file = "/.crossarchiveignore";
|
||||
if(vfs->FileExists(file))
|
||||
{
|
||||
auto strm = vfs->OpenFile(file,"rb");
|
||||
if(strm != nullptr)
|
||||
{
|
||||
Tesses::Framework::TextStreams::StreamReader reader(strm);
|
||||
std::string ignores;
|
||||
while(reader.ReadLine(ignores))
|
||||
{
|
||||
if(!ignores.empty() && ignores[0] != '#')
|
||||
{
|
||||
ignored_files.push_back(ignores);
|
||||
}
|
||||
ignores.clear();
|
||||
namespace Tesses::CrossLang {
|
||||
|
||||
void CrossArchiveCreate(
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm, std::string name,
|
||||
TVMVersion version, std::string info, std::string icon) {
|
||||
std::vector<std::string> ignored_files;
|
||||
std::string file = "/.crossarchiveignore";
|
||||
if (vfs->FileExists(file)) {
|
||||
auto strm = vfs->OpenFile(file, "rb");
|
||||
if (strm != nullptr) {
|
||||
Tesses::Framework::TextStreams::StreamReader reader(strm);
|
||||
std::string ignores;
|
||||
while (reader.ReadLine(ignores)) {
|
||||
if (!ignores.empty() && ignores[0] != '#') {
|
||||
ignored_files.push_back(ignores);
|
||||
}
|
||||
ignores.clear();
|
||||
}
|
||||
}
|
||||
static std::vector<uint8_t> error_message_byte_code = {
|
||||
PUSHSTRING,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
GETVARIABLE,
|
||||
PUSHSTRING,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
PUSHSTRING,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
4,
|
||||
PUSHLONG,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
CALLMETHOD,
|
||||
RET
|
||||
};
|
||||
auto writeInt = [](std::shared_ptr<Tesses::Framework::Streams::Stream> strm,uint32_t number)->void{
|
||||
uint8_t buff[4];
|
||||
BitConverter::FromUint32BE(buff[0],number);
|
||||
strm->WriteBlock(buff,4);
|
||||
};
|
||||
auto writeStr = [&writeInt](std::shared_ptr<Tesses::Framework::Streams::Stream> strm,std::string text)->void {
|
||||
writeInt(strm,(uint32_t)text.size());
|
||||
strm->WriteBlock((const uint8_t*)text.c_str(),text.size());
|
||||
};
|
||||
|
||||
std::vector<std::string> strs;
|
||||
strs.push_back(name);
|
||||
strs.push_back(info);
|
||||
strs.push_back("Console");
|
||||
strs.push_back("WriteLine");
|
||||
strs.push_back("You are trying to run a crvm archive, stop it you won't get anywhere!\nUse crossarchiveextract instead.");
|
||||
|
||||
std::vector<std::string> resources;
|
||||
|
||||
auto ensureResource = [&resources](std::string path)->uint32_t {
|
||||
for(uint32_t i = 0; i < (uint32_t)resources.size(); i++)
|
||||
{
|
||||
if(resources[i] == path) return i;
|
||||
}
|
||||
uint32_t index = (uint32_t)resources.size();
|
||||
resources.push_back(path);
|
||||
return index;
|
||||
};
|
||||
auto ensureString = [&strs](std::string str)->uint32_t {
|
||||
for(uint32_t i = 0; i < (uint32_t)strs.size(); i++)
|
||||
{
|
||||
if(strs[i] == str) return i;
|
||||
}
|
||||
uint32_t index = (uint32_t)strs.size();
|
||||
strs.push_back(str);
|
||||
return index;
|
||||
};
|
||||
auto ms = std::make_shared<Tesses::Framework::Streams::MemoryStream>(true);
|
||||
|
||||
std::function<void(Tesses::Framework::Filesystem::VFSPath)> walkFS = [&ignored_files,vfs,&ensureString,&ensureResource,&ms,&walkFS,&writeInt](Tesses::Framework::Filesystem::VFSPath path)->void {
|
||||
|
||||
if(vfs->DirectoryExists(path))
|
||||
{
|
||||
|
||||
ms->WriteByte(1);
|
||||
std::vector<std::string> paths;
|
||||
for(auto item : vfs->EnumeratePaths(path))
|
||||
{
|
||||
if(!item.relative && item.path.size() == 1 && item.path[0] == "__resdir_tmp") continue;
|
||||
if(!item.relative && item.path.size() == 1 && item.path[0] == ".crossarchiveignore") continue;
|
||||
std::string filename = item.GetFileName();
|
||||
bool shallIgnore=false;
|
||||
for(auto ign : ignored_files) if(ign == filename) {shallIgnore=true; break;}
|
||||
if(shallIgnore) continue;
|
||||
if(vfs->DirectoryExists(item) || vfs->RegularFileExists(item))
|
||||
paths.push_back(item.GetFileName());
|
||||
}
|
||||
writeInt(ms,(uint32_t)paths.size());
|
||||
for(auto item : paths)
|
||||
{
|
||||
writeInt(ms,ensureString(item));
|
||||
walkFS(path / item);
|
||||
}
|
||||
}
|
||||
else if(vfs->RegularFileExists(path))
|
||||
{
|
||||
ms->WriteByte(0);
|
||||
writeInt(ms,ensureResource(path.ToString()));
|
||||
}
|
||||
};
|
||||
|
||||
walkFS(std::string("/"));
|
||||
if(!icon.empty())
|
||||
ensureResource(icon);
|
||||
|
||||
uint8_t main_header[18];
|
||||
memcpy(main_header,"TCROSSVM",8);
|
||||
TVMVersion rtVersion(CROSSLANG_BYTECODE_MAJOR,CROSSLANG_BYTECODE_MINOR,CROSSLANG_BYTECODE_PATCH,CROSSLANG_BYTECODE_BUILD,CROSSLANG_BYTECODE_VERSIONSTAGE);
|
||||
rtVersion.ToArray(main_header+8);
|
||||
version.ToArray(main_header+13);
|
||||
strm->WriteBlock(main_header,sizeof(main_header));
|
||||
writeInt(strm,(uint32_t)((icon.empty() ? 5 : 6)+resources.size()));
|
||||
strm->WriteBlock((const uint8_t*)"STRS",4);
|
||||
uint32_t sz=4;
|
||||
for(auto str : strs)
|
||||
sz += (uint32_t)(4 + str.size());
|
||||
writeInt(strm,sz);
|
||||
writeInt(strm,(uint32_t)strs.size());
|
||||
for(auto str : strs)
|
||||
{
|
||||
writeStr(strm,str);
|
||||
}
|
||||
strm->WriteBlock((const uint8_t*)"NAME",4);
|
||||
writeInt(strm,4);
|
||||
writeInt(strm,0);
|
||||
strm->WriteBlock((const uint8_t*)"INFO",4);
|
||||
writeInt(strm,4);
|
||||
writeInt(strm,1);
|
||||
if(!icon.empty())
|
||||
{
|
||||
strm->WriteBlock((const uint8_t*)"ICON",4);
|
||||
writeInt(strm,4);
|
||||
writeInt(strm,ensureResource(icon));
|
||||
}
|
||||
strm->WriteBlock((const uint8_t*)"CHKS",4);
|
||||
writeInt(strm,(uint32_t)(12+error_message_byte_code.size()));
|
||||
writeInt(strm,1);
|
||||
writeInt(strm,0);
|
||||
writeInt(strm,(uint32_t)error_message_byte_code.size());
|
||||
strm->WriteBlock(error_message_byte_code.data(),error_message_byte_code.size());
|
||||
|
||||
|
||||
|
||||
for(auto res : resources)
|
||||
{
|
||||
strm->WriteBlock((const uint8_t*)"RESO",4);
|
||||
auto strm2 = vfs->OpenFile(res,"rb");
|
||||
writeInt(strm,(uint32_t)strm2->GetLength());
|
||||
strm2->CopyTo(strm);
|
||||
|
||||
}
|
||||
strm->WriteBlock((const uint8_t*)"ARCV",4);
|
||||
writeInt(strm,(uint32_t)ms->GetLength());
|
||||
ms->Seek(0,Tesses::Framework::Streams::SeekOrigin::Begin);
|
||||
ms->CopyTo(strm);
|
||||
}
|
||||
std::pair<std::pair<std::string,TVMVersion>,std::string> CrossArchiveExtract(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs)
|
||||
{
|
||||
auto ensure = [strm](uint8_t* buffer,size_t count)->void{
|
||||
static std::vector<uint8_t> error_message_byte_code = {
|
||||
PUSHSTRING, 0, 0, 0, 2, GETVARIABLE, PUSHSTRING, 0, 0, 0,
|
||||
3, PUSHSTRING, 0, 0, 0, 4, PUSHLONG, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, CALLMETHOD, RET};
|
||||
auto writeInt = [](std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||
uint32_t number) -> void {
|
||||
uint8_t buff[4];
|
||||
BitConverter::FromUint32BE(buff[0], number);
|
||||
strm->WriteBlock(buff, 4);
|
||||
};
|
||||
auto writeStr =
|
||||
[&writeInt](std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||
std::string text) -> void {
|
||||
writeInt(strm, (uint32_t)text.size());
|
||||
strm->WriteBlock((const uint8_t *)text.c_str(), text.size());
|
||||
};
|
||||
|
||||
size_t read = strm->ReadBlock(buffer, count);
|
||||
if(read < count) throw VMException("End of file, could not read " + std::to_string((int64_t)count) + " byte(s)., offset=" + std::to_string(strm->GetLength()));
|
||||
};
|
||||
auto ensureInt = [&ensure]()->uint32_t {
|
||||
uint8_t buffer[4];
|
||||
ensure(buffer,4);
|
||||
return BitConverter::ToUint32BE(buffer[0]);
|
||||
};
|
||||
auto ensureStr = [&ensure,&ensureInt]()-> std::string {
|
||||
auto len = ensureInt();
|
||||
if(len == 0) return {};
|
||||
std::string str={};
|
||||
str.resize((size_t)len);
|
||||
ensure((uint8_t*)str.data(),str.size());
|
||||
return str;
|
||||
};
|
||||
std::vector<std::string> strs;
|
||||
auto getStr = [&ensure,&ensureInt,&strs]()-> std::string {
|
||||
auto index = ensureInt();
|
||||
if(index > strs.size()) throw VMException("String does not exist in TCrossVM file, expected string index: " + std::to_string(index) + ", total strings: " + std::to_string(strs.size()));
|
||||
return strs[index];
|
||||
};
|
||||
uint8_t main_header[18];
|
||||
ensure(main_header,sizeof(main_header));
|
||||
if(strncmp((const char*)main_header,"TCROSSVM",8) != 0) throw VMException("Invalid TCrossVM image.");
|
||||
TVMVersion version(main_header+8);
|
||||
if(version.CompareToRuntime() == 1)
|
||||
{
|
||||
throw VMException("Runtime is too old.");
|
||||
std::vector<std::string> strs;
|
||||
strs.push_back(name);
|
||||
strs.push_back(info);
|
||||
strs.push_back("Console");
|
||||
strs.push_back("WriteLine");
|
||||
strs.push_back("You are trying to run a crvm archive, stop it you won't "
|
||||
"get anywhere!\nUse crossarchiveextract instead.");
|
||||
|
||||
std::vector<std::string> resources;
|
||||
|
||||
auto ensureResource = [&resources](std::string path) -> uint32_t {
|
||||
for (uint32_t i = 0; i < (uint32_t)resources.size(); i++) {
|
||||
if (resources[i] == path)
|
||||
return i;
|
||||
}
|
||||
TVMVersion v2(main_header+13);
|
||||
std::string name;
|
||||
std::string info;
|
||||
|
||||
uint32_t index = (uint32_t)resources.size();
|
||||
resources.push_back(path);
|
||||
return index;
|
||||
};
|
||||
auto ensureString = [&strs](std::string str) -> uint32_t {
|
||||
for (uint32_t i = 0; i < (uint32_t)strs.size(); i++) {
|
||||
if (strs[i] == str)
|
||||
return i;
|
||||
}
|
||||
uint32_t index = (uint32_t)strs.size();
|
||||
strs.push_back(str);
|
||||
return index;
|
||||
};
|
||||
auto ms = std::make_shared<Tesses::Framework::Streams::MemoryStream>(true);
|
||||
|
||||
size_t _len = (size_t)ensureInt();
|
||||
std::function<void(Tesses::Framework::Filesystem::VFSPath)> walkFS =
|
||||
[&ignored_files, vfs, &ensureString, &ensureResource, &ms, &walkFS,
|
||||
&writeInt](Tesses::Framework::Filesystem::VFSPath path) -> void {
|
||||
if (vfs->DirectoryExists(path)) {
|
||||
|
||||
char table_name[4];
|
||||
|
||||
uint32_t resource_id = 0;
|
||||
|
||||
Tesses::Framework::Filesystem::VFSPath tmpDir("/__resdir_tmp");
|
||||
|
||||
vfs->CreateDirectory(tmpDir);
|
||||
for(size_t i = 0;i < _len; i++)
|
||||
{
|
||||
ensure((uint8_t*)table_name,sizeof(table_name));
|
||||
size_t tableLen = (size_t)ensureInt();
|
||||
if(strncmp(table_name,"NAME",4) == 0)
|
||||
{
|
||||
name = getStr();
|
||||
}
|
||||
else if(strncmp(table_name,"INFO",4) == 0)
|
||||
{
|
||||
info = getStr();
|
||||
|
||||
}
|
||||
|
||||
else if(strncmp(table_name,"RESO",4) == 0) //resources (using embed)
|
||||
{
|
||||
|
||||
auto path = tmpDir /std::to_string(resource_id);
|
||||
|
||||
auto strm2 = vfs->OpenFile(path,"wb");
|
||||
size_t read = 0;
|
||||
size_t offset = 0;
|
||||
uint8_t buff[1024];
|
||||
do {
|
||||
|
||||
read = std::min(std::min(tableLen-offset,tableLen), sizeof(buff));
|
||||
read = strm->Read(buff,read);
|
||||
if(read > 0)
|
||||
strm2->WriteBlock(buff,read);
|
||||
offset+=read;
|
||||
} while(read > 0);
|
||||
|
||||
resource_id++;
|
||||
}
|
||||
|
||||
else if(strncmp(table_name,"STRS",4) == 0) //strings
|
||||
{
|
||||
size_t strsLen = (size_t)ensureInt();
|
||||
for(size_t j = 0;j < strsLen;j++)
|
||||
{
|
||||
strs.push_back(ensureStr());
|
||||
}
|
||||
}
|
||||
else if(strncmp(table_name,"ARCV",4) == 0)
|
||||
{
|
||||
size_t offset = 0;
|
||||
|
||||
std::function<void(Tesses::Framework::Filesystem::VFSPath)> walkEntry = [strm,vfs,&getStr,&ensureInt,&tmpDir,&tableLen,&offset,&walkEntry](Tesses::Framework::Filesystem::VFSPath path)->void {
|
||||
if(offset + 1 > tableLen) return;
|
||||
uint8_t type = strm->ReadByte();
|
||||
offset++;
|
||||
if(type == 1)
|
||||
{
|
||||
//ISDIR
|
||||
vfs->CreateDirectory(path);
|
||||
if(offset + 4 > tableLen) return;
|
||||
uint32_t count = ensureInt();
|
||||
offset +=4;
|
||||
for(uint32_t i = 0; i < count; i++)
|
||||
{
|
||||
if(offset + 4 > tableLen) return;
|
||||
std::string name = getStr();
|
||||
offset +=4;
|
||||
walkEntry(path / name);
|
||||
}
|
||||
}
|
||||
else if(type == 0)
|
||||
{
|
||||
if(offset + 4 > tableLen) return;
|
||||
uint32_t index = ensureInt();
|
||||
auto fSrc = tmpDir /std::to_string(index);
|
||||
vfs->MoveFile(fSrc, path);
|
||||
ms->WriteByte(1);
|
||||
std::vector<std::string> paths;
|
||||
for (auto item : vfs->EnumeratePaths(path)) {
|
||||
if (!item.relative && item.path.size() == 1 &&
|
||||
item.path[0] == "__resdir_tmp")
|
||||
continue;
|
||||
if (!item.relative && item.path.size() == 1 &&
|
||||
item.path[0] == ".crossarchiveignore")
|
||||
continue;
|
||||
std::string filename = item.GetFileName();
|
||||
bool shallIgnore = false;
|
||||
for (auto ign : ignored_files)
|
||||
if (ign == filename) {
|
||||
shallIgnore = true;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
walkEntry(std::string("/"));
|
||||
if (shallIgnore)
|
||||
continue;
|
||||
if (vfs->DirectoryExists(item) || vfs->RegularFileExists(item))
|
||||
paths.push_back(item.GetFileName());
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strm->CanSeek())
|
||||
{
|
||||
strm->Seek((int64_t)tableLen,Tesses::Framework::Streams::SeekOrigin::Current);
|
||||
}
|
||||
else{
|
||||
uint8_t* buffer=new uint8_t[tableLen];
|
||||
ensure(buffer,tableLen);
|
||||
delete[] buffer;
|
||||
}
|
||||
writeInt(ms, (uint32_t)paths.size());
|
||||
for (auto item : paths) {
|
||||
writeInt(ms, ensureString(item));
|
||||
walkFS(path / item);
|
||||
}
|
||||
} else if (vfs->RegularFileExists(path)) {
|
||||
ms->WriteByte(0);
|
||||
writeInt(ms, ensureResource(path.ToString()));
|
||||
}
|
||||
vfs->DeleteDirectoryRecurse(tmpDir);
|
||||
|
||||
return std::pair<std::pair<std::string,TVMVersion>,std::string>(std::pair<std::string,TVMVersion>(name,v2),info);
|
||||
};
|
||||
|
||||
walkFS(std::string("/"));
|
||||
if (!icon.empty())
|
||||
ensureResource(icon);
|
||||
|
||||
uint8_t main_header[18];
|
||||
memcpy(main_header, "TCROSSVM", 8);
|
||||
TVMVersion rtVersion(CROSSLANG_BYTECODE_MAJOR, CROSSLANG_BYTECODE_MINOR,
|
||||
CROSSLANG_BYTECODE_PATCH, CROSSLANG_BYTECODE_BUILD,
|
||||
CROSSLANG_BYTECODE_VERSIONSTAGE);
|
||||
rtVersion.ToArray(main_header + 8);
|
||||
version.ToArray(main_header + 13);
|
||||
strm->WriteBlock(main_header, sizeof(main_header));
|
||||
writeInt(strm, (uint32_t)((icon.empty() ? 5 : 6) + resources.size()));
|
||||
strm->WriteBlock((const uint8_t *)"STRS", 4);
|
||||
uint32_t sz = 4;
|
||||
for (auto str : strs)
|
||||
sz += (uint32_t)(4 + str.size());
|
||||
writeInt(strm, sz);
|
||||
writeInt(strm, (uint32_t)strs.size());
|
||||
for (auto str : strs) {
|
||||
writeStr(strm, str);
|
||||
}
|
||||
strm->WriteBlock((const uint8_t *)"NAME", 4);
|
||||
writeInt(strm, 4);
|
||||
writeInt(strm, 0);
|
||||
strm->WriteBlock((const uint8_t *)"INFO", 4);
|
||||
writeInt(strm, 4);
|
||||
writeInt(strm, 1);
|
||||
if (!icon.empty()) {
|
||||
strm->WriteBlock((const uint8_t *)"ICON", 4);
|
||||
writeInt(strm, 4);
|
||||
writeInt(strm, ensureResource(icon));
|
||||
}
|
||||
strm->WriteBlock((const uint8_t *)"CHKS", 4);
|
||||
writeInt(strm, (uint32_t)(12 + error_message_byte_code.size()));
|
||||
writeInt(strm, 1);
|
||||
writeInt(strm, 0);
|
||||
writeInt(strm, (uint32_t)error_message_byte_code.size());
|
||||
strm->WriteBlock(error_message_byte_code.data(),
|
||||
error_message_byte_code.size());
|
||||
|
||||
for (auto res : resources) {
|
||||
strm->WriteBlock((const uint8_t *)"RESO", 4);
|
||||
auto strm2 = vfs->OpenFile(res, "rb");
|
||||
writeInt(strm, (uint32_t)strm2->GetLength());
|
||||
strm2->CopyTo(strm);
|
||||
}
|
||||
strm->WriteBlock((const uint8_t *)"ARCV", 4);
|
||||
writeInt(strm, (uint32_t)ms->GetLength());
|
||||
ms->Seek(0, Tesses::Framework::Streams::SeekOrigin::Begin);
|
||||
ms->CopyTo(strm);
|
||||
}
|
||||
std::pair<std::pair<std::string, TVMVersion>, std::string>
|
||||
CrossArchiveExtract(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs) {
|
||||
auto ensure = [strm](uint8_t *buffer, size_t count) -> void {
|
||||
size_t read = strm->ReadBlock(buffer, count);
|
||||
if (read < count)
|
||||
throw VMException(
|
||||
"End of file, could not read " +
|
||||
std::to_string((int64_t)count) +
|
||||
" byte(s)., offset=" + std::to_string(strm->GetLength()));
|
||||
};
|
||||
auto ensureInt = [&ensure]() -> uint32_t {
|
||||
uint8_t buffer[4];
|
||||
ensure(buffer, 4);
|
||||
return BitConverter::ToUint32BE(buffer[0]);
|
||||
};
|
||||
auto ensureStr = [&ensure, &ensureInt]() -> std::string {
|
||||
auto len = ensureInt();
|
||||
if (len == 0)
|
||||
return {};
|
||||
std::string str = {};
|
||||
str.resize((size_t)len);
|
||||
ensure((uint8_t *)str.data(), str.size());
|
||||
return str;
|
||||
};
|
||||
std::vector<std::string> strs;
|
||||
auto getStr = [&ensure, &ensureInt, &strs]() -> std::string {
|
||||
auto index = ensureInt();
|
||||
if (index > strs.size())
|
||||
throw VMException("String does not exist in TCrossVM file, "
|
||||
"expected string index: " +
|
||||
std::to_string(index) + ", total strings: " +
|
||||
std::to_string(strs.size()));
|
||||
return strs[index];
|
||||
};
|
||||
uint8_t main_header[18];
|
||||
ensure(main_header, sizeof(main_header));
|
||||
if (strncmp((const char *)main_header, "TCROSSVM", 8) != 0)
|
||||
throw VMException("Invalid TCrossVM image.");
|
||||
TVMVersion version(main_header + 8);
|
||||
if (version.CompareToRuntime() == 1) {
|
||||
throw VMException("Runtime is too old.");
|
||||
}
|
||||
TVMVersion v2(main_header + 13);
|
||||
std::string name;
|
||||
std::string info;
|
||||
|
||||
size_t _len = (size_t)ensureInt();
|
||||
|
||||
char table_name[4];
|
||||
|
||||
uint32_t resource_id = 0;
|
||||
|
||||
Tesses::Framework::Filesystem::VFSPath tmpDir("/__resdir_tmp");
|
||||
|
||||
vfs->CreateDirectory(tmpDir);
|
||||
for (size_t i = 0; i < _len; i++) {
|
||||
ensure((uint8_t *)table_name, sizeof(table_name));
|
||||
size_t tableLen = (size_t)ensureInt();
|
||||
if (strncmp(table_name, "NAME", 4) == 0) {
|
||||
name = getStr();
|
||||
} else if (strncmp(table_name, "INFO", 4) == 0) {
|
||||
info = getStr();
|
||||
|
||||
}
|
||||
|
||||
else if (strncmp(table_name, "RESO", 4) == 0) // resources (using embed)
|
||||
{
|
||||
|
||||
auto path = tmpDir / std::to_string(resource_id);
|
||||
|
||||
auto strm2 = vfs->OpenFile(path, "wb");
|
||||
size_t read = 0;
|
||||
size_t offset = 0;
|
||||
uint8_t buff[1024];
|
||||
do {
|
||||
|
||||
read = std::min(std::min(tableLen - offset, tableLen),
|
||||
sizeof(buff));
|
||||
read = strm->Read(buff, read);
|
||||
if (read > 0)
|
||||
strm2->WriteBlock(buff, read);
|
||||
offset += read;
|
||||
} while (read > 0);
|
||||
|
||||
resource_id++;
|
||||
}
|
||||
|
||||
else if (strncmp(table_name, "STRS", 4) == 0) // strings
|
||||
{
|
||||
size_t strsLen = (size_t)ensureInt();
|
||||
for (size_t j = 0; j < strsLen; j++) {
|
||||
strs.push_back(ensureStr());
|
||||
}
|
||||
} else if (strncmp(table_name, "ARCV", 4) == 0) {
|
||||
size_t offset = 0;
|
||||
|
||||
std::function<void(Tesses::Framework::Filesystem::VFSPath)>
|
||||
walkEntry =
|
||||
[strm, vfs, &getStr, &ensureInt, &tmpDir, &tableLen,
|
||||
&offset, &walkEntry](
|
||||
Tesses::Framework::Filesystem::VFSPath path) -> void {
|
||||
if (offset + 1 > tableLen)
|
||||
return;
|
||||
uint8_t type = strm->ReadByte();
|
||||
offset++;
|
||||
if (type == 1) {
|
||||
// ISDIR
|
||||
vfs->CreateDirectory(path);
|
||||
if (offset + 4 > tableLen)
|
||||
return;
|
||||
uint32_t count = ensureInt();
|
||||
offset += 4;
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
if (offset + 4 > tableLen)
|
||||
return;
|
||||
std::string name = getStr();
|
||||
offset += 4;
|
||||
walkEntry(path / name);
|
||||
}
|
||||
} else if (type == 0) {
|
||||
if (offset + 4 > tableLen)
|
||||
return;
|
||||
uint32_t index = ensureInt();
|
||||
auto fSrc = tmpDir / std::to_string(index);
|
||||
vfs->MoveFile(fSrc, path);
|
||||
}
|
||||
};
|
||||
|
||||
walkEntry(std::string("/"));
|
||||
} else {
|
||||
if (strm->CanSeek()) {
|
||||
strm->Seek((int64_t)tableLen,
|
||||
Tesses::Framework::Streams::SeekOrigin::Current);
|
||||
} else {
|
||||
uint8_t *buffer = new uint8_t[tableLen];
|
||||
ensure(buffer, tableLen);
|
||||
delete[] buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
vfs->DeleteDirectoryRecurse(tmpDir);
|
||||
|
||||
return std::pair<std::pair<std::string, TVMVersion>, std::string>(
|
||||
std::pair<std::string, TVMVersion>(name, v2), info);
|
||||
}
|
||||
} // namespace Tesses::CrossLang
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,917 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
namespace Tesses::CrossLang {
|
||||
class CrossLangFileReader {
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
|
||||
void Ensure(uint8_t* buffer, size_t len)
|
||||
{
|
||||
auto read = this->strm->ReadBlock(buffer, len);
|
||||
if(read < len) throw VMException("End of file, could not read " + std::to_string((int64_t)len) + " byte(s)., offset=" + std::to_string(strm->GetLength()));
|
||||
}
|
||||
|
||||
uint32_t ReadInt()
|
||||
{
|
||||
uint8_t buffer[4];
|
||||
Ensure(buffer,4);
|
||||
return BitConverter::ToUint32BE(buffer[0]);
|
||||
}
|
||||
std::string ReadString()
|
||||
{
|
||||
auto len = ReadInt();
|
||||
if(len == 0) return {};
|
||||
std::string str={};
|
||||
str.resize((size_t)len);
|
||||
Ensure((uint8_t*)str.data(),str.size());
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string GetString()
|
||||
{
|
||||
uint32_t index=ReadInt();
|
||||
if(index >= this->strings.size()) throw VMException("String does not exist in TCrossVM file, expected string index: " + std::to_string(index) + ", total strings: " + std::to_string(this->strings.size()));
|
||||
return this->strings[index];
|
||||
}
|
||||
|
||||
public:
|
||||
CrossLangFileReader(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)
|
||||
{
|
||||
this->strm = strm;
|
||||
|
||||
|
||||
|
||||
uint8_t main_header[18];
|
||||
Ensure(main_header,sizeof(main_header));
|
||||
if(strncmp((const char*)main_header,"TCROSSVM",8) != 0) throw VMException("Invalid TCrossVM image.");
|
||||
TVMVersion version(main_header+8);
|
||||
if(version.CompareToRuntime() == 1)
|
||||
{
|
||||
throw VMException("Runtime is too old.");
|
||||
}
|
||||
TVMVersion v2(main_header+13);
|
||||
this->version = v2;
|
||||
|
||||
size_t _len = (size_t)ReadInt();
|
||||
|
||||
char table_name[4];
|
||||
|
||||
for(size_t i = 0;i < _len; i++)
|
||||
{
|
||||
Ensure((uint8_t*)table_name,sizeof(table_name));
|
||||
size_t tableLen = (size_t)ReadInt();
|
||||
if(strncmp(table_name,"NAME",4) == 0)
|
||||
{
|
||||
this->name = GetString();
|
||||
}
|
||||
else if(strncmp(table_name,"INFO",4) == 0)
|
||||
{
|
||||
this->info = GetString();
|
||||
}
|
||||
else if(strncmp(table_name,"DEPS",4) == 0) //dependencies
|
||||
{
|
||||
std::string name = GetString();
|
||||
uint8_t version_bytes[5];
|
||||
Ensure(version_bytes,sizeof(version_bytes));
|
||||
TVMVersion depVersion(version_bytes);
|
||||
this->dependencies.push_back(std::pair<std::string,TVMVersion>(name, depVersion));
|
||||
}
|
||||
else if(strncmp(table_name,"TOOL",4) == 0) //compile tools (for package manager)
|
||||
{
|
||||
std::string name = GetString();
|
||||
uint8_t version_bytes[5];
|
||||
Ensure(version_bytes,sizeof(version_bytes));
|
||||
TVMVersion depVersion(version_bytes);
|
||||
this->tools.push_back(std::pair<std::string,TVMVersion>(name, depVersion));
|
||||
}
|
||||
else if(strncmp(table_name,"RESO",4) == 0) //resources (using embed)
|
||||
{
|
||||
std::vector<uint8_t> data;
|
||||
data.resize(tableLen);
|
||||
Ensure(data.data(), tableLen);
|
||||
this->resources.push_back(data);
|
||||
}
|
||||
else if(strncmp(table_name,"CHKS",4) == 0) //chunks
|
||||
{
|
||||
size_t chunkCount = (size_t)ReadInt();
|
||||
for(size_t j = 0; j < chunkCount; j++)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
|
||||
|
||||
size_t argCount = (size_t)ReadInt();
|
||||
for(size_t k = 0; k < argCount; k++)
|
||||
{
|
||||
args.push_back(GetString());
|
||||
}
|
||||
std::vector<uint8_t> code;
|
||||
size_t len = (size_t)ReadInt();
|
||||
code.resize(len);
|
||||
Ensure(code.data(),len);
|
||||
//reader.ReadIntoBuffer(chunk->code);
|
||||
|
||||
this->chunks.emplace(this->chunks.end(),args,code);
|
||||
}
|
||||
|
||||
}
|
||||
else if(strncmp(table_name,"FUNS",4) == 0) //functions
|
||||
{
|
||||
size_t funLength = (size_t)ReadInt();
|
||||
|
||||
for(size_t j = 0; j < funLength;j++)
|
||||
{
|
||||
std::vector<std::string> fnParts;
|
||||
uint32_t fnPartsC = ReadInt();
|
||||
for(uint32_t k = 0; k < fnPartsC; k++)
|
||||
{
|
||||
fnParts.push_back(GetString());
|
||||
}
|
||||
|
||||
uint32_t fnNumber = ReadInt();
|
||||
this->functions.push_back(std::pair<std::vector<std::string>,uint32_t>(fnParts,fnNumber));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if(strncmp(table_name,"STRS",4) == 0) //strings
|
||||
{
|
||||
size_t strsLen = (size_t)ReadInt();
|
||||
for(size_t j = 0;j < strsLen;j++)
|
||||
{
|
||||
this->strings.push_back(ReadString());
|
||||
}
|
||||
}
|
||||
else if(strncmp(table_name,"ICON",4) == 0) //icon
|
||||
{
|
||||
this->icon = (int32_t)ReadInt();
|
||||
}
|
||||
else if(strncmp(table_name,"MACH",4) == 0) //machine
|
||||
{
|
||||
std::string name = GetString();
|
||||
std::string howToGet = GetString();
|
||||
this->vms.push_back(std::pair<std::string,std::string>(name,howToGet));
|
||||
}
|
||||
else if(strncmp(table_name,"CLSS",4) == 0) //classes
|
||||
{
|
||||
uint32_t clsCnt = ReadInt();
|
||||
for(uint32_t j = 0; j < clsCnt; j++)
|
||||
{
|
||||
TClass cls;
|
||||
cls.documentation= GetString();
|
||||
uint32_t name_cnt = ReadInt();
|
||||
for(uint32_t k = 0; k < name_cnt; k++)
|
||||
{
|
||||
cls.name.push_back(GetString());
|
||||
}
|
||||
name_cnt = ReadInt();
|
||||
for(uint32_t k = 0; k < name_cnt; k++)
|
||||
{
|
||||
cls.inherits.push_back(GetString());
|
||||
}
|
||||
name_cnt = ReadInt();
|
||||
for(uint32_t k = 0; k < name_cnt; k++)
|
||||
{
|
||||
TClassEntry ent;
|
||||
Ensure(main_header,1);
|
||||
uint8_t sig = main_header[0];
|
||||
ent.isAbstract = (sig & 0b00001000) != 0;
|
||||
ent.isFunction = (sig & 0b00000100) == 0;
|
||||
ent.modifier = (TClassModifier)(sig & 3);
|
||||
ent.documentation = GetString();
|
||||
ent.name = GetString();
|
||||
uint32_t arglen = ReadInt();
|
||||
for(uint32_t l = 0; l < arglen; l++)
|
||||
ent.args.push_back(GetString());
|
||||
ent.chunkId = ReadInt();
|
||||
cls.entry.push_back(ent);
|
||||
}
|
||||
this->classes.push_back(cls);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<uint8_t> data;
|
||||
data.resize(tableLen);
|
||||
Ensure(data.data(), tableLen);
|
||||
std::string key(std::string(table_name), 4);
|
||||
this->sections.push_back(std::pair<std::string,std::vector<uint8_t>>(key,data));
|
||||
}
|
||||
}
|
||||
}
|
||||
std::vector<std::string> strings;
|
||||
std::vector<std::pair<std::vector<std::string>,std::vector<uint8_t>>> chunks;
|
||||
std::vector<std::pair<std::string,std::string>> vms;
|
||||
std::vector<std::pair<std::vector<std::string>, uint32_t>> functions;
|
||||
std::vector<std::pair<std::string,TVMVersion>> dependencies;
|
||||
std::vector<std::pair<std::string,TVMVersion>> tools;
|
||||
std::vector<std::pair<std::string,std::vector<uint8_t>>> sections;
|
||||
std::vector<std::vector<uint8_t>> resources;
|
||||
std::vector<TClass> classes;
|
||||
std::string name;
|
||||
TVMVersion version;
|
||||
std::string info;
|
||||
int32_t icon;
|
||||
|
||||
std::string Chunk2String(size_t chunkId,size_t tab)
|
||||
{
|
||||
if(chunkId >= this->chunks.size()) return {};
|
||||
auto& code = this->chunks[chunkId].second;
|
||||
|
||||
std::string buffer = {};
|
||||
std::vector<uint32_t> labels;
|
||||
size_t i = 0;
|
||||
while(i < code.size())
|
||||
{
|
||||
switch(code[i++])
|
||||
{
|
||||
case PUSHRESOURCESTREAM:
|
||||
case PUSHRESOURCE:
|
||||
case PUSHSTRING:
|
||||
case SCOPEENDTIMES:
|
||||
case PUSHCLOSURE:
|
||||
case PUSHSCOPELESSCLOSURE:
|
||||
i+=4;
|
||||
break;
|
||||
case PUSHLONG:
|
||||
case PUSHDOUBLE:
|
||||
i+=8;
|
||||
break;
|
||||
case PUSHCHAR:
|
||||
i+=1;
|
||||
break;
|
||||
case JMP:
|
||||
case JMPC:
|
||||
case JMPIFBREAK:
|
||||
case JMPIFCONTINUE:
|
||||
case JMPIFDEFINED:
|
||||
case JMPUNDEFINED:
|
||||
{
|
||||
bool already = false;
|
||||
for(auto item : labels)
|
||||
{
|
||||
if(item == i) {
|
||||
already=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!already)
|
||||
labels.push_back(BitConverter::ToUint32BE(code[i]));
|
||||
i+=4;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
i=0;
|
||||
|
||||
while(i < code.size())
|
||||
{
|
||||
for(size_t j = 0; j < labels.size(); j++)
|
||||
{
|
||||
if(labels[j] == i)
|
||||
{
|
||||
buffer.append(tab,'\t');
|
||||
buffer.append("lbl l" + std::to_string((uint32_t)j) + "\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
buffer.append(tab,'\t');
|
||||
|
||||
|
||||
switch(code[i++])
|
||||
{
|
||||
case ADD:
|
||||
buffer.append("add");
|
||||
break;
|
||||
case SUB:
|
||||
buffer.append("sub");
|
||||
break;
|
||||
case TIMES:
|
||||
buffer.append("mul");
|
||||
break;
|
||||
case DIVIDE:
|
||||
buffer.append("div");
|
||||
break;
|
||||
case MODULO:
|
||||
buffer.append("mod");
|
||||
break;
|
||||
case LEFTSHIFT:
|
||||
buffer.append("lsh");
|
||||
break;
|
||||
case RIGHTSHIFT:
|
||||
buffer.append("rsh");
|
||||
break;
|
||||
case BITWISEOR:
|
||||
buffer.append("bor");
|
||||
break;
|
||||
case BITWISEAND:
|
||||
buffer.append("band");
|
||||
break;
|
||||
case BITWISENOT:
|
||||
buffer.append("bnot");
|
||||
break;
|
||||
case LESSTHAN:
|
||||
buffer.append("lt");
|
||||
break;
|
||||
case GREATERTHAN:
|
||||
buffer.append("gt");
|
||||
break;
|
||||
case LESSTHANEQ:
|
||||
buffer.append("lte");
|
||||
break;
|
||||
case GREATERTHANEQ:
|
||||
buffer.append("gte");
|
||||
break;
|
||||
case EQ:
|
||||
buffer.append("eq");
|
||||
break;
|
||||
case NEQ:
|
||||
buffer.append("neq");
|
||||
break;
|
||||
case NOT:
|
||||
buffer.append("not");
|
||||
break;
|
||||
case NEGATIVE:
|
||||
buffer.append("neg");
|
||||
break;
|
||||
case XOR:
|
||||
buffer.append("xor");
|
||||
break;
|
||||
case POP:
|
||||
buffer.append("pop");
|
||||
break;
|
||||
case DUP:
|
||||
buffer.append("dup");
|
||||
break;
|
||||
case PUSHCLOSURE:
|
||||
{
|
||||
uint32_t clId = (uint32_t)code[i++] << 24;
|
||||
clId |= (uint32_t)code[i++] << 16;
|
||||
clId |= (uint32_t)code[i++] << 8;
|
||||
clId |= (uint32_t)code[i++];
|
||||
buffer.append("pushclosure (");
|
||||
bool first=true;
|
||||
|
||||
for(auto item : this->chunks.at(clId).first)
|
||||
{
|
||||
if(!first)
|
||||
buffer.append(", ");
|
||||
buffer.append(item);
|
||||
first=false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
buffer.append(") {\n");
|
||||
buffer.append(Chunk2String((size_t)clId,tab+1));
|
||||
buffer.append(tab,'\t');
|
||||
buffer.append("}");
|
||||
}
|
||||
break;
|
||||
case CREATEDICTIONARY:
|
||||
buffer.append("createdict");
|
||||
break;
|
||||
case CREATEARRAY:
|
||||
buffer.append("createarray");
|
||||
break;
|
||||
case APPENDLIST:
|
||||
buffer.append("appendlist");
|
||||
break;
|
||||
case APPENDDICT:
|
||||
buffer.append("appenddict");
|
||||
break;
|
||||
case PUSHRESOUURCEDIR:
|
||||
buffer.append("embeddir");
|
||||
break;
|
||||
case PUSHRESOURCE:
|
||||
{
|
||||
uint32_t clId = (uint32_t)code[i++] << 24;
|
||||
clId |= (uint32_t)code[i++] << 16;
|
||||
clId |= (uint32_t)code[i++] << 8;
|
||||
clId |= (uint32_t)code[i++];
|
||||
buffer.append("embed ");
|
||||
buffer.append(EscapeString(name + "-" + version.ToString()+"_"+ std::to_string(clId) + ".bin",true));
|
||||
}
|
||||
break;
|
||||
case PUSHRESOURCESTREAM:
|
||||
{
|
||||
uint32_t clId = (uint32_t)code[i++] << 24;
|
||||
clId |= (uint32_t)code[i++] << 16;
|
||||
clId |= (uint32_t)code[i++] << 8;
|
||||
clId |= (uint32_t)code[i++];
|
||||
buffer.append("embedstrm ");
|
||||
buffer.append(EscapeString(name + "-" + version.ToString()+"_"+ std::to_string(clId) + ".bin",true));
|
||||
}
|
||||
break;
|
||||
case PUSHLONG:
|
||||
{
|
||||
uint64_t number = (uint64_t)code[i++] << 56;
|
||||
number |= (uint64_t)code[i++] << 48;
|
||||
number |= (uint64_t)code[i++] << 40;
|
||||
number |= (uint64_t)code[i++] << 32;
|
||||
number |= (uint64_t)code[i++] << 24;
|
||||
number |= (uint64_t)code[i++] << 16;
|
||||
number |= (uint64_t)code[i++] << 8;
|
||||
number |= (uint64_t)code[i++];
|
||||
buffer.append("push " + std::to_string(number));
|
||||
|
||||
}
|
||||
break;
|
||||
case PUSHCHAR:
|
||||
{
|
||||
buffer.append("push '" + EscapeString(std::string({(char)code[i++]}),false) + "'");
|
||||
}
|
||||
break;
|
||||
case PUSHDOUBLE:
|
||||
{
|
||||
|
||||
auto res = BitConverter::ToDoubleBE(code[i]);
|
||||
i+=8;
|
||||
buffer.append("push " + std::to_string(res));
|
||||
}
|
||||
break;
|
||||
case PUSHSTRING:
|
||||
{
|
||||
auto res = BitConverter::ToUint32BE(code[i]);
|
||||
i+=4;
|
||||
buffer.append("push " + EscapeString(strings[res],true));
|
||||
}
|
||||
break;
|
||||
case PUSHNULL:
|
||||
buffer.append("push null");
|
||||
break;
|
||||
case PUSHUNDEFINED:
|
||||
buffer.append("push undefined");
|
||||
break;
|
||||
case SCOPEBEGIN:
|
||||
buffer.append("scopebegin");
|
||||
break;
|
||||
case SCOPEEND:
|
||||
buffer.append("scopeend");
|
||||
break;
|
||||
case SCOPEENDTIMES:
|
||||
{
|
||||
auto res = BitConverter::ToUint32BE(code[i]);
|
||||
i+=4;
|
||||
buffer.append("scopeendtimes " + std::to_string(res));
|
||||
}
|
||||
break;
|
||||
case PUSHFALSE:
|
||||
buffer.append("push false");
|
||||
break;
|
||||
case PUSHTRUE:
|
||||
buffer.append("push true");
|
||||
break;
|
||||
case SETVARIABLE:
|
||||
buffer.append("setvariable");
|
||||
break;
|
||||
case GETVARIABLE:
|
||||
buffer.append("getvariable");
|
||||
break;
|
||||
case DECLAREVARIABLE:
|
||||
buffer.append("declarevariable");
|
||||
break;
|
||||
case DECLARECONSTVARIABLE:
|
||||
buffer.append("declareconstvariable");
|
||||
break;
|
||||
case SETFIELD:
|
||||
buffer.append("setfield");
|
||||
break;
|
||||
case GETFIELD:
|
||||
buffer.append("getfield");
|
||||
break;
|
||||
case CALLFUNCTION:
|
||||
buffer.append("callfunction");
|
||||
break;
|
||||
case CALLMETHOD:
|
||||
buffer.append("callmethod");
|
||||
break;
|
||||
case RET:
|
||||
buffer.append("ret");
|
||||
break;
|
||||
case JMPC:
|
||||
{
|
||||
auto res = BitConverter::ToUint32BE(code[i]);
|
||||
i+=4;
|
||||
buffer.append("jmpc l");
|
||||
for(size_t j = 0; j < labels.size(); j++)
|
||||
{
|
||||
if(labels[j] == res)
|
||||
{
|
||||
buffer.append(std::to_string((uint32_t)j));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case JMP:
|
||||
{
|
||||
auto res = BitConverter::ToUint32BE(code[i]);
|
||||
i+=4;
|
||||
buffer.append("jmp l");
|
||||
for(size_t j = 0; j < labels.size(); j++)
|
||||
{
|
||||
if(labels[j] == res)
|
||||
{
|
||||
buffer.append(std::to_string((uint32_t)j));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case JMPUNDEFINED:
|
||||
{
|
||||
auto res = BitConverter::ToUint32BE(code[i]);
|
||||
i+=4;
|
||||
buffer.append("jmpundefined l");
|
||||
for(size_t j = 0; j < labels.size(); j++)
|
||||
{
|
||||
if(labels[j] == res)
|
||||
{
|
||||
buffer.append(std::to_string((uint32_t)j));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case DEFER:
|
||||
buffer.append("defer");
|
||||
break;
|
||||
case TRYCATCH:
|
||||
buffer.append("trycatch");
|
||||
break;
|
||||
case THROW:
|
||||
buffer.append("throw");
|
||||
break;
|
||||
case PUSHSCOPELESSCLOSURE:
|
||||
{
|
||||
uint32_t clId = (uint32_t)code[i++] << 24;
|
||||
clId |= (uint32_t)code[i++] << 16;
|
||||
clId |= (uint32_t)code[i++] << 8;
|
||||
clId |= (uint32_t)code[i++];
|
||||
buffer.append("pushscopelessclosure (");
|
||||
bool first=true;
|
||||
|
||||
for(auto item : this->chunks.at(clId).first)
|
||||
{
|
||||
if(!first)
|
||||
buffer.append(", ");
|
||||
buffer.append(item);
|
||||
first=false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
buffer.append(") {\n");
|
||||
buffer.append(Chunk2String((size_t)clId,tab+1));
|
||||
buffer.append(tab,'\t');
|
||||
buffer.append("}");
|
||||
}
|
||||
break;
|
||||
case YIELD:
|
||||
buffer.append("yield");
|
||||
break;
|
||||
case PUSHROOTPATH:
|
||||
buffer.append("push /");
|
||||
break;
|
||||
case PUSHRELATIVEPATH:
|
||||
buffer.append("push .");
|
||||
break;
|
||||
case BREAKPOINT:
|
||||
buffer.append("breakpoint");
|
||||
break;
|
||||
case LINEINFO:
|
||||
buffer.append("lineinfo");
|
||||
break;
|
||||
case PUSHBREAK:
|
||||
buffer.append("push break");
|
||||
break;
|
||||
case PUSHCONTINUE:
|
||||
buffer.append("push continue");
|
||||
break;
|
||||
case JMPIFBREAK:
|
||||
{
|
||||
auto res = BitConverter::ToUint32BE(code[i]);
|
||||
i+=4;
|
||||
buffer.append("jmpifbreak l");
|
||||
for(size_t j = 0; j < labels.size(); j++)
|
||||
{
|
||||
if(labels[j] == res)
|
||||
{
|
||||
buffer.append(std::to_string((uint32_t)j));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case JMPIFCONTINUE:
|
||||
{
|
||||
auto res = BitConverter::ToUint32BE(code[i]);
|
||||
i+=4;
|
||||
buffer.append("jmpifcontinue l");
|
||||
for(size_t j = 0; j < labels.size(); j++)
|
||||
{
|
||||
if(labels[j] == res)
|
||||
{
|
||||
buffer.append(std::to_string((uint32_t)j));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case JMPIFDEFINED:
|
||||
{
|
||||
auto res = BitConverter::ToUint32BE(code[i]);
|
||||
i+=4;
|
||||
buffer.append("jmpifdefined l");
|
||||
for(size_t j = 0; j < labels.size(); j++)
|
||||
{
|
||||
if(labels[j] == res)
|
||||
{
|
||||
buffer.append(std::to_string((uint32_t)j));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("ILL: %i\n", (int)code[i-1]);
|
||||
break;
|
||||
}
|
||||
|
||||
buffer.push_back('\n');
|
||||
}
|
||||
|
||||
if(code.empty()) buffer.push_back('\n');
|
||||
|
||||
return buffer;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void Disassemble(std::shared_ptr<Tesses::Framework::Streams::Stream> src,std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, bool generateJSON,bool extractResources)
|
||||
{
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
CrossLangFileReader file(src);
|
||||
if(extractResources)
|
||||
{
|
||||
std::string resdir = "res";
|
||||
VFSPath path=resdir;
|
||||
vfs->CreateDirectory(path);
|
||||
for(size_t i = 0; i < file.resources.size(); i++)
|
||||
{
|
||||
auto path2 = path / file.name + "-" + file.version.ToString()+"_"+ std::to_string((uint32_t)i) + ".bin";
|
||||
auto strm = vfs->OpenFile(path2,"wb");
|
||||
strm->WriteBlock(file.resources[i].data(),file.resources[i].size());
|
||||
|
||||
}
|
||||
|
||||
std::string secdir = "sections";
|
||||
VFSPath secpath=secdir;
|
||||
vfs->CreateDirectory(secpath);
|
||||
|
||||
for(size_t i = 0; i < file.sections.size(); i++)
|
||||
{
|
||||
auto path2 = secpath / file.name + "-" + file.version.ToString()+"_"+ std::to_string((uint32_t)i) + ".tsec";
|
||||
|
||||
if(file.sections[i].first.size() != 4) {
|
||||
throw std::runtime_error("Chunk name is not 4 bytes");
|
||||
}
|
||||
auto strm = vfs->OpenFile(path2,"wb");
|
||||
strm->WriteBlock((const uint8_t*)file.sections[i].first.data(), 4);
|
||||
strm->WriteBlock(file.sections[i].second.data(),file.sections[i].second.size());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
std::string srcFile = {};
|
||||
|
||||
srcFile.append("root {\n");
|
||||
srcFile.append(file.Chunk2String(0,1));
|
||||
srcFile.append("}\n");
|
||||
|
||||
for(auto& item : file.functions)
|
||||
{
|
||||
if(!item.first[0].empty())
|
||||
{
|
||||
srcFile.append("/^" + Tesses::Framework::Http::HttpUtils::Replace(item.first[0],"^","^^") +"^/\n");
|
||||
}
|
||||
srcFile.append("func ");
|
||||
for(size_t i = 1; i < item.first.size(); i++)
|
||||
{
|
||||
if(i > 1)
|
||||
{
|
||||
srcFile.push_back('.');
|
||||
}
|
||||
srcFile.append(item.first[i]);
|
||||
}
|
||||
srcFile.append("(");
|
||||
auto& chunk = file.chunks.at(item.second);
|
||||
for(size_t i = 0; i < chunk.first.size(); i++)
|
||||
{
|
||||
if(i > 0)
|
||||
{
|
||||
srcFile.append(", ");
|
||||
}
|
||||
srcFile.append(chunk.first[i]);
|
||||
}
|
||||
srcFile.append(") {\n");
|
||||
srcFile.append(file.Chunk2String((size_t)item.second,1));
|
||||
srcFile.append("}\n");
|
||||
}
|
||||
for(auto& cls : file.classes)
|
||||
{
|
||||
if(!cls.documentation.empty())
|
||||
{
|
||||
srcFile.append("/^" + Tesses::Framework::Http::HttpUtils::Replace(cls.documentation,"^","^^") +"^/\n");
|
||||
}
|
||||
srcFile.append("class ");
|
||||
for(size_t i = 0; i < cls.name.size(); i++)
|
||||
{
|
||||
if(i > 0)
|
||||
{
|
||||
srcFile.push_back('.');
|
||||
}
|
||||
srcFile.append(cls.name[i]);
|
||||
}
|
||||
|
||||
if(!(cls.inherits.size() == 1 && cls.inherits[0] == "ClassObject"))
|
||||
{
|
||||
srcFile.append(" : ");
|
||||
for(size_t i = 0; i < cls.inherits.size(); i++)
|
||||
{
|
||||
if(i > 0)
|
||||
{
|
||||
srcFile.push_back('.');
|
||||
}
|
||||
srcFile.append(cls.inherits[i]);
|
||||
}
|
||||
}
|
||||
srcFile.append(" {\n");
|
||||
for(auto& item : cls.entry)
|
||||
{
|
||||
if(!item.documentation.empty())
|
||||
srcFile.append("\t/^"+Tesses::Framework::Http::HttpUtils::Replace(item.documentation,"^","^^")+"^/\n");
|
||||
|
||||
switch(item.modifier)
|
||||
{
|
||||
case TClassModifier::Private:
|
||||
srcFile.append("\tprivate ");
|
||||
break;
|
||||
case TClassModifier::Protected:
|
||||
srcFile.append("\tprotected ");
|
||||
break;
|
||||
case TClassModifier::Public:
|
||||
srcFile.append("\tpublic ");
|
||||
break;
|
||||
case TClassModifier::Static:
|
||||
srcFile.append("\tstatic ");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(item.isFunction)
|
||||
{
|
||||
|
||||
if(item.isAbstract)
|
||||
{
|
||||
srcFile.append("abstract " + item.name);
|
||||
srcFile.append("(");
|
||||
for(size_t i = 0; i < item.args.size(); i++)
|
||||
{
|
||||
if(i > 0)
|
||||
{
|
||||
srcFile.append(", ");
|
||||
}
|
||||
srcFile.append(item.args[i]);
|
||||
}
|
||||
srcFile.append(");\n");
|
||||
}
|
||||
else {
|
||||
srcFile.append(item.name);
|
||||
srcFile.append("(");
|
||||
for(size_t i = 0; i < item.args.size(); i++)
|
||||
{
|
||||
if(i > 0)
|
||||
{
|
||||
srcFile.append(", ");
|
||||
}
|
||||
srcFile.append(item.args[i]);
|
||||
}
|
||||
srcFile.append(") {\n");
|
||||
srcFile.append(file.Chunk2String(item.chunkId,2));
|
||||
srcFile.append("\t}\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
srcFile.append(item.name);
|
||||
if(item.isAbstract)
|
||||
{
|
||||
|
||||
srcFile.append(";\n");
|
||||
}
|
||||
else {
|
||||
srcFile.append(" {\n");
|
||||
srcFile.append(file.Chunk2String(item.chunkId,2));
|
||||
srcFile.append("\t}\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
srcFile.append("}\n");
|
||||
}
|
||||
std::string srcdirs = "src";
|
||||
VFSPath srcdir=srcdirs;
|
||||
vfs->CreateDirectory(srcdir);
|
||||
Tesses::Framework::TextStreams::StreamWriter writer(vfs->OpenFile(srcdir / file.name + "-" + file.version.ToString() + ".tcasm","wb"));
|
||||
writer.Write(srcFile);
|
||||
|
||||
if(generateJSON)
|
||||
{
|
||||
using namespace Tesses::Framework::Serialization::Json;
|
||||
|
||||
JObject json_data {
|
||||
JOItem{"name", file.name},
|
||||
JOItem{"version",file.version.ToString()}
|
||||
};
|
||||
if(!file.info.empty())
|
||||
{
|
||||
json_data.SetValue("info",Json::Decode(file.info));
|
||||
|
||||
}
|
||||
|
||||
if(file.icon > -1 && file.icon < file.resources.size())
|
||||
{
|
||||
json_data.SetValue("icon",file.name + "-" + file.version.ToString()+"_"+ std::to_string(file.icon) + ".bin");
|
||||
}
|
||||
if(!file.dependencies.empty())
|
||||
{
|
||||
JArray array;
|
||||
for(auto& item : file.dependencies)
|
||||
{
|
||||
array.Add(JObject {
|
||||
JOItem {
|
||||
"name",
|
||||
item.first
|
||||
},
|
||||
JOItem {
|
||||
"version",
|
||||
item.second.ToString()
|
||||
}
|
||||
});
|
||||
}
|
||||
json_data.SetValue("dependencies", array);
|
||||
}
|
||||
if(!file.tools.empty())
|
||||
{
|
||||
JArray array;
|
||||
for(auto& item : file.tools)
|
||||
{
|
||||
array.Add(JObject {
|
||||
JOItem {
|
||||
"name",
|
||||
item.first
|
||||
},
|
||||
JOItem {
|
||||
"version",
|
||||
item.second.ToString()
|
||||
}
|
||||
});
|
||||
}
|
||||
json_data.SetValue("tools", array);
|
||||
}
|
||||
if(!file.vms.empty())
|
||||
{
|
||||
JArray array;
|
||||
for(auto& item : file.vms)
|
||||
{
|
||||
array.Add(JObject {
|
||||
JOItem {
|
||||
"name",
|
||||
item.first
|
||||
},
|
||||
JOItem {
|
||||
"how_to_get",
|
||||
item.second
|
||||
}
|
||||
});
|
||||
}
|
||||
json_data.SetValue("vms", array);
|
||||
}
|
||||
|
||||
|
||||
Tesses::Framework::TextStreams::StreamWriter json_writer(vfs->OpenFile(VFSPath() / "crossapp.json","wb" ));
|
||||
json_writer.WriteLine(Json::Encode(json_data,true));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
using namespace Tesses::Framework::Serialization::Json;
|
||||
namespace Tesses::CrossLang {
|
||||
static void LoadDependency(std::shared_ptr<Tesses::Framework::Filesystem::VFS> srcFS, Tesses::Framework::Filesystem::VFSPath sourceDir, std::pair<std::string,TVMVersion> dep, std::vector<std::pair<std::string, TVMVersion>>& files, std::vector<std::pair<std::string, TVMVersion>>& tools);
|
||||
static void LoadDependencies(std::shared_ptr<Tesses::Framework::Filesystem::VFS> srcFS, Tesses::Framework::Filesystem::VFSPath sourceDir,TFile* file, std::vector<std::pair<std::string, TVMVersion>>& files, std::vector<std::pair<std::string, TVMVersion>>& tools);
|
||||
static void LoadDependency(std::shared_ptr<Tesses::Framework::Filesystem::VFS> srcFS, Tesses::Framework::Filesystem::VFSPath sourceDir, std::pair<std::string,TVMVersion> dep, std::vector<std::pair<std::string, TVMVersion>>& files, std::vector<std::pair<std::string, TVMVersion>>& tools)
|
||||
{
|
||||
for(auto index = files.begin(); index != files.end(); index++)
|
||||
{
|
||||
if(index->first == dep.first)
|
||||
{
|
||||
if(index->second.CompareTo(dep.second) >= 0) return;
|
||||
files.erase(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::string name = {};
|
||||
name.append(dep.first);
|
||||
name.push_back('-');
|
||||
name.append(dep.second.ToString());
|
||||
name.append(".crvm");
|
||||
auto filename= sourceDir / name;
|
||||
|
||||
if(srcFS->RegularFileExists(filename))
|
||||
{
|
||||
auto file = srcFS->OpenFile(filename,"rb");
|
||||
|
||||
TFile f;
|
||||
f.Load(nullptr, file);
|
||||
|
||||
LoadDependencies(srcFS,sourceDir,&f,files,tools);
|
||||
}
|
||||
else throw VMException("Could not open file: \"" + name + "\".");
|
||||
|
||||
}
|
||||
static void LoadDependencies(std::shared_ptr<Tesses::Framework::Filesystem::VFS> srcFS, Tesses::Framework::Filesystem::VFSPath sourceDir,TFile* file, std::vector<std::pair<std::string, TVMVersion>>& files, std::vector<std::pair<std::string, TVMVersion>>& tools)
|
||||
{
|
||||
files.push_back(std::pair<std::string,TVMVersion>(file->name,file->version));
|
||||
for(auto item : file->tools)
|
||||
{
|
||||
bool exists = false;
|
||||
for(auto& itm2 : tools)
|
||||
{
|
||||
if(itm2.first == item.first)
|
||||
{
|
||||
exists=true;
|
||||
if(itm2.second.CompareTo(item.second) < 0) {
|
||||
itm2.second = item.second;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!exists)
|
||||
tools.push_back(item);
|
||||
}
|
||||
for(auto item : file->dependencies)
|
||||
{
|
||||
LoadDependency(srcFS,sourceDir,item,files,tools);
|
||||
}
|
||||
}
|
||||
static void EnumerateCRVM(std::shared_ptr<Tesses::Framework::Filesystem::VFS> srcFS, Tesses::Framework::Filesystem::VFSPath sourceDir,std::string filename, std::vector<std::pair<std::string, TVMVersion>>& files, std::shared_ptr<Tesses::Framework::Filesystem::VFS> destFS)
|
||||
{
|
||||
|
||||
|
||||
TFile file;
|
||||
auto strm = srcFS->OpenFile(sourceDir / filename,"rb");
|
||||
if(strm->EndOfStream()) {
|
||||
|
||||
|
||||
throw std::runtime_error("File does not exist: " + (sourceDir / filename).ToString() );
|
||||
}
|
||||
file.Load(nullptr,strm);
|
||||
|
||||
|
||||
|
||||
std::vector<std::pair<std::string, TVMVersion>> tools;
|
||||
LoadDependencies(srcFS,sourceDir,&file,files,tools);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
JObject json_data {
|
||||
JOItem{"name", file.name},
|
||||
JOItem{"version",file.version.ToString()}
|
||||
|
||||
};
|
||||
if(!file.info.empty())
|
||||
{
|
||||
json_data.SetValue("info",Json::Decode(file.info));
|
||||
|
||||
}
|
||||
|
||||
if(file.icon > -1 && file.icon < file.resources.size())
|
||||
{
|
||||
json_data.SetValue("icon",file.name + "-" + file.version.ToString()+"_"+ std::to_string(file.icon) + ".bin");
|
||||
}
|
||||
if(!file.tools.empty())
|
||||
{
|
||||
JArray array;
|
||||
for(auto& item : file.tools)
|
||||
{
|
||||
array.Add(JObject {
|
||||
JOItem {
|
||||
"name",
|
||||
item.first
|
||||
},
|
||||
JOItem {
|
||||
"version",
|
||||
item.second.ToString()
|
||||
}
|
||||
});
|
||||
}
|
||||
json_data.SetValue("tools", array);
|
||||
}
|
||||
if(!file.vms.empty())
|
||||
{
|
||||
JArray array;
|
||||
for(auto& item : file.vms)
|
||||
{
|
||||
array.Add(JObject {
|
||||
JOItem {
|
||||
"name",
|
||||
item.first
|
||||
},
|
||||
JOItem {
|
||||
"how_to_get",
|
||||
item.second
|
||||
}
|
||||
});
|
||||
}
|
||||
json_data.SetValue("vms", array);
|
||||
}
|
||||
|
||||
|
||||
Tesses::Framework::TextStreams::StreamWriter json_writer(destFS->OpenFile(Tesses::Framework::Filesystem::VFSPath() / "crossapp.json","wb" ));
|
||||
json_writer.WriteLine(Json::Encode(json_data,true));
|
||||
}
|
||||
Tesses::Framework::Filesystem::VFSPath Merge(std::shared_ptr<Tesses::Framework::Filesystem::VFS> srcFS, Tesses::Framework::Filesystem::VFSPath sourcePath, std::shared_ptr<Tesses::Framework::Filesystem::VFS> destFS)
|
||||
{
|
||||
std::vector<std::pair<std::string, TVMVersion>> files;
|
||||
|
||||
for(auto ent : destFS->EnumeratePaths(Tesses::Framework::Filesystem::VFSPath()))
|
||||
{
|
||||
if(destFS->DirectoryExists(ent))
|
||||
{
|
||||
destFS->DeleteDirectoryRecurse(ent);
|
||||
}
|
||||
else {
|
||||
destFS->DeleteFile(ent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EnumerateCRVM(srcFS,sourcePath.GetParent(), sourcePath.GetFileName(),files,destFS);
|
||||
|
||||
for(auto item : files)
|
||||
{
|
||||
auto filePath = sourcePath.GetParent() / item.first + "-" + item.second.ToString() + ".crvm";
|
||||
if(srcFS->RegularFileExists(filePath))
|
||||
{
|
||||
auto strm = srcFS->OpenFile(filePath,"rb");
|
||||
Disassemble(strm,destFS,false);
|
||||
}
|
||||
}
|
||||
|
||||
return Assemble(destFS);
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
#if defined(CROSSLANG_ENABLE_JSON)
|
||||
#include <jansson.h>
|
||||
#endif
|
||||
namespace Tesses::CrossLang
|
||||
{
|
||||
AdvancedSyntaxNode AdvancedSyntaxNode::Create(std::string_view nodeName,bool isExpression, std::vector<SyntaxNode> nodes)
|
||||
{
|
||||
namespace Tesses::CrossLang {
|
||||
AdvancedSyntaxNode AdvancedSyntaxNode::Create(std::string_view nodeName,
|
||||
bool isExpression,
|
||||
std::vector<SyntaxNode> nodes) {
|
||||
AdvancedSyntaxNode asn;
|
||||
asn.nodeName = std::string(nodeName);
|
||||
asn.isExpression = isExpression;
|
||||
@@ -14,45 +14,43 @@ AdvancedSyntaxNode AdvancedSyntaxNode::Create(std::string_view nodeName,bool isE
|
||||
}
|
||||
|
||||
#if defined(CROSSLANG_ENABLE_JSON)
|
||||
static SyntaxNode Deserialize2(json_t* json)
|
||||
{
|
||||
if(json_is_null(json)) return nullptr;
|
||||
if(json_is_true(json)) return true;
|
||||
if(json_is_false(json)) return false;
|
||||
if(json_is_integer(json)) return (int64_t)json_integer_value(json);
|
||||
if(json_is_real(json)) return json_real_value(json);
|
||||
if(json_is_string(json)) return std::string(json_string_value(json),json_string_length(json));
|
||||
if(json_is_object(json))
|
||||
{
|
||||
json_t* typ = json_object_get(json, "type");
|
||||
if(json_is_string(typ))
|
||||
{
|
||||
std::string type(json_string_value(typ),json_string_length(typ));
|
||||
if(type == CharExpression)
|
||||
{
|
||||
json_t* chrData = json_object_get(json,"value");
|
||||
if(json_is_integer(chrData))
|
||||
{
|
||||
static SyntaxNode Deserialize2(json_t *json) {
|
||||
if (json_is_null(json))
|
||||
return nullptr;
|
||||
if (json_is_true(json))
|
||||
return true;
|
||||
if (json_is_false(json))
|
||||
return false;
|
||||
if (json_is_integer(json))
|
||||
return (int64_t)json_integer_value(json);
|
||||
if (json_is_real(json))
|
||||
return json_real_value(json);
|
||||
if (json_is_string(json))
|
||||
return std::string(json_string_value(json), json_string_length(json));
|
||||
if (json_is_object(json)) {
|
||||
json_t *typ = json_object_get(json, "type");
|
||||
if (json_is_string(typ)) {
|
||||
std::string type(json_string_value(typ), json_string_length(typ));
|
||||
if (type == CharExpression) {
|
||||
json_t *chrData = json_object_get(json, "value");
|
||||
if (json_is_integer(chrData)) {
|
||||
return (char)(uint8_t)json_integer_value(chrData);
|
||||
}
|
||||
}
|
||||
if(type == UndefinedExpression)
|
||||
{
|
||||
if (type == UndefinedExpression) {
|
||||
return Undefined();
|
||||
}
|
||||
json_t* isExpr = json_object_get(json,"isExpression");
|
||||
json_t *isExpr = json_object_get(json, "isExpression");
|
||||
bool isExprB = json_is_true(isExpr);
|
||||
AdvancedSyntaxNode asn;
|
||||
AdvancedSyntaxNode asn;
|
||||
asn.nodeName = type;
|
||||
asn.isExpression = isExprB;
|
||||
json_t* args = json_object_get(json, "args");
|
||||
if(json_is_array(args))
|
||||
{
|
||||
json_t *args = json_object_get(json, "args");
|
||||
if (json_is_array(args)) {
|
||||
size_t index;
|
||||
json_t* value;
|
||||
|
||||
json_array_foreach(args, index, value)
|
||||
{
|
||||
json_t *value;
|
||||
|
||||
json_array_foreach(args, index, value) {
|
||||
asn.nodes.push_back(Deserialize2(value));
|
||||
}
|
||||
}
|
||||
@@ -63,89 +61,79 @@ static SyntaxNode Deserialize2(json_t* json)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
SyntaxNode Deserialize(std::string astData)
|
||||
{
|
||||
#if defined(CROSSLANG_ENABLE_JSON)
|
||||
json_t* json = json_loadb(astData.c_str(),astData.size(), 0, NULL);
|
||||
SyntaxNode Deserialize(std::string astData) {
|
||||
#if defined(CROSSLANG_ENABLE_JSON)
|
||||
json_t *json = json_loadb(astData.c_str(), astData.size(), 0, NULL);
|
||||
|
||||
auto r = Deserialize2(json);
|
||||
json_decref(json);
|
||||
|
||||
return r;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
#if defined(CROSSLANG_ENABLE_JSON)
|
||||
static json_t* Serialize2(SyntaxNode node)
|
||||
{
|
||||
if(std::holds_alternative<std::nullptr_t>(node))
|
||||
static json_t *Serialize2(SyntaxNode node) {
|
||||
if (std::holds_alternative<std::nullptr_t>(node))
|
||||
return json_null();
|
||||
if(std::holds_alternative<int64_t>(node))
|
||||
{
|
||||
if (std::holds_alternative<int64_t>(node)) {
|
||||
return json_integer(std::get<int64_t>(node));
|
||||
}
|
||||
if(std::holds_alternative<double>(node))
|
||||
{
|
||||
if (std::holds_alternative<double>(node)) {
|
||||
return json_real(std::get<double>(node));
|
||||
}
|
||||
if(std::holds_alternative<bool>(node))
|
||||
{
|
||||
if (std::holds_alternative<bool>(node)) {
|
||||
return json_boolean(std::get<bool>(node));
|
||||
}
|
||||
if(std::holds_alternative<std::string>(node))
|
||||
{
|
||||
if (std::holds_alternative<std::string>(node)) {
|
||||
std::string str = std::get<std::string>(node);
|
||||
return json_stringn(str.c_str(),str.size());
|
||||
return json_stringn(str.c_str(), str.size());
|
||||
}
|
||||
if(std::holds_alternative<char>(node))
|
||||
{
|
||||
if (std::holds_alternative<char>(node)) {
|
||||
char c = std::get<char>(node);
|
||||
json_t* json = json_object();
|
||||
json_object_set_new(json,"type",json_string((const char*)CharExpression.data()));
|
||||
json_t *json = json_object();
|
||||
json_object_set_new(json, "type",
|
||||
json_string((const char *)CharExpression.data()));
|
||||
json_object_set_new(json, "value", json_integer((uint8_t)c));
|
||||
return json;
|
||||
}
|
||||
if(std::holds_alternative<Undefined>(node))
|
||||
{
|
||||
json_t* json = json_object();
|
||||
json_object_set_new(json,"type",json_string((const char*)UndefinedExpression.data()));
|
||||
if (std::holds_alternative<Undefined>(node)) {
|
||||
json_t *json = json_object();
|
||||
json_object_set_new(
|
||||
json, "type",
|
||||
json_string((const char *)UndefinedExpression.data()));
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
if(std::holds_alternative<AdvancedSyntaxNode>(node))
|
||||
{
|
||||
if (std::holds_alternative<AdvancedSyntaxNode>(node)) {
|
||||
auto asn = std::get<AdvancedSyntaxNode>(node);
|
||||
json_t* j = json_object();
|
||||
json_t *j = json_object();
|
||||
json_object_set_new(j, "type", json_string(asn.nodeName.c_str()));
|
||||
json_object_set_new(j, "isExpression",json_boolean(asn.isExpression));
|
||||
json_t* arr=json_array();
|
||||
for(auto item : asn.nodes)
|
||||
{
|
||||
json_array_append_new(arr,Serialize2(item));
|
||||
json_object_set_new(j, "isExpression", json_boolean(asn.isExpression));
|
||||
json_t *arr = json_array();
|
||||
for (auto item : asn.nodes) {
|
||||
json_array_append_new(arr, Serialize2(item));
|
||||
}
|
||||
json_object_set_new(j, "args", arr);
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
return json_null();
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string Serialize(SyntaxNode node)
|
||||
{
|
||||
std::string Serialize(SyntaxNode node) {
|
||||
|
||||
#if defined(CROSSLANG_ENABLE_JSON)
|
||||
json_t* json = Serialize2(node);
|
||||
char* txt = json_dumps(json,0);
|
||||
std::string str(txt);
|
||||
free(json);
|
||||
json_decref(json);
|
||||
return str;
|
||||
json_t *json = Serialize2(node);
|
||||
char *txt = json_dumps(json, 0);
|
||||
std::string str(txt);
|
||||
free(json);
|
||||
json_decref(json);
|
||||
return str;
|
||||
#endif
|
||||
return "";
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Tesses::CrossLang
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,22 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Streams;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
using namespace Tesses::CrossLang;
|
||||
TF_Init();
|
||||
if(argc > 1 && strcmp(argv[1],"--help"))
|
||||
{
|
||||
std::cout << "Run this command in directory you want to assemble (with the crossasm.json)" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
auto curdir = VFSPath::GetAbsoluteCurrentDirectory();
|
||||
auto sdfs=std::make_shared<SubdirFilesystem>(LocalFS,curdir);
|
||||
auto path = Assemble(sdfs);
|
||||
path.relative = true;
|
||||
std::cout << "Output: " << (curdir / path).ToString() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
void help(char* program)
|
||||
{
|
||||
std::cout << "USAGE: " << program << " [flags] FILE.CRVM" << std::endl;
|
||||
std::cout << "USAGE: " << program << " [flags] FILE.CRVM DIR" << std::endl;
|
||||
std::cout << "Flags:" << std::endl;
|
||||
std::cout << "--no-json\tNo json" << std::endl;
|
||||
std::cout << "--no-resources\nNo resources" << std::endl;
|
||||
|
||||
exit(0);
|
||||
}
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Streams;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
using namespace Tesses::CrossLang;
|
||||
TF_Init();
|
||||
|
||||
std::string file;
|
||||
Tesses::Framework::Filesystem::VFSPath path = VFSPath::GetAbsoluteCurrentDirectory();
|
||||
int curPos = 0;
|
||||
bool json=true;
|
||||
bool resources = true;
|
||||
for(int i = 1; i < argc; i++)
|
||||
{
|
||||
if(strcmp(argv[i],"--no-json") == 0)
|
||||
{
|
||||
json = false;
|
||||
}
|
||||
else if(strcmp(argv[i],"--no-resources") == 0)
|
||||
{
|
||||
resources = false;
|
||||
}
|
||||
else if(strcmp(argv[i],"--help") == 0)
|
||||
{
|
||||
help(argv[0]);
|
||||
}
|
||||
else {
|
||||
if(curPos == 0)
|
||||
{
|
||||
file = argv[i];
|
||||
curPos++;
|
||||
}
|
||||
else if(curPos == 1)
|
||||
{
|
||||
path = LocalFS->SystemToVFSPath(argv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(file.empty())
|
||||
{
|
||||
help(argv[0]);
|
||||
}
|
||||
auto strm = LocalFS->OpenFile(file,"rb");
|
||||
auto sdir = std::make_shared<SubdirFilesystem>(LocalFS,path);
|
||||
if(strm->CanRead())
|
||||
Disassemble(strm, sdir,json,resources);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,285 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
using namespace Tesses::CrossLang;
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
void Help(const char* filename)
|
||||
{
|
||||
printf("USAGE: %s [OPTIONS] source_file1 source_file2 source_file_n \n", filename);
|
||||
printf("OPTIONS:\n");
|
||||
printf(" -o: Output directory (OUTDIR, defaults to ./bin)\n");
|
||||
printf(" -i: Set info (ex {\"maintainer\": \"Mike Nolan\", \"repo\": \"https://example.com/\", \"homepage\": \"https://example.com/\",\"license\":\"MIT\"})\n");
|
||||
printf(" -I: Set icon resource name (in the resource folder), should be a 128x128 png\n");
|
||||
printf(" -v: Set version (1.0.0.0-prod defaults to 1.0.0.0-dev)\n");
|
||||
printf(" -d: Add dependency (DependencyName-1.0.0.0-prod)\n");
|
||||
printf(" -D: enable debug)\n");
|
||||
printf(" -t: Declare a tool (ToolName-1.0.0.0-prod)\n");
|
||||
printf(" -n: Set name (MyAppOrLibName defaults to out)\n");
|
||||
printf(" -r: Set resource directory (RESDIR defaults to res)\n");
|
||||
printf(" -h, --help: Prints help\n");
|
||||
printf(" -e: Set comptime permissions defaults to none, none for no support, \"secure\" for sane without file access, \"secure_file\" for sane with file access to current directory and sub directories, \"full\" has full runtime.\n");
|
||||
printf("Options except for help have flag with arg like this: -F ARG\n");
|
||||
exit(1);
|
||||
}
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
/*std::ifstream strm(argv[1],std::ios_base::in|std::ios_base::binary);
|
||||
std::vector<LexToken> tokens;
|
||||
Lex(argv[1],strm,tokens);
|
||||
|
||||
Parser parser(tokens);
|
||||
|
||||
CodeGen gen;
|
||||
gen.GenRoot(parser.ParseRoot());
|
||||
std::vector<uint8_t> data;
|
||||
ByteCodeVectorWriter w(data);
|
||||
gen.Save(std::filesystem::current_path(),w);
|
||||
*/
|
||||
TF_InitWithConsole();
|
||||
std::filesystem::path outputDir = std::filesystem::current_path() / "bin";
|
||||
std::vector<std::filesystem::path> source;
|
||||
std::filesystem::path resourceDir = std::filesystem::current_path() / "res";
|
||||
std::vector<std::pair<std::string, TVMVersion>> dependencies;
|
||||
std::vector<std::pair<std::string, TVMVersion>> tools;
|
||||
std::string name="out";
|
||||
std::string info="{}";
|
||||
std::string icon="";
|
||||
std::string comptime="none";
|
||||
TVMVersion version;
|
||||
bool debug=false;
|
||||
|
||||
|
||||
|
||||
for(int i = 1; i < argc; i++)
|
||||
{
|
||||
if(strcmp(argv[i],"--help") == 0 || strcmp(argv[i],"-h")==0)
|
||||
{
|
||||
Help(argv[0]);
|
||||
}
|
||||
|
||||
else if(strcmp(argv[i], "-o") == 0)
|
||||
{
|
||||
i++;
|
||||
if(i < argc)
|
||||
{
|
||||
outputDir = argv[i];
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[i], "-r") == 0)
|
||||
{
|
||||
i++;
|
||||
if(i < argc)
|
||||
{
|
||||
resourceDir = argv[i];
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[i], "-e") == 0)
|
||||
{
|
||||
i++;
|
||||
if(i < argc)
|
||||
{
|
||||
comptime = argv[i];
|
||||
}
|
||||
}
|
||||
|
||||
else if(strcmp(argv[i], "-i") == 0)
|
||||
{
|
||||
i++;
|
||||
if(i < argc)
|
||||
{
|
||||
info = argv[i];
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[i],"-I") == 0)
|
||||
{
|
||||
i++;
|
||||
if(i < argc)
|
||||
{
|
||||
icon = argv[i];
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[i], "-d") == 0)
|
||||
{
|
||||
i++;
|
||||
if(i < argc)
|
||||
{
|
||||
std::string str = argv[i];
|
||||
auto lastDash = str.find_last_of('-');
|
||||
if(lastDash < str.size())
|
||||
{
|
||||
std::string str2 = str.substr(lastDash+1);
|
||||
if(str2 == "dev" || str2 == "alpha" || str2 == "beta" || str2 == "prod")
|
||||
{
|
||||
lastDash = str.find_last_of('-',lastDash-1);
|
||||
}
|
||||
std::string str1 = str.substr(0,lastDash);
|
||||
str2 = str.substr(lastDash+1);
|
||||
|
||||
TVMVersion v2;
|
||||
if(!TVMVersion::TryParse(str2,v2))
|
||||
{
|
||||
printf("ERROR: Invalid syntax for version\n");
|
||||
printf("Expected MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]]]]\n");
|
||||
exit(1);
|
||||
}
|
||||
dependencies.push_back(std::pair<std::string,TVMVersion>(str1,v2));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ERROR: Dependency must have version\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[i], "-t") == 0)
|
||||
{
|
||||
i++;
|
||||
if(i < argc)
|
||||
{
|
||||
std::string str = argv[i];
|
||||
auto lastDash = str.find_last_of('-');
|
||||
if(lastDash < str.size())
|
||||
{
|
||||
std::string str2 = str.substr(lastDash+1);
|
||||
if(str2 == "dev" || str2 == "alpha" || str2 == "beta" || str2 == "prod")
|
||||
{
|
||||
lastDash = str.find_last_of('-',lastDash-1);
|
||||
}
|
||||
std::string str1 = str.substr(0,lastDash);
|
||||
str2 = str.substr(lastDash+1);
|
||||
|
||||
TVMVersion v2;
|
||||
if(!TVMVersion::TryParse(str2,v2))
|
||||
{
|
||||
printf("ERROR: Invalid syntax for version\n");
|
||||
printf("Expected MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]]]]\n");
|
||||
exit(1);
|
||||
}
|
||||
tools.push_back(std::pair<std::string,TVMVersion>(str1,v2));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ERROR: Tool must have version\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[i], "-n") == 0)
|
||||
{
|
||||
i++;
|
||||
if(i < argc)
|
||||
{
|
||||
name = argv[i];
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[i], "-v") == 0)
|
||||
{
|
||||
i++;
|
||||
if(i < argc)
|
||||
{
|
||||
|
||||
if(!TVMVersion::TryParse(argv[i],version))
|
||||
{
|
||||
printf("ERROR: Invalid syntax for version\n");
|
||||
printf("Expected MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]]]]\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[i],"-D") == 0)
|
||||
{
|
||||
debug = true;
|
||||
}
|
||||
else {
|
||||
source.push_back(argv[i]);
|
||||
}
|
||||
}
|
||||
if(source.empty())
|
||||
{
|
||||
Help(argv[0]);
|
||||
}
|
||||
|
||||
|
||||
std::vector<LexToken> tokens;
|
||||
|
||||
for(auto src : source)
|
||||
{
|
||||
std::ifstream strm(src,std::ios_base::in|std::ios_base::binary);
|
||||
int res = Lex(std::filesystem::absolute(src).string(),strm,tokens);
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<GC> gc;
|
||||
std::shared_ptr<GCList> ls;
|
||||
TRootEnvironment* env=nullptr;
|
||||
if(comptime != "none")
|
||||
{
|
||||
gc = std::make_shared<GC>();
|
||||
gc->Start();
|
||||
ls = std::make_shared<GCList>(gc);
|
||||
env = TRootEnvironment::Create(*ls,TDictionary::Create(*ls));
|
||||
|
||||
if(comptime == "secure")
|
||||
{
|
||||
TStd::RegisterConsole(gc,env);
|
||||
TStd::RegisterClass(gc,env);
|
||||
TStd::RegisterCrypto(gc,env);
|
||||
TStd::RegisterDictionary(gc,env);
|
||||
TStd::RegisterJson(gc,env);
|
||||
TStd::RegisterRoot(gc,env);
|
||||
TStd::RegisterIO(gc,env,false);
|
||||
env->permissions.locked=true;
|
||||
}
|
||||
else if(comptime == "secure_file")
|
||||
{
|
||||
TStd::RegisterConsole(gc,env);
|
||||
TStd::RegisterClass(gc,env);
|
||||
TStd::RegisterCrypto(gc,env);
|
||||
TStd::RegisterDictionary(gc,env);
|
||||
TStd::RegisterJson(gc,env);
|
||||
TStd::RegisterRoot(gc,env);
|
||||
TStd::RegisterIO(gc,env,false);
|
||||
env->permissions.locked=true;
|
||||
auto fs = env->EnsureDictionary(gc,"FS");
|
||||
fs->SetValue("Local", std::make_shared<SubdirFilesystem>(LocalFS,Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory()));
|
||||
}
|
||||
else if(comptime == "full")
|
||||
{
|
||||
TStd::RegisterStd(gc,env);
|
||||
env->permissions.locked=true;
|
||||
}
|
||||
}
|
||||
|
||||
Parser parser(tokens,gc,env);
|
||||
parser.debug = debug;
|
||||
CodeGen gen;
|
||||
|
||||
auto sfs = std::make_shared<SubdirFilesystem>(LocalFS,LocalFS->SystemToVFSPath(resourceDir.string()));
|
||||
gen.embedFS = sfs;
|
||||
|
||||
gen.GenRoot(parser.ParseRoot());
|
||||
gen.name = name;
|
||||
gen.version = version;
|
||||
gen.info = info;
|
||||
gen.icon = icon;
|
||||
for(auto deps : dependencies)
|
||||
{
|
||||
gen.dependencies.push_back(deps);
|
||||
}
|
||||
for(auto tool : tools)
|
||||
{
|
||||
gen.tools.push_back(tool);
|
||||
}
|
||||
|
||||
std::filesystem::create_directory(outputDir);
|
||||
|
||||
{
|
||||
auto strm = std::make_shared<Tesses::Framework::Streams::FileStream>(outputDir / (name + "-" + version.ToString() + ".crvm"),"wb");
|
||||
|
||||
gen.Save(strm);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
void help(char* program)
|
||||
{
|
||||
std::cout << "USAGE: " << program << " FILE.CRVM DEST.CRVM" << std::endl;
|
||||
|
||||
exit(0);
|
||||
}
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Streams;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
using namespace Tesses::CrossLang;
|
||||
TF_Init();
|
||||
|
||||
if(argc < 3)
|
||||
{
|
||||
help(argv[0]);
|
||||
}
|
||||
|
||||
std::string src=argv[1];
|
||||
std::string dest=argv[2];
|
||||
|
||||
|
||||
|
||||
VFSPath srcF = src;
|
||||
VFSPath destF = dest;
|
||||
srcF.MakeAbsolute();
|
||||
destF.MakeAbsolute();
|
||||
|
||||
|
||||
auto sdir = std::make_shared<SubdirFilesystem>(LocalFS,srcF.GetParent());
|
||||
auto ddir = std::make_shared<SubdirFilesystem>(LocalFS,destF+"_tmp");
|
||||
|
||||
|
||||
auto outpath = Merge(sdir,"/"+srcF.GetFileName(), ddir);
|
||||
outpath.relative=true;
|
||||
outpath = (destF+"_tmp") / outpath;
|
||||
LocalFS->MoveFile(outpath,destF);
|
||||
LocalFS->DeleteDirectoryRecurse(destF+"_tmp");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -3,57 +3,49 @@
|
||||
#include <TessesFramework/Filesystem/LocalFS.hpp>
|
||||
#include <TessesFramework/Filesystem/VFS.hpp>
|
||||
#include <TessesFramework/Streams/Stream.hpp>
|
||||
#include <fstream>
|
||||
#include <ios>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
Tesses::Framework::TF_Init();
|
||||
std::string p = argv[0];
|
||||
auto emptyThumb =Tesses::Framework::Platform::Environment::GetRealExecutablePath(p).GetParent().GetParent() / "share" / "icons" / "crosslang.png";
|
||||
|
||||
if(argc < 3)
|
||||
{
|
||||
auto emptyThumb =
|
||||
Tesses::Framework::Platform::Environment::GetRealExecutablePath(p)
|
||||
.GetParent()
|
||||
.GetParent() /
|
||||
"share" / "icons" / "crosslang.png";
|
||||
|
||||
if (argc < 3) {
|
||||
std::cout << "USAGE: " << argv[0] << " CRVMFILE NEWPNG" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::string crvm = argv[1];
|
||||
std::string png = argv[2];
|
||||
|
||||
|
||||
if(Tesses::Framework::Filesystem::LocalFS->FileExists(crvm))
|
||||
{
|
||||
|
||||
Tesses::CrossLang::TFile file;
|
||||
auto f = Tesses::Framework::Filesystem::LocalFS->OpenFile(crvm, "rb");
|
||||
|
||||
file.Load(nullptr,f);
|
||||
if (Tesses::Framework::Filesystem::LocalFS->FileExists(crvm)) {
|
||||
|
||||
Tesses::CrossLang::TFile file;
|
||||
auto f = Tesses::Framework::Filesystem::LocalFS->OpenFile(crvm, "rb");
|
||||
|
||||
if(file.icon >= 0 && file.icon < file.resources.size())
|
||||
{
|
||||
auto f2 = Tesses::Framework::Filesystem::LocalFS->OpenFile(png, "wb");
|
||||
if(f2 != nullptr)
|
||||
{
|
||||
auto& icon = file.resources[file.icon];
|
||||
f2->WriteBlock(icon.data(),icon.size());
|
||||
|
||||
}
|
||||
return 0;
|
||||
|
||||
file.Load(nullptr, f);
|
||||
|
||||
if (file.icon >= 0 && file.icon < file.resources.size()) {
|
||||
auto f2 =
|
||||
Tesses::Framework::Filesystem::LocalFS->OpenFile(png, "wb");
|
||||
if (f2 != nullptr) {
|
||||
auto &icon = file.resources[file.icon];
|
||||
f2->WriteBlock(icon.data(), icon.size());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if(Tesses::Framework::Filesystem::LocalFS->FileExists(emptyThumb))
|
||||
{
|
||||
auto src = Tesses::Framework::Filesystem::LocalFS->OpenFile(emptyThumb,"rb");
|
||||
auto dest = Tesses::Framework::Filesystem::LocalFS->OpenFile(png,"wb");
|
||||
if(src != nullptr && dest != nullptr)
|
||||
{
|
||||
if (Tesses::Framework::Filesystem::LocalFS->FileExists(emptyThumb)) {
|
||||
auto src =
|
||||
Tesses::Framework::Filesystem::LocalFS->OpenFile(emptyThumb, "rb");
|
||||
auto dest = Tesses::Framework::Filesystem::LocalFS->OpenFile(png, "wb");
|
||||
if (src != nullptr && dest != nullptr) {
|
||||
src->CopyTo(dest);
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,37 +1,25 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
namespace Tesses::CrossLang
|
||||
{
|
||||
SharedPtrTObject::SharedPtrTObject(std::shared_ptr<GC> gc, TObject o)
|
||||
{
|
||||
this->ls = new GCList(gc);
|
||||
this->ls->Add(o);
|
||||
this->o = o;
|
||||
}
|
||||
TObject& SharedPtrTObject::GetObject()
|
||||
{
|
||||
return this->o;
|
||||
}
|
||||
SharedPtrTObject::~SharedPtrTObject()
|
||||
{
|
||||
if(this->ls)
|
||||
namespace Tesses::CrossLang {
|
||||
SharedPtrTObject::SharedPtrTObject(std::shared_ptr<GC> gc, TObject o) {
|
||||
this->ls = new GCList(gc);
|
||||
this->ls->Add(o);
|
||||
this->o = o;
|
||||
}
|
||||
TObject &SharedPtrTObject::GetObject() { return this->o; }
|
||||
SharedPtrTObject::~SharedPtrTObject() {
|
||||
if (this->ls)
|
||||
delete this->ls;
|
||||
}
|
||||
std::shared_ptr<GC> SharedPtrTObject::GetGC()
|
||||
{
|
||||
return this->ls->GetGC();
|
||||
}
|
||||
MarkedTObject CreateMarkedTObject(std::shared_ptr<GC> gc, TObject o)
|
||||
{
|
||||
return std::make_shared<SharedPtrTObject>(gc,o);
|
||||
}
|
||||
|
||||
MarkedTObject CreateMarkedTObject(GCList* gc, TObject o)
|
||||
{
|
||||
return CreateMarkedTObject(gc->GetGC(),o);
|
||||
}
|
||||
MarkedTObject CreateMarkedTObject(GCList& gc, TObject o)
|
||||
{
|
||||
return CreateMarkedTObject(gc.GetGC(),o);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::shared_ptr<GC> SharedPtrTObject::GetGC() { return this->ls->GetGC(); }
|
||||
MarkedTObject CreateMarkedTObject(std::shared_ptr<GC> gc, TObject o) {
|
||||
return std::make_shared<SharedPtrTObject>(gc, o);
|
||||
}
|
||||
|
||||
MarkedTObject CreateMarkedTObject(GCList *gc, TObject o) {
|
||||
return CreateMarkedTObject(gc->GetGC(), o);
|
||||
}
|
||||
MarkedTObject CreateMarkedTObject(GCList &gc, TObject o) {
|
||||
return CreateMarkedTObject(gc.GetGC(), o);
|
||||
}
|
||||
} // namespace Tesses::CrossLang
|
||||
@@ -3,12 +3,15 @@
|
||||
namespace Tesses::CrossLang::Programs {
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
using namespace Tesses::Framework::Streams;
|
||||
static void Help(std::string& filename)
|
||||
{
|
||||
std::cout << "USAGE: " << filename << " [OPTIONS] <dirasroot> <archive.crvm>" << std::endl;
|
||||
static void Help(std::string &filename) {
|
||||
std::cout << "USAGE: " << filename
|
||||
<< " [OPTIONS] <dirasroot> <archive.crvm>" << std::endl;
|
||||
printf("OPTIONS:\n");
|
||||
printf(" -i: Set info (ex {\"maintainer\": \"Mike Nolan\", \"repo\": \"https://example.com/\", \"homepage\": \"https://example.com/\",\"license\":\"MIT\"})\n");
|
||||
printf(" -I: Set icon name (relative to dirasroot), should be a 128x128 png\n");
|
||||
printf(" -i: Set info (ex {\"maintainer\": \"Mike Nolan\", \"repo\": "
|
||||
"\"https://example.com/\", \"homepage\": "
|
||||
"\"https://example.com/\",\"license\":\"MIT\"})\n");
|
||||
printf(" -I: Set icon name (relative to dirasroot), should be a 128x128 "
|
||||
"png\n");
|
||||
printf(" -v: Set version (1.0.0.0-prod defaults to 1.0.0.0-dev)\n");
|
||||
printf(" -n: Set name (MyAppOrLibName defaults to out)\n");
|
||||
printf(" -h, --help: Prints help\n");
|
||||
@@ -16,80 +19,66 @@ static void Help(std::string& filename)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int64_t CrossArchiveCreate(std::vector<std::string>& argv)
|
||||
{
|
||||
int64_t CrossArchiveCreate(std::vector<std::string> &argv) {
|
||||
Tesses::Framework::TF_Init();
|
||||
std::string name="out";
|
||||
std::string info="{}";
|
||||
TVMVersion version;
|
||||
std::string icon="";
|
||||
std::vector<std::string> args;
|
||||
for(int i = 1; i < argv.size(); i++)
|
||||
{
|
||||
if(argv[i] == "--help" || argv[i] == "-h")
|
||||
{
|
||||
std::string name = "out";
|
||||
std::string info = "{}";
|
||||
TVMVersion version;
|
||||
std::string icon = "";
|
||||
std::vector<std::string> args;
|
||||
for (int i = 1; i < argv.size(); i++) {
|
||||
if (argv[i] == "--help" || argv[i] == "-h") {
|
||||
Help(argv[0]);
|
||||
}
|
||||
else if(argv[i] == "-i")
|
||||
{
|
||||
} else if (argv[i] == "-i") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
info = argv[i];
|
||||
}
|
||||
}
|
||||
else if(argv[i] == "-I")
|
||||
{
|
||||
} else if (argv[i] == "-I") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
icon = argv[i];
|
||||
}
|
||||
}
|
||||
else if(argv[i] == "-n")
|
||||
{
|
||||
} else if (argv[i] == "-n") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
name = argv[i];
|
||||
}
|
||||
}
|
||||
else if(argv[i] == "-v")
|
||||
{
|
||||
} else if (argv[i] == "-v") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
|
||||
if(!TVMVersion::TryParse(argv[i],version))
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
|
||||
if (!TVMVersion::TryParse(argv[i], version)) {
|
||||
printf("ERROR: Invalid syntax for version\n");
|
||||
printf("Expected MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]]]]\n");
|
||||
printf("Expected "
|
||||
"MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]"
|
||||
"]]]\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(args.size() < 2) Help(argv[0]);
|
||||
|
||||
|
||||
auto path = Tesses::Framework::Filesystem::LocalFS->SystemToVFSPath(args[0]);
|
||||
if (args.size() < 2)
|
||||
Help(argv[0]);
|
||||
|
||||
auto path =
|
||||
Tesses::Framework::Filesystem::LocalFS->SystemToVFSPath(args[0]);
|
||||
Tesses::Framework::Filesystem::LocalFS->CreateDirectory(path);
|
||||
auto sdfs = std::make_shared<SubdirFilesystem>(Tesses::Framework::Filesystem::LocalFS,path);
|
||||
auto sdfs = std::make_shared<SubdirFilesystem>(
|
||||
Tesses::Framework::Filesystem::LocalFS, path);
|
||||
|
||||
FILE* f = fopen(args[1].c_str(),"wb");
|
||||
if(f == NULL)
|
||||
{
|
||||
FILE *f = fopen(args[1].c_str(), "wb");
|
||||
if (f == NULL) {
|
||||
printf("ERROR: could not open %s\n", args[1].c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto strm = std::make_shared<FileStream>(f,true,"wb",true);
|
||||
CrossArchiveCreate(sdfs,strm,name,version,info,icon);
|
||||
auto strm = std::make_shared<FileStream>(f, true, "wb", true);
|
||||
CrossArchiveCreate(sdfs, strm, name, version, info, icon);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} // namespace Tesses::CrossLang::Programs
|
||||
@@ -5,25 +5,23 @@ namespace Tesses::CrossLang::Programs {
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
using namespace Tesses::Framework::Streams;
|
||||
|
||||
int64_t CrossArchiveExtract(std::vector<std::string>& argv)
|
||||
{
|
||||
int64_t CrossArchiveExtract(std::vector<std::string> &argv) {
|
||||
Tesses::Framework::TF_Init();
|
||||
if(argv.size() < 3)
|
||||
{
|
||||
std::cout << "USAGE: " << argv[0] << " <archive.crvm> <dirasroot>" << std::endl;
|
||||
if (argv.size() < 3) {
|
||||
std::cout << "USAGE: " << argv[0] << " <archive.crvm> <dirasroot>"
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto sdfs= std::make_shared<SubdirFilesystem>(Tesses::Framework::Filesystem::LocalFS,std::string(argv[2]));
|
||||
auto strm= LocalFS->OpenFile(argv[1], "rb");
|
||||
if(strm->CanRead())
|
||||
{
|
||||
auto sdfs = std::make_shared<SubdirFilesystem>(
|
||||
Tesses::Framework::Filesystem::LocalFS, std::string(argv[2]));
|
||||
auto strm = LocalFS->OpenFile(argv[1], "rb");
|
||||
if (!strm->CanRead()) {
|
||||
std::cout << "ERROR: could not open " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
auto res = Tesses::CrossLang::CrossArchiveExtract(strm,sdfs);
|
||||
auto res = Tesses::CrossLang::CrossArchiveExtract(strm, sdfs);
|
||||
|
||||
std::cout << "Crvm Name: " << res.first.first << std::endl;
|
||||
std::cout << "Crvm Version: " << res.first.second.ToString() << std::endl;
|
||||
@@ -31,4 +29,4 @@ int64_t CrossArchiveExtract(std::vector<std::string>& argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} // namespace Tesses::CrossLang::Programs
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
#include "CrossLang.hpp"
|
||||
#include <iostream>
|
||||
namespace Tesses::CrossLang::Programs {
|
||||
static void Ensure(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,uint8_t* buffer, size_t len)
|
||||
{
|
||||
if(strm->ReadBlock(buffer,len) != len)
|
||||
{
|
||||
throw VMException("Could not read " + std::to_string(len) + " byte(s).");
|
||||
static void Ensure(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||
uint8_t *buffer, size_t len) {
|
||||
if (strm->ReadBlock(buffer, len) != len) {
|
||||
throw VMException("Could not read " + std::to_string(len) +
|
||||
" byte(s).");
|
||||
}
|
||||
}
|
||||
static uint32_t EnsureInt(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)
|
||||
{
|
||||
static uint32_t
|
||||
EnsureInt(std::shared_ptr<Tesses::Framework::Streams::Stream> strm) {
|
||||
uint8_t buff[4];
|
||||
Ensure(strm,buff,sizeof(buff));
|
||||
Ensure(strm, buff, sizeof(buff));
|
||||
return BitConverter::ToUint32BE(buff[0]);
|
||||
}
|
||||
static std::string EnsureString(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)
|
||||
{
|
||||
static std::string
|
||||
EnsureString(std::shared_ptr<Tesses::Framework::Streams::Stream> strm) {
|
||||
size_t len = (size_t)EnsureInt(strm);
|
||||
std::string myStr={};
|
||||
std::string myStr = {};
|
||||
myStr.resize(len);
|
||||
Ensure(strm,(uint8_t*)myStr.data(), len);
|
||||
Ensure(strm, (uint8_t *)myStr.data(), len);
|
||||
return myStr;
|
||||
}
|
||||
void CrossLangDump(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)
|
||||
{
|
||||
void CrossLangDump(std::shared_ptr<Tesses::Framework::Streams::Stream> strm) {
|
||||
uint8_t main_header[18];
|
||||
Ensure(strm,main_header,sizeof(main_header));
|
||||
if(strncmp((const char*)main_header,"TCROSSVM",8) != 0) throw VMException("Invalid TCrossVM image.");
|
||||
TVMVersion version(main_header+8);
|
||||
if(version.CompareToRuntime() == 1)
|
||||
{
|
||||
Ensure(strm, main_header, sizeof(main_header));
|
||||
if (strncmp((const char *)main_header, "TCROSSVM", 8) != 0)
|
||||
throw VMException("Invalid TCrossVM image.");
|
||||
TVMVersion version(main_header + 8);
|
||||
if (version.CompareToRuntime() == 1) {
|
||||
throw VMException("Runtime is too old.");
|
||||
}
|
||||
TVMVersion v2(main_header+13);
|
||||
TVMVersion v2(main_header + 13);
|
||||
std::cout << "Version: " << v2.ToString() << std::endl;
|
||||
|
||||
size_t _len = (size_t)EnsureInt(strm);
|
||||
@@ -41,215 +40,188 @@ void CrossLangDump(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)
|
||||
|
||||
std::vector<std::string> strs;
|
||||
|
||||
std::unordered_map<uint32_t, std::vector<std::string>> funs;
|
||||
std::vector<std::vector<std::string>> closures;
|
||||
std::unordered_map<uint32_t, std::vector<std::string>> funs;
|
||||
std::vector<std::vector<std::string>> closures;
|
||||
|
||||
|
||||
char table_name[4];
|
||||
bool hasIcon = false;
|
||||
|
||||
char table_name[4];
|
||||
bool hasIcon=false;
|
||||
for (size_t i = 0; i < _len; i++) {
|
||||
Ensure(strm, (uint8_t *)table_name, sizeof(table_name));
|
||||
size_t tableLen = (size_t)EnsureInt(strm);
|
||||
std::string tableName(table_name, 4);
|
||||
if (tableName == "ICON") {
|
||||
hasIcon = true;
|
||||
} else if (tableName == "STRS") {
|
||||
size_t strsLen = (size_t)EnsureInt(strm);
|
||||
for (size_t j = 0; j < strsLen; j++) {
|
||||
strs.push_back(EnsureString(strm));
|
||||
}
|
||||
} else if (tableName == "DEPS") {
|
||||
|
||||
for(size_t i = 0; i < _len; i++)
|
||||
{
|
||||
Ensure(strm,(uint8_t*)table_name,sizeof(table_name));
|
||||
size_t tableLen = (size_t)EnsureInt(strm);
|
||||
std::string tableName(table_name,4);
|
||||
if(tableName == "ICON")
|
||||
{
|
||||
hasIcon=true;
|
||||
std::string name = strs.at((size_t)EnsureInt(strm));
|
||||
|
||||
uint8_t version_bytes[5];
|
||||
Ensure(strm, version_bytes, sizeof(version_bytes));
|
||||
TVMVersion depVersion(version_bytes);
|
||||
std::cout << "Dependency: " << name << "-" << depVersion.ToString()
|
||||
<< std::endl;
|
||||
} else if (tableName == "NAME") {
|
||||
std::cout << "Name: " << strs.at((size_t)EnsureInt(strm))
|
||||
<< std::endl;
|
||||
} else if (tableName == "CLSS") {
|
||||
std::cout << "Classes:\n";
|
||||
uint32_t clss_cnt = EnsureInt(strm);
|
||||
for (uint32_t j = 0; j < clss_cnt; j++) {
|
||||
std::cout << "\t/^" << strs.at(EnsureInt(strm)) << "^/"
|
||||
<< std::endl;
|
||||
uint32_t fnPartsC = EnsureInt(strm);
|
||||
std::cout << "\tName: ";
|
||||
for (uint32_t k = 0; k < fnPartsC; k++) {
|
||||
if (k > 0)
|
||||
std::cout << ".";
|
||||
std::cout << strs.at(EnsureInt(strm));
|
||||
}
|
||||
else if(tableName == "STRS")
|
||||
{
|
||||
size_t strsLen = (size_t)EnsureInt(strm);
|
||||
for(size_t j = 0;j < strsLen;j++)
|
||||
{
|
||||
strs.push_back(EnsureString(strm));
|
||||
std::cout << std::endl;
|
||||
fnPartsC = EnsureInt(strm);
|
||||
std::cout << "\tInherits: ";
|
||||
for (uint32_t k = 0; k < fnPartsC; k++) {
|
||||
if (k > 0)
|
||||
std::cout << ".";
|
||||
std::cout << strs.at(EnsureInt(strm));
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
uint32_t ents = EnsureInt(strm);
|
||||
|
||||
for (uint8_t k = 0; k < ents; k++) {
|
||||
Ensure(strm, main_header, 1);
|
||||
uint8_t flags = main_header[0];
|
||||
std::cout << "\t\t/^" << strs.at(EnsureInt(strm)) << "^/"
|
||||
<< std::endl;
|
||||
std::string fnname = strs.at(EnsureInt(strm));
|
||||
std::string fnargs;
|
||||
uint32_t argParts = EnsureInt(strm);
|
||||
|
||||
for (uint32_t l = 0; l < argParts; l++) {
|
||||
if (l > 0)
|
||||
fnargs += ", ";
|
||||
fnargs += strs.at(EnsureInt(strm));
|
||||
}
|
||||
}
|
||||
else if(tableName == "DEPS")
|
||||
{
|
||||
|
||||
std::string name = strs.at((size_t)EnsureInt(strm));
|
||||
|
||||
uint8_t version_bytes[5];
|
||||
Ensure(strm,version_bytes,sizeof(version_bytes));
|
||||
TVMVersion depVersion(version_bytes);
|
||||
std::cout << "Dependency: " << name << "-" << depVersion.ToString() << std::endl;
|
||||
}
|
||||
else if(tableName == "NAME")
|
||||
{
|
||||
std::cout << "Name: " << strs.at((size_t)EnsureInt(strm)) << std::endl;
|
||||
}
|
||||
else if(tableName == "CLSS")
|
||||
{
|
||||
std::cout << "Classes:\n";
|
||||
uint32_t clss_cnt= EnsureInt(strm);
|
||||
for(uint32_t j = 0; j < clss_cnt; j++)
|
||||
{
|
||||
std::cout << "\t/^" << strs.at(EnsureInt(strm)) << "^/" << std::endl;
|
||||
uint32_t fnPartsC = EnsureInt(strm);
|
||||
std::cout << "\tName: ";
|
||||
for(uint32_t k = 0; k < fnPartsC; k++)
|
||||
{
|
||||
if(k > 0) std::cout << ".";
|
||||
std::cout << strs.at(EnsureInt(strm));
|
||||
}
|
||||
std::cout << std::endl;
|
||||
fnPartsC = EnsureInt(strm);
|
||||
std::cout << "\tInherits: ";
|
||||
for(uint32_t k = 0; k < fnPartsC; k++)
|
||||
{
|
||||
if(k > 0) std::cout << ".";
|
||||
std::cout << strs.at(EnsureInt(strm));
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
uint32_t ents = EnsureInt(strm);
|
||||
|
||||
for(uint8_t k = 0; k < ents; k++)
|
||||
{
|
||||
Ensure(strm,main_header,1);
|
||||
uint8_t flags = main_header[0];
|
||||
std::cout << "\t\t/^" << strs.at(EnsureInt(strm)) << "^/" << std::endl;
|
||||
std::string fnname = strs.at(EnsureInt(strm));
|
||||
std::string fnargs;
|
||||
uint32_t argParts = EnsureInt(strm);
|
||||
|
||||
for(uint32_t l = 0; l < argParts; l++)
|
||||
{
|
||||
if(l > 0) fnargs += ", ";
|
||||
fnargs += strs.at(EnsureInt(strm));
|
||||
}
|
||||
uint32_t fnchunk = EnsureInt(strm);
|
||||
switch(flags & 3)
|
||||
{
|
||||
case 0:
|
||||
std::cout << "\t\tprivate ";
|
||||
break;
|
||||
case 1:
|
||||
std::cout << "\t\tprotected ";
|
||||
break;
|
||||
case 2:
|
||||
std::cout << "\t\tpublic ";
|
||||
break;
|
||||
case 3:
|
||||
std::cout << "\t\tstatic ";
|
||||
break;
|
||||
}
|
||||
|
||||
switch((flags >> 2) & 3)
|
||||
{
|
||||
case 0:
|
||||
std::cout << "func " << fnname << "(" << fnargs << "), chunk = " << fnchunk << std::endl;
|
||||
|
||||
break;
|
||||
case 1:
|
||||
std::cout << "field " << fnname << ", chunk = " << fnchunk << std::endl;
|
||||
break;
|
||||
case 2:
|
||||
std::cout << "abstract " << fnname << "(" << fnargs << ")" << std::endl;
|
||||
break;
|
||||
case 3:
|
||||
std::cout << "unset_field " << fnname << std::endl;
|
||||
break;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(tableName == "CHKS")
|
||||
{
|
||||
size_t chunkCount = (size_t)EnsureInt(strm);
|
||||
|
||||
for(size_t j = 0; j < chunkCount; j++)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
size_t argCount = (size_t)EnsureInt(strm);
|
||||
for(size_t k = 0; k < argCount; k++)
|
||||
{
|
||||
args.push_back(strs.at(EnsureInt(strm)));
|
||||
}
|
||||
auto len = EnsureInt(strm);
|
||||
|
||||
strm->Seek(len,Tesses::Framework::Streams::SeekOrigin::Current);
|
||||
|
||||
closures.push_back(args);
|
||||
}
|
||||
}
|
||||
else if(tableName == "FUNS")
|
||||
{
|
||||
size_t funLength = (size_t)EnsureInt(strm);
|
||||
|
||||
for(size_t j = 0; j < funLength;j++)
|
||||
{
|
||||
std::vector<std::string> fnParts;
|
||||
uint32_t fnPartsC = EnsureInt(strm);
|
||||
for(uint32_t k = 0; k < fnPartsC; k++)
|
||||
{
|
||||
fnParts.push_back(strs.at(EnsureInt(strm)));
|
||||
uint32_t fnchunk = EnsureInt(strm);
|
||||
switch (flags & 3) {
|
||||
case 0:
|
||||
std::cout << "\t\tprivate ";
|
||||
break;
|
||||
case 1:
|
||||
std::cout << "\t\tprotected ";
|
||||
break;
|
||||
case 2:
|
||||
std::cout << "\t\tpublic ";
|
||||
break;
|
||||
case 3:
|
||||
std::cout << "\t\tstatic ";
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t fnNumber = EnsureInt(strm);
|
||||
funs[fnNumber] = fnParts;
|
||||
|
||||
}
|
||||
}
|
||||
else if(tableName == "INFO")
|
||||
{
|
||||
switch ((flags >> 2) & 3) {
|
||||
case 0:
|
||||
std::cout << "func " << fnname << "(" << fnargs
|
||||
<< "), chunk = " << fnchunk << std::endl;
|
||||
|
||||
std::cout << "Info: " << strs.at((size_t)EnsureInt(strm)) << std::endl;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
strm->Seek((int64_t)tableLen,Tesses::Framework::Streams::SeekOrigin::Current);
|
||||
break;
|
||||
case 1:
|
||||
std::cout << "field " << fnname
|
||||
<< ", chunk = " << fnchunk << std::endl;
|
||||
break;
|
||||
case 2:
|
||||
std::cout << "abstract " << fnname << "(" << fnargs
|
||||
<< ")" << std::endl;
|
||||
break;
|
||||
case 3:
|
||||
std::cout << "unset_field " << fnname << std::endl;
|
||||
break;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
if(hasIcon)
|
||||
std::cout << "Has Icon: yes" << std::endl;
|
||||
else
|
||||
std::cout << "Has Icon: no" << std::endl;
|
||||
} else if (tableName == "CHKS") {
|
||||
size_t chunkCount = (size_t)EnsureInt(strm);
|
||||
|
||||
for(size_t i = 1; i < closures.size(); i++)
|
||||
{
|
||||
if(funs.count((uint32_t)i) > 0)
|
||||
{
|
||||
std::cout << "Func: ";
|
||||
auto res = funs[(uint32_t)i];
|
||||
if(!res.empty()) {
|
||||
std::cout << "/^" << res[0] << "^/ ";
|
||||
}
|
||||
for(size_t i = 1; i < res.size(); i++)
|
||||
{
|
||||
if(i > 1) std::cout << ".";
|
||||
std::cout << res[i];
|
||||
}
|
||||
for (size_t j = 0; j < chunkCount; j++) {
|
||||
std::vector<std::string> args;
|
||||
size_t argCount = (size_t)EnsureInt(strm);
|
||||
for (size_t k = 0; k < argCount; k++) {
|
||||
args.push_back(strs.at(EnsureInt(strm)));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Closure: ";
|
||||
}
|
||||
std::cout << "(";
|
||||
bool first=true;
|
||||
for(auto arg : closures[i])
|
||||
{
|
||||
if(!first) std::cout << ", ";
|
||||
std::cout << arg;
|
||||
auto len = EnsureInt(strm);
|
||||
|
||||
if(first) first=false;
|
||||
}
|
||||
std::cout << ")" << std::endl;
|
||||
strm->Seek(len,
|
||||
Tesses::Framework::Streams::SeekOrigin::Current);
|
||||
|
||||
closures.push_back(args);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
std::cout << "String Table:" << std::endl;
|
||||
} else if (tableName == "FUNS") {
|
||||
size_t funLength = (size_t)EnsureInt(strm);
|
||||
|
||||
for(auto str : strs) {
|
||||
std::cout << EscapeString(str, true) << std::endl;
|
||||
for (size_t j = 0; j < funLength; j++) {
|
||||
std::vector<std::string> fnParts;
|
||||
uint32_t fnPartsC = EnsureInt(strm);
|
||||
for (uint32_t k = 0; k < fnPartsC; k++) {
|
||||
fnParts.push_back(strs.at(EnsureInt(strm)));
|
||||
}
|
||||
|
||||
uint32_t fnNumber = EnsureInt(strm);
|
||||
funs[fnNumber] = fnParts;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} else if (tableName == "INFO") {
|
||||
|
||||
std::cout << "Info: " << strs.at((size_t)EnsureInt(strm))
|
||||
<< std::endl;
|
||||
|
||||
} else {
|
||||
strm->Seek((int64_t)tableLen,
|
||||
Tesses::Framework::Streams::SeekOrigin::Current);
|
||||
}
|
||||
}
|
||||
if (hasIcon)
|
||||
std::cout << "Has Icon: yes" << std::endl;
|
||||
else
|
||||
std::cout << "Has Icon: no" << std::endl;
|
||||
|
||||
for (size_t i = 1; i < closures.size(); i++) {
|
||||
if (funs.count((uint32_t)i) > 0) {
|
||||
std::cout << "Func: ";
|
||||
auto res = funs[(uint32_t)i];
|
||||
if (!res.empty()) {
|
||||
std::cout << "/^" << res[0] << "^/ ";
|
||||
}
|
||||
for (size_t i = 1; i < res.size(); i++) {
|
||||
if (i > 1)
|
||||
std::cout << ".";
|
||||
std::cout << res[i];
|
||||
}
|
||||
} else {
|
||||
std::cout << "Closure: ";
|
||||
}
|
||||
std::cout << "(";
|
||||
bool first = true;
|
||||
for (auto arg : closures[i]) {
|
||||
if (!first)
|
||||
std::cout << ", ";
|
||||
std::cout << arg;
|
||||
|
||||
if (first)
|
||||
first = false;
|
||||
}
|
||||
std::cout << ")" << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
std::cout << "String Table:" << std::endl;
|
||||
|
||||
for (auto str : strs) {
|
||||
std::cout << EscapeString(str, true) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Tesses::CrossLang::Programs
|
||||
@@ -6,153 +6,150 @@
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Http;
|
||||
|
||||
namespace Tesses::CrossLang::Programs
|
||||
{
|
||||
namespace Tesses::CrossLang::Programs {
|
||||
|
||||
static bool Download(Tesses::Framework::Filesystem::VFSPath filename,std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs)
|
||||
{
|
||||
auto inContainer=Platform::Environment::GetVariable("CROSSLANG_CONTAINER");
|
||||
if(inContainer && (*inContainer=="1" || *inContainer=="y" || *inContainer=="Y"))
|
||||
{
|
||||
static bool Download(Tesses::Framework::Filesystem::VFSPath filename,
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs) {
|
||||
auto inContainer =
|
||||
Platform::Environment::GetVariable("CROSSLANG_CONTAINER");
|
||||
if (inContainer &&
|
||||
(*inContainer == "1" || *inContainer == "y" || *inContainer == "Y")) {
|
||||
HttpRequest req;
|
||||
req.followRedirects=true;
|
||||
req.followRedirects = true;
|
||||
req.url = "https://redirect.tesses.net/crosslang-shell";
|
||||
req.method = "GET";
|
||||
HttpResponse resp(req);
|
||||
if(resp.statusCode == StatusCode::OK)
|
||||
{
|
||||
if (resp.statusCode == StatusCode::OK) {
|
||||
auto strm = resp.ReadAsStream();
|
||||
CrossLang::CrossArchiveExtract(strm, vfs);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Error when fetching the script error: " << std::to_string(resp.statusCode) << " " << HttpUtils::StatusCodeString(resp.statusCode) << std::endl;
|
||||
} else {
|
||||
std::cout << "Error when fetching the script error: "
|
||||
<< std::to_string(resp.statusCode) << " "
|
||||
<< HttpUtils::StatusCodeString(resp.statusCode)
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
while(true)
|
||||
{
|
||||
std::cout << "File " << filename.ToString() << " not found, do you want to download the installer from: https://redirect.tesses.net/crosslang-shell (this may install other stuff as well) (Y/n)? ";
|
||||
while (true) {
|
||||
std::cout << "File " << filename.ToString()
|
||||
<< " not found, do you want to download the installer from: "
|
||||
"https://redirect.tesses.net/crosslang-shell (this may "
|
||||
"install other stuff as well) (Y/n)? ";
|
||||
std::string line;
|
||||
std::getline(std::cin,line);
|
||||
if(line == "Y" || line == "y")
|
||||
{
|
||||
std::getline(std::cin, line);
|
||||
if (line == "Y" || line == "y") {
|
||||
HttpRequest req;
|
||||
req.followRedirects = true;
|
||||
req.url = "https://redirect.tesses.net/crosslang-shell";
|
||||
req.method = "GET";
|
||||
HttpResponse resp(req);
|
||||
if(resp.statusCode == StatusCode::OK)
|
||||
{
|
||||
if (resp.statusCode == StatusCode::OK) {
|
||||
auto strm = resp.ReadAsStream();
|
||||
CrossLang::CrossArchiveExtract(strm, vfs);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Error when fetching the script error: " << std::to_string(resp.statusCode) << " " << HttpUtils::StatusCodeString(resp.statusCode) << std::endl;
|
||||
} else {
|
||||
std::cout << "Error when fetching the script error: "
|
||||
<< std::to_string(resp.statusCode) << " "
|
||||
<< HttpUtils::StatusCodeString(resp.statusCode)
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(line == "N" || line == "n")
|
||||
{
|
||||
std::cout << "Looks like you will need to install manually" << std::endl;
|
||||
} else if (line == "N" || line == "n") {
|
||||
std::cout << "Looks like you will need to install manually"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
std::cout << "Please use Y or N (case insensitive)" << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
TObject CrossLangShell(GCList& ls, std::vector<std::string>& argv)
|
||||
{
|
||||
TObject CrossLangShell(GCList &ls, std::vector<std::string> &argv) {
|
||||
|
||||
Tesses::Framework::Filesystem::VFSPath dir = GetCrossLangConfigDir();
|
||||
|
||||
Tesses::Framework::Filesystem::VFSPath filename = dir / "Shell" / "Shell.crvm";
|
||||
Tesses::Framework::Filesystem::VFSPath filename =
|
||||
dir / "Shell" / "Shell.crvm";
|
||||
|
||||
|
||||
auto p = Tesses::Framework::Platform::Environment::GetRealExecutablePath(Tesses::Framework::Filesystem::LocalFS->SystemToVFSPath(argv[0])).GetParent().GetParent() / "share" / "Tesses" / "CrossLang" / "Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm";
|
||||
if(argv.size() == 2 && argv[1] == "configdir")
|
||||
{
|
||||
auto p =
|
||||
Tesses::Framework::Platform::Environment::GetRealExecutablePath(
|
||||
Tesses::Framework::Filesystem::LocalFS->SystemToVFSPath(argv[0]))
|
||||
.GetParent()
|
||||
.GetParent() /
|
||||
"share" / "Tesses" / "CrossLang" /
|
||||
"Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm";
|
||||
if (argv.size() == 2 && argv[1] == "configdir") {
|
||||
std::cout << dir.ToString() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
if(argv.size() > 1 && argv[1] == "update-shell")
|
||||
{
|
||||
if (argv.size() > 1 && argv[1] == "update-shell") {
|
||||
|
||||
auto subdir = std::make_shared<Tesses::Framework::Filesystem::SubdirFilesystem>(Tesses::Framework::Filesystem::LocalFS,dir);
|
||||
auto subdir =
|
||||
std::make_shared<Tesses::Framework::Filesystem::SubdirFilesystem>(
|
||||
Tesses::Framework::Filesystem::LocalFS, dir);
|
||||
HttpRequest req;
|
||||
req.followRedirects=true;
|
||||
req.url = "https://redirect.tesses.net/crosslang-shell";
|
||||
req.method = "GET";
|
||||
HttpResponse resp(req);
|
||||
if(resp.statusCode == StatusCode::OK)
|
||||
{
|
||||
auto strm = resp.ReadAsStream();
|
||||
CrossLang::CrossArchiveExtract(strm, subdir);
|
||||
req.followRedirects = true;
|
||||
req.url = "https://redirect.tesses.net/crosslang-shell";
|
||||
req.method = "GET";
|
||||
HttpResponse resp(req);
|
||||
if (resp.statusCode == StatusCode::OK) {
|
||||
auto strm = resp.ReadAsStream();
|
||||
CrossLang::CrossArchiveExtract(strm, subdir);
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Error when fetching the script error: " << std::to_string(resp.statusCode) << " " << HttpUtils::StatusCodeString(resp.statusCode) << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
std::cout << "Error when fetching the script error: "
|
||||
<< std::to_string(resp.statusCode) << " "
|
||||
<< HttpUtils::StatusCodeString(resp.statusCode)
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!Tesses::Framework::Filesystem::LocalFS->RegularFileExists(filename))
|
||||
{
|
||||
auto subdir = std::make_shared<Tesses::Framework::Filesystem::SubdirFilesystem>(Tesses::Framework::Filesystem::LocalFS,dir);
|
||||
if(Tesses::Framework::Filesystem::LocalFS->RegularFileExists(p))
|
||||
{
|
||||
std::cout << "Installing " << p.ToString() << " -> " << dir.ToString() << std::endl;
|
||||
auto strm = Tesses::Framework::Filesystem::LocalFS->OpenFile(p,"rb");
|
||||
if(strm != nullptr)
|
||||
{
|
||||
if (!Tesses::Framework::Filesystem::LocalFS->RegularFileExists(filename)) {
|
||||
auto subdir =
|
||||
std::make_shared<Tesses::Framework::Filesystem::SubdirFilesystem>(
|
||||
Tesses::Framework::Filesystem::LocalFS, dir);
|
||||
if (Tesses::Framework::Filesystem::LocalFS->RegularFileExists(p)) {
|
||||
std::cout << "Installing " << p.ToString() << " -> "
|
||||
<< dir.ToString() << std::endl;
|
||||
auto strm =
|
||||
Tesses::Framework::Filesystem::LocalFS->OpenFile(p, "rb");
|
||||
if (strm != nullptr) {
|
||||
CrossLang::CrossArchiveExtract(strm, subdir);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!Download(filename,subdir)) return 1;
|
||||
} else {
|
||||
if (!Download(filename, subdir))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
TRootEnvironment *env =
|
||||
TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
|
||||
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
TStd::RegisterStd(ls.GetGC(), env);
|
||||
|
||||
env->LoadFileWithDependencies(
|
||||
ls.GetGC(), Tesses::Framework::Filesystem::LocalFS, filename);
|
||||
|
||||
TStd::RegisterStd(ls.GetGC(),env);
|
||||
|
||||
|
||||
env->LoadFileWithDependencies(ls.GetGC(), Tesses::Framework::Filesystem::LocalFS, filename);
|
||||
|
||||
|
||||
TList* args = TList::Create(ls);
|
||||
TList *args = TList::Create(ls);
|
||||
|
||||
args->Add(filename.ToString());
|
||||
|
||||
for(size_t arg=1;arg<argv.size();arg++)
|
||||
for (size_t arg = 1; arg < argv.size(); arg++)
|
||||
args->Add(std::string(argv[arg]));
|
||||
|
||||
return env->CallFunctionWithFatalError(ls,"main",{args});
|
||||
|
||||
return env->CallFunctionWithFatalError(ls, "main", {args});
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Tesses::CrossLang::Programs
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
#include "CrossLang.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
namespace Tesses::CrossLang::Programs {
|
||||
static void Help(std::string filename)
|
||||
{
|
||||
std::cout << "USAGE: " << filename << " [OPTIONS] source_file1 source_file2 source_file_n" << std::endl;
|
||||
static void Help(std::string filename) {
|
||||
std::cout << "USAGE: " << filename
|
||||
<< " [OPTIONS] source_file1 source_file2 source_file_n"
|
||||
<< std::endl;
|
||||
printf("OPTIONS:\n");
|
||||
printf(" -o: Output directory (OUTDIR, defaults to ./bin)\n");
|
||||
printf(" -i: Set info (ex {\"maintainer\": \"Mike Nolan\", \"repo\": \"https://example.com/\", \"homepage\": \"https://example.com/\",\"license\":\"MIT\"})\n");
|
||||
printf(" -I: Set icon resource name (in the resource folder), should be a 128x128 png\n");
|
||||
printf(" -i: Set info (ex {\"maintainer\": \"Mike Nolan\", \"repo\": "
|
||||
"\"https://example.com/\", \"homepage\": "
|
||||
"\"https://example.com/\",\"license\":\"MIT\"})\n");
|
||||
printf(" -I: Set icon resource name (in the resource folder), should be "
|
||||
"a 128x128 png\n");
|
||||
printf(" -v: Set version (1.0.0.0-prod defaults to 1.0.0.0-dev)\n");
|
||||
printf(" -d: Add dependency (DependencyName-1.0.0.0-prod)\n");
|
||||
printf(" -D: enable debug)\n");
|
||||
@@ -18,12 +22,14 @@ static void Help(std::string filename)
|
||||
printf(" -n: Set name (MyAppOrLibName defaults to out)\n");
|
||||
printf(" -r: Set resource directory (RESDIR defaults to res)\n");
|
||||
printf(" -h, --help: Prints help\n");
|
||||
printf(" -e: Set comptime permissions defaults to none, none for no support, \"secure\" for sane without file access, \"secure_file\" for sane with file access to current directory and sub directories, \"full\" has full runtime.\n");
|
||||
printf(" -e: Set comptime permissions defaults to none, none for no "
|
||||
"support, \"secure\" for sane without file access, \"secure_file\" "
|
||||
"for sane with file access to current directory and sub "
|
||||
"directories, \"full\" has full runtime.\n");
|
||||
printf("Options except for help have flag with arg like this: -F ARG\n");
|
||||
exit(1);
|
||||
}
|
||||
void CrossLangCompiler(std::vector<std::string>& argv)
|
||||
{
|
||||
void CrossLangCompiler(std::vector<std::string> &argv) {
|
||||
/*std::ifstream strm(argv[1],std::ios_base::in|std::ios_base::binary);
|
||||
std::vector<LexToken> tokens;
|
||||
Lex(argv[1],strm,tokens);
|
||||
@@ -36,228 +42,189 @@ void CrossLangCompiler(std::vector<std::string>& argv)
|
||||
ByteCodeVectorWriter w(data);
|
||||
gen.Save(std::filesystem::current_path(),w);
|
||||
*/
|
||||
TF_InitWithConsole();
|
||||
std::filesystem::path outputDir = std::filesystem::current_path() / "bin";
|
||||
std::vector<std::filesystem::path> source;
|
||||
std::filesystem::path resourceDir = std::filesystem::current_path() / "res";
|
||||
std::vector<std::pair<std::string, TVMVersion>> dependencies;
|
||||
std::vector<std::pair<std::string, TVMVersion>> tools;
|
||||
std::string name="out";
|
||||
std::string info="{}";
|
||||
std::string icon="";
|
||||
std::string comptime="none";
|
||||
TVMVersion version;
|
||||
bool debug=false;
|
||||
TF_InitWithConsole();
|
||||
std::filesystem::path outputDir = std::filesystem::current_path() / "bin";
|
||||
std::vector<std::filesystem::path> source;
|
||||
std::filesystem::path resourceDir = std::filesystem::current_path() / "res";
|
||||
std::vector<std::pair<std::string, TVMVersion>> dependencies;
|
||||
std::vector<std::pair<std::string, TVMVersion>> tools;
|
||||
std::string name = "out";
|
||||
std::string info = "{}";
|
||||
std::string icon = "";
|
||||
std::string comptime = "none";
|
||||
TVMVersion version;
|
||||
bool debug = false;
|
||||
|
||||
|
||||
|
||||
for(size_t i = 1; i < argv.size(); i++)
|
||||
{
|
||||
if(argv[i] == "--help" || argv[i] == "-h")
|
||||
{
|
||||
for (size_t i = 1; i < argv.size(); i++) {
|
||||
if (argv[i] == "--help" || argv[i] == "-h") {
|
||||
Help(argv[0]);
|
||||
}
|
||||
|
||||
else if(argv[i] == "-o")
|
||||
{
|
||||
|
||||
else if (argv[i] == "-o") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
outputDir = argv[i];
|
||||
}
|
||||
}
|
||||
else if(argv[i] == "-r")
|
||||
{
|
||||
} else if (argv[i] == "-r") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
resourceDir = argv[i];
|
||||
}
|
||||
}
|
||||
else if(argv[i] == "-e")
|
||||
{
|
||||
} else if (argv[i] == "-e") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
comptime = argv[i];
|
||||
}
|
||||
}
|
||||
|
||||
else if(argv[i] == "-i")
|
||||
{
|
||||
|
||||
else if (argv[i] == "-i") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
info = argv[i];
|
||||
}
|
||||
}
|
||||
else if(argv[i] == "-I")
|
||||
{
|
||||
} else if (argv[i] == "-I") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
icon = argv[i];
|
||||
}
|
||||
}
|
||||
else if(argv[i] == "-d")
|
||||
{
|
||||
} else if (argv[i] == "-d") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
std::string str = argv[i];
|
||||
auto lastDash = str.find_last_of('-');
|
||||
if(lastDash < str.size())
|
||||
{
|
||||
std::string str2 = str.substr(lastDash+1);
|
||||
if(str2 == "dev" || str2 == "alpha" || str2 == "beta" || str2 == "prod")
|
||||
{
|
||||
lastDash = str.find_last_of('-',lastDash-1);
|
||||
if (lastDash < str.size()) {
|
||||
std::string str2 = str.substr(lastDash + 1);
|
||||
if (str2 == "dev" || str2 == "alpha" || str2 == "beta" ||
|
||||
str2 == "prod") {
|
||||
lastDash = str.find_last_of('-', lastDash - 1);
|
||||
}
|
||||
std::string str1 = str.substr(0,lastDash);
|
||||
str2 = str.substr(lastDash+1);
|
||||
|
||||
std::string str1 = str.substr(0, lastDash);
|
||||
str2 = str.substr(lastDash + 1);
|
||||
|
||||
TVMVersion v2;
|
||||
if(!TVMVersion::TryParse(str2,v2))
|
||||
{
|
||||
if (!TVMVersion::TryParse(str2, v2)) {
|
||||
printf("ERROR: Invalid syntax for version\n");
|
||||
printf("Expected MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]]]]\n");
|
||||
printf("Expected "
|
||||
"MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-"
|
||||
"prod]]]]\n");
|
||||
exit(1);
|
||||
}
|
||||
dependencies.push_back(std::pair<std::string,TVMVersion>(str1,v2));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dependencies.push_back(
|
||||
std::pair<std::string, TVMVersion>(str1, v2));
|
||||
|
||||
} else {
|
||||
printf("ERROR: Dependency must have version\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(argv[i] == "-t")
|
||||
{
|
||||
} else if (argv[i] == "-t") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
std::string str = argv[i];
|
||||
auto lastDash = str.find_last_of('-');
|
||||
if(lastDash < str.size())
|
||||
{
|
||||
std::string str2 = str.substr(lastDash+1);
|
||||
if(str2 == "dev" || str2 == "alpha" || str2 == "beta" || str2 == "prod")
|
||||
{
|
||||
lastDash = str.find_last_of('-',lastDash-1);
|
||||
if (lastDash < str.size()) {
|
||||
std::string str2 = str.substr(lastDash + 1);
|
||||
if (str2 == "dev" || str2 == "alpha" || str2 == "beta" ||
|
||||
str2 == "prod") {
|
||||
lastDash = str.find_last_of('-', lastDash - 1);
|
||||
}
|
||||
std::string str1 = str.substr(0,lastDash);
|
||||
str2 = str.substr(lastDash+1);
|
||||
|
||||
std::string str1 = str.substr(0, lastDash);
|
||||
str2 = str.substr(lastDash + 1);
|
||||
|
||||
TVMVersion v2;
|
||||
if(!TVMVersion::TryParse(str2,v2))
|
||||
{
|
||||
if (!TVMVersion::TryParse(str2, v2)) {
|
||||
printf("ERROR: Invalid syntax for version\n");
|
||||
printf("Expected MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]]]]\n");
|
||||
printf("Expected "
|
||||
"MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-"
|
||||
"prod]]]]\n");
|
||||
exit(1);
|
||||
}
|
||||
tools.push_back(std::pair<std::string,TVMVersion>(str1,v2));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
tools.push_back(
|
||||
std::pair<std::string, TVMVersion>(str1, v2));
|
||||
|
||||
} else {
|
||||
printf("ERROR: Tool must have version\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(argv[i] == "-n")
|
||||
{
|
||||
} else if (argv[i] == "-n") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
name = argv[i];
|
||||
}
|
||||
}
|
||||
else if(argv[i] == "-v")
|
||||
{
|
||||
} else if (argv[i] == "-v") {
|
||||
i++;
|
||||
if(i < argv.size())
|
||||
{
|
||||
|
||||
if(!TVMVersion::TryParse(argv[i],version))
|
||||
{
|
||||
if (i < argv.size()) {
|
||||
|
||||
if (!TVMVersion::TryParse(argv[i], version)) {
|
||||
printf("ERROR: Invalid syntax for version\n");
|
||||
printf("Expected MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]]]]\n");
|
||||
printf("Expected "
|
||||
"MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]"
|
||||
"]]]\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(argv[i] == "-D" || argv[i] == "--debug")
|
||||
{
|
||||
} else if (argv[i] == "-D" || argv[i] == "--debug") {
|
||||
debug = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
source.push_back(argv[i]);
|
||||
}
|
||||
}
|
||||
if(source.empty())
|
||||
{
|
||||
}
|
||||
if (source.empty()) {
|
||||
Help(argv[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::vector<LexToken> tokens;
|
||||
|
||||
for(auto src : source)
|
||||
{
|
||||
std::ifstream strm(src,std::ios_base::in|std::ios_base::binary);
|
||||
int res = Lex(std::filesystem::absolute(src).string(),strm,tokens);
|
||||
|
||||
for (auto src : source) {
|
||||
std::ifstream strm(src, std::ios_base::in | std::ios_base::binary);
|
||||
int res = Lex(std::filesystem::absolute(src).string(), strm, tokens);
|
||||
}
|
||||
|
||||
std::shared_ptr<GC> gc;
|
||||
std::shared_ptr<GCList> ls;
|
||||
TRootEnvironment* env=nullptr;
|
||||
if(comptime != "none")
|
||||
{
|
||||
std::shared_ptr<GC> gc= std::make_shared<GC>();
|
||||
TRootEnvironment *env = nullptr;
|
||||
if (comptime != "none") {
|
||||
std::shared_ptr<GC> gc = std::make_shared<GC>();
|
||||
gc->Start();
|
||||
ls = std::make_shared<GCList>(gc);
|
||||
env = TRootEnvironment::Create(*ls,TDictionary::Create(*ls));
|
||||
env = TRootEnvironment::Create(*ls, TDictionary::Create(*ls));
|
||||
|
||||
if(comptime == "secure")
|
||||
{
|
||||
TStd::RegisterConsole(gc,env);
|
||||
TStd::RegisterClass(gc,env);
|
||||
TStd::RegisterCrypto(gc,env);
|
||||
TStd::RegisterDictionary(gc,env);
|
||||
TStd::RegisterJson(gc,env);
|
||||
TStd::RegisterRoot(gc,env);
|
||||
TStd::RegisterIO(gc,env,false);
|
||||
env->permissions.locked=true;
|
||||
}
|
||||
else if(comptime == "secure_file")
|
||||
{
|
||||
TStd::RegisterConsole(gc,env);
|
||||
TStd::RegisterClass(gc,env);
|
||||
TStd::RegisterCrypto(gc,env);
|
||||
TStd::RegisterDictionary(gc,env);
|
||||
TStd::RegisterJson(gc,env);
|
||||
TStd::RegisterRoot(gc,env);
|
||||
TStd::RegisterIO(gc,env,false);
|
||||
env->permissions.locked=true;
|
||||
auto fs = env->EnsureDictionary(gc,"FS");
|
||||
fs->SetValue("Local", std::make_shared<SubdirFilesystem>(LocalFS,Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory()));
|
||||
}
|
||||
else if(comptime == "full")
|
||||
{
|
||||
TStd::RegisterStd(gc,env);
|
||||
env->permissions.locked=true;
|
||||
if (comptime == "secure") {
|
||||
TStd::RegisterConsole(gc, env);
|
||||
TStd::RegisterClass(gc, env);
|
||||
TStd::RegisterCrypto(gc, env);
|
||||
TStd::RegisterDictionary(gc, env);
|
||||
TStd::RegisterJson(gc, env);
|
||||
TStd::RegisterRoot(gc, env);
|
||||
TStd::RegisterIO(gc, env, false);
|
||||
env->permissions.locked = true;
|
||||
} else if (comptime == "secure_file") {
|
||||
TStd::RegisterConsole(gc, env);
|
||||
TStd::RegisterClass(gc, env);
|
||||
TStd::RegisterCrypto(gc, env);
|
||||
TStd::RegisterDictionary(gc, env);
|
||||
TStd::RegisterJson(gc, env);
|
||||
TStd::RegisterRoot(gc, env);
|
||||
TStd::RegisterIO(gc, env, false);
|
||||
env->permissions.locked = true;
|
||||
auto fs = env->EnsureDictionary(gc, "FS");
|
||||
fs->SetValue("Local",
|
||||
std::make_shared<SubdirFilesystem>(
|
||||
LocalFS, Tesses::Framework::Filesystem::VFSPath::
|
||||
GetAbsoluteCurrentDirectory()));
|
||||
} else if (comptime == "full") {
|
||||
TStd::RegisterStd(gc, env);
|
||||
env->permissions.locked = true;
|
||||
}
|
||||
}
|
||||
|
||||
Parser parser(tokens,gc,env);
|
||||
|
||||
Parser parser(tokens, gc, env);
|
||||
parser.debug = debug;
|
||||
CodeGen gen;
|
||||
|
||||
auto sfs = std::make_shared<SubdirFilesystem>(LocalFS,LocalFS->SystemToVFSPath(resourceDir.string()));
|
||||
auto sfs = std::make_shared<SubdirFilesystem>(
|
||||
LocalFS, LocalFS->SystemToVFSPath(resourceDir.string()));
|
||||
gen.embedFS = sfs;
|
||||
|
||||
gen.GenRoot(parser.ParseRoot());
|
||||
@@ -265,21 +232,20 @@ void CrossLangCompiler(std::vector<std::string>& argv)
|
||||
gen.version = version;
|
||||
gen.info = info;
|
||||
gen.icon = icon;
|
||||
for(auto deps : dependencies)
|
||||
{
|
||||
for (auto deps : dependencies) {
|
||||
gen.dependencies.push_back(deps);
|
||||
}
|
||||
for(auto tool : tools)
|
||||
{
|
||||
for (auto tool : tools) {
|
||||
gen.tools.push_back(tool);
|
||||
}
|
||||
|
||||
|
||||
std::filesystem::create_directory(outputDir);
|
||||
|
||||
{
|
||||
auto strm = std::make_shared<Tesses::Framework::Streams::FileStream>(outputDir / (name + "-" + version.ToString() + ".crvm"),"wb");
|
||||
|
||||
auto strm = std::make_shared<Tesses::Framework::Streams::FileStream>(
|
||||
outputDir / (name + "-" + version.ToString() + ".crvm"), "wb");
|
||||
|
||||
gen.Save(strm);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Tesses::CrossLang::Programs
|
||||
@@ -1,124 +1,114 @@
|
||||
#include "CrossLang.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
namespace Tesses::CrossLang::Programs {
|
||||
TObject CrossLangInterperter(GCList& ls,TRootEnvironment* env,std::vector<std::string>& argv)
|
||||
{
|
||||
std::shared_ptr<GC> gc = ls.GetGC();
|
||||
if(argv.size() > 1)
|
||||
{
|
||||
std::ifstream strm(argv[1],std::ios_base::in|std::ios_base::binary);
|
||||
TObject CrossLangInterperter(GCList &ls, TRootEnvironment *env,
|
||||
std::vector<std::string> &argv) {
|
||||
std::shared_ptr<GC> gc = ls.GetGC();
|
||||
if (argv.size() > 1) {
|
||||
std::ifstream strm(argv[1], std::ios_base::in | std::ios_base::binary);
|
||||
std::vector<LexToken> tokens;
|
||||
Lex(argv[1],strm,tokens);
|
||||
Lex(argv[1], strm, tokens);
|
||||
|
||||
Parser parser(tokens);
|
||||
|
||||
CodeGen gen;
|
||||
|
||||
auto sfs = std::make_shared<SubdirFilesystem>(LocalFS,VFSPath("."));
|
||||
auto sfs = std::make_shared<SubdirFilesystem>(LocalFS, VFSPath("."));
|
||||
gen.embedFS = sfs;
|
||||
gen.GenRoot(parser.ParseRoot());
|
||||
std::vector<uint8_t> data;
|
||||
{
|
||||
auto strm2 = std::make_shared<Tesses::Framework::Streams::MemoryStream>(true);
|
||||
auto strm2 =
|
||||
std::make_shared<Tesses::Framework::Streams::MemoryStream>(
|
||||
true);
|
||||
gen.Save(strm2);
|
||||
|
||||
|
||||
{
|
||||
TFile* file = TFile::Create(ls);
|
||||
TFile *file = TFile::Create(ls);
|
||||
|
||||
strm2->Seek(0, Tesses::Framework::Streams::SeekOrigin::Begin);
|
||||
file->Load(gc, strm2);
|
||||
|
||||
strm2->Seek(0,Tesses::Framework::Streams::SeekOrigin::Begin);
|
||||
file->Load(gc,strm2);
|
||||
|
||||
env->LoadFile(gc, file);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
TList* args = TList::Create(ls);
|
||||
for(int arg=1;arg<argv.size();arg++)
|
||||
TList *args = TList::Create(ls);
|
||||
for (int arg = 1; arg < argv.size(); arg++)
|
||||
args->Add(std::string(argv[arg]));
|
||||
|
||||
return env->CallFunctionWithFatalError(ls,"main",{args});
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
while(true)
|
||||
{
|
||||
|
||||
return env->CallFunctionWithFatalError(ls, "main", {args});
|
||||
|
||||
} else {
|
||||
|
||||
while (true) {
|
||||
std::cout << "> ";
|
||||
std::string source;
|
||||
std::getline(std::cin,source);
|
||||
std::getline(std::cin, source);
|
||||
|
||||
auto strm2 = std::make_shared<Tesses::Framework::Streams::MemoryStream>(true);
|
||||
auto strm2 =
|
||||
std::make_shared<Tesses::Framework::Streams::MemoryStream>(
|
||||
true);
|
||||
|
||||
if(source.find("loadfile ") == 0)
|
||||
{
|
||||
if (source.find("loadfile ") == 0) {
|
||||
std::string filename = source.substr(9);
|
||||
|
||||
std::ifstream strm(filename,std::ios_base::in|std::ios_base::binary);
|
||||
std::ifstream strm(filename,
|
||||
std::ios_base::in | std::ios_base::binary);
|
||||
std::vector<LexToken> tokens;
|
||||
Lex(filename,strm,tokens);
|
||||
Lex(filename, strm, tokens);
|
||||
|
||||
Parser parser(tokens);
|
||||
|
||||
CodeGen gen;
|
||||
|
||||
auto sfs = std::make_shared<SubdirFilesystem>(LocalFS,VFSPath("."));
|
||||
auto sfs =
|
||||
std::make_shared<SubdirFilesystem>(LocalFS, VFSPath("."));
|
||||
gen.embedFS = sfs;
|
||||
gen.GenRoot(parser.ParseRoot());
|
||||
|
||||
|
||||
gen.Save(strm2);
|
||||
|
||||
}
|
||||
else if(source == "exit")
|
||||
{
|
||||
} else if (source == "exit") {
|
||||
return (int64_t)0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
std::vector<LexToken> tokens;
|
||||
std::stringstream strm(source,std::ios_base::in | std::ios_base::binary);
|
||||
Lex("lexed.tcross",strm,tokens);
|
||||
std::stringstream strm(source, std::ios_base::in |
|
||||
std::ios_base::binary);
|
||||
Lex("lexed.tcross", strm, tokens);
|
||||
|
||||
Parser parser(tokens);
|
||||
|
||||
CodeGen gen;
|
||||
|
||||
auto sfs = std::make_shared<SubdirFilesystem>(LocalFS,VFSPath("."));
|
||||
auto sfs =
|
||||
std::make_shared<SubdirFilesystem>(LocalFS, VFSPath("."));
|
||||
gen.embedFS = sfs;
|
||||
|
||||
gen.GenRoot(parser.ParseRoot());
|
||||
|
||||
|
||||
gen.Save(strm2);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
TFile* file = TFile::Create(ls);
|
||||
|
||||
strm2->Seek(0,Tesses::Framework::Streams::SeekOrigin::Begin);
|
||||
file->Load(gc,strm2);
|
||||
|
||||
env->LoadFile(gc, file);
|
||||
TFile *file = TFile::Create(ls);
|
||||
|
||||
|
||||
}
|
||||
strm2->Seek(0, Tesses::Framework::Streams::SeekOrigin::Begin);
|
||||
file->Load(gc, strm2);
|
||||
|
||||
|
||||
env->LoadFile(gc, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (int64_t)0;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Tesses::CrossLang::Programs
|
||||
@@ -1,61 +1,58 @@
|
||||
#include "CrossLang.hpp"
|
||||
using namespace Tesses::Framework;
|
||||
namespace Tesses::CrossLang::Programs {
|
||||
TObject CrossLangVM(GCList& ls,TRootEnvironment* env, std::vector<std::string>& argv)
|
||||
{
|
||||
if(argv.size() < 2)
|
||||
{
|
||||
std::cout << "USAGE: " << (argv.empty() ? (std::string)"crossvm" : argv[0]) << " <filename.crvm> <args...>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
env->LoadFileWithDependencies(ls.GetGC(), Tesses::Framework::Filesystem::LocalFS, Tesses::Framework::Filesystem::LocalFS->SystemToVFSPath(argv[1]));
|
||||
|
||||
if(env->HasVariable("WebAppMain"))
|
||||
{
|
||||
Args args(argv);
|
||||
int port = 4206;
|
||||
for(auto& item : args.options)
|
||||
{
|
||||
if(item.first == "port")
|
||||
{
|
||||
port = std::stoi(item.second);
|
||||
}
|
||||
}
|
||||
|
||||
env->EnsureDictionary(ls.GetGC(),"Net")->SetValue("WebServerPort", (int64_t)port);
|
||||
TList* args2 = TList::Create(ls);
|
||||
for(auto& item : args.positional)
|
||||
{
|
||||
args2->Add(item);
|
||||
}
|
||||
|
||||
auto res = env->CallFunctionWithFatalError(ls, "WebAppMain", {args2});
|
||||
auto svr2 = Tesses::CrossLang::ToHttpServer(ls.GetGC(),res);
|
||||
if(svr2 == nullptr) return 1;
|
||||
Tesses::Framework::Http::HttpServer svr(port,svr2);
|
||||
svr.StartAccepting();
|
||||
TF_RunEventLoop();
|
||||
TDictionary* _dict;
|
||||
TClassObject* _co;
|
||||
if(GetObjectHeap(res,_dict))
|
||||
{
|
||||
_dict->CallMethod(ls,"Close",{});
|
||||
}
|
||||
if(GetObjectHeap(res,_co))
|
||||
{
|
||||
_co->CallMethod(ls,"","Close",{});
|
||||
}
|
||||
TF_Quit();
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
TList* args = TList::Create(ls);
|
||||
for(size_t arg=1;arg<argv.size();arg++)
|
||||
args->Add(std::string(argv[arg]));
|
||||
|
||||
return env->CallFunctionWithFatalError(ls,"main",{args});
|
||||
|
||||
}
|
||||
TObject CrossLangVM(GCList &ls, TRootEnvironment *env,
|
||||
std::vector<std::string> &argv) {
|
||||
if (argv.size() < 2) {
|
||||
std::cout << "USAGE: "
|
||||
<< (argv.empty() ? (std::string) "crossvm" : argv[0])
|
||||
<< " <filename.crvm> <args...>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
env->LoadFileWithDependencies(
|
||||
ls.GetGC(), Tesses::Framework::Filesystem::LocalFS,
|
||||
Tesses::Framework::Filesystem::LocalFS->SystemToVFSPath(argv[1]));
|
||||
|
||||
if (env->HasVariable("WebAppMain")) {
|
||||
Args args(argv);
|
||||
int port = 4206;
|
||||
for (auto &item : args.options) {
|
||||
if (item.first == "port") {
|
||||
port = std::stoi(item.second);
|
||||
}
|
||||
}
|
||||
|
||||
env->EnsureDictionary(ls.GetGC(), "Net")
|
||||
->SetValue("WebServerPort", (int64_t)port);
|
||||
TList *args2 = TList::Create(ls);
|
||||
for (auto &item : args.positional) {
|
||||
args2->Add(item);
|
||||
}
|
||||
|
||||
auto res = env->CallFunctionWithFatalError(ls, "WebAppMain", {args2});
|
||||
auto svr2 = Tesses::CrossLang::ToHttpServer(ls.GetGC(), res);
|
||||
if (svr2 == nullptr)
|
||||
return 1;
|
||||
Tesses::Framework::Http::HttpServer svr(port, svr2);
|
||||
svr.StartAccepting();
|
||||
TF_RunEventLoop();
|
||||
TDictionary *_dict;
|
||||
TClassObject *_co;
|
||||
if (GetObjectHeap(res, _dict)) {
|
||||
_dict->CallMethod(ls, "Close", {});
|
||||
}
|
||||
if (GetObjectHeap(res, _co)) {
|
||||
_co->CallMethod(ls, "", "Close", {});
|
||||
}
|
||||
TF_Quit();
|
||||
return 0;
|
||||
} else {
|
||||
TList *args = TList::Create(ls);
|
||||
for (size_t arg = 1; arg < argv.size(); arg++)
|
||||
args->Add(std::string(argv[arg]));
|
||||
|
||||
return env->CallFunctionWithFatalError(ls, "main", {args});
|
||||
}
|
||||
}
|
||||
} // namespace Tesses::CrossLang::Programs
|
||||
@@ -1,9 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> args(argc);
|
||||
for(int i = 0; i < argc; i++)
|
||||
args[i] = argv[i];
|
||||
return (int)Tesses::CrossLang::Programs::CrossArchiveCreate(args);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> args(argc);
|
||||
for(int i = 0; i < argc; i++)
|
||||
args[i] = argv[i];
|
||||
return (int)Tesses::CrossLang::Programs::CrossArchiveExtract(args);
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::CrossLang;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
if(argc > 0)
|
||||
TF_AllowPortable(argv[0]);
|
||||
std::shared_ptr<GC> gc= std::make_shared<GC>();
|
||||
gc->Start();
|
||||
GCList ls(gc);
|
||||
|
||||
|
||||
std::vector<std::string> args(argc);
|
||||
for(int i = 0; i < argc; i++)
|
||||
args[i] = argv[i];
|
||||
auto res = Programs::CrossLangShell(ls, args);
|
||||
|
||||
int64_t myi64;
|
||||
if(GetObject(res,myi64))
|
||||
return (int)myi64;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::CrossLang;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
if(argc > 0)
|
||||
TF_AllowPortable(argv[0]);
|
||||
|
||||
|
||||
|
||||
std::vector<std::string> args(argc);
|
||||
for(int i = 0; i < argc; i++)
|
||||
args[i] = argv[i];
|
||||
Programs::CrossLangCompiler(args);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::CrossLang;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
if(argc > 0)
|
||||
TF_AllowPortable(argv[0]);
|
||||
|
||||
for(int i = 1; i < argc; i++)
|
||||
{
|
||||
VFSPath path(argv[i]);
|
||||
if(LocalFS->FileExists(path))
|
||||
{
|
||||
std::cout << "File: " << path.ToString() << std::endl;
|
||||
auto strm = LocalFS->OpenFile(path, "rb");
|
||||
Programs::CrossLangDump(strm);
|
||||
}
|
||||
else {
|
||||
std::cout << "File: " << path.ToString() << " does not exist." << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::CrossLang;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
if(argc > 0)
|
||||
TF_AllowPortable(argv[0]);
|
||||
std::shared_ptr<GC> gc= std::make_shared<GC>();
|
||||
gc->Start();
|
||||
GCList ls(gc);
|
||||
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
TStd::RegisterStd(gc,env);
|
||||
|
||||
std::vector<std::string> args(argc);
|
||||
for(int i = 0; i < argc; i++)
|
||||
args[i] = argv[i];
|
||||
auto res = Programs::CrossLangInterperter(ls, env, args);
|
||||
|
||||
int64_t myi64;
|
||||
if(GetObject(res,myi64))
|
||||
return (int)myi64;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#include "CrossLang.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::CrossLang;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
if(argc > 0)
|
||||
TF_AllowPortable(argv[0]);
|
||||
std::shared_ptr<GC> gc= std::make_shared<GC>();
|
||||
gc->Start();
|
||||
GCList ls(gc);
|
||||
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
TStd::RegisterStd(gc,env);
|
||||
|
||||
std::vector<std::string> args(argc);
|
||||
for(int i = 0; i < argc; i++)
|
||||
args[i] = argv[i];
|
||||
auto res = Programs::CrossLangVM(ls, env, args);
|
||||
|
||||
int64_t myi64;
|
||||
if(GetObject(res,myi64))
|
||||
return (int)myi64;
|
||||
return 0;
|
||||
}
|
||||
@@ -4,173 +4,190 @@ using namespace Tesses::Framework;
|
||||
using namespace Tesses::CrossLang;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
//crosslang crossint
|
||||
//crosslang
|
||||
//crosslang ...
|
||||
|
||||
std::string programName = "crosslang";
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
TF_InitWithConsole();
|
||||
if(argc > 0)
|
||||
{
|
||||
TF_AllowPortable(argv[0]);
|
||||
Tesses::Framework::Filesystem::VFSPath path=(std::string)argv[0];
|
||||
path.RemoveExtension();
|
||||
programName = path.GetFileName();
|
||||
}
|
||||
TF_AllowPortable();
|
||||
|
||||
std::vector<std::string> args(argc);
|
||||
for(int i = 0; i < argc; i++)
|
||||
|
||||
for (int i = 0; i < argc; i++)
|
||||
args[i] = argv[i];
|
||||
if(programName == "crossint")
|
||||
{
|
||||
|
||||
int64_t myi64=0;
|
||||
|
||||
std::shared_ptr<GC> gc= std::make_shared<GC>();
|
||||
|
||||
auto execName = TF_GetExecutableName();
|
||||
|
||||
if (!execName.empty()) {
|
||||
Tesses::Framework::Filesystem::VFSPath execPath = execName;
|
||||
if (execPath.HasExtension()) {
|
||||
execPath.RemoveExtension();
|
||||
}
|
||||
|
||||
if (Tesses::Framework::Filesystem::LocalFS->FileExists(execPath +
|
||||
".crvm")) {
|
||||
|
||||
if (args.empty())
|
||||
args.push_back(execPath.GetFileName());
|
||||
|
||||
auto crvmFile = execPath + ".crvm";
|
||||
|
||||
args.insert(args.begin() + 1, crvmFile.ToString());
|
||||
int64_t myi64 = 0;
|
||||
|
||||
args.erase(args.begin());
|
||||
std::shared_ptr<GC> gc = std::make_shared<GC>();
|
||||
gc->Start();
|
||||
GCList ls(gc);
|
||||
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
TStd::RegisterStd(gc,env);
|
||||
auto res= Programs::CrossLangInterperter(ls, env, args);
|
||||
|
||||
GetObject(res,myi64);
|
||||
|
||||
|
||||
TRootEnvironment *env =
|
||||
TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
TStd::RegisterStd(gc, env);
|
||||
auto res = Programs::CrossLangVM(ls, env, args);
|
||||
GetObject(res, myi64);
|
||||
return (int)myi64;
|
||||
}
|
||||
else if(programName == "crossc")
|
||||
{
|
||||
Programs::CrossLangCompiler(args);
|
||||
return 0;
|
||||
}
|
||||
else if(programName == "crossarchivecreate")
|
||||
{
|
||||
Programs::CrossArchiveCreate(args);
|
||||
return 0;
|
||||
}
|
||||
else if(programName == "crossarchiveextract")
|
||||
{
|
||||
Programs::CrossArchiveExtract(args);
|
||||
return 0;
|
||||
}
|
||||
else if(programName == "crossdump")
|
||||
{
|
||||
for(size_t i = 1; i < args.size(); i++)
|
||||
{
|
||||
VFSPath path = args[i];
|
||||
if(LocalFS->FileExists(path))
|
||||
{
|
||||
std::cout << "File: " << path.ToString() << std::endl;
|
||||
auto strm = LocalFS->OpenFile(path, "rb");
|
||||
Programs::CrossLangDump(strm);
|
||||
}
|
||||
else {
|
||||
std::cout << "File: " << path.ToString() << " does not exist." << std::endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if(programName == "crossvm")
|
||||
{
|
||||
std::shared_ptr<GC> gc= std::make_shared<GC>();
|
||||
gc->Start();
|
||||
int64_t myi64=0;
|
||||
|
||||
|
||||
GCList ls(gc);
|
||||
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
TStd::RegisterStd(gc,env);
|
||||
auto res= Programs::CrossLangVM(ls, env, args);
|
||||
GetObject(res,myi64);
|
||||
|
||||
return (int)myi64;
|
||||
|
||||
}
|
||||
else if(args.size() > 1)
|
||||
{
|
||||
|
||||
if(args[1] == "crossint")
|
||||
{
|
||||
int64_t myi64=0;
|
||||
if (args.size() > 1) {
|
||||
if (args[1] == "--help") {
|
||||
if (!Tesses::Framework::Filesystem::LocalFS->FileExists(
|
||||
GetCrossLangConfigDir() / "Shell" / "Shell.crvm")) {
|
||||
Console::WriteLine(args[0] + " COMMAND");
|
||||
Console::WriteLine("COMMANDS:");
|
||||
Console::WriteLine(
|
||||
"int: interperter, used to be crossint");
|
||||
Console::WriteLine(
|
||||
"c: the compiler, used to be crossc");
|
||||
Console::WriteLine("archivecreate: create archives, used to "
|
||||
"be crossarchivecreate");
|
||||
Console::WriteLine("archiveextract: extract archives, used to "
|
||||
"be crossarchiveextract");
|
||||
Console::WriteLine("thumbnailer: create thumbnails on "
|
||||
"freedesktop, used to be crossthumbnailer");
|
||||
Console::WriteLine("dump: dump metadata about crvm "
|
||||
"file, used to be crossdump");
|
||||
Console::WriteLine("vm: interpert bytecode file, "
|
||||
"used to be crossvm");
|
||||
Console::WriteLine("update-shell: update the shell");
|
||||
Console::WriteLine(
|
||||
"configdir: print the config directory");
|
||||
|
||||
Console::WriteLine("");
|
||||
Console::WriteLine("NOTE: As you don't have the shell, these "
|
||||
"commands are limited");
|
||||
Console::WriteLine(
|
||||
"NOTE: You can put this binary in a folder with a crvm "
|
||||
"file, as long as filename matches (ignoring extension) it "
|
||||
"will directly launch the crvm file");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (args[1] == "int") {
|
||||
int64_t myi64 = 0;
|
||||
args.erase(args.begin());
|
||||
std::shared_ptr<GC> gc= std::make_shared<GC>();
|
||||
std::shared_ptr<GC> gc = std::make_shared<GC>();
|
||||
gc->Start();
|
||||
GCList ls(gc);
|
||||
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
TStd::RegisterStd(gc,env);
|
||||
auto res= Programs::CrossLangInterperter(ls, env, args);
|
||||
TRootEnvironment *env =
|
||||
TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
TStd::RegisterStd(gc, env);
|
||||
auto res = Programs::CrossLangInterperter(ls, env, args);
|
||||
|
||||
GetObject(res, myi64);
|
||||
|
||||
GetObject(res,myi64);
|
||||
|
||||
return (int)myi64;
|
||||
|
||||
}
|
||||
else if(args[1] == "crossc")
|
||||
{
|
||||
} else if (args[1] == "c") {
|
||||
args.erase(args.begin());
|
||||
Programs::CrossLangCompiler(args);
|
||||
return 0;
|
||||
}
|
||||
else if(args[1] == "crossarchivecreate")
|
||||
{
|
||||
} else if (args[1] == "archivecreate") {
|
||||
args.erase(args.begin());
|
||||
Programs::CrossArchiveCreate(args);
|
||||
return 0;
|
||||
}
|
||||
else if(args[1] == "crossarchiveextract")
|
||||
{
|
||||
} else if (args[1] == "archiveextract") {
|
||||
args.erase(args.begin());
|
||||
Programs::CrossArchiveExtract(args);
|
||||
return 0;
|
||||
}
|
||||
else if(args[1] == "crossdump")
|
||||
{
|
||||
for(size_t i = 2; i < args.size(); i++)
|
||||
{
|
||||
VFSPath path = args[i];
|
||||
if(LocalFS->FileExists(path))
|
||||
{
|
||||
std::cout << "File: " << path.ToString() << std::endl;
|
||||
auto strm = LocalFS->OpenFile(path, "rb");
|
||||
Programs::CrossLangDump(strm);
|
||||
} else if (args[1] == "thumbnailer") {
|
||||
Tesses::Framework::Filesystem::VFSPath execPath =
|
||||
TF_GetExecutableName();
|
||||
auto emptyThumb = execPath.GetParent().GetParent() / "share" /
|
||||
"icons" / "crosslang.png";
|
||||
if (argc < 4) {
|
||||
std::cout << "USAGE: " << argv[0]
|
||||
<< " thumbnailer CRVMFILE NEWPNG" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string crvm = argv[2];
|
||||
std::string png = argv[3];
|
||||
|
||||
if (Tesses::Framework::Filesystem::LocalFS->FileExists(crvm)) {
|
||||
|
||||
Tesses::CrossLang::TFile file;
|
||||
auto f = Tesses::Framework::Filesystem::LocalFS->OpenFile(crvm,
|
||||
"rb");
|
||||
|
||||
file.Load(nullptr, f);
|
||||
|
||||
if (file.icon >= 0 && file.icon < file.resources.size()) {
|
||||
auto f2 = Tesses::Framework::Filesystem::LocalFS->OpenFile(
|
||||
png, "wb");
|
||||
if (f2 != nullptr) {
|
||||
auto &icon = file.resources[file.icon];
|
||||
f2->WriteBlock(icon.data(), icon.size());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
std::cout << "File: " << path.ToString() << " does not exist." << std::endl;
|
||||
}
|
||||
if (Tesses::Framework::Filesystem::LocalFS->FileExists(
|
||||
emptyThumb)) {
|
||||
auto src = Tesses::Framework::Filesystem::LocalFS->OpenFile(
|
||||
emptyThumb, "rb");
|
||||
auto dest =
|
||||
Tesses::Framework::Filesystem::LocalFS->OpenFile(png, "wb");
|
||||
if (src != nullptr && dest != nullptr) {
|
||||
src->CopyTo(dest);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if(args[1] == "crossvm")
|
||||
{
|
||||
int64_t myi64=0;
|
||||
} else if (args[1] == "dump") {
|
||||
for (size_t i = 2; i < args.size(); i++) {
|
||||
VFSPath path = args[i];
|
||||
if (LocalFS->FileExists(path)) {
|
||||
std::cout << "File: " << path.ToString() << std::endl;
|
||||
auto strm = LocalFS->OpenFile(path, "rb");
|
||||
Programs::CrossLangDump(strm);
|
||||
} else {
|
||||
std::cout << "File: " << path.ToString()
|
||||
<< " does not exist." << std::endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} else if (args[1] == "vm") {
|
||||
int64_t myi64 = 0;
|
||||
|
||||
args.erase(args.begin());
|
||||
std::shared_ptr<GC> gc= std::make_shared<GC>();
|
||||
std::shared_ptr<GC> gc = std::make_shared<GC>();
|
||||
gc->Start();
|
||||
GCList ls(gc);
|
||||
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
TStd::RegisterStd(gc,env);
|
||||
auto res= Programs::CrossLangVM(ls, env, args);
|
||||
GetObject(res,myi64);
|
||||
|
||||
TRootEnvironment *env =
|
||||
TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
TStd::RegisterStd(gc, env);
|
||||
auto res = Programs::CrossLangVM(ls, env, args);
|
||||
GetObject(res, myi64);
|
||||
|
||||
return (int)myi64;
|
||||
}
|
||||
}
|
||||
{
|
||||
int64_t myi64=0;
|
||||
std::shared_ptr<GC> gc= std::make_shared<GC>();
|
||||
int64_t myi64 = 0;
|
||||
std::shared_ptr<GC> gc = std::make_shared<GC>();
|
||||
gc->Start();
|
||||
GCList ls(gc);
|
||||
auto res= Programs::CrossLangShell(ls, args);
|
||||
GCList ls(gc);
|
||||
auto res = Programs::CrossLangShell(ls, args);
|
||||
|
||||
GetObject(res,myi64);
|
||||
GetObject(res, myi64);
|
||||
|
||||
|
||||
|
||||
return (int)myi64;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,287 +1,255 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
namespace Tesses::CrossLang {
|
||||
static TList *VectorOfStringToList(GCList &ls, std::vector<std::string> &strs) {
|
||||
TList *list = TList::Create(ls);
|
||||
ls.GetGC()->BarrierBegin();
|
||||
for (auto &item : strs)
|
||||
list->Add(item);
|
||||
ls.GetGC()->BarrierEnd();
|
||||
return list;
|
||||
}
|
||||
static TList *EntriesToList(GCList &ls, std::vector<TClassEntry> &ents) {
|
||||
TList *list = TList::Create(ls);
|
||||
ls.GetGC()->BarrierBegin();
|
||||
for (auto &item : ents) {
|
||||
std::string modifier = "public";
|
||||
switch (item.modifier) {
|
||||
case TClassModifier::Public:
|
||||
modifier = "public";
|
||||
break;
|
||||
case TClassModifier::Private:
|
||||
modifier = "private";
|
||||
break;
|
||||
case TClassModifier::Protected:
|
||||
modifier = "protected";
|
||||
break;
|
||||
case TClassModifier::Static:
|
||||
modifier = "static";
|
||||
break;
|
||||
}
|
||||
|
||||
namespace Tesses::CrossLang
|
||||
{
|
||||
static TList* VectorOfStringToList(GCList& ls, std::vector<std::string>& strs)
|
||||
{
|
||||
TList* list = TList::Create(ls);
|
||||
ls.GetGC()->BarrierBegin();
|
||||
for(auto& item : strs)
|
||||
list->Add(item);
|
||||
ls.GetGC()->BarrierEnd();
|
||||
return list;
|
||||
list->Add(TDictionary::Create(
|
||||
ls,
|
||||
{TDItem("Name", item.name), TDItem("IsAbstract", item.isAbstract),
|
||||
TDItem("IsFunction", item.isFunction),
|
||||
TDItem("Documentation", item.documentation),
|
||||
TDItem("ChunkId", (int64_t)item.chunkId),
|
||||
TDItem("Arguments", VectorOfStringToList(ls, item.args)),
|
||||
TDItem("Modifier", modifier)}));
|
||||
}
|
||||
static TList* EntriesToList(GCList& ls, std::vector<TClassEntry>& ents)
|
||||
{
|
||||
TList* list=TList::Create(ls);
|
||||
ls.GetGC()->BarrierBegin();
|
||||
for(auto& item : ents)
|
||||
{
|
||||
std::string modifier = "public";
|
||||
switch(item.modifier)
|
||||
{
|
||||
case TClassModifier::Public:
|
||||
modifier = "public";
|
||||
break;
|
||||
case TClassModifier::Private:
|
||||
modifier = "private";
|
||||
break;
|
||||
case TClassModifier::Protected:
|
||||
modifier = "protected";
|
||||
break;
|
||||
case TClassModifier::Static:
|
||||
modifier = "static";
|
||||
break;
|
||||
}
|
||||
|
||||
list->Add(TDictionary::Create(ls,{
|
||||
TDItem("Name",item.name),
|
||||
TDItem("IsAbstract",item.isAbstract),
|
||||
TDItem("IsFunction",item.isFunction),
|
||||
TDItem("Documentation",item.documentation),
|
||||
TDItem("ChunkId",(int64_t)item.chunkId),
|
||||
TDItem("Arguments",VectorOfStringToList(ls,item.args)),
|
||||
TDItem("Modifier",modifier)
|
||||
}));
|
||||
ls.GetGC()->BarrierEnd();
|
||||
return list;
|
||||
}
|
||||
static TList *ClassInstanceToList(GCList &ls, TClassObject *co) {
|
||||
TList *list = TList::Create(ls);
|
||||
ls.GetGC()->BarrierBegin();
|
||||
for (auto &item : co->entries) {
|
||||
if (item.modifier == TClassModifier::Public) {
|
||||
list->Add(TDictionary::Create(
|
||||
ls,
|
||||
{TDItem("Name", item.name), TDItem("IsFunction", !item.canSet),
|
||||
TDItem("Owner", item.owner), TDItem("Value", item.value)}));
|
||||
}
|
||||
ls.GetGC()->BarrierEnd();
|
||||
return list;
|
||||
}
|
||||
static TList* ClassInstanceToList(GCList& ls, TClassObject* co)
|
||||
{
|
||||
TList* list=TList::Create(ls);
|
||||
ls.GetGC()->BarrierBegin();
|
||||
for(auto& item : co->entries)
|
||||
{
|
||||
if(item.modifier == TClassModifier::Public)
|
||||
{
|
||||
list->Add(TDictionary::Create(ls, {
|
||||
TDItem(
|
||||
"Name", item.name
|
||||
),
|
||||
TDItem(
|
||||
"IsFunction", !item.canSet
|
||||
),
|
||||
TDItem(
|
||||
"Owner", item.owner
|
||||
),
|
||||
TDItem(
|
||||
"Value", item.value
|
||||
)
|
||||
}));
|
||||
}
|
||||
}
|
||||
ls.GetGC()->BarrierEnd();
|
||||
return list;
|
||||
}
|
||||
TObject GetClassInfo(GCList& ls,TFile* f, uint32_t index)
|
||||
{
|
||||
return TDictionary::Create(ls,{
|
||||
TDItem("Name", JoinPeriod(f->classes.at(index).name)),
|
||||
TDItem("NameParts",VectorOfStringToList(ls,f->classes.at(index).name)),
|
||||
TDItem("Inherits", JoinPeriod(f->classes.at(index).inherits)),
|
||||
TDItem("InheritsParts",VectorOfStringToList(ls,f->classes.at(index).inherits)),
|
||||
TDItem("Documentation",f->classes.at(index).documentation),
|
||||
TDItem("Entries",EntriesToList(ls,f->classes.at(index).entry))
|
||||
});
|
||||
}
|
||||
static TObject Class_CreateInstance(TRootEnvironment* env,GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
TList* args_ls;
|
||||
if(!GetArgumentHeap(args,1,args_ls)) return nullptr;
|
||||
TList* list;
|
||||
TClassObject* obj;
|
||||
std::string str;
|
||||
if(GetArgumentHeap(args,0,list))
|
||||
{
|
||||
std::vector<std::string> clsName;
|
||||
for(int64_t i = 0; i < list->Count(); i++)
|
||||
{
|
||||
auto o = list->Get(i);
|
||||
if(GetObject(o,str)) clsName.push_back(str);
|
||||
}
|
||||
for(auto& item : env->classes)
|
||||
{
|
||||
auto& f=item.first->classes.at(item.second);
|
||||
|
||||
if(f.name.size() != clsName.size()) continue;
|
||||
|
||||
bool found=true;
|
||||
for(size_t i = 0; i < f.name.size(); i++)
|
||||
if(f.name[i] != clsName[i])
|
||||
{
|
||||
found=false;
|
||||
break;
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
return TClassObject::Create(ls,item.first,item.second,env,args_ls->items);
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if(GetArgument(args,0,str))
|
||||
{
|
||||
std::vector<std::string> clsName=Tesses::Framework::Http::HttpUtils::SplitString(str,".");
|
||||
for(auto& item : env->classes)
|
||||
{
|
||||
auto& f=item.first->classes.at(item.second);
|
||||
|
||||
if(f.name.size() != clsName.size()) continue;
|
||||
|
||||
bool found=true;
|
||||
for(size_t i = 0; i < f.name.size(); i++)
|
||||
if(f.name[i] != clsName[i])
|
||||
{
|
||||
found=false;
|
||||
break;
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
return TClassObject::Create(ls,item.first,item.second,env,args_ls->items);
|
||||
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ls.GetGC()->BarrierEnd();
|
||||
return list;
|
||||
}
|
||||
TObject GetClassInfo(GCList &ls, TFile *f, uint32_t index) {
|
||||
return TDictionary::Create(
|
||||
ls, {TDItem("Name", JoinPeriod(f->classes.at(index).name)),
|
||||
TDItem("NameParts",
|
||||
VectorOfStringToList(ls, f->classes.at(index).name)),
|
||||
TDItem("Inherits", JoinPeriod(f->classes.at(index).inherits)),
|
||||
TDItem("InheritsParts",
|
||||
VectorOfStringToList(ls, f->classes.at(index).inherits)),
|
||||
TDItem("Documentation", f->classes.at(index).documentation),
|
||||
TDItem("Entries", EntriesToList(ls, f->classes.at(index).entry))});
|
||||
}
|
||||
static TObject Class_CreateInstance(TRootEnvironment *env, GCList &ls,
|
||||
std::vector<TObject> args) {
|
||||
TList *args_ls;
|
||||
if (!GetArgumentHeap(args, 1, args_ls))
|
||||
return nullptr;
|
||||
}
|
||||
static TObject Class_GetClassNames(TRootEnvironment* env,GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
TList* list = TList::Create(ls);
|
||||
ls.GetGC()->BarrierBegin();
|
||||
for(auto& item : env->classes)
|
||||
{
|
||||
list->Add(JoinPeriod(item.first->classes.at(item.second).name));
|
||||
TList *list;
|
||||
TClassObject *obj;
|
||||
std::string str;
|
||||
if (GetArgumentHeap(args, 0, list)) {
|
||||
std::vector<std::string> clsName;
|
||||
for (int64_t i = 0; i < list->Count(); i++) {
|
||||
auto o = list->Get(i);
|
||||
if (GetObject(o, str))
|
||||
clsName.push_back(str);
|
||||
}
|
||||
ls.GetGC()->BarrierEnd();
|
||||
return list;
|
||||
}
|
||||
static TObject Class_GetInfo(TRootEnvironment* env,GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
|
||||
TList* list;
|
||||
TClassObject* obj;
|
||||
std::string str;
|
||||
if(GetArgumentHeap(args,0,list))
|
||||
{
|
||||
std::vector<std::string> clsName;
|
||||
for(int64_t i = 0; i < list->Count(); i++)
|
||||
{
|
||||
auto o = list->Get(i);
|
||||
if(GetObject(o,str)) clsName.push_back(str);
|
||||
}
|
||||
for(auto& item : env->classes)
|
||||
{
|
||||
auto& f=item.first->classes.at(item.second);
|
||||
|
||||
if(f.name.size() != clsName.size()) continue;
|
||||
|
||||
bool found=true;
|
||||
for(size_t i = 0; i < f.name.size(); i++)
|
||||
if(f.name[i] != clsName[i])
|
||||
{
|
||||
found=false;
|
||||
break;
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
return GetClassInfo(ls,item.first,item.second);
|
||||
for (auto &item : env->classes) {
|
||||
auto &f = item.first->classes.at(item.second);
|
||||
|
||||
if (f.name.size() != clsName.size())
|
||||
continue;
|
||||
|
||||
bool found = true;
|
||||
for (size_t i = 0; i < f.name.size(); i++)
|
||||
if (f.name[i] != clsName[i]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
if (found) {
|
||||
return TClassObject::Create(ls, item.first, item.second, env,
|
||||
args_ls->items);
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
else if(GetArgument(args,0,str))
|
||||
{
|
||||
std::vector<std::string> clsName=Tesses::Framework::Http::HttpUtils::SplitString(str,".");
|
||||
for(auto& item : env->classes)
|
||||
{
|
||||
auto& f=item.first->classes.at(item.second);
|
||||
|
||||
if(f.name.size() != clsName.size()) continue;
|
||||
|
||||
bool found=true;
|
||||
for(size_t i = 0; i < f.name.size(); i++)
|
||||
if(f.name[i] != clsName[i])
|
||||
{
|
||||
found=false;
|
||||
break;
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
return GetClassInfo(ls,item.first,item.second);
|
||||
} else if (GetArgument(args, 0, str)) {
|
||||
std::vector<std::string> clsName =
|
||||
Tesses::Framework::Http::HttpUtils::SplitString(str, ".");
|
||||
for (auto &item : env->classes) {
|
||||
auto &f = item.first->classes.at(item.second);
|
||||
|
||||
if (f.name.size() != clsName.size())
|
||||
continue;
|
||||
|
||||
bool found = true;
|
||||
for (size_t i = 0; i < f.name.size(); i++)
|
||||
if (f.name[i] != clsName[i]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if(GetArgumentHeap(args,0,obj))
|
||||
{
|
||||
return GetClassInfo(ls,obj->file,obj->classIndex);
|
||||
}
|
||||
if (found) {
|
||||
return TClassObject::Create(ls, item.first, item.second, env,
|
||||
args_ls->items);
|
||||
|
||||
return nullptr;
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
void TStd::RegisterClass(std::shared_ptr<GC> gc, TRootEnvironment* env)
|
||||
{
|
||||
GCList ls(gc);
|
||||
env->permissions.canRegisterClass=true;
|
||||
TDictionary* cls= env->EnsureDictionary(gc, "Class");
|
||||
gc->BarrierBegin();
|
||||
|
||||
TExternalMethod* ext = TExternalMethod::Create(ls ,"Get the class info",{"classInstanceOrClassName"},[env](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
return Class_GetInfo(env,ls,args);
|
||||
});
|
||||
ext->watch.push_back(env);
|
||||
|
||||
cls->SetValue("GetInfo",ext);
|
||||
return nullptr;
|
||||
}
|
||||
static TObject Class_GetClassNames(TRootEnvironment *env, GCList &ls,
|
||||
std::vector<TObject> args) {
|
||||
TList *list = TList::Create(ls);
|
||||
ls.GetGC()->BarrierBegin();
|
||||
for (auto &item : env->classes) {
|
||||
list->Add(JoinPeriod(item.first->classes.at(item.second).name));
|
||||
}
|
||||
ls.GetGC()->BarrierEnd();
|
||||
return list;
|
||||
}
|
||||
static TObject Class_GetInfo(TRootEnvironment *env, GCList &ls,
|
||||
std::vector<TObject> args) {
|
||||
|
||||
ext = TExternalMethod::Create(ls ,"Get the class names",{},[env](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
return Class_GetClassNames(env,ls,args);
|
||||
});
|
||||
ext->watch.push_back(env);
|
||||
|
||||
cls->SetValue("GetClassNames",ext);
|
||||
ext = TExternalMethod::Create(ls ,"Create an instance of class",{"name","args"},[env](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
return Class_CreateInstance(env,ls,args);
|
||||
});
|
||||
ext->watch.push_back(env);
|
||||
|
||||
cls->SetValue("CreateInstance",ext);
|
||||
cls->DeclareFunction(gc,"Name","Get class name via instance",{"instance"},[](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
TClassObject* cls;
|
||||
if(GetArgumentHeap(args,0,cls))
|
||||
{
|
||||
return cls->name;
|
||||
}
|
||||
return "";
|
||||
});
|
||||
TList *list;
|
||||
TClassObject *obj;
|
||||
std::string str;
|
||||
if (GetArgumentHeap(args, 0, list)) {
|
||||
std::vector<std::string> clsName;
|
||||
for (int64_t i = 0; i < list->Count(); i++) {
|
||||
auto o = list->Get(i);
|
||||
if (GetObject(o, str))
|
||||
clsName.push_back(str);
|
||||
}
|
||||
for (auto &item : env->classes) {
|
||||
auto &f = item.first->classes.at(item.second);
|
||||
|
||||
if (f.name.size() != clsName.size())
|
||||
continue;
|
||||
|
||||
cls->DeclareFunction(gc, "GetInstanceInfo", "Get the instance specific info, including current values", {}, [](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
TClassObject* co;
|
||||
if(GetArgumentHeap(args, 0, co))
|
||||
{
|
||||
bool found = true;
|
||||
for (size_t i = 0; i < f.name.size(); i++)
|
||||
if (f.name[i] != clsName[i]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
if (found) {
|
||||
return GetClassInfo(ls, item.first, item.second);
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
} else if (GetArgument(args, 0, str)) {
|
||||
std::vector<std::string> clsName =
|
||||
Tesses::Framework::Http::HttpUtils::SplitString(str, ".");
|
||||
for (auto &item : env->classes) {
|
||||
auto &f = item.first->classes.at(item.second);
|
||||
|
||||
if (f.name.size() != clsName.size())
|
||||
continue;
|
||||
|
||||
bool found = true;
|
||||
for (size_t i = 0; i < f.name.size(); i++)
|
||||
if (f.name[i] != clsName[i]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
if (found) {
|
||||
return GetClassInfo(ls, item.first, item.second);
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
} else if (GetArgumentHeap(args, 0, obj)) {
|
||||
return GetClassInfo(ls, obj->file, obj->classIndex);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
void TStd::RegisterClass(std::shared_ptr<GC> gc, TRootEnvironment *env) {
|
||||
GCList ls(gc);
|
||||
env->permissions.canRegisterClass = true;
|
||||
TDictionary *cls = env->EnsureDictionary(gc, "Class");
|
||||
gc->BarrierBegin();
|
||||
|
||||
TExternalMethod *ext = TExternalMethod::Create(
|
||||
ls, "Get the class info", {"classInstanceOrClassName"},
|
||||
[env](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
return Class_GetInfo(env, ls, args);
|
||||
});
|
||||
ext->watch.push_back(env);
|
||||
|
||||
cls->SetValue("GetInfo", ext);
|
||||
|
||||
ext = TExternalMethod::Create(
|
||||
ls, "Get the class names", {},
|
||||
[env](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
return Class_GetClassNames(env, ls, args);
|
||||
});
|
||||
ext->watch.push_back(env);
|
||||
|
||||
cls->SetValue("GetClassNames", ext);
|
||||
ext = TExternalMethod::Create(
|
||||
ls, "Create an instance of class", {"name", "args"},
|
||||
[env](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
return Class_CreateInstance(env, ls, args);
|
||||
});
|
||||
ext->watch.push_back(env);
|
||||
|
||||
cls->SetValue("CreateInstance", ext);
|
||||
cls->DeclareFunction(gc, "Name", "Get class name via instance",
|
||||
{"instance"},
|
||||
[](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
TClassObject *cls;
|
||||
if (GetArgumentHeap(args, 0, cls)) {
|
||||
return cls->name;
|
||||
}
|
||||
return "";
|
||||
});
|
||||
|
||||
cls->DeclareFunction(
|
||||
gc, "GetInstanceInfo",
|
||||
"Get the instance specific info, including current values", {},
|
||||
[](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
TClassObject *co;
|
||||
if (GetArgumentHeap(args, 0, co)) {
|
||||
ls.GetGC()->BarrierBegin();
|
||||
auto res= TDictionary::Create(ls,
|
||||
{
|
||||
TDItem("Name", co->name),
|
||||
TDItem("File", co->file),
|
||||
TDItem("ClassIndex", (int64_t)co->classIndex),
|
||||
TDItem("InheritList", VectorOfStringToList(ls, co->inherit_tree)),
|
||||
TDItem("Entries", ClassInstanceToList(ls,co))
|
||||
}
|
||||
);
|
||||
auto res = TDictionary::Create(
|
||||
ls, {TDItem("Name", co->name), TDItem("File", co->file),
|
||||
TDItem("ClassIndex", (int64_t)co->classIndex),
|
||||
TDItem("InheritList",
|
||||
VectorOfStringToList(ls, co->inherit_tree)),
|
||||
TDItem("Entries", ClassInstanceToList(ls, co))});
|
||||
ls.GetGC()->BarrierEnd();
|
||||
return res;
|
||||
}
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
}
|
||||
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
} // namespace Tesses::CrossLang
|
||||
@@ -2,334 +2,237 @@
|
||||
#include "CrossLang.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#if defined(GEKKO) || defined(__SWITCH__) || defined(_WIN32)
|
||||
#undef CROSSLANG_ENABLE_TERMIOS
|
||||
#endif
|
||||
|
||||
#ifdef CROSSLANG_ENABLE_TERMIOS
|
||||
#include <termios.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
namespace Tesses::CrossLang {
|
||||
#ifdef CROSSLANG_ENABLE_TERMIOS
|
||||
struct termios orig_termios;
|
||||
static void disableRawMode()
|
||||
{
|
||||
tcsetattr(0, TCSAFLUSH, &orig_termios);
|
||||
}
|
||||
#endif
|
||||
TObject Console_getEcho(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
#ifdef CROSSLANG_ENABLE_TERMIOS
|
||||
struct termios raw;
|
||||
tcgetattr(0, &raw);
|
||||
return (raw.c_lflag & ECHO) > 0;
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
TObject Console_setEcho(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.size() == 1 && std::holds_alternative<bool>(args[0]))
|
||||
{
|
||||
bool cooked = std::get<bool>(args[0]);
|
||||
#ifdef CROSSLANG_ENABLE_TERMIOS
|
||||
struct termios raw;
|
||||
tcgetattr(0, &raw);
|
||||
if(cooked)
|
||||
{
|
||||
raw.c_lflag |= ECHO;
|
||||
}
|
||||
else
|
||||
{
|
||||
raw.c_lflag &= ~(ECHO);
|
||||
}
|
||||
|
||||
tcsetattr(0, TCSAFLUSH, &raw);
|
||||
|
||||
#endif
|
||||
return cooked;
|
||||
}
|
||||
TObject Console_getIsTTY(GCList &ls, std::vector<TObject> args) {
|
||||
|
||||
return Tesses::Framework::Console::IsTTY();
|
||||
}
|
||||
TObject Console_getEcho(GCList &ls, std::vector<TObject> args) {
|
||||
|
||||
return Tesses::Framework::Console::GetEcho();
|
||||
}
|
||||
TObject Console_setEcho(GCList &ls, std::vector<TObject> args) {
|
||||
if (args.size() == 1 && std::holds_alternative<bool>(args[0])) {
|
||||
bool cooked = std::get<bool>(args[0]);
|
||||
Tesses::Framework::Console::SetEcho(cooked);
|
||||
return cooked;
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
TObject Console_getCanonical(GCList &ls, std::vector<TObject> args) {
|
||||
return Tesses::Framework::Console::GetCanonical();
|
||||
}
|
||||
TObject Console_setCanonical(GCList &ls, std::vector<TObject> args) {
|
||||
if (args.size() == 1 && std::holds_alternative<bool>(args[0])) {
|
||||
bool cooked = std::get<bool>(args[0]);
|
||||
Tesses::Framework::Console::SetCanonical(cooked);
|
||||
return cooked;
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
TObject Console_getSignals(GCList &ls, std::vector<TObject> args) {
|
||||
return Tesses::Framework::Console::GetSignals();
|
||||
}
|
||||
TObject Console_setSignals(GCList &ls, std::vector<TObject> args) {
|
||||
if (args.size() == 1 && std::holds_alternative<bool>(args[0])) {
|
||||
bool cooked = std::get<bool>(args[0]);
|
||||
Tesses::Framework::Console::SetSignals(cooked);
|
||||
return cooked;
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
TObject Console_Read(GCList &ls, std::vector<TObject> args) {
|
||||
return (int64_t)Tesses::Framework::Console::Read();
|
||||
}
|
||||
TObject Console_ReadLine(GCList &ls, std::vector<TObject> args) {
|
||||
return Tesses::Framework::Console::ReadLine();
|
||||
}
|
||||
TObject Console_ReadPassword(GCList &ls, std::vector<TObject> args) {
|
||||
return Tesses::Framework::Console::ReadPassword();
|
||||
}
|
||||
TObject Console_Write(GCList &ls, std::vector<TObject> args) {
|
||||
if (args.size() < 1) {
|
||||
return Undefined();
|
||||
}
|
||||
TObject Console_getCanonical(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
#ifdef CROSSLANG_ENABLE_TERMIOS
|
||||
struct termios raw;
|
||||
tcgetattr(0, &raw);
|
||||
return (raw.c_lflag & ICANON) > 0;
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
TObject Console_setCanonical(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.size() == 1 && std::holds_alternative<bool>(args[0]))
|
||||
{
|
||||
bool cooked = std::get<bool>(args[0]);
|
||||
#ifdef CROSSLANG_ENABLE_TERMIOS
|
||||
struct termios raw;
|
||||
tcgetattr(0, &raw);
|
||||
if(cooked)
|
||||
{
|
||||
raw.c_lflag |= ICANON;
|
||||
}
|
||||
else
|
||||
{
|
||||
raw.c_lflag &= ~(ICANON);
|
||||
}
|
||||
|
||||
tcsetattr(0, TCSAFLUSH, &raw);
|
||||
|
||||
#endif
|
||||
return cooked;
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
TObject Console_getSignals(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
#ifdef CROSSLANG_ENABLE_TERMIOS
|
||||
struct termios raw;
|
||||
tcgetattr(0, &raw);
|
||||
return (raw.c_lflag & ISIG) > 0;
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
TObject Console_setSignals(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.size() == 1 && std::holds_alternative<bool>(args[0]))
|
||||
{
|
||||
bool cooked = std::get<bool>(args[0]);
|
||||
#ifdef CROSSLANG_ENABLE_TERMIOS
|
||||
struct termios raw;
|
||||
tcgetattr(0, &raw);
|
||||
if(cooked)
|
||||
{
|
||||
raw.c_lflag |= ISIG;
|
||||
}
|
||||
else
|
||||
{
|
||||
raw.c_lflag &= ~(ISIG);
|
||||
}
|
||||
|
||||
tcsetattr(0, TCSAFLUSH, &raw);
|
||||
|
||||
#endif
|
||||
return cooked;
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
TObject Console_Read(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
uint8_t byte;
|
||||
std::cin.read((char*)&byte,1);
|
||||
return std::cin.eof() ? (int64_t)-1 : (int64_t)byte;
|
||||
}
|
||||
TObject Console_ReadLine(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
std::string str;
|
||||
std::getline(std::cin,str);
|
||||
return str;
|
||||
}
|
||||
TObject Console_Write(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.size() < 1)
|
||||
{
|
||||
return Undefined();
|
||||
}
|
||||
std::cout << ToString(ls.GetGC(),args[0]);
|
||||
return Undefined();
|
||||
}
|
||||
TObject Console_Fatal(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.size() < 1)
|
||||
{
|
||||
std::cout << "FATAL: <NO MESSAGE>" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
std::cout << "FATAL: " << ToString(ls.GetGC(),args[0]) << std::endl;
|
||||
Tesses::Framework::Console::Write(ToString(ls.GetGC(), args[0]));
|
||||
return Undefined();
|
||||
}
|
||||
TObject Console_Fatal(GCList &ls, std::vector<TObject> args) {
|
||||
if (args.size() < 1) {
|
||||
Tesses::Framework::Console::ErrorLine("FATAL: <NO MESSAGE>");
|
||||
exit(1);
|
||||
}
|
||||
TObject Console_WriteLine(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.size() < 1)
|
||||
{
|
||||
std::cout << "\n";
|
||||
return Undefined();
|
||||
}
|
||||
std::cout << ToString(ls.GetGC(),args[0]) << "\n";
|
||||
return Undefined();
|
||||
}
|
||||
TObject Console_Error(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.size() < 1)
|
||||
{
|
||||
return Undefined();
|
||||
}
|
||||
std::cerr << ToString(ls.GetGC(),args[0]);
|
||||
return Undefined();
|
||||
}
|
||||
TObject Console_ErrorLine(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.size() < 1)
|
||||
{
|
||||
std::cout << "\n";
|
||||
return Undefined();
|
||||
}
|
||||
std::cerr << ToString(ls.GetGC(),args[0]) << "\n";
|
||||
return Undefined();
|
||||
}
|
||||
TObject Console_getIn(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
return std::make_shared<Tesses::Framework::Streams::FileStream>(stdin,false,"r",false);
|
||||
}
|
||||
|
||||
TObject Console_getOut(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
return std::make_shared<Tesses::Framework::Streams::FileStream>(stdout,false,"w",false);
|
||||
}
|
||||
TObject Console_getError(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
return std::make_shared<Tesses::Framework::Streams::FileStream>(stderr,false,"w",false);
|
||||
}
|
||||
TObject Console_Clear(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
//because I just really want a clear function
|
||||
#if defined(_WIN32)
|
||||
system("cls");
|
||||
#else
|
||||
std::cout << "\x1b[2J\x1b[H" << std::flush; //because of wii and stuff (dont want to rely on clear command)
|
||||
#endif
|
||||
return Undefined();
|
||||
}
|
||||
static void con_sz(int& w, int& h)
|
||||
{
|
||||
w = 0;
|
||||
h = 0;
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||