mirror of
https://onedev.site.tesses.net/crosslang
synced 2026-04-18 14:07:03 +00:00
Compare commits
11 Commits
c37b26af14
...
v0.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 46850e8edf | |||
| 86c7d85f0e | |||
| 45dcd9e7c5 | |||
| 447e9e6d37 | |||
| cc62377919 | |||
| b3c92707b9 | |||
| ba7213e184 | |||
| 23df4838ff | |||
| e6ce053c2e | |||
| a49b61c532 | |||
| 40205a928d |
70
.gitea/workflows/tag.yaml
Normal file
70
.gitea/workflows/tag.yaml
Normal file
@@ -0,0 +1,70 @@
|
||||
name: Build and Deploy on Tag
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
env:
|
||||
GITEA_AUTH: ${{ secrets.MY_GITEA_AUTH }}
|
||||
|
||||
jobs:
|
||||
build-arch:
|
||||
runs-on: arch-builder
|
||||
steps:
|
||||
- run: pacman --noconfirm -Sy nodejs npm
|
||||
- uses: actions/checkout@v4
|
||||
- run: wget -O /root/repository.key https://git.tesseslanguage.com/api/packages/tesses50/arch/repository.key
|
||||
- run: pacman-key --add /root/repository.key
|
||||
- run: pacman-key --config /opt/cross/ppc/pacman.conf --add /root/repository.key
|
||||
- run: printf "[tesses50.git.tesseslanguage.com]\nSigLevel = Optional TrustAll\nServer = https://git.tesseslanguage.com/api/packages/tesses50/arch/core/\$arch\n" >> /etc/pacman.conf
|
||||
- run: printf "[tesses50.git.tesseslanguage.com]\nSigLevel = Optional TrustAll\nServer = https://git.tesseslanguage.com/api/packages/tesses50/arch/core/\$arch\n" >> /opt/cross/ppc/pacman.conf
|
||||
- run: pacman --noconfirm -Sy mbedtls curl tesses-framework
|
||||
- run: pacman --config /opt/cross/ppc/pacman.conf --noconfirm -Sy mbedtls tesses-framework
|
||||
- run: cp Packaging/Linux/PKGBUILD /home/build/PKGBUILD
|
||||
- run: cp Packaging/Linux/build-arch.sh /home/build/build-arch.sh
|
||||
- run: chmod 755 /home/build/build-arch.sh
|
||||
- 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
|
||||
build-jammy:
|
||||
runs-on: deb-builder-jammy
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build for jammy, noble
|
||||
run: |
|
||||
mkdir ../../artifacts
|
||||
apt update -y
|
||||
apt install -y pkg-config git
|
||||
bash build-ubuntu-jammy.sh
|
||||
bash push-ubuntu-jammy.sh
|
||||
bash build-tars.sh
|
||||
working-directory: ./Packaging/Linux
|
||||
- uses: akkuman/gitea-release-action@v1
|
||||
env:
|
||||
NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
|
||||
with:
|
||||
files: |-
|
||||
artifacts/**
|
||||
build-plucky:
|
||||
runs-on: deb-builder-plucky
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build for plucky, resolute
|
||||
run: |
|
||||
mkdir ../../artifacts
|
||||
apt update -y
|
||||
apt install -y pkg-config git gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 gcc-mingw-w64-i686 g++-mingw-w64-i686 nsis
|
||||
bash build-ubuntu-plucky.sh
|
||||
bash push-ubuntu-plucky.sh
|
||||
working-directory: ./Packaging/Linux
|
||||
|
||||
- name: Build for windows
|
||||
run: bash build.sh
|
||||
|
||||
working-directory: ./Packaging/Windows
|
||||
- uses: akkuman/gitea-release-action@v1
|
||||
env:
|
||||
NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
|
||||
with:
|
||||
files: |-
|
||||
artifacts/**
|
||||
@@ -1,18 +1,21 @@
|
||||
version: 39
|
||||
version: 43
|
||||
jobs:
|
||||
- name: Build for x86_64
|
||||
steps:
|
||||
- !CheckoutStep
|
||||
- type: CheckoutStep
|
||||
name: Checkout
|
||||
cloneCredential: !DefaultCredential {}
|
||||
cloneCredential:
|
||||
type: DefaultCredential
|
||||
withLfs: true
|
||||
withSubmodules: false
|
||||
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
|
||||
- !CommandStep
|
||||
condition: SUCCESSFUL
|
||||
optional: false
|
||||
- type: CommandStep
|
||||
name: Execute build
|
||||
runInContainer: true
|
||||
image: onedev.site.tesses.net/tesses-framework/tesses-framework:latest
|
||||
interpreter: !DefaultInterpreter
|
||||
interpreter:
|
||||
type: DefaultInterpreter
|
||||
commands: |
|
||||
mkdir build
|
||||
cd build
|
||||
@@ -20,127 +23,32 @@ jobs:
|
||||
make -j12
|
||||
make install DESTDIR=../out
|
||||
useTTY: true
|
||||
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
|
||||
- !BuildImageStep
|
||||
condition: SUCCESSFUL
|
||||
optional: false
|
||||
- type: BuildImageStep
|
||||
name: Build Docker Image
|
||||
dockerfile: Dockerfile.run
|
||||
output: !RegistryOutput
|
||||
output:
|
||||
type: RegistryOutput
|
||||
tags: onedev.site.tesses.net/crosslang/crosslang:latest onedev.site.tesses.net/crosslang/crosslang:@commit_hash@
|
||||
registryLogins:
|
||||
- registryUrl: '@server_url@'
|
||||
userName: '@job_token@'
|
||||
passwordSecret: dockersecret
|
||||
platforms: linux/amd64
|
||||
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
|
||||
- !CommandStep
|
||||
name: Wii Build
|
||||
runInContainer: true
|
||||
image: onedev.site.tesses.net/dependencies/wiidev:latest
|
||||
interpreter: !DefaultInterpreter
|
||||
commands: |
|
||||
cd Packaging/CPKG
|
||||
bash wiibuild.sh
|
||||
useTTY: true
|
||||
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
|
||||
- !CommandStep
|
||||
name: Build archlinux
|
||||
runInContainer: true
|
||||
image: git.tesseslanguage.com/tesses50/arch-builds:2025-11-11
|
||||
interpreter: !DefaultInterpreter
|
||||
commands: |
|
||||
wget -O /root/repository.key https://git.tesseslanguage.com/api/packages/tesses50/arch/repository.key
|
||||
pacman-key --add /root/repository.key
|
||||
pacman-key --config /opt/cross/ppc/pacman.conf --add /root/repository.key
|
||||
printf "[tesses50.git.tesseslanguage.com]\nSigLevel = Optional TrustAll\nServer = https://git.tesseslanguage.com/api/packages/tesses50/arch/core/\$arch\n" >> /etc/pacman.conf
|
||||
printf "[tesses50.git.tesseslanguage.com]\nSigLevel = Optional TrustAll\nServer = https://git.tesseslanguage.com/api/packages/tesses50/arch/core/\$arch\n" >> /opt/cross/ppc/pacman.conf
|
||||
|
||||
pacman --noconfirm -Sy mbedtls curl tesses-framework
|
||||
pacman --config /opt/cross/ppc/pacman.conf --noconfirm -Sy mbedtls tesses-framework
|
||||
cp Packaging/Linux/PKGBUILD /home/build/PKGBUILD
|
||||
cp Packaging/Linux/build-arch.sh /home/build/build-arch.sh
|
||||
chmod 755 /home/build/build-arch.sh
|
||||
chown build:build /home/build/PKGBUILD
|
||||
chown build:build /home/build/build-arch.sh
|
||||
su build -c /home/build/build-arch.sh
|
||||
envVars:
|
||||
- name: GITEA_AUTH
|
||||
value: '@secret:GITEA_AUTH@'
|
||||
useTTY: true
|
||||
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
|
||||
- !CommandStep
|
||||
name: Build and Publish Deb Package (Plucky)
|
||||
runInContainer: true
|
||||
image: onedev.site.tesses.net/dependencies/debbuilder/plucky:latest
|
||||
interpreter: !DefaultInterpreter
|
||||
commands: |
|
||||
mkdir artifacts
|
||||
apt update -y
|
||||
apt install -y pkg-config git gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 gcc-mingw-w64-i686 g++-mingw-w64-i686 nsis
|
||||
cd Packaging/Linux
|
||||
bash build-ubuntu-plucky.sh
|
||||
bash push-ubuntu-plucky.sh
|
||||
cd ../CPKG
|
||||
bash winbuild.sh
|
||||
cd ../Windows
|
||||
bash build.sh
|
||||
envVars:
|
||||
- name: GITEA_AUTH
|
||||
value: '@secret:GITEA_AUTH@'
|
||||
- name: BUILD_NO
|
||||
value: '@build_number@'
|
||||
useTTY: true
|
||||
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
|
||||
- !CommandStep
|
||||
name: Build and Publish Deb Package
|
||||
runInContainer: true
|
||||
image: onedev.site.tesses.net/dependencies/debbuilder/jammy:latest
|
||||
interpreter: !DefaultInterpreter
|
||||
commands: |
|
||||
apt update -y
|
||||
apt install -y pkg-config git
|
||||
cd Packaging/Linux
|
||||
bash build-ubuntu-jammy.sh
|
||||
bash push-ubuntu-jammy.sh
|
||||
bash build-tars.sh
|
||||
apt update -y
|
||||
apt install -y crosslang
|
||||
cd ../CPKG
|
||||
bash pack_and_publish.sh
|
||||
envVars:
|
||||
- name: GITEA_AUTH
|
||||
value: '@secret:GITEA_AUTH@'
|
||||
- name: CPKG_KEY
|
||||
value: '@secret:CPKG_KEY@'
|
||||
- name: BUILD_NO
|
||||
value: '@build_number@'
|
||||
useTTY: true
|
||||
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
|
||||
- !SCPCommandStep
|
||||
name: Copy Files
|
||||
privateKeySecret: TRUENAS_SSH
|
||||
source: artifacts
|
||||
target: mike@@10.137.42.30:/mnt/storage24tb/Files/Public/CrossLang/@build_number@
|
||||
options: -r
|
||||
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
|
||||
- !SSHCommandStep
|
||||
name: Link latest
|
||||
remoteMachine: 10.137.42.30
|
||||
userName: mike
|
||||
privateKeySecret: TRUENAS_SSH
|
||||
commands: |
|
||||
cd /mnt/storage24tb/Files/Public/CrossLang
|
||||
rm -f latest
|
||||
ln -s @build_number@ latest
|
||||
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
|
||||
condition: SUCCESSFUL
|
||||
optional: false
|
||||
triggers:
|
||||
- !DependencyFinishedTrigger
|
||||
- type: DependencyFinishedTrigger
|
||||
projects: tesses-framework
|
||||
- !BranchUpdateTrigger
|
||||
- type: BranchUpdateTrigger
|
||||
branches: master
|
||||
userMatch: anyone
|
||||
projects: crosslang
|
||||
projectDependencies:
|
||||
- projectPath: tesses-framework
|
||||
buildProvider: !LastFinishedBuild
|
||||
buildProvider:
|
||||
type: LastFinishedBuild
|
||||
jobName: Build for x86_64
|
||||
artifacts: '*'
|
||||
retryCondition: never
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(TessesCrossLang VERSION 1.0)
|
||||
set(CROSSLANG_MAJOR_VERSION 0)
|
||||
set(CROSSLANG_MINOR_VERSION 0)
|
||||
set(CROSSLANG_PATCH_VERSION 1)
|
||||
|
||||
project(TessesCrossLang VERSION ${CROSSLANG_MAJOR_VERSION}.${CROSSLANG_MINOR_VERSION}.${CROSSLANG_PATCH_VERSION})
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
@@ -78,6 +82,11 @@ if(CROSSLANG_ENABLE_FFI AND CROSSLANG_ENABLE_SHARED)
|
||||
pkg_check_modules(LIBFFI REQUIRED IMPORTED_TARGET libffi)
|
||||
endif()
|
||||
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)
|
||||
@@ -170,6 +179,7 @@ src/types/vfsheapobject.cpp
|
||||
src/types/streamheapobject.cpp
|
||||
src/types/class.cpp
|
||||
src/types/classenvironment.cpp
|
||||
src/types/random.cpp
|
||||
src/vm/filereader.cpp
|
||||
src/vm/gc.cpp
|
||||
src/vm/gclist.cpp
|
||||
@@ -235,7 +245,7 @@ install(TARGETS ${TessesCrossLangLibs}
|
||||
)
|
||||
|
||||
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
|
||||
FILE TessesCrossLangTargets.cmake
|
||||
NAMESPACE TessesCrossLang::
|
||||
@@ -244,6 +254,8 @@ install(EXPORT TessesCrossLangTargets
|
||||
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/TessesCrossLangConfig.cmake"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesCrossLang)
|
||||
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)
|
||||
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TessesCrossLangConfig.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesCrossLang)
|
||||
|
||||
5
CrossLangVersion.h.in
Normal file
5
CrossLangVersion.h.in
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define CROSSLANG_MAJOR @CROSSLANG_MAJOR_VERSION@
|
||||
#define CROSSLANG_MINOR @CROSSLANG_MINOR_VERSION@
|
||||
#define CROSSLANG_PATCH @CROSSLANG_PATCH_VERSION@
|
||||
@@ -1,55 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(CrossLangPublish)
|
||||
|
||||
option(CROSSAPPPUBLISH_STATIC "Build static version" OFF)
|
||||
|
||||
if(CROSSAPPPUBLISH_STATIC)
|
||||
set(TESSESFRAMEWORK_ENABLE_RPATH OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_STATIC ON CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_EXAMPLES OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_APPS OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_SHARED OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_FETCHCONTENT ON CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(CROSSLANG_ENABLE_BINARIES OFF CACHE INTERNAL "For CrossLang" FORCE)
|
||||
else()
|
||||
set(TESSESFRAMEWORK_ENABLE_RPATH OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_STATIC OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_EXAMPLES OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_APPS OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_SHARED ON CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_FETCHCONTENT ON CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(CROSSLANG_ENABLE_BINARIES OFF CACHE INTERNAL "For CrossLang" FORCE)
|
||||
set(CMAKE_INSTALL_BINDIR "." CACHE INTERNAL "For CrossLang" FORCE)
|
||||
set(CMAKE_INSTALL_LIBDIR "." CACHE INTERNAL "For CrossLang" FORCE)
|
||||
set(CMAKE_INSTALL_PREFIX "/dir" CACHE INTERNAL "For CrossLang" FORCE)
|
||||
set(CMAKE_PLATFORM_NO_VERSIONED_SONAME ON CACHE INTERNAL "For CrossLang" FORCE)
|
||||
set(CMAKE_MACOSX_RPATH 1)
|
||||
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON CACHE INTERNAL "For CrossLang" FORCE)
|
||||
if (APPLE)
|
||||
set(CMAKE_INSTALL_RPATH "@executable_path/" CACHE INTERNAL "For CrossLang" FORCE)
|
||||
else()
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/" CACHE INTERNAL "For CrossLang" FORCE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
TessesCrossLang
|
||||
GIT_REPOSITORY https://onedev.site.tesses.net/crosslang.git
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(TessesCrossLang)
|
||||
|
||||
|
||||
|
||||
add_executable(crossapp main.cpp)
|
||||
if(CROSSAPPPUBLISH_STATIC)
|
||||
target_link_libraries(crossapp PUBLIC crosslang_static)
|
||||
else()
|
||||
install(TARGETS crossapp DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
target_link_libraries(crossapp PUBLIC crosslang_shared)
|
||||
|
||||
endif()
|
||||
@@ -1,72 +0,0 @@
|
||||
#include <CrossLang.hpp>
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::CrossLang;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
std::string name = argv[0];
|
||||
Tesses::Framework::Filesystem::VFSPath exePath=Tesses::Framework::Filesystem::LocalFS->SystemToVFSPath(name);
|
||||
exePath.MakeAbsolute();
|
||||
exePath.ChangeExtension(".crvm");
|
||||
|
||||
|
||||
|
||||
|
||||
GC gc;
|
||||
gc.Start();
|
||||
GCList ls(gc);
|
||||
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
|
||||
TStd::RegisterStd(&gc,env);
|
||||
env->LoadFileWithDependencies(&gc, Tesses::Framework::Filesystem::LocalFS, exePath);
|
||||
|
||||
|
||||
|
||||
if(env->HasVariable("WebAppMain"))
|
||||
{
|
||||
Args args(argc, argv);
|
||||
int port = 4206;
|
||||
for(auto& item : args.options)
|
||||
{
|
||||
if(item.first == "port")
|
||||
{
|
||||
port = std::stoi(item.second);
|
||||
}
|
||||
}
|
||||
TList* args2 = TList::Create(ls);
|
||||
args2->Add(exePath.ToString());
|
||||
for(auto& item : args.positional)
|
||||
{
|
||||
args2->Add(item);
|
||||
}
|
||||
|
||||
auto res = env->CallFunction(ls, "WebAppMain", {args2});
|
||||
auto svr2 = Tesses::CrossLang::ToHttpServer(&gc,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();
|
||||
}
|
||||
else {
|
||||
TList* args = TList::Create(ls);
|
||||
args->Add(exePath.ToString());
|
||||
for(int arg=1;arg<argc;arg++)
|
||||
args->Add(argv[arg]);
|
||||
auto res = env->CallFunction(ls,"main",{args});
|
||||
int64_t iresult;
|
||||
if(GetObject(res,iresult))
|
||||
return (int)iresult;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(CrossLangWii)
|
||||
|
||||
|
||||
set(TESSESFRAMEWORK_FETCHCONTENT OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_RPATH OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_STATIC ON CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_EXAMPLES OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_APPS OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(TESSESFRAMEWORK_ENABLE_SHARED OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(CROSSLANG_ENABLE_BINARIES OFF CACHE INTERNAL "For CrossLang" FORCE)
|
||||
set(MBEDTLS_DIR "/opt/devkitpro/portlibs/wii" CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
TessesCrossLang
|
||||
GIT_REPOSITORY https://onedev.site.tesses.net/crosslang.git
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(TessesCrossLang)
|
||||
|
||||
|
||||
|
||||
add_executable(boot main.cpp)
|
||||
target_link_libraries(boot PUBLIC crosslang_static)
|
||||
ogc_create_dol(boot)
|
||||
@@ -1,78 +0,0 @@
|
||||
#include <CrossLang.hpp>
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::CrossLang;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
std::string name = "boot.dol";
|
||||
Tesses::Framework::Filesystem::VFSPath exePath=Tesses::Framework::Filesystem::LocalFS->SystemToVFSPath(name);
|
||||
exePath.MakeAbsolute();
|
||||
exePath.ChangeExtension(".crvm");
|
||||
|
||||
|
||||
|
||||
|
||||
GC gc;
|
||||
gc.Start();
|
||||
GCList ls(gc);
|
||||
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
|
||||
TStd::RegisterStd(&gc,env);
|
||||
env->LoadFileWithDependencies(&gc, Tesses::Framework::Filesystem::LocalFS, exePath);
|
||||
|
||||
|
||||
|
||||
if(env->HasVariable("WebAppMain"))
|
||||
{
|
||||
std::vector<std::string> argsls={"boot.dol"};
|
||||
for(int i = 0; i < argc; i++)
|
||||
{
|
||||
argsls.push_back(argv[i]);
|
||||
}
|
||||
|
||||
Args args(argsls);
|
||||
int port = 4206;
|
||||
for(auto& item : args.options)
|
||||
{
|
||||
if(item.first == "port")
|
||||
{
|
||||
port = std::stoi(item.second);
|
||||
}
|
||||
}
|
||||
TList* args2 = TList::Create(ls);
|
||||
args2->Add(exePath.ToString());
|
||||
for(auto& item : args.positional)
|
||||
{
|
||||
args2->Add(item);
|
||||
}
|
||||
|
||||
auto res = env->CallFunction(ls, "WebAppMain", {args2});
|
||||
auto svr2 = Tesses::CrossLang::ToHttpServer(&gc,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();
|
||||
}
|
||||
else {
|
||||
TList* args = TList::Create(ls);
|
||||
args->Add(exePath.ToString());
|
||||
for(int arg=0;arg<argc;arg++)
|
||||
args->Add(argv[arg]);
|
||||
auto res = env->CallFunction(ls,"main",{args});
|
||||
int64_t iresult;
|
||||
if(GetObject(res,iresult))
|
||||
return (int)iresult;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
set(CMAKE_C_COMPILER "/usr/bin/x86_64-w64-mingw32-gcc")
|
||||
set(CMAKE_CXX_COMPILER "/usr/bin/x86_64-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_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||
@@ -1,7 +0,0 @@
|
||||
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_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR i686)
|
||||
@@ -1,9 +0,0 @@
|
||||
#!/bin/bash
|
||||
rm -r compilers
|
||||
mkdir -p compilers
|
||||
cd compilers
|
||||
wget https://downloads.tesses.net/cache/compilers/$1-cross.tgz
|
||||
tar xvzf $1-cross.tgz
|
||||
mv $1-cross/* .
|
||||
rmdir $1-cross
|
||||
rm $1-cross.tgz
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
mkdir compilers
|
||||
crossint pack.tcross
|
||||
@@ -1,282 +0,0 @@
|
||||
var VERSION="1.0.0.0-dev";
|
||||
var statics = [
|
||||
{
|
||||
target="powerpc-linux-musl",
|
||||
cpu = "powerpc"
|
||||
},
|
||||
{
|
||||
target="powerpc64-linux-musl",
|
||||
cpu = "powerpc64"
|
||||
},
|
||||
{
|
||||
target="i686-linux-musl",
|
||||
cpu = "i686"
|
||||
},
|
||||
{
|
||||
target="arm-linux-musleabihf",
|
||||
cpu="armv7l"
|
||||
},
|
||||
{
|
||||
target="riscv32-linux-musl",
|
||||
cpu="riscv32"
|
||||
},
|
||||
{
|
||||
target="riscv64-linux-musl",
|
||||
cpu="riscv64"
|
||||
},
|
||||
{
|
||||
target="x86_64-linux-musl",
|
||||
cpu="x86_64"
|
||||
},
|
||||
{
|
||||
target="mips-linux-musl",
|
||||
cpu="mips"
|
||||
},
|
||||
{
|
||||
target="mips64-linux-musl",
|
||||
cpu="mips64"
|
||||
},
|
||||
{
|
||||
target="aarch64-linux-musl",
|
||||
cpu="aarch64"
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
func CPUS()
|
||||
{
|
||||
var p = Process.Start({
|
||||
FileName = Env.GetRealExecutablePath("nproc").ToString(),
|
||||
RedirectStandardOutput=true
|
||||
});
|
||||
var ms = new MemoryStream(true);
|
||||
p.StandardOutput.CopyTo(ms);
|
||||
return ParseLong(ms.GetBytes().ToString().Replace("\n","").Replace("\r",""));
|
||||
}
|
||||
var nproc = CPUS();
|
||||
func BuildConsoleOrServerWindowsStatic(arch)
|
||||
{
|
||||
Console.WriteLine($"Building Windows Static {arch}");
|
||||
var build_dir = "builds" / $"win-{arch}";
|
||||
var publish_dir = "publish" / $"win-{arch}";
|
||||
FS.Local.CreateDirectory(build_dir);
|
||||
FS.Local.CreateDirectory(publish_dir);
|
||||
|
||||
var args = ["-S","ConsoleOrServer","-B",build_dir.ToString(),"-DCROSSAPPPUBLISH_STATIC=ON"];
|
||||
|
||||
var file= ("WindowsToolchains"/$"{arch}.cmake").MakeAbsolute().ToString();
|
||||
|
||||
args.Add($"-DCMAKE_TOOLCHAIN_FILE={file}");
|
||||
|
||||
Process.Start({
|
||||
FileName = Env.GetRealExecutablePath("cmake").ToString(),
|
||||
Arguments = args
|
||||
}).Join();
|
||||
|
||||
|
||||
var p = new Process();
|
||||
p.FileName = Env.GetRealExecutablePath("make").ToString();
|
||||
p.WorkingDirectory = build_dir.MakeAbsolute().ToString();
|
||||
p.Arguments = [$"-j{nproc}"];
|
||||
if(p.Start())
|
||||
p.Join();
|
||||
|
||||
|
||||
|
||||
}
|
||||
func BuildConsoleOrServerLinuxStatic(dir,cmake_toolchain)
|
||||
{
|
||||
Console.WriteLine($"Building Linux Static {dir}");
|
||||
var build_dir = "builds" / $"linux-{dir}-static";
|
||||
var publish_dir = "publish" / $"linux-{dir}-static";
|
||||
FS.Local.CreateDirectory(build_dir);
|
||||
FS.Local.CreateDirectory(publish_dir);
|
||||
|
||||
var args = ["-S","ConsoleOrServer","-B",build_dir.ToString(),"-DCROSSAPPPUBLISH_STATIC=ON"];
|
||||
if(TypeOf(cmake_toolchain) == "String")
|
||||
{
|
||||
args.Add($"-DCMAKE_TOOLCHAIN_FILE={cmake_toolchain}");
|
||||
}
|
||||
Process.Start({
|
||||
FileName = Env.GetRealExecutablePath("cmake").ToString(),
|
||||
Arguments = args
|
||||
}).Join();
|
||||
|
||||
|
||||
var p = new Process();
|
||||
p.FileName = Env.GetRealExecutablePath("make").ToString();
|
||||
p.WorkingDirectory = build_dir.MakeAbsolute().ToString();
|
||||
p.Arguments = [$"-j{nproc}"];
|
||||
if(p.Start())
|
||||
p.Join();
|
||||
|
||||
|
||||
mvFile(build_dir/"crossapp", publish_dir / "crossapp");
|
||||
var info = {
|
||||
type = "archive",
|
||||
maintainer = "Mike Nolan",
|
||||
repo = "https://onedev.site.tesses.net/crosslang",
|
||||
homepage = "https://crosslang.tesseslanguage.com/",
|
||||
executable_name = "crossapp",
|
||||
executable_can_be_renamed = true,
|
||||
executable_runtime = $"linux-{dir}-static",
|
||||
description = $"Runtime files for linux-{dir}-static",
|
||||
};
|
||||
|
||||
var name = $"Tesses.CrossLang.Runtime.linux-{dir}-static";
|
||||
|
||||
var subDir = new SubdirFilesystem(FS.Local,publish_dir);
|
||||
var pkgStrm = FS.Local.OpenFile("publish"/$"{name}-{VERSION}.crvm","wb");
|
||||
FS.CreateArchive(subDir,pkgStrm, name ,VERSION, Json.Encode(info));
|
||||
pkgStrm.Close();
|
||||
}
|
||||
func BuildConsoleOrServerLinuxStaticBasedOnTarget(target,cpu)
|
||||
{
|
||||
var compiler = ("compilers"/"bin"/target).MakeAbsolute().ToString();
|
||||
var p = new Process();
|
||||
p.FileName = Env.GetRealExecutablePath("bash").ToString();
|
||||
p.Arguments = ["extract_compiler.sh",target];
|
||||
if(p.Start())
|
||||
p.Join();
|
||||
|
||||
var toolchain = $"
|
||||
set(CMAKE_C_COMPILER \"{compiler}-gcc\")
|
||||
set(CMAKE_CXX_COMPILER \"{compiler}-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_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR {cpu})
|
||||
";
|
||||
if(target == "riscv32-linux-musl" || target == "riscv64-linux-musl")
|
||||
{
|
||||
toolchain += "set(CMAKE_POSITION_INDEPENDENT_CODE ON)\n";
|
||||
}
|
||||
FS.WriteAllText(FS.Local,"compilers"/$"{target}.cmake", toolchain);
|
||||
BuildConsoleOrServerLinuxStatic(cpu,("compilers"/$"{target}.cmake").MakeAbsolute().ToString());
|
||||
}
|
||||
func BuildConsoleOrServerLinuxShared(dir,$cmake_toolchain)
|
||||
{
|
||||
Console.WriteLine($"Building Linux Shared {dir}");
|
||||
var build_dir = "builds" / $"linux-{dir}";
|
||||
var publish_dir = "publish" / $"linux-{dir}";
|
||||
FS.Local.CreateDirectory(build_dir);
|
||||
FS.Local.CreateDirectory(publish_dir);
|
||||
|
||||
var args = ["-S","ConsoleOrServer","-B",build_dir.ToString()];
|
||||
if(TypeOf(cmake_toolchain) == "String")
|
||||
{
|
||||
args.Add($"-DCMAKE_TOOLCHAIN_FILE={cmake_toolchain}");
|
||||
}
|
||||
Process.Start({
|
||||
FileName = Env.GetRealExecutablePath("cmake").ToString(),
|
||||
Arguments = args
|
||||
}).Join();
|
||||
|
||||
|
||||
var p = new Process();
|
||||
p.FileName = Env.GetRealExecutablePath("make").ToString();
|
||||
p.WorkingDirectory = build_dir.MakeAbsolute().ToString();
|
||||
p.Arguments = [$"-j{nproc}"];
|
||||
if(p.Start())
|
||||
p.Join();
|
||||
p = new Process();
|
||||
p.FileName = Env.GetRealExecutablePath("make").ToString();
|
||||
p.WorkingDirectory = build_dir.MakeAbsolute().ToString();
|
||||
p.Arguments = ["install","DESTDIR=."];
|
||||
if(p.Start())
|
||||
p.Join();
|
||||
|
||||
mvFile(build_dir/"dir"/"crossapp", publish_dir / "crossapp");
|
||||
each(var lib : FS.Local.EnumeratePaths(build_dir/"dir"))
|
||||
{
|
||||
if(lib.GetExtension() == ".so")
|
||||
{
|
||||
mvFile(lib,publish_dir / lib.GetFileName());
|
||||
}
|
||||
}
|
||||
var info = {
|
||||
type = "archive",
|
||||
maintainer = "Mike Nolan",
|
||||
repo = "https://onedev.site.tesses.net/crosslang",
|
||||
homepage = "https://crosslang.tesseslanguage.com/",
|
||||
description = $"Runtime files for linux-{dir}",
|
||||
executable_name = "crossapp",
|
||||
executable_can_be_renamed = true,
|
||||
executable_runtime = $"linux-{dir}"
|
||||
};
|
||||
|
||||
var name = $"Tesses.CrossLang.Runtime.linux-{dir}";
|
||||
|
||||
var subDir = new SubdirFilesystem(FS.Local,publish_dir);
|
||||
var pkgStrm = FS.Local.OpenFile("publish"/$"{name}-{VERSION}.crvm","wb");
|
||||
FS.CreateArchive(subDir,pkgStrm, name ,VERSION, Json.Encode(info));
|
||||
pkgStrm.Close();
|
||||
}
|
||||
func mvFile(src,dest)
|
||||
{
|
||||
Process.Start({
|
||||
FileName = Env.GetRealExecutablePath("mv").ToString(),
|
||||
Arguments = [src.MakeAbsolute().ToString(),dest.MakeAbsolute().ToString()]
|
||||
}).Join();
|
||||
}
|
||||
func main(args)
|
||||
{
|
||||
Console.WriteLine($"Got {nproc} cpus");
|
||||
each(var arch : ["x86","x64"])
|
||||
{
|
||||
var build_dir = "build" / $"win-{arch}";
|
||||
var publish_dir = "publish" / $"win-{arch}";
|
||||
FS.Local.CreateDirectory(publish_dir);
|
||||
mvFile(build_dir/"crossapp.exe", publish_dir / "crossapp.exe");
|
||||
var info = {
|
||||
type = "archive",
|
||||
maintainer = "Mike Nolan",
|
||||
repo = "https://onedev.site.tesses.net/crosslang",
|
||||
homepage = "https://crosslang.tesseslanguage.com/",
|
||||
executable_name = "crossapp.exe",
|
||||
executable_can_be_renamed = true,
|
||||
executable_runtime = $"win-{arch}",
|
||||
description = $"Runtime files for win-{arch}",
|
||||
};
|
||||
|
||||
var name = $"Tesses.CrossLang.Runtime.win-{arch}";
|
||||
|
||||
var subDir = new SubdirFilesystem(FS.Local,publish_dir);
|
||||
var pkgStrm = FS.Local.OpenFile("publish"/$"{name}-{VERSION}.crvm","wb");
|
||||
FS.CreateArchive(subDir,pkgStrm, name ,VERSION, Json.Encode(info));
|
||||
pkgStrm.Close();
|
||||
}
|
||||
|
||||
BuildConsoleOrServerLinuxShared("x86_64");
|
||||
BuildConsoleOrServerLinuxShared("aarch64", "/opt/toolchains/arm64.cmake");
|
||||
BuildConsoleOrServerLinuxShared("armv7l", "/opt/toolchains/armhf.cmake");
|
||||
BuildConsoleOrServerLinuxShared("riscv64", "/opt/toolchains/riscv64.cmake");
|
||||
|
||||
|
||||
each(var static : statics)
|
||||
{
|
||||
BuildConsoleOrServerLinuxStaticBasedOnTarget(static.target,static.cpu);
|
||||
}
|
||||
|
||||
var info = {
|
||||
type = "archive",
|
||||
maintainer = "Mike Nolan",
|
||||
repo = "https://onedev.site.tesses.net/crosslang",
|
||||
homepage = "https://crosslang.tesseslanguage.com/",
|
||||
executable_name = "boot.dol",
|
||||
executable_can_be_renamed = false,
|
||||
executable_runtime = "wii",
|
||||
description = $"Runtime files for wii",
|
||||
};
|
||||
|
||||
var name = $"Tesses.CrossLang.Runtime.wii";
|
||||
|
||||
var subDir = new SubdirFilesystem(FS.Local,"publish"/"wii");
|
||||
var pkgStrm = FS.Local.OpenFile("publish"/$"{name}-{VERSION}.crvm","wb");
|
||||
FS.CreateArchive(subDir,pkgStrm, name ,VERSION, Json.Encode(info));
|
||||
pkgStrm.Close();
|
||||
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
bash ./pack.sh
|
||||
bash ./publish.sh
|
||||
@@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
find publish -name "*.crvm" -exec crosslang upload-package --token="$CPKG_KEY" --host="https://cpkg.tesseslanguage.com/" "{}" \;
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/bin/bash
|
||||
mkdir -p publish/wii
|
||||
cd Wii
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -S .. -B . -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Wii.cmake
|
||||
make -j`nproc`
|
||||
mv boot.dol ../../publish/wii/boot.dol
|
||||
@@ -1,10 +0,0 @@
|
||||
echo "Building Windows Static x86"
|
||||
cmake -S "ConsoleOrServer" -B build/win-x86 -DCROSSAPPPUBLISH_STATIC=ON -DCMAKE_TOOLCHAIN_FILE=`pwd`/WindowsToolchains/x86.cmake
|
||||
cd build/win-x86
|
||||
make -j`nproc`
|
||||
cd ../..
|
||||
echo "Building Windows Static x64"
|
||||
cmake -S "ConsoleOrServer" -B build/win-x64 -DCROSSAPPPUBLISH_STATIC=ON -DCMAKE_TOOLCHAIN_FILE=`pwd`/WindowsToolchains/x64.cmake
|
||||
cd build/win-x64
|
||||
make -j`nproc`
|
||||
cd ../..
|
||||
@@ -1,6 +1,6 @@
|
||||
# Maintainer: Mike Nolan <tesses@tesses.net>
|
||||
pkgname=crosslang # '-bzr', '-git', '-hg' or '-svn'
|
||||
pkgver=1.0.0
|
||||
pkgver=0.0.1
|
||||
pkgrel=1
|
||||
pkgdesc=""
|
||||
arch=('x86_64' 'powerpc')
|
||||
@@ -21,18 +21,7 @@ fi
|
||||
# Please refer to the 'USING VCS SOURCES' section of the PKGBUILD man page for
|
||||
# a description of each element in the source array.
|
||||
|
||||
pkgver() {
|
||||
cd "$srcdir/${pkgname}"
|
||||
|
||||
# The examples below are not absolute and need to be adapted to each repo. The
|
||||
# primary goal is to generate version numbers that will increase according to
|
||||
# pacman's version comparisons with later commits to the repo. The format
|
||||
# VERSION='VER_NUM.rREV_NUM.HASH', or a relevant subset in case VER_NUM or HASH
|
||||
# are not available, is recommended.
|
||||
|
||||
# Git, no tags available
|
||||
printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
|
||||
}
|
||||
|
||||
prepare() {
|
||||
cd "$srcdir/${pkgname}"
|
||||
|
||||
@@ -3,10 +3,10 @@ mkdir build-x86_64-tar
|
||||
cd build-x86_64-tar
|
||||
cmake -S ../../.. -B . -DTESSESFRAMEWORK_ENABLE_SHARED=ON -DTESSESFRAMEWORK_ENABLE_STATIC=OFF -DTESSESFRAMEWORK_FETCHCONTENT=ON
|
||||
make -j`nproc`
|
||||
make install DESTDIR=./crosslang
|
||||
mkdir -p crosslang/share/Tesses/CrossLang
|
||||
cp ../build/jammy/Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm crosslang/share/Tesses/CrossLang/Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm
|
||||
tar cvzf ../../../artifacts/crosslang-linux-x86_64.tar.gz crosslang
|
||||
make install DESTDIR=./crosslang-x86_64
|
||||
mkdir -p crosslang-x86_64/share/Tesses/CrossLang
|
||||
cp ../build/jammy/Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm crosslang-x86_64/share/Tesses/CrossLang/Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm
|
||||
tar cvzf ../../../artifacts/crosslang-linux-x86_64.tar.gz crosslang-x86_64
|
||||
cd ..
|
||||
|
||||
foreign() {
|
||||
@@ -14,10 +14,10 @@ mkdir build-$1\-tar
|
||||
cd build-$1\-tar
|
||||
cmake -S ../../.. -B . -DTESSESFRAMEWORK_ENABLE_SHARED=ON -DTESSESFRAMEWORK_ENABLE_STATIC=OFF -DTESSESFRAMEWORK_FETCHCONTENT=ON -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/$1\.cmake
|
||||
make -j`nproc`
|
||||
make install DESTDIR=./crosslang
|
||||
mkdir -p crosslang/share/Tesses/CrossLang
|
||||
cp ../build/jammy/Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm crosslang/share/Tesses/CrossLang/Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm
|
||||
tar cvzf ../../../artifacts/crosslang-linux-$1\.tar.gz crosslang
|
||||
make install DESTDIR=./crosslang-$1
|
||||
mkdir -p crosslang-$1\/share/Tesses/CrossLang
|
||||
cp ../build/jammy/Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm crosslang-$1\/share/Tesses/CrossLang/Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm
|
||||
tar cvzf ../../../artifacts/crosslang-linux-$1\.tar.gz crosslang-$1
|
||||
cd ..
|
||||
}
|
||||
foreign arm64
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export BUILD=$(($BUILD_NO-142))
|
||||
export DEB_VERSION=1.0.0-$BUILD
|
||||
|
||||
export DEB_VERSION=0.0.1
|
||||
@@ -1 +0,0 @@
|
||||
# C++ Layer
|
||||
@@ -1,232 +0,0 @@
|
||||
Extending the runtime
|
||||
=====================
|
||||
|
||||
See [this](CPP_LAYER.md)
|
||||
|
||||
There are a couple ways of doing this
|
||||
|
||||
- Creating a shared library (only works if using shared libs)
|
||||
- Embeding the runtime
|
||||
- Forking crosslang and adding functionality (I don't support pull requests at this time)
|
||||
|
||||
### Shared Library
|
||||
|
||||
This assumes you are on linux, if on windows use MyPlugin.dll on mac libMyPlugin.dylib in crosslang project (it would be a good idea to check Env.Platform)
|
||||
|
||||
CMakeLists.txt:
|
||||
```cmake
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(MyPlugin)
|
||||
|
||||
find_package(TessesCrossLang REQUIRED)
|
||||
|
||||
add_library(MyPlugin SHARED lib.cpp)
|
||||
|
||||
target_link_libraries(MyPlugin PUBLIC TessesCrossLang::crosslang_shared)
|
||||
```
|
||||
|
||||
lib.cpp:
|
||||
```c++
|
||||
#include <CrossLang.hpp>
|
||||
|
||||
using namespace Tesses::CrossLang;
|
||||
|
||||
void MyPlugin(GC* gc, TRootEnvironment* env)
|
||||
{
|
||||
GCList ls(gc);
|
||||
TDictionary* dict = TDictionary::Create(ls,{
|
||||
TDItem("MyFunction", TExternalMethod::Create(ls, "A description for function",{"myLong","$optionalList"},[](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
int64_t n;
|
||||
if(GetArgument(args,0,n))
|
||||
{
|
||||
TList* myLs;
|
||||
if(GetArgumentHeap(args,1,myLs))
|
||||
{
|
||||
//do something with the list
|
||||
myLs->Add(n);
|
||||
return TList::Create(ls, {n,myLs});
|
||||
}
|
||||
|
||||
|
||||
return TList::Create(ls, {n});
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}))
|
||||
});
|
||||
|
||||
gc->BarrierBegin();
|
||||
env->SetVariable("MyPlugin",dict);
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
|
||||
CROSSLANG_PLUGIN(MyPlugin);
|
||||
|
||||
```
|
||||
|
||||
main.tcross:
|
||||
```go
|
||||
func main(args)
|
||||
{
|
||||
Reflection.LoadNativePlugin(FS.MakeFull("libMyPlugin.so"));
|
||||
|
||||
var res = MyPlugin.MyFunction(42);
|
||||
if(TypeOf(res) == "List")
|
||||
{
|
||||
Console.WriteLine(res);
|
||||
}
|
||||
|
||||
var res = MyPlugin.MyFunction(42,["Hello","John"]);
|
||||
if(TypeOf(res) == "List")
|
||||
{
|
||||
Console.WriteLine(res);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Embeding the runtime
|
||||
|
||||
CMakeLists.txt:
|
||||
```cmake
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(MyCrossLangBinary)
|
||||
|
||||
find_package(TessesCrossLang REQUIRED)
|
||||
|
||||
add_executable(MyCrossLangBinary SHARED app.cpp)
|
||||
|
||||
target_link_libraries(MyCrossLangBinary PUBLIC TessesCrossLang::crosslang_shared) # or crosslang_static for static linking
|
||||
|
||||
|
||||
```
|
||||
|
||||
app.cpp:
|
||||
```c++
|
||||
#include <CrossLang.hpp>
|
||||
|
||||
using namespace Tesses::CrossLang;
|
||||
using namespace Tesses::Framework;
|
||||
|
||||
void MyPlugin(GC* gc, TRootEnvironment* env)
|
||||
{
|
||||
GCList ls(gc);
|
||||
TDictionary* dict = TDictionary::Create(ls,{
|
||||
TDItem("MyFunction", TExternalMethod::Create(ls, "A description for function",{"myLong","$optionalList"},[](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
int64_t n;
|
||||
if(GetArgument(args,0,n))
|
||||
{
|
||||
TList* myLs;
|
||||
if(GetArgumentHeap(args,1,myLs))
|
||||
{
|
||||
//do something with the list
|
||||
myLs->Add(n);
|
||||
return TList::Create(ls, {n,myLs});
|
||||
}
|
||||
|
||||
|
||||
return TList::Create(ls, {n});
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}))
|
||||
});
|
||||
|
||||
gc->BarrierBegin();
|
||||
env->SetVariable("MyPlugin",dict);
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_Init();
|
||||
if(argc < 2)
|
||||
{
|
||||
printf("USAGE: %s <filename.crvm> <args...>\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
GC gc;
|
||||
gc.RegisterEverythingCallback(MyPlugin);
|
||||
gc.Start();
|
||||
GCList ls(gc);
|
||||
TRootEnvironment* env = TRootEnvironment::Create(ls,TDictionary::Create(ls));
|
||||
Tesses::Framework::Filesystem::LocalFilesystem fs;
|
||||
TStd::RegisterStd(&gc,env);
|
||||
env->LoadFileWithDependencies(&gc, &fs, fs.SystemToVFSPath(argv[1]));
|
||||
|
||||
TList* args = TList::Create(ls);
|
||||
for(int arg=1;arg<argc;arg++)
|
||||
args->Add(std::string(argv[arg]));
|
||||
|
||||
auto res = env->CallFunction(ls,"main",{args});
|
||||
int64_t iresult;
|
||||
if(GetObject(res,iresult))
|
||||
return (int)iresult;
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
main.tcross (needs to be compiled with crossc):
|
||||
```go
|
||||
func main(args)
|
||||
{
|
||||
//no reflection necessary
|
||||
|
||||
var res = MyPlugin.MyFunction(42);
|
||||
if(TypeOf(res) == "List")
|
||||
{
|
||||
Console.WriteLine(res);
|
||||
}
|
||||
|
||||
var res = MyPlugin.MyFunction(42,["Hello","John"]);
|
||||
if(TypeOf(res) == "List")
|
||||
{
|
||||
Console.WriteLine(res);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Forking (implementing it in runtime library itself)
|
||||
- edit include/CrossLang.hpp
|
||||
- in TStd class insert, static void RegisterMyPlugin(GC* gc, TRootEnvironment* env); where MyPlugin is whatever you want
|
||||
- edit src/runtime_methods/std.cpp
|
||||
- in TStd::RegisterStd before register everything call TStd::RegisterMyPlugin(gc, env);
|
||||
- in CMakeLists.txt within list(APPEND CROSSLANG_SOURCE **Many Source Files**) you must add src/runtime_methods/myplugin.cpp
|
||||
|
||||
src/runtime_methods/myplugin.cpp:
|
||||
```c++
|
||||
#include <CrossLang.hpp>
|
||||
namespace Tesses::CrossLang
|
||||
{
|
||||
void TStd::RegisterMyPlugin(GC* gc, TRootEnvironment* env)
|
||||
{
|
||||
GCList ls(gc);
|
||||
TDictionary* dict = TDictionary::Create(ls,{
|
||||
TDItem("MyFunction", TExternalMethod::Create(ls, "A description for function",{"myLong","$optionalList"},[](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
int64_t n;
|
||||
if(GetArgument(args,0,n))
|
||||
{
|
||||
TList* myLs;
|
||||
if(GetArgumentHeap(args,1,myLs))
|
||||
{
|
||||
//do something with the list
|
||||
myLs->Add(n);
|
||||
return TList::Create(ls, {n,myLs});
|
||||
}
|
||||
|
||||
|
||||
return TList::Create(ls, {n});
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}))
|
||||
});
|
||||
|
||||
gc->BarrierBegin();
|
||||
env->SetVariable("MyPlugin",dict);
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
}
|
||||
```
|
||||
598
docs/HANDBOOK.md
598
docs/HANDBOOK.md
@@ -1,598 +0,0 @@
|
||||
## CrossLang Handbook
|
||||
|
||||
This is a book for my language found [here](https://crosslang.tesseslanguage.com/)
|
||||
|
||||
## Statements and loops
|
||||
|
||||
|
||||
|
||||
#### Declare a variable (it is an expression)
|
||||
|
||||
You can (the var is optional but should be used if the root environment has the same variable and you don't want to set it)
|
||||
|
||||
```js
|
||||
var myVariable = 42;
|
||||
```
|
||||
|
||||
#### Set a variable (it is an expression)
|
||||
|
||||
```js
|
||||
myVariable = "I have set the variable to a string";
|
||||
```
|
||||
|
||||
#### Reflective variables
|
||||
|
||||
```js
|
||||
var nameOfVariable = "Var 1";
|
||||
.[nameOfVariable] = 42; //the variable name in this instance will be Var 1
|
||||
Console.WriteLine(.[nameOfVariable]); //prints 42
|
||||
|
||||
|
||||
var nameOfVariable2 = "Var 2";
|
||||
var nameOfField = "This field has spaces and \n New Lines";
|
||||
.[nameOfVariable2] = {
|
||||
.[nameOfField] = "Hello, world"
|
||||
};
|
||||
|
||||
Console.WriteLine(.[nameOfVariable2].[nameOfField]); //should print Hello, world
|
||||
|
||||
```
|
||||
|
||||
|
||||
#### If statements
|
||||
|
||||
The {} are optional if you only need one statement
|
||||
|
||||
```js
|
||||
var myExpression = 0;
|
||||
var myOtherExpression = {
|
||||
mol = 42
|
||||
};
|
||||
|
||||
if(myExpression)
|
||||
{
|
||||
Console.WriteLine("myExpression is truthy");
|
||||
}
|
||||
else if(myOtherExpression)
|
||||
{
|
||||
//this will run based on the condition
|
||||
Console.WriteLine("myExpression is falsey but myOtherExpression is truthy");
|
||||
}
|
||||
else {
|
||||
Console.WriteLine("both myExpression and myOtherExpression are falsey");
|
||||
}
|
||||
```
|
||||
|
||||
#### For loop
|
||||
|
||||
Note: i will leak, also you can use curly brackets like if
|
||||
|
||||
```js
|
||||
for(var i = 0; i < 42; i++)
|
||||
Console.WriteLine(i);
|
||||
```
|
||||
|
||||
#### Each loop
|
||||
|
||||
```js
|
||||
enumerable MyItterator()
|
||||
{
|
||||
yield 42;
|
||||
yield 100;
|
||||
yield 88;
|
||||
}
|
||||
each(var item : MyItterator())
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
}
|
||||
|
||||
|
||||
each(var item : [3,7,12])
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
This should output
|
||||
42
|
||||
100
|
||||
88
|
||||
3
|
||||
7
|
||||
12
|
||||
*/
|
||||
```
|
||||
|
||||
#### While loop
|
||||
|
||||
```js
|
||||
while(conditionLikeIf)
|
||||
{
|
||||
Console.WriteLine("Hi");
|
||||
}
|
||||
|
||||
//If conditionLikeIf is falsey we never print Hi
|
||||
//If conditionLikeIf is truthy we print Hi until it is falsey
|
||||
```
|
||||
|
||||
#### Do loop
|
||||
|
||||
```js
|
||||
do(conditionLikeIf)
|
||||
{
|
||||
Console.WriteLine("Hi");
|
||||
}
|
||||
|
||||
//If conditionLikeIf is falsey we print Hi once
|
||||
//If conditionLikeIf is truthy we print Hi until it is falsey
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Try statement
|
||||
|
||||
NOTE: you can't return undefined (but you can return other types) (It will just return from try and will still execute the body past the try statement) due to the try statement being a closure (you can still break and continue due to special TObjects being returned)
|
||||
|
||||
```js
|
||||
try {
|
||||
Console.WriteLine("God is good.");
|
||||
throw "my error";
|
||||
Console.WriteLine("I am lonely, I am never called.");
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
Console.WriteLine($"I got an error {ex}.");
|
||||
}
|
||||
finally {
|
||||
Console.WriteLine("For God so loved the world that he gave his only begotten Son, that whoever believes in him should not perish but have eternal life.");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
This should print
|
||||
God is good.
|
||||
I got an error my error.
|
||||
For God so loved the world that he gave his only begotten Son, that whoever believes in him should not perish but have eternal life.
|
||||
*/
|
||||
```
|
||||
|
||||
#### Switch statement
|
||||
|
||||
NOTE: you can use dictionaries with overloaded equals operator (we will pass the switch's expression as the argument)
|
||||
|
||||
```js
|
||||
o = {
|
||||
operator== = (this,v) => {
|
||||
//this is implicitly passed by runtime, but you must declare it if you want it
|
||||
return (v * 7) == 42;
|
||||
}
|
||||
};
|
||||
|
||||
var val = 6;
|
||||
|
||||
switch(val)
|
||||
{
|
||||
case 4:
|
||||
Console.WriteLine("I am four");
|
||||
break;
|
||||
case 5:
|
||||
Console.WriteLine("I am five");
|
||||
break;
|
||||
case o:
|
||||
Console.WriteLine("Hitchhiker's guide to the galaxy meaning of life");
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("We don't support it we are sorry");
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Function declaration
|
||||
|
||||
```go
|
||||
//you can create functions on dictionaries so long as they are on root environment (they are declared there before root scope is evaluated so this is possible)
|
||||
My.Func.Joel = 59; //Because My.Func.Is.A.Few.Deep creates the dictionaries via runtime
|
||||
|
||||
func My.Func.Is.A.Few.Deep(a, b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
func main(args)
|
||||
{
|
||||
Console.WriteLine(My.Func.Is.A.Few.Deep(6,7));
|
||||
}
|
||||
```
|
||||
|
||||
#### Function inside a function
|
||||
|
||||
Oh yeah functions can have exclusively a expression as a body which does not need a return keyword
|
||||
|
||||
```go
|
||||
func main(args)
|
||||
{
|
||||
func MyOther(a,b) a * b;
|
||||
Console.WriteLine(MyOther(a,b));
|
||||
}
|
||||
```
|
||||
|
||||
#### Document a function
|
||||
|
||||
```go
|
||||
/^
|
||||
This function returns 42
|
||||
^/
|
||||
func MyFunction() 42;
|
||||
```
|
||||
|
||||
#### Return statement
|
||||
|
||||
You can also return nothing
|
||||
|
||||
```js
|
||||
return 42;
|
||||
return;
|
||||
```
|
||||
|
||||
#### Yield statement
|
||||
|
||||
This will halt the function's execution and return the running function object (were you can pop the item and resume it)
|
||||
|
||||
To automaticly make a function enumerable (with each statement) you must use ``enumerable`` instead of func when declaring your function
|
||||
|
||||
```js
|
||||
yield 42;
|
||||
```
|
||||
|
||||
#### Throw statement
|
||||
|
||||
You can catch this with ``try statement`` with ``catch`` clause
|
||||
|
||||
```js
|
||||
throw "You can replace me with another string or any other object";
|
||||
```
|
||||
|
||||
#### Defer statement
|
||||
|
||||
Your code will be called when your scope is destroyed
|
||||
|
||||
```go
|
||||
{
|
||||
defer {
|
||||
Console.WriteLine("In defer");
|
||||
}
|
||||
Console.WriteLine("About to leave scope");
|
||||
}
|
||||
Console.WriteLine("Left scope");
|
||||
|
||||
|
||||
/*
|
||||
The output should be
|
||||
|
||||
About to leave scope
|
||||
In defer
|
||||
Left scope
|
||||
*/
|
||||
```
|
||||
|
||||
## Expressions
|
||||
|
||||
We will place it as a parameter to a function ``doThing`` but these will work anywhere like setting a variable or another expression
|
||||
|
||||
#### Undefined
|
||||
|
||||
```js
|
||||
doThing(undefined);
|
||||
```
|
||||
|
||||
#### Null
|
||||
|
||||
```js
|
||||
doThing(null);
|
||||
```
|
||||
|
||||
#### Boolean
|
||||
|
||||
```js
|
||||
doThing(false);
|
||||
doThing(true);
|
||||
```
|
||||
|
||||
#### Long
|
||||
|
||||
A signed 64 bit number
|
||||
|
||||
```js
|
||||
doThing(94);
|
||||
doThing(599929022);
|
||||
```
|
||||
|
||||
#### Double
|
||||
|
||||
A 64 bit floating pointer number
|
||||
|
||||
```js
|
||||
doThing(5.25);
|
||||
doThing(942.90204);
|
||||
```
|
||||
|
||||
#### Char
|
||||
|
||||
Yes we support single character strings (this escapes a double quote)
|
||||
|
||||
```csharp
|
||||
doThing('\"');
|
||||
```
|
||||
|
||||
#### String
|
||||
|
||||
Second is an interopolated string
|
||||
|
||||
```csharp
|
||||
doThing("Hi");
|
||||
doThing($"My name is {name}");
|
||||
```
|
||||
|
||||
#### List
|
||||
|
||||
```js
|
||||
doThing(
|
||||
[4,5,9,42,true,"Hi",'\n']
|
||||
);
|
||||
```
|
||||
|
||||
#### Dictionary
|
||||
|
||||
```js
|
||||
doThing(
|
||||
{
|
||||
a = "This is an option",
|
||||
b = 42,
|
||||
c = 9
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
###### Enumerating a dictionary
|
||||
|
||||
```js
|
||||
var dict = { a = 5, b = 42};
|
||||
each(var item : Dictionary.Items(dict))
|
||||
{
|
||||
Console.WriteLine($"Key: {item.Key}");
|
||||
Console.WriteLine($"Value: {item.Value}");
|
||||
Console.WriteLine();
|
||||
}
|
||||
/*
|
||||
This prints
|
||||
Key: a
|
||||
Value: 5
|
||||
|
||||
Key: b
|
||||
Value: 42
|
||||
|
||||
*/
|
||||
```
|
||||
|
||||
|
||||
|
||||
###### Getting a value from dictionary
|
||||
|
||||
```go
|
||||
func doThing(data)
|
||||
{
|
||||
Console.WriteLine(data.b); //will print 42
|
||||
}
|
||||
```
|
||||
|
||||
###### Setting a value to dictionary
|
||||
|
||||
```go
|
||||
func doThing(data)
|
||||
{
|
||||
data.a = true; //replace a with a different value
|
||||
data.someFieldThatDoesNotExist = 9; //define a new field entirely
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
###### Methods
|
||||
|
||||
Note that this is optional but if you do have it it must be the first argument, the this argument points to the dictionary
|
||||
|
||||
```go
|
||||
var item = {
|
||||
myMethod = (this, a, b) => {
|
||||
return a * b;
|
||||
}
|
||||
};
|
||||
|
||||
Console.WriteLine(item.myMethod(6,7)); //prints 42
|
||||
```
|
||||
|
||||
Or
|
||||
|
||||
```go
|
||||
var item = {};
|
||||
func item.myMethod(this, a, b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
Console.WriteLine(item.myMethod(6,7)); //prints 42
|
||||
```
|
||||
|
||||
###### Properties
|
||||
|
||||
They are declared like every other method except they are prefixed with ``get`` or ``set``
|
||||
|
||||
```go
|
||||
var item = {
|
||||
getProp = (this)=>{
|
||||
return 42;
|
||||
},
|
||||
setProp = (this,v)=>{
|
||||
//do something with v
|
||||
}
|
||||
};
|
||||
|
||||
Console.WriteLine(item.Prop); //equivalent to Console.WriteLine(item.getProp());
|
||||
|
||||
item.Prop = 100; //equivalent to item.setProp(100); will do nothing in this example
|
||||
|
||||
```
|
||||
|
||||
###### Operator overloading
|
||||
|
||||
```js
|
||||
var item = {
|
||||
operator+ = (this,right) => {
|
||||
return 4 + a;
|
||||
}
|
||||
operator- = (this,right) => {
|
||||
return 4 - right; //be careful right may be undefined if the negate operator is used
|
||||
}
|
||||
};
|
||||
|
||||
Console.WriteLine(item + 5); //prints 9
|
||||
```
|
||||
|
||||
###### Array operator overloading
|
||||
|
||||
```js
|
||||
var item = {
|
||||
GetAt = (index)=>{
|
||||
return index * 2; //we multiply index by two and return
|
||||
},
|
||||
SetAt => (index,value)=>{
|
||||
Console.WriteLine($"The index was {index} and value was {value}");
|
||||
}
|
||||
};
|
||||
|
||||
Console.WriteLine(item[21]); //prints 42
|
||||
item["Hi"] = "John"; //prints The index was Hi and value was John
|
||||
```
|
||||
|
||||
#### ByteArray
|
||||
|
||||
```js
|
||||
var bA = new ByteArray(1);
|
||||
ba[0] = 42;
|
||||
Console.WriteLine(ba.ToString()); //prints *
|
||||
```
|
||||
|
||||
###### ByteArray from string
|
||||
|
||||
```js
|
||||
var bA = new ByteArray("Hi");
|
||||
//we can get bytes like this bA[0] which will be 72
|
||||
//we can get length by bA.Count or bA.Length
|
||||
```
|
||||
|
||||
#### Embedding files (you can't do this easily in C/C++ and C# not as easy as this)
|
||||
|
||||
```js
|
||||
var bA = embed("myFile.png"); //will embed the file res/myFile.png
|
||||
//it is stored as a RESO in the crvm file and bA is a ByteArray
|
||||
//note the argument MUST be a constant string
|
||||
//note you can access a subdirectory of res as well just use dir/file.bin
|
||||
```
|
||||
|
||||
#### Streams
|
||||
|
||||
|
||||
|
||||
###### From an existing file
|
||||
|
||||
```js
|
||||
var strm = FS.Local.OpenFile("file.bin","rb");
|
||||
|
||||
var data = new ByteArray(1024);
|
||||
var read = strm.Read(data,0,data.Count);
|
||||
//use ReadBlock to ensure you have 1024 bytes if not near end of stream
|
||||
|
||||
//use WriteBlock to ensure you write the amount you say you need
|
||||
|
||||
strm.Close();
|
||||
```
|
||||
|
||||
#### VFS
|
||||
|
||||
```js
|
||||
var myVFS = FS.Local; //FS.Local is the local filesystem
|
||||
|
||||
|
||||
myVFS.CreateDirectory("myDir"); //creates directory in current dir (only local)
|
||||
|
||||
myVFS.DeleteDirectory("myDir"); //now we delete it
|
||||
|
||||
|
||||
myVFS.CreateDirectory(Path.FromString(Env.Downloads) / "Folder in Downloads"); //Create a folder in downloads
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Path
|
||||
|
||||
```js
|
||||
var path = / "Path" / "To" / "Directory";
|
||||
var relativePath = ./"another"/"path";
|
||||
var combined = path / relativePath;
|
||||
var someString = "joel";
|
||||
var combinedAndStr = combined / someString;
|
||||
var combinedWithExtension = combined + ".mp4";
|
||||
Console.WriteLine(combined); // outputs /Path/To/Directory/another/path
|
||||
Console.WriteLine(combined); // outputs /Path/To/Directory/another/path/joel
|
||||
Console.WriteLine(combinedWithExtension); //outputs /Path/To/Directory/another/path.mp4
|
||||
//these paths are used with vfs
|
||||
|
||||
|
||||
//to get parent directory use combined.GetParent();
|
||||
//to get filename use combined.GetFileName();
|
||||
//to get extension use combinedWithExtension.GetExtension();, it will be the extension including .
|
||||
//to change the extension use combinedWithExtension.ChangeExtension(".mkv");
|
||||
//to remove the extension use combinedWithExtension.ChangeExtension(null); or combinedWithExtension.ChangeExtension();
|
||||
```
|
||||
|
||||
#### Html Litterals
|
||||
```go
|
||||
//comments are just crosslang ones
|
||||
|
||||
//we will be setting to myHtml for the html (returns a string) (it is already html escaped)
|
||||
myHtml = <h1>{someStringExpression}</h1>;
|
||||
|
||||
//a link, in this example we have a dictionary named node with string fields href and text
|
||||
//lets say node.text equaled List<int> and href contained ./mypage?name=Joel&file=steve.bin myHtml would be equal to "<a target=\"_blank\" href=\"./mypage?name=Joel&file=steve.bin\">List<int></a>" (the \ are just there to make this a valid string for demonstration purposes, there aren't really backslashes)
|
||||
myHtml = <a target="_blank" href={node.href}>{node.text}</a>;
|
||||
|
||||
|
||||
//for (works like for loop but is in html form, the for part is not rendered in the final string)
|
||||
myHtml = <for(var i = 0; i < 42; i++)>
|
||||
<h6>{i}</h6>
|
||||
</for>;
|
||||
|
||||
//each
|
||||
myHtml = <each(var item : list)></each>;
|
||||
|
||||
//do
|
||||
myHtml = <do(expr == 42)></do>;
|
||||
|
||||
//while
|
||||
myHtml = <while(expr == 42)></while>;
|
||||
|
||||
//if
|
||||
|
||||
myHtml = <if(expr == 42)>
|
||||
<true>
|
||||
//if expr is 42
|
||||
</true>
|
||||
<false>
|
||||
//if expr is not 42
|
||||
//you would use another if here instead of else if
|
||||
</false>
|
||||
</if>;
|
||||
|
||||
myHtml = <null>Hello</null>; //would just be Hello (useful for templating as it works just like div but the null part is not emited into string)
|
||||
|
||||
myHtml = <raw(stringExpr)>; //allowing you to emit unescaped html from string into html litteral (useful for templating)
|
||||
```
|
||||
@@ -1,7 +0,0 @@
|
||||
# Tesses CrossLang
|
||||
|
||||
This is the docs for my language
|
||||
|
||||
- [Handbook](HANDBOOK.md)
|
||||
- [C++ Layer](CPP_LAYER.md)
|
||||
- [Extend the runtime](EXTENDING_RUNTIME.md)
|
||||
@@ -1,16 +0,0 @@
|
||||
What is TObject
|
||||
===============
|
||||
|
||||
It is a std::variant that can be (not in that order)
|
||||
|
||||
- Undefined (Tesses::CrossLang::Undefined)
|
||||
- Null (std::nullptr_t)
|
||||
- Long (int64_t)
|
||||
- Double (double)
|
||||
- Char (char)
|
||||
- String (std::string)
|
||||
- Version (Tesses::CrossLang::TVMVersion)
|
||||
- Regex (std::regex)
|
||||
- Path (Tesses::Framework::Filesystem::VFSPath)
|
||||
- MethodInvoker (Tesses::CrossLang::MethodInvoker)
|
||||
- HeapObjects (Tesses::CrossLang::THeapObjectHolder)
|
||||
@@ -19,31 +19,13 @@
|
||||
#include <time.h>
|
||||
#include <any>
|
||||
|
||||
/**
|
||||
* @brief CrossLang Runtime Major version
|
||||
*
|
||||
*/
|
||||
#define TVM_MAJOR 1
|
||||
/**
|
||||
* @brief CrossLang Runtime Minor version
|
||||
*
|
||||
*/
|
||||
#define TVM_MINOR 0
|
||||
/**
|
||||
* @brief CrossLang Runtime Patch version
|
||||
*
|
||||
*/
|
||||
#define TVM_PATCH 0
|
||||
/**
|
||||
* @brief CrossLang Runtime Build version
|
||||
*
|
||||
*/
|
||||
#define TVM_BUILD 0
|
||||
/**
|
||||
* @brief CrossLang Runtime Stage version
|
||||
*
|
||||
*/
|
||||
#define TVM_VERSIONSTAGE DevVersion
|
||||
#include "CrossLangVersion.h"
|
||||
|
||||
#define CROSSLANG_BYTECODE_MAJOR 1
|
||||
#define CROSSLANG_BYTECODE_MINOR 0
|
||||
#define CROSSLANG_BYTECODE_PATCH 0
|
||||
#define CROSSLANG_BYTECODE_BUILD 0 //SHOULD ALWAYS BE 0
|
||||
#define CROSSLANG_BYTECODE_VERSIONSTAGE DevVersion
|
||||
|
||||
#if defined(_WIN32)
|
||||
#undef Yield
|
||||
@@ -341,13 +323,13 @@ namespace Tesses::CrossLang {
|
||||
return v;
|
||||
}
|
||||
/**
|
||||
* @brief Compares this to the runtime version
|
||||
* @brief Compares this to the runtime version (for Bytecode)
|
||||
*
|
||||
* @return int CompareTo(RuntimeVersion) where RuntimeVersion is the runtime version
|
||||
*/
|
||||
int CompareToRuntime()
|
||||
{
|
||||
TVMVersion version(TVM_MAJOR,TVM_MINOR,TVM_PATCH,TVM_BUILD,TVM_VERSIONSTAGE);
|
||||
TVMVersion version(CROSSLANG_BYTECODE_MAJOR,CROSSLANG_BYTECODE_MINOR,CROSSLANG_BYTECODE_PATCH,CROSSLANG_BYTECODE_BUILD,CROSSLANG_BYTECODE_VERSIONSTAGE);
|
||||
return CompareTo(version);
|
||||
}
|
||||
/**
|
||||
@@ -871,8 +853,10 @@ class CodeGen {
|
||||
std::vector<std::pair<std::vector<uint32_t>, std::vector<ByteCodeInstruction*>>> chunks;
|
||||
std::vector<std::pair<std::vector<uint32_t>,uint32_t>> funcs;
|
||||
std::vector<CodeGenClass> classes;
|
||||
|
||||
|
||||
std::vector<std::vector<uint8_t>> meta;
|
||||
SyntaxNode OptimizeNode(SyntaxNode n);
|
||||
void WriteMetadataObject(std::vector<uint8_t>& bytes, SyntaxNode n);
|
||||
void GenNode(std::vector<ByteCodeInstruction*>& instructions, SyntaxNode n,int32_t scope, int32_t contscope, int32_t brkscope, int32_t contI, int32_t brkI);
|
||||
void GenPop(std::vector<ByteCodeInstruction*>& instrs,SyntaxNode n);
|
||||
public:
|
||||
@@ -1264,6 +1248,11 @@ constexpr std::string_view NullCoalescingExpression = "nullCoalescingExpression"
|
||||
* @brief For debugging (store line info and filename)
|
||||
*/
|
||||
constexpr std::string_view LineNode="lineNode";
|
||||
/**
|
||||
* @brief For storing generic metadata
|
||||
*/
|
||||
constexpr std::string_view MetadataStatement = "MetadataStatement";
|
||||
|
||||
/**
|
||||
* @brief Advanced AST node
|
||||
*
|
||||
@@ -1532,7 +1521,7 @@ class GC {
|
||||
TObject value;
|
||||
|
||||
};
|
||||
|
||||
class TDictionary;
|
||||
class TFile : public THeapObject
|
||||
{
|
||||
public:
|
||||
@@ -1547,6 +1536,7 @@ class GC {
|
||||
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::pair<std::string,std::vector<uint8_t>>> metadata;
|
||||
std::vector<std::vector<uint8_t>> resources;
|
||||
std::vector<TClass> classes;
|
||||
std::string name;
|
||||
@@ -1564,6 +1554,8 @@ class GC {
|
||||
void Mark();
|
||||
|
||||
void EnsureCanRunInCrossLang();
|
||||
|
||||
TDictionary* MetadataDecode(GCList& ls, size_t index);
|
||||
};
|
||||
class TAssociativeArray : public THeapObject
|
||||
{
|
||||
@@ -1687,6 +1679,8 @@ class GC {
|
||||
virtual TObject Call(GCList& ls,std::vector<TObject> args)=0;
|
||||
TObject CallWithFatalError(GCList& ls, std::vector<TObject> args);
|
||||
virtual void Mark();
|
||||
|
||||
Tesses::Framework::Http::ServerRequestHandler ToRouteServerRequestHandler(GC* gc);
|
||||
};
|
||||
|
||||
void ThrowFatalError(std::exception& ex);
|
||||
@@ -2045,6 +2039,9 @@ class GC {
|
||||
void CreateHardlink(Tesses::Framework::Filesystem::VFSPath existingFile, Tesses::Framework::Filesystem::VFSPath newName);
|
||||
bool DirectoryExists(Tesses::Framework::Filesystem::VFSPath path);
|
||||
void DeleteFile(Tesses::Framework::Filesystem::VFSPath path);
|
||||
void Lock(Tesses::Framework::Filesystem::VFSPath path);
|
||||
void Unlock(Tesses::Framework::Filesystem::VFSPath path);
|
||||
|
||||
void DeleteDirectoryRecurse(Tesses::Framework::Filesystem::VFSPath path);
|
||||
Tesses::Framework::Filesystem::VFSPathEnumerator EnumeratePaths(Tesses::Framework::Filesystem::VFSPath path);
|
||||
void MoveFile(Tesses::Framework::Filesystem::VFSPath src, Tesses::Framework::Filesystem::VFSPath dest);
|
||||
@@ -2370,6 +2367,16 @@ class GC {
|
||||
virtual bool Equals(GC* gc, TObject right);
|
||||
virtual ~TNativeObject();
|
||||
};
|
||||
class TRandom : public TNativeObject
|
||||
{
|
||||
public:
|
||||
Tesses::Framework::Random random;
|
||||
TRandom();
|
||||
TRandom(uint64_t seed);
|
||||
std::string TypeName();
|
||||
TObject CallMethod(GCList& ls,std::string name, std::vector<TObject> args);
|
||||
|
||||
};
|
||||
class TNative : public THeapObject
|
||||
{
|
||||
std::atomic<bool> destroyed;
|
||||
@@ -2387,7 +2394,7 @@ class GC {
|
||||
~TNative();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class ThreadHandle : public THeapObject {
|
||||
public:
|
||||
@@ -2540,6 +2547,8 @@ class GC {
|
||||
void LoadPlugin(GC* gc, TRootEnvironment* env, Tesses::Framework::Filesystem::VFSPath sharedObjectPath);
|
||||
std::string Json_Encode(TObject o,bool indent=false);
|
||||
TObject Json_Decode(GCList ls,std::string str);
|
||||
std::string Json_DocEncode(TObject o,bool indent);
|
||||
TObject Json_DocDecode(GCList ls,std::string str);
|
||||
//DO NOT USE DIRECTLY
|
||||
class SharedPtrTObject {
|
||||
GCList* ls;
|
||||
@@ -2602,4 +2611,6 @@ class GC {
|
||||
std::string VFSPathToSystem(Tesses::Framework::Filesystem::VFSPath path);
|
||||
Tesses::Framework::Filesystem::VFSPath SystemToVFSPath(std::string path);
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Tesses::CrossLang
|
||||
|
||||
uint8_t main_header[18];
|
||||
memcpy(main_header,"TCROSSVM",8);
|
||||
TVMVersion rtVersion(TVM_MAJOR,TVM_MINOR,TVM_PATCH,TVM_BUILD,TVM_VERSIONSTAGE);
|
||||
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));
|
||||
@@ -151,6 +151,12 @@ namespace Tesses::CrossLang
|
||||
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);
|
||||
|
||||
@@ -773,7 +773,7 @@ namespace Tesses::CrossLang {
|
||||
void Save(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, std::shared_ptr<Tesses::Framework::Streams::Stream> stream)
|
||||
{
|
||||
|
||||
TVMVersion runtime_version(TVM_MAJOR,TVM_MINOR,TVM_PATCH,TVM_BUILD,TVM_VERSIONSTAGE);
|
||||
TVMVersion runtime_version(CROSSLANG_BYTECODE_MAJOR,CROSSLANG_BYTECODE_MINOR,CROSSLANG_BYTECODE_PATCH,CROSSLANG_BYTECODE_BUILD,CROSSLANG_BYTECODE_VERSIONSTAGE);
|
||||
uint8_t buffer[18];
|
||||
memcpy(buffer,"TCROSSVM",8);
|
||||
runtime_version.ToArray(buffer+8);
|
||||
|
||||
@@ -33,10 +33,354 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
}
|
||||
|
||||
SyntaxNode CodeGen::OptimizeNode(SyntaxNode n)
|
||||
{
|
||||
if(std::holds_alternative<AdvancedSyntaxNode>(n))
|
||||
{
|
||||
auto& asn = std::get<AdvancedSyntaxNode>(n);
|
||||
if(asn.nodeName == AddExpression && asn.nodes.size() == 2)
|
||||
{
|
||||
auto leftNode = OptimizeNode(asn.nodes[0]);
|
||||
auto rightNode = OptimizeNode(asn.nodes[1]);
|
||||
|
||||
|
||||
if(std::holds_alternative<int64_t>(leftNode) && std::holds_alternative<int64_t>(rightNode))
|
||||
{
|
||||
return std::get<int64_t>(leftNode) + std::get<int64_t>(rightNode);
|
||||
}
|
||||
if(std::holds_alternative<double>(leftNode) && std::holds_alternative<double>(rightNode))
|
||||
{
|
||||
return std::get<double>(leftNode) + std::get<double>(rightNode);
|
||||
}
|
||||
if(std::holds_alternative<int64_t>(leftNode) && std::holds_alternative<double>(rightNode))
|
||||
{
|
||||
return (double)std::get<int64_t>(leftNode) + std::get<double>(rightNode);
|
||||
}
|
||||
if(std::holds_alternative<double>(leftNode) && std::holds_alternative<int64_t>(rightNode))
|
||||
{
|
||||
return std::get<double>(leftNode) + (double)std::get<int64_t>(rightNode);
|
||||
}
|
||||
if(std::holds_alternative<std::string>(leftNode) && std::holds_alternative<std::string>(rightNode))
|
||||
{
|
||||
return std::get<std::string>(leftNode) + std::get<std::string>(rightNode);
|
||||
}
|
||||
if(std::holds_alternative<std::string>(leftNode) && std::holds_alternative<char>(rightNode))
|
||||
{
|
||||
return std::get<std::string>(leftNode) + std::get<char>(rightNode);
|
||||
}
|
||||
if(std::holds_alternative<char>(leftNode) && std::holds_alternative<std::string>(rightNode))
|
||||
{
|
||||
return std::get<char>(leftNode) + std::get<std::string>(rightNode);
|
||||
}
|
||||
}
|
||||
if(asn.nodeName == SubExpression && asn.nodes.size() == 2)
|
||||
{
|
||||
auto leftNode = OptimizeNode(asn.nodes[0]);
|
||||
auto rightNode = OptimizeNode(asn.nodes[1]);
|
||||
|
||||
|
||||
if(std::holds_alternative<int64_t>(leftNode) && std::holds_alternative<int64_t>(rightNode))
|
||||
{
|
||||
return std::get<int64_t>(leftNode) - std::get<int64_t>(rightNode);
|
||||
}
|
||||
if(std::holds_alternative<double>(leftNode) && std::holds_alternative<double>(rightNode))
|
||||
{
|
||||
return std::get<double>(leftNode) - std::get<double>(rightNode);
|
||||
}
|
||||
if(std::holds_alternative<int64_t>(leftNode) && std::holds_alternative<double>(rightNode))
|
||||
{
|
||||
return (double)std::get<int64_t>(leftNode) - std::get<double>(rightNode);
|
||||
}
|
||||
if(std::holds_alternative<double>(leftNode) && std::holds_alternative<int64_t>(rightNode))
|
||||
{
|
||||
return std::get<double>(leftNode) - (double)std::get<int64_t>(rightNode);
|
||||
}
|
||||
}
|
||||
if(asn.nodeName == CommaExpression && asn.nodes.size() == 2)
|
||||
{
|
||||
return AdvancedSyntaxNode::Create(CommaExpression,true, {
|
||||
OptimizeNode(asn.nodes[0]),
|
||||
OptimizeNode(asn.nodes[1])
|
||||
});
|
||||
}
|
||||
if(asn.nodeName == ScopeNode)
|
||||
{
|
||||
if(asn.nodes.empty())
|
||||
{
|
||||
asn.nodeName = NodeList;
|
||||
return asn;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(auto& item : asn.nodes)
|
||||
{
|
||||
item = OptimizeNode(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
0: false,
|
||||
1: true,
|
||||
2: null,
|
||||
3: Long,
|
||||
4: Double,
|
||||
5: Char
|
||||
6: String,
|
||||
7: List,
|
||||
8: Dictionary,
|
||||
9: ByteArray (embed),
|
||||
10: Stream (embedstrm),
|
||||
11: VFS (embeddir),
|
||||
12: ClosureOfEmbedStream (used by embeddir)
|
||||
*/
|
||||
|
||||
void CodeGen::WriteMetadataObject(std::vector<uint8_t>& bytes, SyntaxNode n)
|
||||
{
|
||||
if(std::holds_alternative<bool>(n))
|
||||
{
|
||||
bytes.push_back(std::get<bool>(n) ? 1 : 0);
|
||||
return;
|
||||
}
|
||||
if(std::holds_alternative<std::nullptr_t>(n))
|
||||
{
|
||||
bytes.push_back(2);
|
||||
return;
|
||||
}
|
||||
if(std::holds_alternative<int64_t>(n))
|
||||
{
|
||||
auto num = std::get<int64_t>(n);
|
||||
bytes.push_back(3);
|
||||
size_t offset = bytes.size();
|
||||
bytes.resize(offset+8);
|
||||
BitConverter::FromUint64BE(bytes[offset],num);
|
||||
return;
|
||||
}
|
||||
if(std::holds_alternative<double>(n))
|
||||
{
|
||||
auto num = std::get<double>(n);
|
||||
bytes.push_back(4);
|
||||
size_t offset = bytes.size();
|
||||
bytes.resize(offset+8);
|
||||
BitConverter::FromDoubleBE(bytes[offset],num);
|
||||
return;
|
||||
}
|
||||
if(std::holds_alternative<char>(n))
|
||||
{
|
||||
auto chr = std::get<char>(n);
|
||||
bytes.push_back(5);
|
||||
bytes.push_back((uint8_t)chr);
|
||||
return;
|
||||
}
|
||||
if(std::holds_alternative<std::string>(n))
|
||||
{
|
||||
auto& str = std::get<std::string>(n);
|
||||
bytes.push_back(6);
|
||||
size_t offset = bytes.size();
|
||||
bytes.resize(offset+4);
|
||||
BitConverter::FromUint32BE(bytes[offset], GetString(str));
|
||||
return;
|
||||
}
|
||||
if(std::holds_alternative<AdvancedSyntaxNode>(n))
|
||||
{
|
||||
auto& asn = std::get<AdvancedSyntaxNode>(n);
|
||||
if(asn.nodeName == ArrayExpression)
|
||||
{
|
||||
std::vector<SyntaxNode> itms;
|
||||
if(asn.nodes.size() > 0)
|
||||
|
||||
GetFunctionArgs(itms,asn.nodes[0]);
|
||||
bytes.push_back(7);
|
||||
size_t offset = bytes.size();
|
||||
bytes.resize(offset+4);
|
||||
BitConverter::FromUint32BE(bytes[offset], (uint32_t)itms.size());
|
||||
for(auto& item : itms)
|
||||
{
|
||||
WriteMetadataObject(bytes,item);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(asn.nodeName == DictionaryExpression)
|
||||
{
|
||||
std::vector<SyntaxNode> itms;
|
||||
if(asn.nodes.size() > 0)
|
||||
|
||||
GetFunctionArgs(itms,asn.nodes[0]);
|
||||
bytes.push_back(8);
|
||||
size_t offset = bytes.size();
|
||||
bytes.resize(offset+4);
|
||||
BitConverter::FromUint32BE(bytes[offset], (uint32_t)itms.size());
|
||||
for(auto& item : itms)
|
||||
{
|
||||
if(std::holds_alternative<AdvancedSyntaxNode>(item))
|
||||
{
|
||||
auto tkn = std::get<AdvancedSyntaxNode>(item);
|
||||
if(tkn.nodeName == GetVariableExpression && !tkn.nodes.empty())
|
||||
{
|
||||
if(std::holds_alternative<std::string>(tkn.nodes[0]))
|
||||
{
|
||||
size_t offset2 = bytes.size();
|
||||
bytes.resize(offset2+4);
|
||||
BitConverter::FromUint32BE(bytes[offset2], GetString(std::get<std::string>(tkn.nodes[0])));
|
||||
bytes.push_back(2);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
size_t offset2 = bytes.size();
|
||||
bytes.resize(offset2+4);
|
||||
BitConverter::FromUint32BE(bytes[offset2], GetString("__unknown"));
|
||||
bytes.push_back(2);
|
||||
|
||||
}
|
||||
}
|
||||
else if(tkn.nodeName == AssignExpression && tkn.nodes.size()==2 && std::holds_alternative<AdvancedSyntaxNode>(tkn.nodes[0]))
|
||||
{
|
||||
auto myTn = std::get<AdvancedSyntaxNode>(tkn.nodes[0]);
|
||||
if(myTn.nodeName == GetVariableExpression && !myTn.nodes.empty())
|
||||
{
|
||||
if(std::holds_alternative<std::string>(myTn.nodes[0]))
|
||||
{
|
||||
size_t offset2 = bytes.size();
|
||||
bytes.resize(offset2+4);
|
||||
BitConverter::FromUint32BE(bytes[offset2], GetString(std::get<std::string>(myTn.nodes[0])));
|
||||
WriteMetadataObject(bytes,tkn.nodes[1]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
size_t offset2 = bytes.size();
|
||||
bytes.resize(offset2+4);
|
||||
BitConverter::FromUint32BE(bytes[offset2], GetString("__unknown"));
|
||||
bytes.push_back(2);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
size_t offset2 = bytes.size();
|
||||
bytes.resize(offset2+4);
|
||||
BitConverter::FromUint32BE(bytes[offset2], GetString("__unknown"));
|
||||
bytes.push_back(2);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
size_t offset2 = bytes.size();
|
||||
bytes.resize(offset2+4);
|
||||
BitConverter::FromUint32BE(bytes[offset2], GetString("__unknown"));
|
||||
bytes.push_back(2);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(asn.nodeName == EmbedExpression)
|
||||
{
|
||||
if(!asn.nodes.empty() && std::holds_alternative<std::string>(asn.nodes[0]))
|
||||
{
|
||||
auto& filename = std::get<std::string>(asn.nodes[0]);
|
||||
bytes.push_back(9);
|
||||
size_t offset = bytes.size();
|
||||
bytes.resize(offset+4);
|
||||
BitConverter::FromUint32BE(bytes[offset], GetResource(std::make_shared<ResourceFile>(filename)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(asn.nodeName == EmbedStreamExpression)
|
||||
{
|
||||
if(!asn.nodes.empty() && std::holds_alternative<std::string>(asn.nodes[0]))
|
||||
{
|
||||
auto& filename = std::get<std::string>(asn.nodes[0]);
|
||||
bytes.push_back(10);
|
||||
size_t offset = bytes.size();
|
||||
bytes.resize(offset+4);
|
||||
BitConverter::FromUint32BE(bytes[offset], GetResource(std::make_shared<ResourceFile>(filename)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(asn.nodeName == EmbedDirectoryExpression)
|
||||
{
|
||||
if(!asn.nodes.empty() && std::holds_alternative<std::string>(asn.nodes[0]))
|
||||
{
|
||||
auto& filename = std::get<std::string>(asn.nodes[0]);
|
||||
bytes.push_back(11);
|
||||
|
||||
|
||||
std::function<void(Tesses::Framework::Filesystem::VFSPath path)> embedDir;
|
||||
embedDir = [&](Tesses::Framework::Filesystem::VFSPath path)-> void {
|
||||
bytes.push_back(8);
|
||||
std::vector<std::pair<Tesses::Framework::Filesystem::VFSPath, bool>> entries;
|
||||
if(embedFS != nullptr && embedFS->DirectoryExists(path))
|
||||
for(auto& item : embedFS->EnumeratePaths(path))
|
||||
{
|
||||
if(embedFS->DirectoryExists(item))
|
||||
entries.emplace_back(item,true);
|
||||
else if(embedFS->FileExists(item))
|
||||
entries.emplace_back(item,false);
|
||||
|
||||
|
||||
/*GenNode(instructions,item.GetFileName(),scope,contscope,brkscope,contI,brkI);
|
||||
if(embedFS->DirectoryExists(item))
|
||||
{
|
||||
embedDir(item);
|
||||
}
|
||||
else if(embedFS->RegularFileExists(item))
|
||||
{
|
||||
auto ce = AdvancedSyntaxNode::Create(ClosureExpression,true,{
|
||||
AdvancedSyntaxNode::Create(ParenthesesExpression,true,{}),
|
||||
AdvancedSyntaxNode::Create(ReturnStatement,false,{
|
||||
AdvancedSyntaxNode::Create(EmbedStreamExpression,true,{item.ToString()})
|
||||
})
|
||||
});
|
||||
GenNode(instructions,ce,scope,contscope,brkscope,contI,brkI);
|
||||
}
|
||||
else {
|
||||
instructions.push_back(new SimpleInstruction(PUSHUNDEFINED));
|
||||
}
|
||||
|
||||
instructions.push_back(new SimpleInstruction(APPENDDICT));*/
|
||||
}
|
||||
size_t offset = bytes.size();
|
||||
bytes.resize(offset+4);
|
||||
BitConverter::FromUint32BE(bytes[offset], (uint32_t)entries.size());
|
||||
for(auto& item : entries)
|
||||
{
|
||||
offset = bytes.size();
|
||||
bytes.resize(offset+4);
|
||||
BitConverter::FromUint32BE(bytes[offset],GetString(item.first.GetFileName()));
|
||||
if(item.second)
|
||||
embedDir(item.first);
|
||||
else {
|
||||
bytes.push_back(12);
|
||||
offset = bytes.size();
|
||||
bytes.resize(offset+4);
|
||||
bytes.resize(offset+4);
|
||||
BitConverter::FromUint32BE(bytes[offset],GetResource(std::make_shared<ResourceFile>(item.first.ToString())));
|
||||
}
|
||||
}
|
||||
};
|
||||
embedDir(filename);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bytes.push_back(2);
|
||||
}
|
||||
|
||||
void CodeGen::Save(std::shared_ptr<Tesses::Framework::Streams::Stream> stream)
|
||||
{
|
||||
TVMVersion runtime_version(TVM_MAJOR,TVM_MINOR,TVM_PATCH,TVM_BUILD,TVM_VERSIONSTAGE);
|
||||
TVMVersion runtime_version(CROSSLANG_BYTECODE_MAJOR,CROSSLANG_BYTECODE_MINOR,CROSSLANG_BYTECODE_PATCH,CROSSLANG_BYTECODE_BUILD,CROSSLANG_BYTECODE_VERSIONSTAGE);
|
||||
uint8_t buffer[18];
|
||||
memcpy(buffer,"TCROSSVM",8);
|
||||
runtime_version.ToArray(buffer+8);
|
||||
@@ -56,6 +400,10 @@ namespace Tesses::CrossLang
|
||||
GetString(tool.first);
|
||||
sections++;
|
||||
}
|
||||
for(auto& meta : this->meta)
|
||||
{
|
||||
sections++;
|
||||
}
|
||||
if(!this->icon.empty())
|
||||
{
|
||||
this->GetResource(std::make_shared<ResourceFile>(this->icon));
|
||||
@@ -246,6 +594,13 @@ namespace Tesses::CrossLang
|
||||
WriteInt(stream,this->GetResource(std::make_shared<ResourceFile>(this->icon)));
|
||||
|
||||
}
|
||||
for(auto& meta : this->meta)
|
||||
{
|
||||
memcpy(buffer,"META", 4);
|
||||
Write(stream,buffer,4);
|
||||
WriteInt(stream,(uint32_t)meta.size());
|
||||
Write(stream,meta.data(),meta.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1380,6 +1735,17 @@ namespace Tesses::CrossLang
|
||||
instructions.push_back(new EmbedInstruction(GetResource(std::make_shared<ResourceFile>(filename))));
|
||||
|
||||
}
|
||||
else if(adv.nodeName == MetadataStatement && adv.nodes.size() == 2 && std::holds_alternative<std::string>(adv.nodes[0]))
|
||||
{
|
||||
auto& name = std::get<std::string>(adv.nodes[0]);
|
||||
|
||||
|
||||
auto& metabytes= this->meta.emplace_back();
|
||||
metabytes.resize(4);
|
||||
BitConverter::FromUint32BE(metabytes[0],GetString(name));
|
||||
|
||||
WriteMetadataObject(metabytes, adv.nodes[1]);
|
||||
}
|
||||
else if(adv.nodeName == EmbedStreamExpression && adv.nodes.size() == 1 && std::holds_alternative<std::string>(adv.nodes[0]))
|
||||
{
|
||||
std::string filename = std::get<std::string>(adv.nodes[0]);
|
||||
@@ -1446,6 +1812,7 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
else if(adv.nodeName == ScopeNode)
|
||||
{
|
||||
|
||||
scope++;
|
||||
instructions.push_back(new SimpleInstruction(SCOPEBEGIN));
|
||||
for(size_t i = 0; i < adv.nodes.size(); i++)
|
||||
|
||||
@@ -1456,7 +1456,7 @@ namespace Tesses::CrossLang
|
||||
EnsureSymbol("(");
|
||||
SyntaxNode list = ParseExpression();
|
||||
SyntaxNode body = nullptr;
|
||||
if(IsSymbol(":"))
|
||||
if(IsSymbol(":") || IsIdentifier("in"))
|
||||
{
|
||||
item = list;
|
||||
list = ParseExpression();
|
||||
@@ -1467,6 +1467,11 @@ namespace Tesses::CrossLang
|
||||
{
|
||||
body = ParseNode();
|
||||
}
|
||||
if(std::holds_alternative<std::nullptr_t>(item))
|
||||
item = AdvancedSyntaxNode::Create(DeclareExpression,true, {
|
||||
AdvancedSyntaxNode::Create(GetVariableExpression,true,{"item"})
|
||||
});
|
||||
|
||||
return AdvancedSyntaxNode::Create(EachStatement,false,{item,list,body});
|
||||
}
|
||||
if(IsIdentifier("class"))
|
||||
@@ -1681,6 +1686,25 @@ namespace Tesses::CrossLang
|
||||
});
|
||||
}
|
||||
}
|
||||
if(IsIdentifier("meta"))
|
||||
{
|
||||
if(i >= tokens.size() || tokens[i].type != LexTokenType::String)
|
||||
{
|
||||
std::cout << "WARN: meta is a conditional keyword,\nif you suffix it with a string, it will be assumed to be a metadata tag" << std::endl;
|
||||
i--;
|
||||
}
|
||||
else {
|
||||
std::string name = tokens[i++].text;
|
||||
EnsureSymbol("{");
|
||||
auto expr = ParseExpression();
|
||||
|
||||
|
||||
EnsureSymbol("}");
|
||||
|
||||
return AdvancedSyntaxNode::Create(MetadataStatement,false,{name, AdvancedSyntaxNode::Create(DictionaryExpression,true,{expr})});
|
||||
}
|
||||
|
||||
}
|
||||
if(IsIdentifier("func"))
|
||||
{
|
||||
|
||||
|
||||
@@ -49,6 +49,8 @@ bool Download(Tesses::Framework::Filesystem::VFSPath filename,std::shared_ptr<Te
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
if(argc > 0)
|
||||
TF_AllowPortable(argv[0]);
|
||||
|
||||
|
||||
|
||||
@@ -58,7 +60,11 @@ int main(int argc, char** argv)
|
||||
|
||||
|
||||
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(argc == 2 && strcmp(argv[1],"configdir") == 0)
|
||||
{
|
||||
std::cout << dir.ToString() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
if(argc > 1 && strcmp(argv[1],"update-shell") == 0)
|
||||
{
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ using namespace Tesses::Framework::Filesystem;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
if(argc > 0)
|
||||
TF_AllowPortable(argv[0]);
|
||||
GC gc;
|
||||
gc.Start();
|
||||
GCList ls(gc);
|
||||
|
||||
@@ -4,11 +4,14 @@ using namespace Tesses::CrossLang;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
|
||||
if(argc < 2)
|
||||
{
|
||||
printf("USAGE: %s <filename.crvm> <args...>\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if(argc > 0)
|
||||
TF_AllowPortable(argv[0]);
|
||||
|
||||
GC gc;
|
||||
gc.Start();
|
||||
@@ -29,6 +32,8 @@ int main(int argc, char** argv)
|
||||
port = std::stoi(item.second);
|
||||
}
|
||||
}
|
||||
|
||||
env->EnsureDictionary(&gc,"Net")->SetValue("WebServerPort", (int64_t)port);
|
||||
TList* args2 = TList::Create(ls);
|
||||
for(auto& item : args.positional)
|
||||
{
|
||||
|
||||
@@ -320,6 +320,15 @@ namespace Tesses::CrossLang {
|
||||
dict->DeclareFunction(gc, "getSize", "Get console size",{},Console_getSize);
|
||||
gc->BarrierBegin();
|
||||
env->DeclareVariable("Console", dict);
|
||||
auto _new = env->EnsureDictionary(gc,"New");
|
||||
_new->DeclareFunction(gc,"ConsoleReader","Read from console",{},[](GCList& ls,std::vector<TObject> args)->TObject {
|
||||
return std::make_shared<Tesses::Framework::TextStreams::ConsoleReader>();
|
||||
});
|
||||
_new->DeclareFunction(gc,"ConsoleWriter","Write to console",{"$isStderr"},[](GCList& ls,std::vector<TObject> args)->TObject {
|
||||
bool err;
|
||||
if(GetArgument(args,0,err)) return std::make_shared<Tesses::Framework::TextStreams::ConsoleWriter>(err);
|
||||
return std::make_shared<Tesses::Framework::TextStreams::ConsoleWriter>();
|
||||
});
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +118,19 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
return Tesses::Framework::Filesystem::VFSPath();
|
||||
}
|
||||
static TObject Env_GetAll(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
ls.GetGC()->BarrierBegin();
|
||||
TList* list = TList::Create(ls);
|
||||
std::vector<std::pair<std::string, std::string>> env;
|
||||
Tesses::Framework::Platform::Environment::GetEnvironmentVariables(env);
|
||||
for(auto& item : env)
|
||||
{
|
||||
list->Add(TDictionary::Create(ls,{TDItem("Key",item.first),TDItem("Value",item.second)}));
|
||||
}
|
||||
ls.GetGC()->BarrierEnd();
|
||||
return list;
|
||||
}
|
||||
void TStd::RegisterEnv(GC* gc, TRootEnvironment* env)
|
||||
{
|
||||
|
||||
@@ -126,8 +139,9 @@ namespace Tesses::CrossLang
|
||||
TDictionary* dict = TDictionary::Create(ls);
|
||||
dict->DeclareFunction(gc,"GetAt","Get environment variable", {"key"}, Env_GetAt);
|
||||
dict->DeclareFunction(gc,"SetAt","Set environment variable", {"key","value"}, Env_SetAt);
|
||||
dict->DeclareFunction(gc,"GetAll","Get all of the environment variables",{},Env_GetAll);
|
||||
|
||||
dict->DeclareFunction(gc,"getDesktop","Get downloads folder",{},Env_getDownloads);
|
||||
dict->DeclareFunction(gc,"getDesktop","Get desktop folder",{},Env_getDesktop);
|
||||
dict->DeclareFunction(gc,"getDownloads","Get downloads folder",{},Env_getDownloads);
|
||||
dict->DeclareFunction(gc,"getDocuments","Get documents folder",{},Env_getDocuments);
|
||||
dict->DeclareFunction(gc,"getMusic","Get music folder",{},Env_getMusic);
|
||||
|
||||
@@ -172,15 +172,157 @@ namespace Tesses::CrossLang
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class FS_Watcher : public TNativeObject {
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::FSWatcher> watcher;
|
||||
|
||||
FS_Watcher(std::shared_ptr<Tesses::Framework::Filesystem::FSWatcher> watcher): watcher(watcher)
|
||||
{}
|
||||
|
||||
TObject CallMethod(GCList& ls, std::string name, std::vector<TObject> args)
|
||||
{
|
||||
if(name == "getPath")
|
||||
{
|
||||
return watcher->GetPath();
|
||||
}
|
||||
if(name == "getFilesystem")
|
||||
{
|
||||
return watcher->GetFilesystem();
|
||||
}
|
||||
if(name == "setEnabled")
|
||||
{
|
||||
bool enabled;
|
||||
if(GetArgument(args,0,enabled))
|
||||
{
|
||||
watcher->SetEnabled(enabled);
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
if(name == "getEnabled")
|
||||
{
|
||||
return watcher->GetEnabled();
|
||||
}
|
||||
if(name == "setEvents")
|
||||
{
|
||||
int64_t evts;
|
||||
if(GetArgument(args,0,evts))
|
||||
{
|
||||
watcher->events = (Tesses::Framework::Filesystem::FSWatcherEventType)evts;
|
||||
return evts;
|
||||
}
|
||||
}
|
||||
if(name == "getEvents")
|
||||
{
|
||||
return (int64_t)watcher->events;
|
||||
}
|
||||
if(name == "setCallback")
|
||||
{
|
||||
TCallable* callable=nullptr;
|
||||
if(GetArgumentHeap(args,0,callable))
|
||||
{
|
||||
auto markedT = CreateMarkedTObject(ls,callable);
|
||||
watcher->event = [markedT](Tesses::Framework::Filesystem::FSWatcherEvent& evt) -> void {
|
||||
GCList ls(markedT->GetGC());
|
||||
TObject o = markedT->GetObject();
|
||||
TCallable* callable;
|
||||
if(GetObjectHeap(o,callable))
|
||||
{
|
||||
auto isEvent = TExternalMethod::Create(ls,"",{},[evt](GCList& ls, std::vector<TObject> args)->TObject
|
||||
{
|
||||
int64_t n;
|
||||
if(GetArgument(args,0,n))
|
||||
{
|
||||
auto myevt = evt;
|
||||
return myevt.IsEvent((Tesses::Framework::Filesystem::FSWatcherEventType)n);
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
auto toString = TExternalMethod::Create(ls,"",{},[evt](GCList& ls, std::vector<TObject> args)->TObject
|
||||
{
|
||||
auto myevt = evt;
|
||||
return myevt.ToString();
|
||||
});
|
||||
|
||||
auto dict = TDictionary::Create(ls, {TDItem("IsDirectory",evt.isDir),TDItem("Type",(int64_t)evt.type),TDItem("Source",evt.src), TDItem("Destination",evt.dest),TDItem("ToString",toString),TDItem("IsEvent",isEvent)});
|
||||
callable->Call(ls,{dict});
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
watcher->event=nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
if(name == "Start")
|
||||
{
|
||||
watcher->SetEnabled(true);
|
||||
}
|
||||
if(name == "Stop")
|
||||
{
|
||||
watcher->SetEnabled(false);
|
||||
}
|
||||
if(name == "ToString")
|
||||
{
|
||||
return "FSWatcher";
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
std::string TypeName() {
|
||||
return "FSWatcher";
|
||||
}
|
||||
};
|
||||
|
||||
TObject New_FSWatcher(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
if(GetArgument(args,0,vfs) && GetArgumentAsPath(args,1,path))
|
||||
{
|
||||
return TNativeObject::Create<FS_Watcher>(ls,Tesses::Framework::Filesystem::FSWatcher::Create(vfs,path));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TStd::RegisterIO(GC* gc,TRootEnvironment* env,bool enableLocalFilesystem)
|
||||
{
|
||||
|
||||
env->permissions.canRegisterIO=true;
|
||||
env->permissions.canRegisterLocalFS = enableLocalFilesystem;
|
||||
GCList ls(gc);
|
||||
TDictionary* dict = TDictionary::Create(ls);
|
||||
|
||||
gc->BarrierBegin();
|
||||
auto newDict = env->EnsureDictionary(gc, "New");
|
||||
newDict->DeclareFunction(gc,"FSWatcher","Watch a file/directory",{"vfs","path"}, New_FSWatcher);
|
||||
auto dict = env->EnsureDictionary(gc,"FS");
|
||||
dict->SetValue("SEEK_SET",(int64_t)Tesses::Framework::Streams::SeekOrigin::Begin);
|
||||
dict->SetValue("SEEK_CUR",(int64_t)Tesses::Framework::Streams::SeekOrigin::Current);
|
||||
dict->SetValue("SEEK_END",(int64_t)Tesses::Framework::Streams::SeekOrigin::End);
|
||||
dict->SetValue("FSWatcherEvents",TDictionary::Create(ls,
|
||||
{
|
||||
TDItem("None", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::None),
|
||||
TDItem("Accessed", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::Accessed),
|
||||
TDItem("AttributeChanged", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::AttributeChanged),
|
||||
TDItem("Writen", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::Writen),
|
||||
TDItem("Read", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::Read),
|
||||
TDItem("Created", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::Created),
|
||||
TDItem("Deleted", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::Deleted),
|
||||
TDItem("WatchEntryDeleted", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::WatchEntryDeleted),
|
||||
TDItem("Modified", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::Modified),
|
||||
TDItem("WatchEntryMoved", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::WatchEntryMoved),
|
||||
TDItem("MoveOld", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::MoveOld),
|
||||
TDItem("MoveNew", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::MoveNew),
|
||||
TDItem("Opened", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::Opened),
|
||||
TDItem("Closed", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::Closed),
|
||||
TDItem("Moved", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::Moved),
|
||||
TDItem("All", (int64_t)Tesses::Framework::Filesystem::FSWatcherEventType::All)
|
||||
}
|
||||
));
|
||||
|
||||
if(enableLocalFilesystem)
|
||||
{
|
||||
|
||||
@@ -202,7 +344,7 @@ namespace Tesses::CrossLang
|
||||
|
||||
dict->DeclareFunction(gc, "CreateArchive", "Create a crvm archive",{"fs","strm","name","version","info"},FS_CreateArchive);
|
||||
dict->DeclareFunction(gc,"ExtractArchive", "Extract a crvm archive",{"strm","vfs"},FS_ExtractArchive);
|
||||
env->DeclareVariable("FS", dict);
|
||||
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
}
|
||||
@@ -81,6 +81,21 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
static TObject JsonDocEncode(GCList& ls2, std::vector<TObject> args)
|
||||
{
|
||||
if(args.size() >= 1)
|
||||
{
|
||||
bool indent = (args.size() == 2 && std::holds_alternative<bool>(args[1]) && std::get<bool>(args[1]));
|
||||
|
||||
auto json = JsonSerialize(args[0]);
|
||||
JArray ar;
|
||||
if(TryGetJToken(json,ar))
|
||||
return Json::DocEncode(ar,indent);
|
||||
|
||||
|
||||
}
|
||||
return "";
|
||||
}
|
||||
static TObject JsonDeserialize(GCList& ls2,JToken json)
|
||||
{
|
||||
if(std::holds_alternative<JUndefined>(json)) return nullptr;
|
||||
@@ -138,6 +153,19 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
static TObject JsonDocDecode(GCList& ls2,std::vector<TObject> args)
|
||||
{
|
||||
if(args.size() > 0 && std::holds_alternative<std::string>(args[0]))
|
||||
{
|
||||
|
||||
|
||||
return JsonDeserialize(ls2, Json::DocDecode(std::get<std::string>(args[0])));
|
||||
|
||||
|
||||
}
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
std::string Json_Encode(TObject o,bool indent)
|
||||
{
|
||||
return Json::Encode(JsonSerialize(o),indent);
|
||||
@@ -146,14 +174,29 @@ namespace Tesses::CrossLang
|
||||
{
|
||||
return JsonDeserialize(ls,Json::Decode(str));
|
||||
}
|
||||
std::string Json_DocEncode(TObject o,bool indent)
|
||||
{
|
||||
auto obj = JsonSerialize(o);
|
||||
JArray ls;
|
||||
if(TryGetJToken(obj,ls))
|
||||
return Json::DocEncode(ls,indent);
|
||||
return "";
|
||||
}
|
||||
TObject Json_DocDecode(GCList ls,std::string str)
|
||||
{
|
||||
return JsonDeserialize(ls,Json::DocDecode(str));
|
||||
}
|
||||
void TStd::RegisterJson(GC* gc,TRootEnvironment* env)
|
||||
{
|
||||
|
||||
env->permissions.canRegisterJSON=true;
|
||||
GCList ls(gc);
|
||||
TDictionary* dict = TDictionary::Create(ls);
|
||||
dict->DeclareFunction(gc, "Decode","Deserialize Json",{"Json string"},JsonDecode);
|
||||
dict->DeclareFunction(gc, "Encode","Serialize Json",{"any","$indent"},JsonEncode);
|
||||
dict->DeclareFunction(gc, "Decode","Deserialize Json",{"jsonString"},JsonDecode);
|
||||
dict->DeclareFunction(gc, "Encode","Serialize Json",{"any","$indent"},JsonEncode);
|
||||
dict->DeclareFunction(gc, "DocDecode", "Deserialize JsonDoc", {"jsonDocString"},JsonDocDecode);
|
||||
dict->DeclareFunction(gc, "DocEncode", "Serialize JsonDoc", {"ls","$indent"},JsonDocEncode);
|
||||
|
||||
|
||||
|
||||
gc->BarrierBegin();
|
||||
|
||||
@@ -295,6 +295,7 @@ namespace Tesses::CrossLang
|
||||
else if(key == "getQueryParams") return TNativeObject::Create<THttpDictionary>(ls, &ctx->queryParams,this);
|
||||
else if(key == "getRequestHeaders") return TNativeObject::Create<THttpDictionary>(ls, &ctx->requestHeaders,this);
|
||||
else if(key == "getResponseHeaders") return TNativeObject::Create<THttpDictionary>(ls, &ctx->responseHeaders,this);
|
||||
else if(key == "getPathArguments") return TNativeObject::Create<THttpDictionary>(ls,&ctx->pathArguments, this);
|
||||
else if(key == "GetStream") return ctx->GetStream();
|
||||
else if(key == "OpenRequestStream") return ctx->OpenRequestStream();
|
||||
else if(key == "OpenResponseStream") return ctx->OpenResponseStream();
|
||||
@@ -578,6 +579,7 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
@@ -897,7 +899,8 @@ namespace Tesses::CrossLang
|
||||
|
||||
~THttpResponse()
|
||||
{
|
||||
Close();
|
||||
delete this->response;
|
||||
this->response = nullptr;
|
||||
}
|
||||
std::string TypeName()
|
||||
{
|
||||
@@ -1478,9 +1481,14 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
static TObject New_MountableServer(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.empty()) return Undefined();
|
||||
if(args.empty()) return std::make_shared<MountableServer>();
|
||||
return std::make_shared<MountableServer>(ToHttpServer(ls.GetGC(),args[0]));
|
||||
}
|
||||
static TObject New_RouteServer(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.empty()) return std::make_shared<RouteServer>();
|
||||
return std::make_shared<RouteServer>(ToHttpServer(ls.GetGC(),args[0]));
|
||||
}
|
||||
static TObject New_StreamHttpRequestBody(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
std::shared_ptr<Stream> strm;
|
||||
@@ -1530,6 +1538,8 @@ namespace Tesses::CrossLang
|
||||
_new->DeclareFunction(gc, "HttpServer", "Create a http server (allows multiple)",{"server","portOrUnixPath","$printIPs"},[env](GCList& ls, std::vector<TObject> args)->TObject{
|
||||
return New_HttpServer(ls,args,env);
|
||||
});
|
||||
|
||||
_new->DeclareFunction(gc, "RouteServer","Create a routeserver",{"$root"}, New_RouteServer);
|
||||
_new->DeclareFunction(gc, "FileServer","Create a file server",{"vfs","allowlisting","spa"}, New_FileServer);
|
||||
_new->DeclareFunction(gc, "BasicAuthServer", "Create a basic auth server", {"$server","$auth","$realm"},New_BasicAuthServer);
|
||||
_new->DeclareFunction(gc, "MountableServer","Create a server you can mount to, must mount parents before child",{"root"}, New_MountableServer);
|
||||
@@ -1564,6 +1574,8 @@ namespace Tesses::CrossLang
|
||||
http->DeclareFunction(gc, "ListenSimpleWithLoop", "Listen (creates application loop)", {"server","port"},Net_Http_ListenSimpleWithLoop);
|
||||
http->DeclareFunction(gc, "ListenOnUnusedPort","Listen on unused localhost port and print Port: theport",{"server"},Net_Http_ListenOnUnusedPort);
|
||||
//FileServer svr()
|
||||
|
||||
http->DeclareFunction(gc, "RouteServer","Create a routeserver",{"$root"}, New_RouteServer);
|
||||
http->DeclareFunction(gc, "FileServer","Create a file server",{"vfs","allowlisting","spa"}, New_FileServer);
|
||||
http->DeclareFunction(gc, "BasicAuthServer", "Create a basic auth server", {"$server","$auth","$realm"},New_BasicAuthServer);
|
||||
http->DeclareFunction(gc, "BasicAuthGetCreds","Get creds from str",{"ctx"},[](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
@@ -1604,4 +1616,25 @@ namespace Tesses::CrossLang
|
||||
dict->SetValue("Smtp", smtp);
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
|
||||
Tesses::Framework::Http::ServerRequestHandler TCallable::ToRouteServerRequestHandler(GC* gc)
|
||||
{
|
||||
auto value = CreateMarkedTObject(gc,this);
|
||||
return [value,this](ServerContext& ctx)->bool {
|
||||
auto v=value;
|
||||
auto gc = v->GetGC();
|
||||
GCList ls(gc);
|
||||
auto res = TNativeObject::Create<TServerContext>(ls, &ctx);
|
||||
bool result;
|
||||
auto out = this->Call(ls,{res});
|
||||
if(GetObject(out,result))
|
||||
{
|
||||
res->Finish();
|
||||
return result;
|
||||
}
|
||||
res->Finish();
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -556,6 +556,18 @@ namespace Tesses::CrossLang
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
return GetArgument(args,0,strm);
|
||||
}
|
||||
static TObject TypeIsTextReader(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.empty()) return nullptr;
|
||||
std::shared_ptr<Tesses::Framework::TextStreams::TextReader> strm;
|
||||
return GetArgument(args,0,strm);
|
||||
}
|
||||
static TObject TypeIsTextWriter(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.empty()) return nullptr;
|
||||
std::shared_ptr<Tesses::Framework::TextStreams::TextWriter> strm;
|
||||
return GetArgument(args,0,strm);
|
||||
}
|
||||
static TObject TypeIsVFS(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(args.empty()) return nullptr;
|
||||
@@ -752,6 +764,7 @@ namespace Tesses::CrossLang
|
||||
{
|
||||
auto fileServer = std::dynamic_pointer_cast<Tesses::Framework::Http::FileServer>(svr);
|
||||
auto mountableServer = std::dynamic_pointer_cast<Tesses::Framework::Http::MountableServer>(svr);
|
||||
auto routableServer = std::dynamic_pointer_cast<Tesses::Framework::Http::RouteServer>(svr);
|
||||
if(fileServer != nullptr)
|
||||
{
|
||||
return "FileServer";
|
||||
@@ -760,10 +773,63 @@ namespace Tesses::CrossLang
|
||||
{
|
||||
return "MountableServer";
|
||||
}
|
||||
|
||||
if(routableServer != nullptr)
|
||||
{
|
||||
return "RoutableServer";
|
||||
}
|
||||
}
|
||||
return "HttpServer";
|
||||
|
||||
}
|
||||
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::TextStreams::TextReader>>(_obj))
|
||||
{
|
||||
auto textReader = std::get<std::shared_ptr<Tesses::Framework::TextStreams::TextReader>>(_obj);
|
||||
if(textReader != nullptr)
|
||||
{
|
||||
auto stringReader = std::dynamic_pointer_cast<Tesses::Framework::TextStreams::StringReader>(textReader);
|
||||
auto streamReader = std::dynamic_pointer_cast<Tesses::Framework::TextStreams::StreamReader>(textReader);
|
||||
auto consoleReader = std::dynamic_pointer_cast<Tesses::Framework::TextStreams::ConsoleReader>(textReader);
|
||||
if(stringReader != nullptr)
|
||||
{
|
||||
return "StringReader";
|
||||
}
|
||||
if(streamReader != nullptr)
|
||||
{
|
||||
return "StreamReader";
|
||||
}
|
||||
if(consoleReader != nullptr)
|
||||
{
|
||||
return "ConsoleReader";
|
||||
}
|
||||
}
|
||||
|
||||
return "TextReader";
|
||||
|
||||
}
|
||||
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::TextStreams::TextWriter>>(_obj))
|
||||
{
|
||||
auto textWriter = std::get<std::shared_ptr<Tesses::Framework::TextStreams::TextWriter>>(_obj);
|
||||
if(textWriter != nullptr)
|
||||
{
|
||||
auto stringWriter = std::dynamic_pointer_cast<Tesses::Framework::TextStreams::StringWriter>(textWriter);
|
||||
auto streamWriter = std::dynamic_pointer_cast<Tesses::Framework::TextStreams::StreamWriter>(textWriter);
|
||||
auto consoleWriter = std::dynamic_pointer_cast<Tesses::Framework::TextStreams::ConsoleReader>(textWriter);
|
||||
if(stringWriter != nullptr)
|
||||
{
|
||||
return "StringWriter";
|
||||
}
|
||||
if(streamWriter != nullptr)
|
||||
{
|
||||
return "StreamWriter";
|
||||
}
|
||||
if(consoleWriter != nullptr)
|
||||
{
|
||||
return "ConsoleWriter";
|
||||
}
|
||||
}
|
||||
|
||||
return "TextReader";
|
||||
|
||||
}
|
||||
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::Filesystem::VFS>>(_obj))
|
||||
{
|
||||
@@ -997,9 +1063,48 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
static TObject New_Task(GCList& ls, std::vector<TObject> args)
|
||||
static TObject New_Promise(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
return TTask::Create(ls);
|
||||
TCallable* call;
|
||||
|
||||
if(GetArgumentHeap(args,0,call))
|
||||
{
|
||||
|
||||
TTask* task = TTask::Create(ls);
|
||||
|
||||
TExternalMethod* resolve = TExternalMethod::Create(ls, "fulfill the promise",{"arg"},[task](GCList& ls,std::vector<TObject> args)->TObject {
|
||||
if(!args.empty())
|
||||
{
|
||||
task->SetSucceeded(args[0]);
|
||||
}
|
||||
return Undefined();
|
||||
});
|
||||
resolve->watch.push_back(task);
|
||||
TExternalMethod* reject = TExternalMethod::Create(ls, "reject the promise",{"arg"},[task](GCList& ls,std::vector<TObject> args)->TObject {
|
||||
if(!args.empty())
|
||||
{
|
||||
auto item = args[0];
|
||||
if(!std::holds_alternative<Undefined>(item))
|
||||
{
|
||||
try {
|
||||
VMByteCodeException ex(ls.GetGC(),item,nullptr);
|
||||
throw ex;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
task->SetFailed(std::current_exception());
|
||||
}
|
||||
}
|
||||
}
|
||||
return Undefined();
|
||||
});
|
||||
reject->watch.push_back(task);
|
||||
|
||||
call->Call(ls,{resolve,reject});
|
||||
|
||||
return task;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
static TObject TimeSpan_Parse(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
@@ -1051,6 +1156,72 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
static TObject New_StreamReader(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
|
||||
if(GetArgument(args,0,strm))
|
||||
{
|
||||
return std::make_shared<Tesses::Framework::TextStreams::StreamReader>(strm);
|
||||
}
|
||||
else if(GetArgument(args,0,vfs) && GetArgumentAsPath(args,1,path))
|
||||
{
|
||||
strm = vfs->OpenFile(path,"rb");
|
||||
return std::make_shared<Tesses::Framework::TextStreams::StreamReader>(strm);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static TObject New_StreamWriter(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
|
||||
if(GetArgument(args,0,strm))
|
||||
{
|
||||
return std::make_shared<Tesses::Framework::TextStreams::StreamWriter>(strm);
|
||||
}
|
||||
else if(GetArgument(args,0,vfs) && GetArgumentAsPath(args,1,path))
|
||||
{
|
||||
bool append=false;
|
||||
GetArgument(args,2,append);
|
||||
|
||||
strm = vfs->OpenFile(path,append ? "ab" : "wb");
|
||||
return std::make_shared<Tesses::Framework::TextStreams::StreamWriter>(strm);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
static TObject New_StringReader(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
std::string str;
|
||||
if(GetArgument(args,0,str))
|
||||
{
|
||||
return std::make_shared<Tesses::Framework::TextStreams::StringReader>(str);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
static TObject New_StringWriter(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
std::string str;
|
||||
if(GetArgument(args,0,str))
|
||||
{
|
||||
return std::make_shared<Tesses::Framework::TextStreams::StringWriter>(str);
|
||||
}
|
||||
|
||||
return std::make_shared<Tesses::Framework::TextStreams::StringWriter>();
|
||||
}
|
||||
static TObject Task_FromResult(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
if(!args.empty())
|
||||
{
|
||||
return TTask::FromResult(ls,args[0]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
void TStd::RegisterRoot(GC* gc, TRootEnvironment* env)
|
||||
{
|
||||
GCList ls(gc);
|
||||
@@ -1095,10 +1266,11 @@ namespace Tesses::CrossLang
|
||||
return TTask::Run(ls,closure);
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
task->DeclareFunction(gc, "FromResult", "async from result", {"result"}, Task_FromResult);
|
||||
|
||||
TDictionary* newTypes = env->EnsureDictionary(gc, "New");
|
||||
|
||||
//newTypes->DeclareFunction(gc,)
|
||||
newTypes->DeclareFunction(gc, "Promise", "Create an async object",{"resolve","reject"},New_Promise);
|
||||
newTypes->DeclareFunction(gc, "DateTime","Create a DateTime object, if only one arg is provided year is epoch, isLocal defaults to true unless epoch",{"year","$month","$day","$hour","$minute","$second","$isLocal"},New_DateTime);
|
||||
newTypes->DeclareFunction(gc, "TimeSpan","Create a DateTime object, if only one arg is provided days is totalSeconds, if there are only three arguments days will be hours, hours will be minutes, minutes will be seconds (according to the argument documentation)",{"days","$hours","$minutes","$seconds"},New_TimeSpan);
|
||||
|
||||
@@ -1133,7 +1305,18 @@ namespace Tesses::CrossLang
|
||||
|
||||
return TVMVersion((uint8_t)major,(uint8_t)minor,(uint8_t)patch,(uint16_t)build,stage);
|
||||
});
|
||||
|
||||
newTypes->DeclareFunction(gc,"Random","Create random number generator",{"$seed"}, [](GCList& ls,std::vector<TObject> args)->TObject{
|
||||
int64_t seed;
|
||||
if(GetArgument(args,0,seed))
|
||||
{
|
||||
return TNativeObject::Create<TRandom>(ls, (uint64_t)seed);
|
||||
}
|
||||
return TNativeObject::Create<TRandom>(ls);
|
||||
});
|
||||
newTypes->DeclareFunction(gc, "StreamReader","Create a StreamReader", {"strmOrVFS","$pathIfVFS"},New_StreamReader);
|
||||
newTypes->DeclareFunction(gc, "StreamWriter","Create a StreamWriter", {"strmOrVFS","$pathIfVFS","$appendIfVFS"},New_StreamWriter);
|
||||
newTypes->DeclareFunction(gc, "StringReader","Create a StringReader", {"str"},New_StringReader);
|
||||
newTypes->DeclareFunction(gc, "StringWriter","Create a StringWriter", {"$str"},New_StringWriter);
|
||||
|
||||
env->DeclareFunction(gc, "ParseLong","Parse Long from String",{"arg","$base"},ParseLong);
|
||||
env->DeclareFunction(gc, "ParseDouble","Parse Double from String",{"arg"},ParseDouble);
|
||||
@@ -1154,6 +1337,8 @@ namespace Tesses::CrossLang
|
||||
env->DeclareFunction(gc, "TypeIsVFS","Get whether object is a virtual filesystem",{"object"},TypeIsVFS);
|
||||
env->DeclareFunction(gc, "TypeIsDateTime","Get whether object is a DateTime",{"object"},TypeIsDateTime);
|
||||
env->DeclareFunction(gc, "TypeIsTimeSpan","Get whether object is a TimeSpan",{"object"},TypeIsTimeSpan);
|
||||
env->DeclareFunction(gc, "TypeIsTextReader","Get whether object is a TextReader",{"object"},TypeIsTextReader);
|
||||
env->DeclareFunction(gc, "TypeIsTextWriter","Get whether object is a TextWriter",{"object"},TypeIsTextWriter);
|
||||
|
||||
|
||||
newTypes->DeclareFunction(gc, "Regex", "Create regex object",{"regex"},[](GCList& ls,std::vector<TObject> args)->TObject {
|
||||
@@ -1200,7 +1385,6 @@ namespace Tesses::CrossLang
|
||||
return TAssociativeArray::Create(ls);
|
||||
});
|
||||
newTypes->DeclareFunction(gc,"ByteArray","Create bytearray, with optional either size (to size it) or string argument (to fill byte array)",{"$data"},ByteArray);
|
||||
newTypes->DeclareFunction(gc,"Task","Create a task for async, to manually create an async object",{},New_Task);
|
||||
|
||||
env->DeclareVariable("Version", TDictionary::Create(ls,{
|
||||
TDItem("Parse",TExternalMethod::Create(ls,"Parse version from string",{"versionStr"},[](GCList& ls, std::vector<TObject> args)->TObject{
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace Tesses::CrossLang
|
||||
|
||||
std::string name = "Out";
|
||||
std::vector<std::pair<std::string,std::string>> sources;
|
||||
TVMVersion version(TVM_MAJOR,TVM_MINOR,TVM_PATCH,TVM_BUILD,TVM_VERSIONSTAGE);
|
||||
TVMVersion version(CROSSLANG_BYTECODE_MAJOR,CROSSLANG_BYTECODE_MINOR,CROSSLANG_BYTECODE_PATCH,CROSSLANG_BYTECODE_BUILD,CROSSLANG_BYTECODE_VERSIONSTAGE);
|
||||
std::vector<std::pair<std::string,TVMVersion>> dependencies;
|
||||
std::vector<std::pair<std::string,TVMVersion>> tools;
|
||||
std::string info;
|
||||
@@ -359,7 +359,10 @@ namespace Tesses::CrossLang
|
||||
|
||||
dict->DeclareFunction(gc, "SourceToAst", "Convert source to ast", {"source"}, VM_SourceToAst);
|
||||
dict->DeclareFunction(gc, "getRuntimeVersion","Get the runtime version",{},[](GCList& ls,std::vector<TObject> args)->TObject {
|
||||
return TVMVersion(TVM_MAJOR,TVM_MINOR,TVM_PATCH,TVM_BUILD,TVM_VERSIONSTAGE);
|
||||
return TVMVersion(CROSSLANG_MAJOR,CROSSLANG_MINOR,CROSSLANG_PATCH,0,TVMVersionStage::DevVersion);
|
||||
});
|
||||
dict->DeclareFunction(gc, "getBytecodeVersion","Get the bytecode version",{},[](GCList& ls,std::vector<TObject> args)->TObject {
|
||||
return TVMVersion(CROSSLANG_BYTECODE_MAJOR,CROSSLANG_BYTECODE_MINOR,CROSSLANG_BYTECODE_PATCH,CROSSLANG_BYTECODE_BUILD,CROSSLANG_BYTECODE_VERSIONSTAGE);
|
||||
});
|
||||
dict->DeclareFunction(gc, "getIsRunning","Is the program still running",{},[](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
return Tesses::Framework::TF_IsRunning();
|
||||
|
||||
47
src/types/random.cpp
Normal file
47
src/types/random.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
namespace Tesses::CrossLang
|
||||
{
|
||||
TRandom::TRandom() : random()
|
||||
{
|
||||
|
||||
}
|
||||
TRandom::TRandom(uint64_t seed) : random(seed)
|
||||
{
|
||||
|
||||
}
|
||||
std::string TRandom::TypeName()
|
||||
{
|
||||
return "Random";
|
||||
}
|
||||
TObject TRandom::CallMethod(GCList& ls,std::string name, std::vector<TObject> args)
|
||||
{
|
||||
if(name == "Next")
|
||||
{
|
||||
int64_t first;
|
||||
int64_t second;
|
||||
if(GetArgument(args,0,first))
|
||||
{
|
||||
if(GetArgument(args,1,second))
|
||||
{
|
||||
return (int64_t)random.Next((int32_t)first,(int32_t)second);
|
||||
}
|
||||
|
||||
return (int64_t)random.Next((uint32_t)first);
|
||||
}
|
||||
|
||||
return random.Next();
|
||||
|
||||
}
|
||||
|
||||
if(name == "NextByte")
|
||||
{
|
||||
return (int64_t)random.NextByte();
|
||||
}
|
||||
|
||||
if(name == "ToString") {
|
||||
return "";
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
}
|
||||
@@ -210,7 +210,11 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
TObjectStream::~TObjectStream()
|
||||
{
|
||||
Close();
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
dict->CallMethod(*ls,"Close",{});
|
||||
}
|
||||
delete this->ls;
|
||||
}
|
||||
|
||||
|
||||
@@ -169,6 +169,26 @@ namespace Tesses::CrossLang {
|
||||
|
||||
}
|
||||
}
|
||||
void TObjectVFS::Lock(Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
GCList ls(this->ls->GetGC());
|
||||
dict->CallMethod(ls, "Lock",{path});
|
||||
|
||||
}
|
||||
}
|
||||
void TObjectVFS::Unlock(Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
GCList ls(this->ls->GetGC());
|
||||
dict->CallMethod(ls, "Unlock",{path});
|
||||
|
||||
}
|
||||
}
|
||||
bool TObjectVFS::RegularFileExists(Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
|
||||
@@ -573,8 +593,12 @@ namespace Tesses::CrossLang {
|
||||
}
|
||||
TObjectVFS::~TObjectVFS()
|
||||
{
|
||||
|
||||
Close();
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
GCList ls(this->ls->GetGC());
|
||||
dict->CallMethod(ls,"Close",{});
|
||||
}
|
||||
delete this->ls;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +118,168 @@ namespace Tesses::CrossLang
|
||||
throw VMException(errorMessage);
|
||||
}
|
||||
|
||||
TDictionary* TFile::MetadataDecode(GCList& ls, size_t midx)
|
||||
{
|
||||
if(midx >= this->metadata.size()) return nullptr;
|
||||
if(this->metadata[midx].second.empty()) return nullptr;
|
||||
if(this->metadata[midx].second[0] != 8) return nullptr;
|
||||
size_t index = 0;
|
||||
auto& bytes = this->metadata[midx].second;
|
||||
|
||||
std::function<TObject()> parseEnt;
|
||||
parseEnt = [&]()->TObject {
|
||||
if(index >= bytes.size()) throw std::out_of_range("Abrupt end of metadata");
|
||||
switch(bytes[index++])
|
||||
{
|
||||
case 0:
|
||||
return false;
|
||||
case 1:
|
||||
return true;
|
||||
case 2:
|
||||
return nullptr;
|
||||
case 3:
|
||||
{
|
||||
if(index + 8 <= bytes.size())
|
||||
{
|
||||
auto val= BitConverter::ToUint64BE(bytes[index]);
|
||||
index+=8;
|
||||
int64_t val2;
|
||||
memcpy(&val2,&val,sizeof(val));
|
||||
return val2;
|
||||
}
|
||||
else throw std::out_of_range("Abrupt end of metadata");
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
if(index + 8 <= bytes.size())
|
||||
{
|
||||
auto val= BitConverter::ToDoubleBE(bytes[index]);
|
||||
index+=8;
|
||||
return val;
|
||||
}
|
||||
else throw std::out_of_range("Abrupt end of metadata");
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
|
||||
if(index + 1 <= bytes.size())
|
||||
{
|
||||
return (char)bytes[index++];
|
||||
}
|
||||
else throw std::out_of_range("Abrupt end of metadata");
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
if(index + 4 <= bytes.size())
|
||||
{
|
||||
auto val= BitConverter::ToUint32BE(bytes[index]);
|
||||
index+=4;
|
||||
return this->strings.at((size_t)val);
|
||||
} else throw std::out_of_range("Abrupt end of metadata");
|
||||
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
if(index + 4 <= bytes.size())
|
||||
{
|
||||
auto val= BitConverter::ToUint32BE(bytes[index]);
|
||||
index+=4;
|
||||
std::vector<TObject> items;
|
||||
for(uint32_t i = 0; i < val; i++)
|
||||
{
|
||||
items.push_back(parseEnt());
|
||||
}
|
||||
|
||||
return TList::Create(ls,items.begin(),items.end());
|
||||
} else throw std::out_of_range("Abrupt end of metadata");
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
if(index + 4 <= bytes.size())
|
||||
{
|
||||
auto val= BitConverter::ToUint32BE(bytes[index]);
|
||||
index+=4;
|
||||
std::vector<TDItem> items;
|
||||
|
||||
for(uint32_t i = 0; i < val; i++)
|
||||
{
|
||||
if(index + 4 <= bytes.size())
|
||||
{
|
||||
auto val2= BitConverter::ToUint32BE(bytes[index]);
|
||||
index+=4;
|
||||
std::string& text=this->strings.at((size_t)val2);
|
||||
items.emplace_back(text,parseEnt());
|
||||
} else throw std::out_of_range("Abrupt end of metadata");
|
||||
|
||||
}
|
||||
|
||||
return TDictionary::Create(ls, items.begin(),items.end());
|
||||
}else throw std::out_of_range("Abrupt end of metadata");
|
||||
break;
|
||||
case 9:
|
||||
{
|
||||
if(index + 4 <= bytes.size())
|
||||
{
|
||||
auto val= BitConverter::ToUint32BE(bytes[index]);
|
||||
index+=4;
|
||||
auto ba = TByteArray::Create(ls);
|
||||
ba->data = this->resources.at((size_t)val);
|
||||
return ba;
|
||||
} else throw std::out_of_range("Abrupt end of metadata");
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
{
|
||||
if(index + 4 <= bytes.size())
|
||||
{
|
||||
auto val= BitConverter::ToUint32BE(bytes[index]);
|
||||
index+=4;
|
||||
return std::make_shared<EmbedStream>(ls.GetGC(),this,val);
|
||||
} else throw std::out_of_range("Abrupt end of metadata");
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
{
|
||||
|
||||
auto data = parseEnt();
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(data,dict))
|
||||
{
|
||||
return std::make_shared<EmbedDirectory>(ls.GetGC(),dict);
|
||||
}
|
||||
else return Undefined();
|
||||
}
|
||||
break;
|
||||
case 12:
|
||||
{
|
||||
if(index + 4 <= bytes.size())
|
||||
{
|
||||
auto val= BitConverter::ToUint32BE(bytes[index]);
|
||||
index+=4;
|
||||
ls.GetGC()->BarrierBegin();
|
||||
auto em = TExternalMethod::Create(ls,"",{},[val,this](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
return std::make_shared<EmbedStream>(ls.GetGC(),this,val);
|
||||
});
|
||||
em->watch.push_back(this);
|
||||
ls.GetGC()->BarrierEnd();
|
||||
|
||||
return em;
|
||||
} else throw std::out_of_range("Abrupt end of metadata");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Invalid metadata opcode");
|
||||
}
|
||||
};
|
||||
|
||||
TDictionary* dict_res;
|
||||
TObject ent = parseEnt();
|
||||
if(GetObjectHeap(ent, dict_res)) return dict_res;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TFile::Load(GC* gc, std::shared_ptr<Tesses::Framework::Streams::Stream> stream)
|
||||
{
|
||||
|
||||
@@ -166,10 +328,8 @@ namespace Tesses::CrossLang
|
||||
}
|
||||
else if(strncmp(table_name,"RESO",4) == 0) //resources (using embed)
|
||||
{
|
||||
std::vector<uint8_t> data;
|
||||
data.resize(tableLen);
|
||||
Ensure(stream,data.data(), tableLen);
|
||||
this->resources.push_back(data);
|
||||
auto& data = this->resources.emplace_back(tableLen);
|
||||
Ensure(stream,data.data(), data.size());
|
||||
}
|
||||
else if(strncmp(table_name,"CHKS",4) == 0 && gc != nullptr) //chunks
|
||||
{
|
||||
@@ -268,13 +428,22 @@ namespace Tesses::CrossLang
|
||||
this->classes.push_back(cls);
|
||||
}
|
||||
}
|
||||
else if(strncmp(table_name,"META",4) == 0) //structured metadata
|
||||
{
|
||||
if(tableLen > 4)
|
||||
{
|
||||
auto name = this->GetString(stream);
|
||||
auto& data = this->metadata.emplace_back(name, std::vector<uint8_t>(tableLen-4));
|
||||
Ensure(stream,data.second.data(), tableLen-4);
|
||||
}
|
||||
else throw VMException("meta tag is not valid");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<uint8_t> data;
|
||||
data.resize(tableLen);
|
||||
Ensure(stream,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));
|
||||
auto& data = this->sections.emplace_back(std::string(table_name, 4), std::vector<uint8_t>(tableLen));
|
||||
Ensure(stream,data.second.data(), tableLen);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
202
src/vm/vm.cpp
202
src/vm/vm.cpp
@@ -3411,6 +3411,17 @@ namespace Tesses::CrossLang {
|
||||
cse.back()->Push(gc, nullptr);
|
||||
return false;
|
||||
}
|
||||
if(key == "ReadLineHttp")
|
||||
{
|
||||
std::string line;
|
||||
if(textReader->ReadLineHttp(line))
|
||||
{
|
||||
cse.back()->Push(gc, line);
|
||||
return false;
|
||||
}
|
||||
cse.back()->Push(gc, nullptr);
|
||||
return false;
|
||||
}
|
||||
if(key == "ReadAllLines")
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
@@ -3763,6 +3774,7 @@ namespace Tesses::CrossLang {
|
||||
if(svr != nullptr)
|
||||
{
|
||||
auto mountable = std::dynamic_pointer_cast<Tesses::Framework::Http::MountableServer>(svr);
|
||||
auto routable = std::dynamic_pointer_cast<Tesses::Framework::Http::RouteServer>(svr);
|
||||
|
||||
if(mountable != nullptr)
|
||||
{
|
||||
@@ -3793,6 +3805,82 @@ namespace Tesses::CrossLang {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(routable != nullptr)
|
||||
{
|
||||
if(key == "Add")
|
||||
{
|
||||
std::string method;
|
||||
std::string pattern;
|
||||
TCallable* callable;
|
||||
if(GetArgument(args,0,method) && GetArgument(args,1,pattern) && GetArgumentHeap(args,2,callable))
|
||||
{
|
||||
routable->Add(method,pattern, callable->ToRouteServerRequestHandler(gc));
|
||||
}
|
||||
}
|
||||
else if(key == "Delete")
|
||||
{
|
||||
std::string pattern;
|
||||
TCallable* callable;
|
||||
if(GetArgument(args,0,pattern) && GetArgumentHeap(args,1,callable))
|
||||
{
|
||||
routable->Delete(pattern, callable->ToRouteServerRequestHandler(gc));
|
||||
}
|
||||
}
|
||||
else if(key == "Get")
|
||||
{
|
||||
std::string pattern;
|
||||
TCallable* callable;
|
||||
if(GetArgument(args,0,pattern) && GetArgumentHeap(args,1,callable))
|
||||
{
|
||||
routable->Get(pattern, callable->ToRouteServerRequestHandler(gc));
|
||||
}
|
||||
}
|
||||
else if(key == "Options")
|
||||
{
|
||||
std::string pattern;
|
||||
TCallable* callable;
|
||||
if(GetArgument(args,0,pattern) && GetArgumentHeap(args,1,callable))
|
||||
{
|
||||
routable->Options(pattern, callable->ToRouteServerRequestHandler(gc));
|
||||
}
|
||||
}
|
||||
else if(key == "Patch")
|
||||
{
|
||||
std::string pattern;
|
||||
TCallable* callable;
|
||||
if(GetArgument(args,0,pattern) && GetArgumentHeap(args,1,callable))
|
||||
{
|
||||
routable->Patch(pattern, callable->ToRouteServerRequestHandler(gc));
|
||||
}
|
||||
}
|
||||
else if(key == "Post")
|
||||
{
|
||||
std::string pattern;
|
||||
TCallable* callable;
|
||||
if(GetArgument(args,0,pattern) && GetArgumentHeap(args,1,callable))
|
||||
{
|
||||
routable->Post(pattern, callable->ToRouteServerRequestHandler(gc));
|
||||
}
|
||||
}
|
||||
else if(key == "Put")
|
||||
{
|
||||
std::string pattern;
|
||||
TCallable* callable;
|
||||
if(GetArgument(args,0,pattern) && GetArgumentHeap(args,1,callable))
|
||||
{
|
||||
routable->Put(pattern, callable->ToRouteServerRequestHandler(gc));
|
||||
}
|
||||
}
|
||||
else if(key == "Trace")
|
||||
{
|
||||
std::string pattern;
|
||||
TCallable* callable;
|
||||
if(GetArgument(args,0,pattern) && GetArgumentHeap(args,1,callable))
|
||||
{
|
||||
routable->Trace(pattern, callable->ToRouteServerRequestHandler(gc));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(key == "Handle")
|
||||
{
|
||||
cse.back()->Push(gc,IHttpServer_Handle(svr,args));
|
||||
@@ -4107,6 +4195,26 @@ namespace Tesses::CrossLang {
|
||||
cse.back()->Push(gc, nullptr);
|
||||
return false;
|
||||
}
|
||||
if(key == "Lock")
|
||||
{
|
||||
Tesses::Framework::Filesystem::VFSPath filename;
|
||||
if(GetArgumentAsPath(args,0,filename))
|
||||
{
|
||||
vfs->Lock(filename);
|
||||
}
|
||||
cse.back()->Push(gc, nullptr);
|
||||
return false;
|
||||
}
|
||||
if(key == "Unlock")
|
||||
{
|
||||
Tesses::Framework::Filesystem::VFSPath filename;
|
||||
if(GetArgumentAsPath(args,0,filename))
|
||||
{
|
||||
vfs->Unlock(filename);
|
||||
}
|
||||
cse.back()->Push(gc, nullptr);
|
||||
return false;
|
||||
}
|
||||
if(key == "DeleteDirectoryRecurse")
|
||||
{
|
||||
Tesses::Framework::Filesystem::VFSPath dirname;
|
||||
@@ -4220,31 +4328,33 @@ namespace Tesses::CrossLang {
|
||||
auto cls = dynamic_cast<TClassObject*>(obj);
|
||||
auto aArray=dynamic_cast<TAssociativeArray*>(obj);
|
||||
auto ttask = dynamic_cast<TTask*>(obj);
|
||||
auto file = dynamic_cast<TFile*>(obj);
|
||||
|
||||
if(file != nullptr)
|
||||
{
|
||||
if(key == "MetadataDecode")
|
||||
{
|
||||
int64_t index;
|
||||
if(GetArgument(args,0, index) && (size_t)index < file->metadata.size())
|
||||
{
|
||||
cse.back()->Push(gc,file->MetadataDecode(ls,(size_t)index));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "MetadataName")
|
||||
{
|
||||
int64_t index;
|
||||
if(GetArgument(args,0, index) && (size_t)index < file->metadata.size())
|
||||
{
|
||||
cse.back()->Push(gc,file->metadata.at((size_t)index).first);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
cse.back()->Push(gc,Undefined());
|
||||
return false;
|
||||
}
|
||||
if(ttask != nullptr)
|
||||
{
|
||||
if(key == "SetSucceeded")
|
||||
{
|
||||
if(args.size() > 0)
|
||||
{
|
||||
ttask->SetSucceeded(args[0]);
|
||||
}
|
||||
cse.back()->Push(gc, Undefined());
|
||||
return false;
|
||||
}
|
||||
if(key == "SetFailed")
|
||||
{
|
||||
if(args.size() > 0)
|
||||
{
|
||||
try {
|
||||
throw VMByteCodeException(gc,args[0],cse.back());
|
||||
} catch(...) {
|
||||
ttask->SetFailed(std::current_exception());
|
||||
}
|
||||
}
|
||||
cse.back()->Push(gc, Undefined());
|
||||
return false;
|
||||
}
|
||||
if(key == "ContinueWith")
|
||||
{
|
||||
TCallable* callable2;
|
||||
@@ -5581,6 +5691,15 @@ namespace Tesses::CrossLang {
|
||||
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::TextStreams::TextWriter>>(instance))
|
||||
{
|
||||
auto writer = std::get<std::shared_ptr<Tesses::Framework::TextStreams::TextWriter>>(instance);
|
||||
auto stringWriter = std::dynamic_pointer_cast<Tesses::Framework::TextStreams::StringWriter>(writer);
|
||||
if(stringWriter != nullptr)
|
||||
{
|
||||
if(key == "Text")
|
||||
{
|
||||
cse.back()->Push(gc, stringWriter->GetString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "NewLine")
|
||||
{
|
||||
cse.back()->Push(gc,writer->newline);
|
||||
@@ -5922,6 +6041,32 @@ namespace Tesses::CrossLang {
|
||||
cse.back()->Push(gc, list);
|
||||
return false;
|
||||
}
|
||||
else if(key == "MetadataCount")
|
||||
{
|
||||
|
||||
cse.back()->Push(gc, (int64_t)file->metadata.size());
|
||||
return false;
|
||||
}
|
||||
else if(key == "Metadata")
|
||||
{
|
||||
TList* meta = TList::Create(ls);
|
||||
gc->BarrierBegin();
|
||||
for(size_t i = 0; i < file->metadata.size(); i++)
|
||||
{
|
||||
meta->Add(
|
||||
TDictionary::Create(ls,
|
||||
{
|
||||
TDItem("Name", file->metadata[i].first),
|
||||
TDItem("Index",(int64_t)i)
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
gc->BarrierEnd();
|
||||
|
||||
cse.back()->Push(gc, meta);
|
||||
return false;
|
||||
}
|
||||
else if(key == "Sections")
|
||||
{
|
||||
TList* sections = TList::Create(ls);
|
||||
@@ -6245,6 +6390,19 @@ namespace Tesses::CrossLang {
|
||||
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::TextStreams::TextWriter>>(instance))
|
||||
{
|
||||
auto writer = std::get<std::shared_ptr<Tesses::Framework::TextStreams::TextWriter>>(instance);
|
||||
auto stringWriter = std::dynamic_pointer_cast<Tesses::Framework::TextStreams::StringWriter>(writer);
|
||||
if(stringWriter != nullptr)
|
||||
{
|
||||
if(key == "Text")
|
||||
{
|
||||
if(std::holds_alternative<std::string>(value))
|
||||
{
|
||||
stringWriter->GetString() = std::get<std::string>(value);
|
||||
}
|
||||
cse.back()->Push(gc, stringWriter->GetString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(key == "NewLine")
|
||||
{
|
||||
if(std::holds_alternative<std::string>(value))
|
||||
|
||||
Reference in New Issue
Block a user