mirror of
https://onedev.site.tesses.net/crosslang/crosslangextras
synced 2026-02-08 17:15:45 +00:00
Adding some documentation to crosslang shell
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
"template_info": {
|
||||
"type": "compile_tool"
|
||||
},
|
||||
"template_ignored_files": ["bin","obj"]
|
||||
"template_ignored_files": ["bin","obj"],
|
||||
"description": "A tool that can be a dependency to a project (including libraries) that runs at compile time"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"template_info": {
|
||||
"type": "console"
|
||||
},
|
||||
"template_ignored_files": ["bin","obj"]
|
||||
"template_ignored_files": ["bin","obj"],
|
||||
"description": "A console application"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"template_info": {
|
||||
"type": "lib"
|
||||
},
|
||||
"template_ignored_files": ["bin","obj"]
|
||||
"template_ignored_files": ["bin","obj"],
|
||||
"description": "A crosslang library"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"homepage": "https://crosslang.tesseslanguage.com/",
|
||||
"license": "MIT",
|
||||
"template_name": "template",
|
||||
"description": "A template for a project",
|
||||
"template_info": {
|
||||
"type": "template",
|
||||
"template_name": "mytemplate",
|
||||
|
||||
2
Templates/tool/.crossarchiveignore
Normal file
2
Templates/tool/.crossarchiveignore
Normal file
@@ -0,0 +1,2 @@
|
||||
bin
|
||||
obj
|
||||
25
Templates/tool/cross.json
Normal file
25
Templates/tool/cross.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"dependencies": [],
|
||||
"info": {
|
||||
"template_ignored_files": [
|
||||
"bin",
|
||||
"obj"
|
||||
],
|
||||
"template_info": {
|
||||
"type": "tool",
|
||||
"description": "This is my tool",
|
||||
"toolname": "changeme"
|
||||
},
|
||||
"template_extra_text_ftles": [],
|
||||
"template_project_dependencies": [],
|
||||
"template_name": "tool",
|
||||
"description": "A crosslang tool that you can run via crosslang tool",
|
||||
"type": "template",
|
||||
"maintainer": "Mike Nolan",
|
||||
"repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras",
|
||||
"homepage": "https://crosslang.tesseslanguage.com/",
|
||||
"license": "MIT"
|
||||
},
|
||||
"version": "1.0.0.0-prod",
|
||||
"name": "Tesses.CrossLang.Template.Tool"
|
||||
}
|
||||
30
Templates/tool/src/main.tcross
Normal file
30
Templates/tool/src/main.tcross
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
you must change the toolname in cross.json -> info -> toolname
|
||||
to run the tool from the project folder use crosslang tool-test [flags-options-and-arguments]
|
||||
to install the tool use crosslang install-tool from working directory
|
||||
to run the tool after being installed use crosslang tool <toolname> [flags-and-options-and-arguments]
|
||||
you can push the tool to cpkg
|
||||
*/
|
||||
func RunTool(arg)
|
||||
{
|
||||
//Flags are strings without the -- just like from Tesses.CrossLang.Args, so --Johnny would yield a string with the value Johnny
|
||||
//Options are a dictionary with a field named Key which is the name without the -- just like from Tesses.CrossLang.Args where the Value is from after the = sign just like Tesses.CrossLang.Args, so --John=Joel would yield a dictionary like this {Key="John", Value="Joel"}
|
||||
//Arguments is a list of strings when an argument does not start with -- or is after the -- (it starts after the tool name)
|
||||
//ToolName is the tool name
|
||||
Console.WriteLine($"TOOLNAME: {arg.ToolName}");
|
||||
Console.WriteLine("FLAGS:");
|
||||
each(var flag : arg.Flags)
|
||||
{
|
||||
Console.WriteLine(flag);
|
||||
}
|
||||
Console.WriteLine("OPTIONS:");
|
||||
each(var option : arg.Options)
|
||||
{
|
||||
Console.WriteLine($"{option.Key}: {option.Value}");
|
||||
}
|
||||
Console.WriteLine("ARGUMENTS:");
|
||||
each(var argument : arg.Arguments)
|
||||
{
|
||||
Console.WriteLine(argument);
|
||||
}
|
||||
}
|
||||
@@ -58,8 +58,8 @@ func Tesses.CrossLang.PackageManager()
|
||||
},
|
||||
GetPackage = (this,name, version) =>
|
||||
{
|
||||
var v = Tesses.CrossLang.Version.Parse(version);
|
||||
var useCache = v.Stage != Tesses.CrossLang.Version.Dev;
|
||||
var v = Version.Parse(version);
|
||||
var useCache = v.Stage != "dev";
|
||||
var pkgFile = packageCache / name / v.ToString();
|
||||
if(useCache && FS.Local.RegularFileExists(pkgFile))
|
||||
{
|
||||
@@ -97,13 +97,13 @@ func Tesses.CrossLang.PackageManager()
|
||||
if(this.Offline || pkgServers.Count == 0)
|
||||
{
|
||||
//user has declared they are offline or don't have packageServers look through packages locally
|
||||
var version = Tesses.CrossLang.Version.Create(0,0,0,0,0);
|
||||
var version = new Version(0,0,0,0,"dev");
|
||||
var configRoot = Path.FromString(Env.Config) / "Tesses" / "CrossLang";
|
||||
var dir = configRoot / "PackageCache" / name;
|
||||
if(FS.Local.DirectoryExists(dir))
|
||||
each(var f : FS.Local.EnumeratePaths(dir))
|
||||
{
|
||||
var v = Tesses.CrossLang.Version.Parse(f.GetFileName());
|
||||
var v = Version.Parse(f.GetFileName());
|
||||
if(v >= version)
|
||||
{
|
||||
version = v;
|
||||
|
||||
@@ -32,8 +32,8 @@ func Tesses.CrossLang.BuildTool(pm)
|
||||
strm.Close();
|
||||
var strm = FS.Local.OpenFile(pkgPath,"rb");
|
||||
|
||||
var package = Tesses.CrossLang.CrossVMFile();
|
||||
package.Read(strm);
|
||||
|
||||
var package = VM.LoadExecutable(strm);
|
||||
strm.Close();
|
||||
|
||||
var deps = [];
|
||||
@@ -42,6 +42,10 @@ func Tesses.CrossLang.BuildTool(pm)
|
||||
{
|
||||
deps.Add(this.GetPackageDependencies(dep.Name, dep.Version, dir));
|
||||
}
|
||||
each(var pkg : package.Tools)
|
||||
{
|
||||
dep.Add(this.GetPackageDependencies(dep.Name, dep.Version, dir));
|
||||
}
|
||||
|
||||
return {
|
||||
Name = name,
|
||||
@@ -55,6 +59,7 @@ func Tesses.CrossLang.BuildTool(pm)
|
||||
var dir = FS.MakeFull(projectDirectory);
|
||||
var dirStr = dir.ToString();
|
||||
|
||||
|
||||
each(var item : this.DirectoriesCompiled)
|
||||
{
|
||||
if(item.Path == dirStr) return item.Data;
|
||||
@@ -71,6 +76,7 @@ func Tesses.CrossLang.BuildTool(pm)
|
||||
var objDir = "obj";
|
||||
var srcDir = "src";
|
||||
var resDir = "res";
|
||||
var icon = "";
|
||||
if(TypeOf(configData.name) != "Undefined")
|
||||
name = configData.name;
|
||||
|
||||
@@ -87,6 +93,8 @@ func Tesses.CrossLang.BuildTool(pm)
|
||||
resDir = configData.resource_directory;
|
||||
if(TypeOf(configData.info) != "Undefined")
|
||||
info = configData.info;
|
||||
if(TypeOf(configData.icon) != "Undefined")
|
||||
icon = configData.icon;
|
||||
|
||||
|
||||
|
||||
@@ -108,7 +116,7 @@ func Tesses.CrossLang.BuildTool(pm)
|
||||
}
|
||||
FS.WriteAllText(FS.Local, dir / ".crossarchiveignore", ignored);
|
||||
}
|
||||
FS.CreateArchive(subdir, outFile, name, version, Json.Encode(info));
|
||||
FS.CreateArchive(subdir, outFile, name, version, Json.Encode(info),icon);
|
||||
outFile.Close();
|
||||
subdir.Close();
|
||||
return null;
|
||||
@@ -140,6 +148,7 @@ func Tesses.CrossLang.BuildTool(pm)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
each(var item : this.DirectoriesCompiled)
|
||||
{
|
||||
if(item.Path == dirStr) return item.Data;
|
||||
@@ -168,7 +177,8 @@ func Tesses.CrossLang.BuildTool(pm)
|
||||
env.GetDictionary().RunTool({
|
||||
Project = FS.SubdirFilesystem(FS.Local, dir),
|
||||
ProjectInfo = info,
|
||||
GeneratedSource = sources
|
||||
GeneratedSource = sources,
|
||||
Config = this.Config
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -182,6 +192,7 @@ func Tesses.CrossLang.BuildTool(pm)
|
||||
}
|
||||
|
||||
var file_deps = [];
|
||||
var file_tools = [];
|
||||
|
||||
each(var dep : dependencies)
|
||||
{
|
||||
@@ -192,6 +203,13 @@ func Tesses.CrossLang.BuildTool(pm)
|
||||
Version = dep.Version
|
||||
});
|
||||
}
|
||||
else if(dep.Info.type == "compile_tool")
|
||||
{
|
||||
file_tools.Add({
|
||||
Name = dep.Name,
|
||||
Version = dep.Version
|
||||
});
|
||||
}
|
||||
walk_for_compiling(dep,dir / outputDir);
|
||||
}
|
||||
|
||||
@@ -225,6 +243,8 @@ func Tesses.CrossLang.BuildTool(pm)
|
||||
Version = version,
|
||||
Sources = sources,
|
||||
Info = Json.Encode(info),
|
||||
Icon = icon,
|
||||
Tools = file_tools,
|
||||
ResourceFileSystem = FS.SubdirFilesystem(FS.Local, dir / resDir),
|
||||
Dependencies = file_deps,
|
||||
Output = outFile
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
func Tesses.CrossLang.CrossVMFile()
|
||||
{
|
||||
return {
|
||||
Info = "",
|
||||
Name = "",
|
||||
Version = "",
|
||||
Dependencies = [],
|
||||
Chunks = [],
|
||||
Strings = [],
|
||||
Functions = [],
|
||||
Resources = [],
|
||||
Sections = [],
|
||||
Ensure = (this,strm,buff,len) =>{
|
||||
if(strm.ReadBlock(buff,0,len) != len)
|
||||
throw $"Could not read {len} byte(s)";
|
||||
},
|
||||
EnsureInt = (this,strm)=>{
|
||||
var buff = ByteArray(4);
|
||||
this.Ensure(strm,buff,4);
|
||||
var number = 0;
|
||||
number |= buff[0] << 24;
|
||||
number |= buff[1] << 16;
|
||||
number |= buff[2] << 8;
|
||||
number |= buff[3];
|
||||
return number;
|
||||
},
|
||||
EnsureString = (this,strm)=>{
|
||||
var len = this.EnsureInt(strm);
|
||||
var buff = ByteArray(len);
|
||||
this.Ensure(strm, buff,len);
|
||||
return buff.ToString();
|
||||
},
|
||||
GetString = (this,strm)=>{
|
||||
var index = this.EnsureInt(strm);
|
||||
if(index < this.Strings.Count) return this.Strings[index];
|
||||
throw $"{index} is not less than {this.Strings.Count}";
|
||||
},
|
||||
Read = (this,stream)=>{
|
||||
var header = ByteArray(8);
|
||||
this.Ensure(stream, header, header.Count);
|
||||
|
||||
var hdrStr = header.ToString();
|
||||
if(hdrStr != "TCROSSVM") throw "Invalid TCrossVM image.";
|
||||
|
||||
this.Ensure(stream, header, 5);
|
||||
|
||||
var version = Tesses.CrossLang.Version.FromBytes(header, 0);
|
||||
|
||||
if(version > Tesses.CrossLang.Version.Current) throw "Runtime is too old.";
|
||||
this.Ensure(stream, header, 5);
|
||||
|
||||
|
||||
this.Version = Tesses.CrossLang.Version.FromBytes(header,0);
|
||||
|
||||
var sec = ByteArray(4);
|
||||
var sectionCount = this.EnsureInt(stream);
|
||||
|
||||
|
||||
for(var i = 0; i < sectionCount; i++)
|
||||
{
|
||||
|
||||
this.Ensure(stream, sec, sec.Count);
|
||||
hdrStr = sec.ToString();
|
||||
var tableLength = this.EnsureInt(stream);
|
||||
if(hdrStr == "NAME")
|
||||
{
|
||||
this.Name = this.GetString(stream);
|
||||
}
|
||||
else if(hdrStr == "INFO")
|
||||
{
|
||||
this.Info = this.GetString(stream);
|
||||
}
|
||||
else if(hdrStr == "DEPS")
|
||||
{
|
||||
var _name = this.GetString(stream);
|
||||
this.Ensure(stream, header, 5);
|
||||
var _version = Tesses.CrossLang.Version.FromBytes(header,0);
|
||||
this.Dependencies.Add({
|
||||
Name = _name,
|
||||
Version = _version
|
||||
});
|
||||
}
|
||||
else if(hdrStr == "RESO")
|
||||
{
|
||||
var resource = ByteArray(tableLength);
|
||||
this.Ensure(stream,resource,resource.Count);
|
||||
this.Resources.Add(resource);
|
||||
}
|
||||
else if(hdrStr == "CHKS")
|
||||
{
|
||||
var chunkCount = this.EnsureInt(stream);
|
||||
for(var j = 0; j < chunkCount; j++)
|
||||
{
|
||||
var _args = [];
|
||||
var _argCount = this.EnsureInt(stream);
|
||||
for(var k = 0; k < _argCount; k++)
|
||||
{
|
||||
_args.Add(this.GetString(stream));
|
||||
}
|
||||
var _code = ByteArray(this.EnsureInt(stream));
|
||||
this.Ensure(stream,_code,_code.Count);
|
||||
var chunk = {
|
||||
Arguments = _args,
|
||||
Code = _code
|
||||
};
|
||||
this.Chunks.Add(chunk);
|
||||
}
|
||||
}
|
||||
else if(hdrStr == "FUNS")
|
||||
{
|
||||
var funLen = this.EnsureInt(stream);
|
||||
for(var j = 0; j < funLen; j++)
|
||||
{
|
||||
var fnPartsCount = this.EnsureInt(stream);
|
||||
var documentation = "";
|
||||
var fnParts = [];
|
||||
for(var k = 0; k < fnPartsCount; k++)
|
||||
{
|
||||
if(k == 0) documentation = this.GetString(stream);
|
||||
else fnParts.Add(this.GetString(stream));
|
||||
}
|
||||
var fnId = this.EnsureInt(stream);
|
||||
this.Functions.Add({
|
||||
Documentation=documentation,
|
||||
FunctionNameParts = fnParts,
|
||||
Closure = fnId
|
||||
});
|
||||
}
|
||||
}
|
||||
else if(hdrStr == "STRS")
|
||||
{
|
||||
var strcnt = this.EnsureInt(stream);
|
||||
for(var j = 0; j < strcnt; j++)
|
||||
{
|
||||
this.Strings.Add(this.EnsureString(stream));
|
||||
}
|
||||
}
|
||||
else {
|
||||
var data = ByteArray(tableLength);
|
||||
this.Ensure(stream,data,data.Count);
|
||||
this.Sections.Add({
|
||||
Name=hdrStr,
|
||||
Data = data
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
19
Tesses.CrossLang.BuildEssentials/src/helpers.tcross
Normal file
19
Tesses.CrossLang.BuildEssentials/src/helpers.tcross
Normal file
@@ -0,0 +1,19 @@
|
||||
func Tesses.CrossLang.GetNameAndDescription(name)
|
||||
{
|
||||
var strm = FS.Local.OpenFile(name,"rb");
|
||||
var file = VM.LoadExecutable(strm);
|
||||
|
||||
strm.Close();
|
||||
|
||||
var name = file.Name;
|
||||
|
||||
var j = Json.Decode(file.Info);
|
||||
var description = TypeOf(j.description) == "String" ? j.description : "";
|
||||
|
||||
if(j.type == "template")
|
||||
name = TypeOf(j.template_name) == "String" ? j.template_name : name;
|
||||
else if(j.type == "tool")
|
||||
name = TypeOf(j.toolname) == "String" ? j.toolname : name;
|
||||
|
||||
return $"{name}: {description}";
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
func Tesses.CrossLang.Version.Create(major,minor,patch,build,stage)
|
||||
{
|
||||
return {
|
||||
Major = major,
|
||||
Minor = minor,
|
||||
Patch = patch,
|
||||
Build = build,
|
||||
Stage = stage,
|
||||
getBuildAsInt = (this)=>{
|
||||
return ((this.Build & 0x3FFF) << 2) | ((this.Stage & 0x03));
|
||||
},
|
||||
getVersionInt = (this)=>{
|
||||
return ((this.Major & 0xFF) << 32) | ((this.Minor & 0xFF) << 24)
|
||||
| ((this.Patch & 0xFF) << 16) | (this.BuildAsInt & 0xFFFF);
|
||||
},
|
||||
operator< = (this,right)=>{
|
||||
return this.VersionInt < right.VersionInt;
|
||||
},
|
||||
operator> = (this,right)=>{
|
||||
return this.VersionInt > right.VersionInt;
|
||||
},
|
||||
operator== = (this,right)=>{
|
||||
return this.VersionInt == right.VersionInt;
|
||||
},
|
||||
operator<= = (this,right)=>{
|
||||
return this.VersionInt <= right.VersionInt;
|
||||
},
|
||||
operator>= = (this,right)=>{
|
||||
return this.VersionInt >= right.VersionInt;
|
||||
},
|
||||
operator!= = (this,right)=>{
|
||||
return this.VersionInt != right.VersionInt;
|
||||
},
|
||||
ToString = (this) => {
|
||||
var stage = this.Stage == 0 ? "dev" : this.Stage == 1 ? "alpha" : this.Stage == 2 ? "beta" : "prod";
|
||||
return $"{this.Major & 0xFF}.{this.Minor & 0xFF}.{this.Patch & 0xFF}.{this.Build & 0x3FFF}-{stage}";
|
||||
},
|
||||
ToBytes = (this, buff, off) => {
|
||||
if((buff.Count - offset) < 5) throw "Not long enough";
|
||||
buff[off] = this.Major;
|
||||
buff[off+1] = this.Minor;
|
||||
buff[off+2] = this.Patch;
|
||||
var b = this.BuildAsInt;
|
||||
buff[off+3] = (b >> 8) & 0xFF;
|
||||
buff[off+4] = b & 0xFF;
|
||||
}
|
||||
};
|
||||
}
|
||||
func Tesses.CrossLang.Version.FromBytes(buffer, offset)
|
||||
{
|
||||
|
||||
if((buffer.Count - offset) < 5) throw "Not long enough";
|
||||
|
||||
var major = buffer[offset];
|
||||
var minor = buffer[offset+1];
|
||||
var patch = buffer[offset+2];
|
||||
|
||||
var buildI = (buffer[offset+3] << 8) | (buffer[offset+4]);
|
||||
|
||||
var build = (buildI >> 2);
|
||||
|
||||
|
||||
var stage = buildI & 0x03;
|
||||
|
||||
var b = Tesses.CrossLang.Version.Create(major,minor,patch,build,stage);
|
||||
return b;
|
||||
}
|
||||
func Tesses.CrossLang.Version.CreateEmpty()
|
||||
{
|
||||
return Tesses.CrossLang.Version.Create(1,0,0,0,Tesses.CrossLang.Version.Prod);
|
||||
}
|
||||
func Tesses.CrossLang.Version.Parse(ver)
|
||||
{
|
||||
var mySplit = ver.Split("-",false,2);
|
||||
var version = 3;
|
||||
if(mySplit.Count >= 1)
|
||||
{
|
||||
if(mySplit.Count == 2)
|
||||
{
|
||||
if(mySplit[1] == "dev") version = 0;
|
||||
else if(mySplit[1] == "alpha") version = 1;
|
||||
else if(mySplit[2] == "beta") version = 2;
|
||||
}
|
||||
var vpart = mySplit[0].Split(".",false,4);
|
||||
var major = 1;
|
||||
var minor = 0;
|
||||
var patch = 0;
|
||||
var build = 0;
|
||||
|
||||
if(vpart.Count >= 1) major = ParseLong(vpart[0]); if(TypeOf(major) != "Long") major = 1;
|
||||
if(vpart.Count >= 2) minor = ParseLong(vpart[1]); if(TypeOf(minor) != "Long") minor = 0;
|
||||
if(vpart.Count >= 3) patch = ParseLong(vpart[2]); if(TypeOf(patch) != "Long") patch = 0;
|
||||
if(vpart.Count >= 4) build = ParseLong(vpart[3]); if(TypeOf(build) != "Long") build = 0;
|
||||
|
||||
return Tesses.CrossLang.Version.Create(major,minor,patch,build,version);
|
||||
}
|
||||
}
|
||||
Tesses.CrossLang.Version.Dev = 0;
|
||||
Tesses.CrossLang.Version.Alpha = 1;
|
||||
Tesses.CrossLang.Version.Beta = 2;
|
||||
Tesses.CrossLang.Version.Prod = 3;
|
||||
|
||||
Tesses.CrossLang.Version.Current = Tesses.CrossLang.Version.Create(1,0,0,0,Tesses.CrossLang.Version.Prod);
|
||||
7
Tesses.CrossLang.Documentation/create_doc.sh
Normal file
7
Tesses.CrossLang.Documentation/create_doc.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
mkdir docs
|
||||
crosslang run > docs/Runtime.md
|
||||
cd doc_projs/RuntimeObjects
|
||||
crosslang build
|
||||
cd ../..
|
||||
crosslang run doc_projs/RuntimeObjects/bin/*.crvm > docs/RuntimeObjects.md
|
||||
14
Tesses.CrossLang.Documentation/cross.json
Normal file
14
Tesses.CrossLang.Documentation/cross.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"version": "1.0.0.0-prod",
|
||||
"info": {
|
||||
"maintainer": "Mike Nolan",
|
||||
"type": "console",
|
||||
"repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras",
|
||||
"homepage": "https://crosslang.tesseslanguage.com/",
|
||||
"license": "LGPLv3"
|
||||
},
|
||||
"project_dependencies": [
|
||||
"../Tesses.CrossLang.BuildEssentials"
|
||||
],
|
||||
"name": "Tesses.CrossLang.Documentation"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"info": {
|
||||
"type": "lib"
|
||||
},
|
||||
"version": "1.0.0.0-prod",
|
||||
"name": "CrossLang Runtime Objects (this and the root dictionaries are implcit)"
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/^Get index of string or char in string, returns -1 if not found^/
|
||||
func String.IndexOf(this, textOrChr)
|
||||
{
|
||||
|
||||
}
|
||||
/^Get index of string or char in string, returns -1 if not found^/
|
||||
func String.LastIndexOf(this, textOrChr)
|
||||
{
|
||||
|
||||
}
|
||||
/^Get the enumerator ^/
|
||||
func String.GetEnumerator(this)
|
||||
{
|
||||
|
||||
}
|
||||
/^Get the substring of a string, if length is not provided it spans the rest of the string provided by this^/
|
||||
func String.Substring(this, offset, $length)
|
||||
{
|
||||
|
||||
}
|
||||
/^Remove text from a string, if length is not provided it spans the rest of the string provided by this^/
|
||||
func String.Remove(this, offset, $length)
|
||||
{
|
||||
|
||||
}
|
||||
/^Trim the start of string till char is not chr, if chr is not provided space will be used^/
|
||||
func String.TrimStart(this, $chr)
|
||||
{
|
||||
|
||||
}
|
||||
/^Trim the end of string till char is not chr, if chr is not provided space will be used^/
|
||||
func String.TrimEnd(this, $chr)
|
||||
{
|
||||
|
||||
}
|
||||
/^Escape a crosslang string for eval, quote determines whether the string should be quoted or not, by default not^/
|
||||
func String.Escape(this, $eval)
|
||||
{
|
||||
|
||||
}
|
||||
497
Tesses.CrossLang.Documentation/docs/Runtime.md
Normal file
497
Tesses.CrossLang.Documentation/docs/Runtime.md
Normal file
@@ -0,0 +1,497 @@
|
||||
# CrossLang Runtime Documentation
|
||||
```go
|
||||
/^ Start a process ^/
|
||||
func Process.Start(process_object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether object is a list or dynamic list ^/
|
||||
func TypeIsList(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether object is a stream ^/
|
||||
func TypeIsStream(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether object is a dictionary or dynamic dictionary ^/
|
||||
func TypeIsDictionary(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether object is callable ^/
|
||||
func TypeIsCallable(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether object is a string ^/
|
||||
func TypeIsString(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether object is a number ^/
|
||||
func TypeIsNumber(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Listen (creates application loop) ^/
|
||||
func Net.Http.ListenSimpleWithLoop(server, port);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create an http request ^/
|
||||
func Net.Http.MakeRequest(url, $extra);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Url encode path ^/
|
||||
func Net.Http.UrlPathEncode(path);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Url decode query param ^/
|
||||
func Net.Http.UrlDecode(param);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Url encode query param ^/
|
||||
func Net.Http.UrlEncode(param);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get mimetype from extension ^/
|
||||
func Net.Http.MimeType(ext);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Url decode path ^/
|
||||
func Net.Http.UrlPathDecode(path);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Html encode ^/
|
||||
func Net.Http.HtmlEncode(param);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create a network stream ^/
|
||||
func Net.NetworkStream(ipv6, datagram);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether object is a double (not a long) ^/
|
||||
func TypeIsDouble(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Clear renderer with renderer draw color ^/
|
||||
func SDL2.RenderClear(renderer);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Init SDL2 ^/
|
||||
func SDL2.Init();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Present frame (you are finished with the frame) ^/
|
||||
func SDL2.RenderPresent(renderer);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Set SDL2 Renderer Draw Color ^/
|
||||
func SDL2.SetRenderDrawColor(renderer, r, g, b, a);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create a SDL2 Window ^/
|
||||
func SDL2.CreateWindow(title, x, y, w, h, flags);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get events ^/
|
||||
func SDL2.PollEvent();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Fill a rectangle using SDL ^/
|
||||
func SDL2.RenderFillRect(renderer, dictionary_with_x_y_w_h);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Draw a rectangle using SDL ^/
|
||||
func SDL2.RenderDrawRect(renderer, dictionary_with_x_y_w_h);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create a SDL2 Renderer ^/
|
||||
func SDL2.CreateRenderer(window, );
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Base64 encode ^/
|
||||
func Crypto.Base64Encode(data);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Sha512 Algorithm ^/
|
||||
func Crypto.Sha512($is384);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Sha256 Algorithm ^/
|
||||
func Crypto.Sha256($is224);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Sha1 Algorithm (needed for WebSocket handshake/BitTorrent etc) (don't use unless you have no other choice) ^/
|
||||
func Crypto.Sha1();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Base64 decode ^/
|
||||
func Crypto.Base64Decode(str);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create bytearray but with random bytes in it instead of zeros (this uses mbedtls by the way) ^/
|
||||
func Crypto.RandomBytes(byteCount, personalString);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Hash passwords with PBKDF2 ^/
|
||||
func Crypto.PBKDF2(pass, salt, itterations, keylen, shanum);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether object is a long (not a double) ^/
|
||||
func TypeIsLong(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether object is not null or undefined ^/
|
||||
func TypeIsDefined(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Eval source code ^/
|
||||
func VM.Eval(source);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Load a crossvm executable ^/
|
||||
func VM.LoadExecutable(stream);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create root environment ^/
|
||||
func VM.CreateEnvironment($dict);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Compile Source ^/
|
||||
func VM.Compile(dict);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get current environment for reflection purposes ^/
|
||||
func VM.getCurrentEnvironment();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get root environment for reflection purposes ^/
|
||||
func VM.getRootEnvironment();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get root environment as a dictionary ^/
|
||||
func VM.getRootEnvironmentAsDictionary();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether object is susceptible to garbage collection ^/
|
||||
func TypeIsHeap(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Parse Long from String ^/
|
||||
func ParseLong(arg, $base);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Parse Double from String ^/
|
||||
func ParseDouble(arg);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get a field in dictionary ^/
|
||||
func Dictionary.GetField(dict, key);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Set a field in dictionary ^/
|
||||
func Dictionary.SetField(dict, key, value);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get Dictionary Item Enumerable for the each(item : Dictionary.Items(myDict)){item.Key; item.Value;} ^/
|
||||
func Dictionary.Items(dictionary);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get environment variable ^/
|
||||
func Env.GetAt(key);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get cache folder ^/
|
||||
func Env.getCache();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Set environment variable ^/
|
||||
func Env.SetAt(key, value);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get downloads folder ^/
|
||||
func Env.getDesktop();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get platform name ^/
|
||||
func Env.getPlatform();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get documents folder ^/
|
||||
func Env.getDocuments();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get downloads folder ^/
|
||||
func Env.getDownloads();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get user folder ^/
|
||||
func Env.getUser();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get pictures folder ^/
|
||||
func Env.getPictures();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get music folder ^/
|
||||
func Env.getMusic();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get videos folder ^/
|
||||
func Env.getVideos();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get state folder ^/
|
||||
func Env.getState();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get the absolute path for executable ^/
|
||||
func Env.GetRealExecutablePath(path);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get config folder ^/
|
||||
func Env.getConfig();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get data folder ^/
|
||||
func Env.getData();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether object is a virtual filesystem ^/
|
||||
func TypeIsVFS(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create regex object ^/
|
||||
func Regex(regex);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create thread ^/
|
||||
func Thread(callback);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create bytearray with optional either size (to size it) or string argument (to fill byte array) ^/
|
||||
func ByteArray($data);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get type of object ^/
|
||||
func TypeOf(object);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create a Path from parts ^/
|
||||
func Path.Create(relative, parts);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create Absolute Root Path ^/
|
||||
func Path.Root();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create a Path from string ^/
|
||||
func Path.FromString(path);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Stop the program with an optional error message ^/
|
||||
func Console.Fatal($text);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Reads a byte from stdin ^/
|
||||
func Console.Read();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Set whether terminal is sending signals for CTRL+C (true) or via read (false) ^/
|
||||
func Console.setSignals(flag);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether terminal is sending signals for CTRL+C (true) or via read (false) ^/
|
||||
func Console.getSignals();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Write text "text" to stdout ^/
|
||||
func Console.Write(text);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Reads line from stdin ^/
|
||||
func Console.ReadLine();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Set whether terminal is buffering line by line (true) or byte by byte (false) ^/
|
||||
func Console.setCanonical(flag);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether terminal is buffering line by line (true) or byte by byte (false) ^/
|
||||
func Console.getCanonical();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Set whether terminal is echoing characters read ^/
|
||||
func Console.setEcho(flag);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Write text "text" to stdout with new line ^/
|
||||
func Console.WriteLine(text);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get whether terminal is echoing characters read ^/
|
||||
func Console.getEcho();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create in memory filesystem ^/
|
||||
func FS.CreateMemoryFilesystem();
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create filesystem ^/
|
||||
func FS.CreateFilesystem(fs);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create stream ^/
|
||||
func FS.CreateStream(strm);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Extract a crvm archive ^/
|
||||
func FS.ExtractArchive(strm, vfs);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create a memory stream ^/
|
||||
func FS.MemoryStream(writable);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create a subdir filesystem ^/
|
||||
func FS.SubdirFilesystem(fs, subdir);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create a mountable filesystem ^/
|
||||
func FS.MountableFilesystem(root);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Write all text to file ^/
|
||||
func FS.WriteAllText(fs, filename, content);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Read all text from file ^/
|
||||
func FS.ReadAllText(fs, filename);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Create a crvm archive ^/
|
||||
func FS.CreateArchive(fs, strm, name, version, info);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Make absolute path from relative path ^/
|
||||
func FS.MakeFull(path);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Escape sql text ^/
|
||||
func Sqlite.Escape(text);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Close sql database ^/
|
||||
func Sqlite.Close(handle);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Execute sql (returns dictionary of columns key=value an error message as string or undefined) ^/
|
||||
func Sqlite.Exec(handle, sql);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Opens the database (returns database handle or an error message as string or undefined) ^/
|
||||
func Sqlite.Open(filename);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Serialize Json ^/
|
||||
func Json.Encode(any, $indent);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Deserialize Json ^/
|
||||
func Json.Decode(Json string);
|
||||
```
|
||||
|
||||
|
||||
42
Tesses.CrossLang.Documentation/docs/RuntimeObjects.md
Normal file
42
Tesses.CrossLang.Documentation/docs/RuntimeObjects.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# CrossLang Runtime Objects (this and the root dictionaries are implcit) Documentation
|
||||
```go
|
||||
/^ Get index of string or char in string returns -1 if not found ^/
|
||||
func String.IndexOf(this, textOrChr);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get index of string or char in string returns -1 if not found ^/
|
||||
func String.LastIndexOf(this, textOrChr);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get the enumerator ^/
|
||||
func String.GetEnumerator(this, textOrChr);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Get the substring of a string if length is not provided it spans the rest of the string provided by this ^/
|
||||
func String.Substring(this, textOrChr);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Remove text from a string if length is not provided it spans the rest of the string provided by this ^/
|
||||
func String.Remove(this, textOrChr);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Trim the start of string till char is not chr if chr is not provided space will be used ^/
|
||||
func String.TrimStart(this, textOrChr);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Trim the end of string till char is not chr if chr is not provided space will be used ^/
|
||||
func String.TrimEnd(this, textOrChr);
|
||||
```
|
||||
|
||||
```go
|
||||
/^ Escape a crosslang string for eval quote determines whether the string should be quoted or not by default not ^/
|
||||
func String.Escape(this, textOrChr);
|
||||
```
|
||||
|
||||
|
||||
83
Tesses.CrossLang.Documentation/src/main.tcross
Normal file
83
Tesses.CrossLang.Documentation/src/main.tcross
Normal file
@@ -0,0 +1,83 @@
|
||||
var fns = [];
|
||||
func Crawl(c,name)
|
||||
{
|
||||
if(TypeOf(c) == "Dictionary")
|
||||
{
|
||||
each(var item : Dictionary.Items(c))
|
||||
{
|
||||
Crawl(item.Value,name.Count == 0 ? item.Key : $"{name}.{item.Key}");
|
||||
}
|
||||
}
|
||||
else if(TypeOf(c) == "ExternalMethod")
|
||||
{
|
||||
fns.Add({
|
||||
Name = name,
|
||||
Documentation = c.Documentation,
|
||||
Arguments = c.Arguments
|
||||
});
|
||||
}
|
||||
}
|
||||
func main(args)
|
||||
{
|
||||
var md = "";
|
||||
if(args.Count == 2)
|
||||
{
|
||||
var strm = FS.Local.OpenFile(args[1],"rb");
|
||||
|
||||
var package = VM.LoadExecutable(strm);
|
||||
|
||||
strm.Close();
|
||||
|
||||
md = $"# {package.Name} Documentation\n";
|
||||
|
||||
each(var fn : package.Functions)
|
||||
{
|
||||
var fnName = "";
|
||||
for(var i = 0; i < fn.FunctionNameParts.Count; i++)
|
||||
{
|
||||
|
||||
if(i > 0) fnName += ".";
|
||||
fnName += fn.FunctionNameParts[i];
|
||||
|
||||
}
|
||||
fns.Add({
|
||||
Arguments=package.Chunks[i].Arguments,
|
||||
Documentation=fn.Documentation,
|
||||
Name=fnName
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
md = "# CrossLang Runtime Documentation\n";
|
||||
var dict = {};
|
||||
var rEnv = VM.CreateEnvironment(dict);
|
||||
rEnv.RegisterEverything();
|
||||
Crawl(dict,"");
|
||||
}
|
||||
|
||||
|
||||
each(var item : fns)
|
||||
{
|
||||
md += "```go\n";
|
||||
if(item.Documentation.Count > 0)
|
||||
{
|
||||
md += "/^ ";
|
||||
md += item.Documentation.Replace(",","");
|
||||
md += " ^/\n";
|
||||
}
|
||||
md += "func ";
|
||||
md += item.Name;
|
||||
md += "(";
|
||||
for(var i = 0; i < item.Arguments.Count; i++)
|
||||
{
|
||||
if(i > 0) md += ", ";
|
||||
md += item.Arguments[i];
|
||||
}
|
||||
md += ");\n";
|
||||
|
||||
md += "```\n\n";
|
||||
}
|
||||
|
||||
Console.WriteLine(md);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
func main(args)
|
||||
{
|
||||
var dd = Tesses.CrossLang.Args(args);
|
||||
|
||||
if(dd.Arguments.Count > 0)
|
||||
{
|
||||
var commandName = dd.Arguments[0];
|
||||
@@ -27,29 +26,98 @@ func main(args)
|
||||
{
|
||||
offline = true;
|
||||
}
|
||||
if(flag == "help")
|
||||
{
|
||||
Console.WriteLine("USAGE: crosslang build [build-flags-and-options]");
|
||||
Console.WriteLine("FLAGS:");
|
||||
Console.WriteLine("offline: build with no internet (don't fetch files)");
|
||||
Console.WriteLine("help: this help");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("OPTIONS:");
|
||||
Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
var conf = "";
|
||||
each(var option : dd.Options)
|
||||
{
|
||||
if(option.Key == "conf")
|
||||
{
|
||||
conf = option.Value;
|
||||
}
|
||||
}
|
||||
var pm = Tesses.CrossLang.PackageManager();
|
||||
pm.Offline = offline;
|
||||
var bt = Tesses.CrossLang.BuildTool(pm);
|
||||
bt.Config = conf;
|
||||
bt.BuildProject(buildPath);
|
||||
}
|
||||
else if(commandName == "run")
|
||||
{
|
||||
var offline=false;
|
||||
var buildPath = ".";
|
||||
|
||||
var nobuild=false;
|
||||
var output="";
|
||||
each(var flag : dd.Flags)
|
||||
{
|
||||
if(flag == "offline")
|
||||
{
|
||||
offline = true;
|
||||
}
|
||||
else if(flag == "help")
|
||||
{
|
||||
Console.WriteLine("USAGE: crosslang run [run-flags-and-options] program-arguments...");
|
||||
Console.WriteLine("USAGE: crosslang run [run-flags-and-options] -- program-arguments-and-options...");
|
||||
Console.WriteLine("FLAGS:");
|
||||
Console.WriteLine("offline: build with no internet (don't fetch files)");
|
||||
Console.WriteLine("help: this help");
|
||||
Console.WriteLine("nobuild: don't build, just run");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("OPTIONS:");
|
||||
Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config");
|
||||
return 0;
|
||||
}
|
||||
else if(flag == "nobuild")
|
||||
{
|
||||
nobuild=true;
|
||||
}
|
||||
}
|
||||
var conf = "";
|
||||
each(var option : dd.Options)
|
||||
{
|
||||
if(option.Key == "conf")
|
||||
{
|
||||
conf = option.Value;
|
||||
}
|
||||
}
|
||||
if(nobuild)
|
||||
{
|
||||
if(FS.Local.FileExists("config.json"))
|
||||
{
|
||||
var proj = Json.Decode(FS.ReadAllText(FS.Local, "config.json"));
|
||||
var nameVer = $"{proj.name}-{proj.version}.crvm";
|
||||
var buildDir = TypeOf(proj.bin_directory) == "String" ? proj.bin_directory : "bin";
|
||||
|
||||
output = ./buildDir/nameVer;
|
||||
if(!FS.Local.FileExists(output))
|
||||
{
|
||||
Console.WriteLine($"ERROR: file {output} does not exist.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("ERROR: could not find project.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var pm = Tesses.CrossLang.PackageManager();
|
||||
pm.Offline = offline;
|
||||
var bt = Tesses.CrossLang.BuildTool(pm);
|
||||
var output = bt.BuildProject(buildPath).Output;
|
||||
|
||||
bt.Config = conf;
|
||||
output = bt.BuildProject(buildPath).Output;
|
||||
}
|
||||
var env = VM.CreateEnvironment({});
|
||||
env.RegisterEverything();
|
||||
env.LockRegister();
|
||||
@@ -83,7 +151,7 @@ func main(args)
|
||||
Console.WriteLine("List of templates:");
|
||||
each(var item : FS.Local.EnumeratePaths(dir))
|
||||
{
|
||||
Console.WriteLine(item.ChangeExtension().GetFileName());
|
||||
Console.WriteLine(Tesses.CrossLang.GetNameAndDescription(item));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -178,6 +246,14 @@ func main(args)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(commandName == "install-console")
|
||||
{
|
||||
//crosslang install-console
|
||||
}
|
||||
else if(commandName == "install-app")
|
||||
{
|
||||
//crosslang install-app
|
||||
}
|
||||
else if(commandName == "install-template")
|
||||
{
|
||||
//crosslang install-template Tesses.CrossLang.Template.Console --version=1.0.0.0-prod
|
||||
@@ -185,10 +261,235 @@ func main(args)
|
||||
else if(commandName == "install-tool")
|
||||
{
|
||||
//crosslang install-tool Tesses.CrossLang.Tool.SomeTool --version=1.0.0.0-prod
|
||||
var toolsDir = Path.FromString(Env.Config) / "Tesses" / "CrossLang" / "Tools";
|
||||
|
||||
var offline=false;
|
||||
var buildPath = ".";
|
||||
var nobuild=false;
|
||||
var output=.;
|
||||
each(var flag : dd.Flags)
|
||||
{
|
||||
if(flag == "offline")
|
||||
{
|
||||
offline = true;
|
||||
}
|
||||
else if(flag == "help")
|
||||
{
|
||||
Console.WriteLine("USAGE: crosslang install-tool [flags-and-options]");
|
||||
Console.WriteLine("USAGE: crosslang install-tool [PackageName] [flags-and-options]");
|
||||
Console.WriteLine("FLAGS:");
|
||||
Console.WriteLine("offline: build with no internet (don't fetch files)");
|
||||
Console.WriteLine("help: this help");
|
||||
Console.WriteLine("nobuild: don't build, just install (irrelevant if you specify a PackageName)");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("OPTIONS:");
|
||||
Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config (irrelevant if you specify a PackageName)");
|
||||
Console.WriteLine("version=1.0.0.0-prod: specify the package version (irrelevant if you don't specify a PackageName)");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("ARGUMENTS:");
|
||||
Console.WriteLine("PackageName: the package name of a tool you want to download and install, if not specified we install the tool from the current directory");
|
||||
return 0;
|
||||
}
|
||||
else if(flag == "nobuild")
|
||||
{
|
||||
nobuild=true;
|
||||
}
|
||||
}
|
||||
|
||||
if(dd.Arguments.Length == 1)
|
||||
{
|
||||
|
||||
var conf = "";
|
||||
each(var option : dd.Options)
|
||||
{
|
||||
if(option.Key == "conf")
|
||||
{
|
||||
conf = option.Value;
|
||||
}
|
||||
}
|
||||
|
||||
if(FS.Local.FileExists("cross.json"))
|
||||
{
|
||||
var proj = Json.Decode(FS.ReadAllText(FS.Local,"cross.json"));
|
||||
var name = TypeOf(proj.info.toolname) == "String" ? proj.info.toolname : proj.name;
|
||||
|
||||
if(proj.info.type != "tool")
|
||||
{
|
||||
Console.WriteLine("The project is not a tool");
|
||||
return 1;
|
||||
}
|
||||
if(TypeOf(name) != "String")
|
||||
{
|
||||
Console.WriteLine("The tool does not have a name");
|
||||
return 1;
|
||||
}
|
||||
var toolDir = toolsDir / name;
|
||||
FS.Local.CreateDirectory(toolDir);
|
||||
var toolFile = toolDir / name + ".crvm";
|
||||
|
||||
if(nobuild)
|
||||
{
|
||||
var nameVer = $"{proj.name}-{proj.version}.crvm";
|
||||
var buildDir = TypeOf(proj.bin_directory) == "String" ? proj.bin_directory : "bin";
|
||||
|
||||
output = ./buildDir/nameVer;
|
||||
if(!FS.Local.FileExists(output))
|
||||
{
|
||||
Console.WriteLine($"ERROR: file {output} does not exist.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var pm = Tesses.CrossLang.PackageManager();
|
||||
pm.Offline = offline;
|
||||
var bt = Tesses.CrossLang.BuildTool(pm);
|
||||
bt.Config = conf;
|
||||
output = bt.BuildProject(buildPath).Output;
|
||||
}
|
||||
|
||||
func CopyCRVM(src,dest)
|
||||
{
|
||||
func copyFile(src,dest)
|
||||
{
|
||||
var _src = FS.Local.OpenFile(src,"rb");
|
||||
var _dest = FS.Local.OpenFile(dest, "wb");
|
||||
_src.CopyTo(_dest);
|
||||
_src.Close();
|
||||
_dest.Close();
|
||||
Console.WriteLine($"{src} -> {dest}");
|
||||
}
|
||||
if(FS.Local.FileExists(dest)) return;
|
||||
copyFile(src,dest);
|
||||
|
||||
|
||||
var srcStrm = FS.Local.OpenFile(src,"rb");
|
||||
var crvm = VM.LoadExecutable(srcStrm);
|
||||
|
||||
srcStrm.Close();
|
||||
each(var dep : crvm.Dependencies)
|
||||
{
|
||||
var name = $"{dep.Name}-{dep.Version.ToString()}.crvm";
|
||||
CopyCRVM(src.GetParent()/name, dest.GetParent()/name);
|
||||
}
|
||||
}
|
||||
CopyCRVM(output,toolFile);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Console.WriteLine("The current directory does not have a project");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(commandName == "console")
|
||||
{
|
||||
//crosslang console myfavoriteapp
|
||||
}
|
||||
else if(commandName == "tool")
|
||||
{
|
||||
|
||||
var dir = FS.MakeFull(Env.Config) / "Tesses" / "CrossLang" / "Tools";
|
||||
if(dd.Arguments.Length == 1)
|
||||
{
|
||||
Console.WriteLine("List of tools:");
|
||||
each(var item : FS.Local.EnumeratePaths(dir))
|
||||
{
|
||||
Console.WriteLine(Tesses.CrossLang.GetNameAndDescription(item / item.GetFileName() + ".crvm"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if(commandName == "tool-test")
|
||||
{
|
||||
var pm = Tesses.CrossLang.PackageManager();
|
||||
pm.Offline = false;
|
||||
var bt = Tesses.CrossLang.BuildTool(pm);
|
||||
|
||||
var proj=bt.BuildProject(".");
|
||||
|
||||
var output = proj.Output;
|
||||
|
||||
var env = VM.CreateEnvironment({});
|
||||
env.RegisterEverything();
|
||||
env.LockRegister();
|
||||
|
||||
env.LoadFileWithDependencies(FS.Local,output);
|
||||
var myArgs = [];
|
||||
for(var i = 1; i < dd.Arguments.Count; i++)
|
||||
{
|
||||
myArgs.Add(dd.Arguments[i]);
|
||||
}
|
||||
return env.GetDictionary().RunTool({
|
||||
Arguments=myArgs,
|
||||
Options = dd.Options,
|
||||
Flags = dd.Flags,
|
||||
ToolName = proj.Info.toolname
|
||||
});
|
||||
}
|
||||
else if(commandName == "add-project")
|
||||
{
|
||||
//crosslang add-project /path/to/project
|
||||
|
||||
if(dd.Arguments.Count > 1)
|
||||
{
|
||||
var dep = dd.Arguments[1];
|
||||
if(FS.Local.DirectoryExists(dep))
|
||||
{
|
||||
var path = Path.FromString(dep) / "cross.json";
|
||||
var pathStr = FS.MakeFull(dep).CollapseRelativeParents().ToString();
|
||||
if(FS.Local.FileExists(path))
|
||||
{
|
||||
if(FS.Local.FileExists("cross.json"))
|
||||
{
|
||||
var f = FS.ReadAllText(FS.Local,"cross.json");
|
||||
var json = Json.Decode(f);
|
||||
if(TypeOf(json.project_dependencies) == "List")
|
||||
{
|
||||
each(var item : json.project_dependencies)
|
||||
{
|
||||
var _path = FS.MakeFull(item).CollapseRelativeParents().ToString();
|
||||
|
||||
if(_path == pathStr)
|
||||
{
|
||||
Console.WriteLine($"The project {dep} already exists in cross.json.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
json.project_dependencies.Add(dep);
|
||||
}
|
||||
else
|
||||
{
|
||||
json.project_dependencies = [dep];
|
||||
|
||||
}
|
||||
Console.WriteLine($"Added project {dep} to cross.json.");
|
||||
FS.WriteAllText(FS.Local, "cross.json", Json.Encode(json,true));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("The current directory does not have a project");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"The project file {path} does not exist");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("The project directory does not exist");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else if(commandName == "add-dependency")
|
||||
{
|
||||
@@ -198,5 +499,32 @@ func main(args)
|
||||
{
|
||||
//crosslang upload-package [PACKAGE_NAME]
|
||||
}
|
||||
else if(commandName == "configdir")
|
||||
{
|
||||
Console.WriteLine(Tesses.CrossLang.ConfigDir);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
each(var flag : dd.Flags)
|
||||
{
|
||||
if(flag == "version")
|
||||
{
|
||||
Console.WriteLine($"VM version: {VM.RuntimeVersion}");
|
||||
Console.WriteLine($"Shell version: {main.File.Version}");
|
||||
Console.WriteLine($"Args version: {Tesses.CrossLang.Args.File.Version}");
|
||||
Console.WriteLine($"BuildTool version: {Tesses.CrossLang.BuildTool.File.Version}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Console.WriteLine($"USAGE: crosslang COMMAND [command-arguments]");
|
||||
Console.WriteLine("COMMANDS:");
|
||||
Console.WriteLine("new: create new project");
|
||||
Console.WriteLine("build: build a project");
|
||||
Console.WriteLine("run: run a project");
|
||||
Console.WriteLine("configdir: print the config directory");
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
7
Tesses.CrossLang.Std/cross.json
Normal file
7
Tesses.CrossLang.Std/cross.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"info": {
|
||||
"type": "lib"
|
||||
},
|
||||
"version": "1.0.0.0-prod",
|
||||
"name": "Tesses.CrossLang.Std"
|
||||
}
|
||||
21
Tesses.CrossLang.Std/src/time.tcross
Normal file
21
Tesses.CrossLang.Std/src/time.tcross
Normal file
@@ -0,0 +1,21 @@
|
||||
func Time.Date.Create(year,month,day,hour,minute,second,timezone,hasDST)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
func Time.Date.FromUnix(timeStamp)
|
||||
{
|
||||
var seconds = (timeStamp % 60).Abs();
|
||||
var min = ((timeStamp / 60) % 60).Abs();
|
||||
var hour = ((timeStamp / 3600) % 24).Abs();
|
||||
var year = ((timeStamp / 31557600));
|
||||
var daysSince1970 = (timeStamp / 86400);
|
||||
|
||||
|
||||
|
||||
return Time.Date.Create(,second);
|
||||
}
|
||||
func Time.Date.getNow()
|
||||
{
|
||||
return Time.Date.FromUnix(Time.Now);
|
||||
}
|
||||
@@ -52,6 +52,7 @@ func create_archive()
|
||||
copyFile("Templates/lib/bin/Tesses.CrossLang.Template.Library-1.0.0.0-prod.crvm", templates / "lib.crvm");
|
||||
copyFile("Templates/template/bin/Tesses.CrossLang.Template.Template-1.0.0.0-prod.crvm", templates / "template.crvm");
|
||||
copyFile("Templates/web/bin/Tesses.CrossLang.Template.Website-1.0.0.0-prod.crvm", templates / "web.crvm");
|
||||
copyFile("Templates/tool/bin/Tesses.CrossLang.Template.Tool-1.0.0.0-prod.crvm", templates / "tool.crvm");
|
||||
var packageCache = r / "PackageCache";
|
||||
|
||||
tmpFS.CreateDirectory(packageCache);
|
||||
|
||||
Binary file not shown.
@@ -8,5 +8,6 @@ crossvm ./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm bu
|
||||
crossvm ./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm build Templates/template
|
||||
crossvm ./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm build Templates/lib
|
||||
crossvm ./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm build Templates/compiletool
|
||||
crossvm ./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm build Templates/tool
|
||||
crossvm ./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm build crosslang_shell_archive_maker
|
||||
|
||||
|
||||
Reference in New Issue
Block a user