Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Reflective, Meta Blocks. Classes and Modular Improvement. #50

Merged
merged 19 commits into from
Nov 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a9424c3
review simple-lang new structure development on the branch
Thecarisma Oct 21, 2018
a5235fc
some oop roadmap achieved
Thecarisma Oct 21, 2018
ee6b1be
add examples for the new oop features
Thecarisma Oct 21, 2018
f6a0bb0
resolves list index of index of zeros [0][0][0]...
Thecarisma Oct 25, 2018
626633e
update from
Thecarisma Oct 25, 2018
5132b34
more list example and resolving
Thecarisma Oct 27, 2018
af4273b
experimenting infinitly large number in examples/basic/misc.sim
Thecarisma Oct 30, 2018
2c6cf8b
add more compiler check to properly determine if VS has C/C++ SDK in …
Thecarisma Oct 31, 2018
4656fbb
add more compiler check to properly determine if VS has C/C++ SDK in …
Thecarisma Oct 31, 2018
d466c38
add more compiler check to properly determine if VS has C/C++ SDK in …
Thecarisma Oct 31, 2018
9bb4d3a
resolve modules testing and create examples unit test
Thecarisma Nov 3, 2018
e24b9dd
Fixed minor bugs!
Youngestdev Nov 8, 2018
a03cc17
add support for variadic parameters in blocks and method
Thecarisma Nov 11, 2018
7e8a920
add support for variadic parameters in blocks and method
Thecarisma Nov 11, 2018
e3b30b9
add support for variadic parameters in blocks and method
Thecarisma Nov 11, 2018
aaa32fe
add support for variadic parameters in blocks and method
Thecarisma Nov 11, 2018
5cd2c6d
add reflective and meta blocks and classes for more efficient oop \ d…
Thecarisma Nov 18, 2018
32d055c
add reflective and meta blocks and classes for more efficient oop …
Thecarisma Nov 18, 2018
dfcb5a6
Update ROADMAP.MD
Youngestdev Nov 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ROADMAP.MD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ build, installation, features e.t.c
- [x] create the simple-lang interpreter
- [x] create a working installer script to enable installation with curl and bash or shell script [working issue](https://github.com/simple-lang/simple/issues/24)
- [ ] build a compiler to allow faster program execution - simplify
- [x] make vm search for **call** files and **dynamic modules** in these folders and order.
- [x] make scanner search for **call** files and **dynamic modules** in these folders and order.
- [x] 1 absolute to path
- [x] 1 relative to modules folder in working directory
- [x] 2 in relative to environment SIMPLE_PATH
Expand Down Expand Up @@ -80,6 +80,8 @@ build, installation, features e.t.c
- [ ] enable `final keyword before `class` keyword to prevent inheriting it
- [ ] enable `final` keyword before `block` keyword to prevent overriding the block in sub classes
- [ ] allow the use of ellipsis `..` between numbers in a for..loop to specify range. `for (1..100) {}`
- [ ] support using braces to call/import multiple files at once call { module1 module2 }
- [ ] make break from multiple loop start from index 0 instead of one `break 0` instead of `break 1`

### simplify
- [ ] hint user as a type of level error when a similar variable that has not been declared is used
Expand Down Expand Up @@ -128,6 +130,7 @@ Modules which are not part of the standard module that comes distributed with si

- [ ] create material and native os extended module for fulltick GUI module
- [ ] a module that convert fultick Widget to HTML element
- [ ] ~write a C/C++ parser module to scan C/C++ sources into resuable token groups~
- [ ] write a C/C++ parser module to scan C/C++ sources into resuable token groups

### Environments
Expand Down
59 changes: 0 additions & 59 deletions environment/dist/contents.sim

This file was deleted.

8 changes: 5 additions & 3 deletions environment/minifier/minifier.sim
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ block minifySourceDir(sourceDir)
}

block minifySourceFile(sourceFile)
if !stringEndsWith(sourceFile.name(),".sim") {
if !strEndsWith(sourceFile.name(),".sim") {
@sourceFile.name()+" : not a simple source file (*.sim) skipping..."
return
}
Expand All @@ -69,7 +69,7 @@ block minifySourceFile(sourceFile)
}
}
source = " "+sourceFile.readFileAsString() + " "
if stringGetLineCount(source) < 1 {
if strGetLineCount(source) < 1 {
@sourceFile.name()+" : already minified"
return
}
Expand Down Expand Up @@ -129,4 +129,6 @@ block minifySourceFile(sourceFile)
}
__writefile(sourceFile.absolutePath(), minifiedSource)
@" (done)"


block isNewLine(val)
return val == crlf or val = nl or val == cr
203 changes: 172 additions & 31 deletions environment/modular/modular.sim
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@ verifierUrl = simpleLangHost+"?page=Packages%20Index&sub_page=Verifier"
addPackageUrl = simpleLangHost+"?page=Packages%20Index&sub_page=Add%20New%20Package"
simpleUpdateUrl = simpleLangCgiUrl+"api/Upgrade.sim"
packageUrl = simpleLangCgiUrl+"api/PackageInstaller.sim"
simpleDistDirectory = simpleDirectory()
simpleDistDirectory = simpleDir()
tempDirectory = getTemporaryDirectory()
modulesDirectory = simpleModulesDirectory()
documentationDirectory = simpleDocDirectory()
dynamicModulesDirectory = simpleDyModulesDirectory()
modulesDirectory = simpleModulesDir()
githubDirectory = modulesDirectory + "/github.com/"
documentationDirectory = simpleDocDir()
dynamicModulesDirectory = simpleDyModulesDir()

deleteTemp = true
showInfo = false
askPermission = true
packageList = null
isShell = false
cmdlen = lengthOf(cmdparams)
type = "whichever"
cmdlen = lengthOf(cmdparams) - 1
type = ""
package = ""
initPackage = ""
version = "latest"
Expand All @@ -71,29 +72,34 @@ UNKNOWN_ERROR = "The status of this package cannot be defined"+crlf+"Visit their
STALL_PACKAGE = "This package is pending verification. "+crlf+"If you wish to join package verifiers visit : "+verifierUrl
INSTALLATION_UNATHORIZED = "Installation not authorized "+crlf+"DONE"

block main()
block main()
executeModular(cmdlen,cmdparams)

block executeModular(cmdlen,cmdparams)
if cmdlen <= 0 { displayHelp() }
for a = 0 to cmdlen {
if stringEquals(cmdparams[a],"--shell",false) or stringEquals(cmdparams[a],"-su",false) if !isShell { isShell = true shell() } break
elif stringEquals(cmdparams[a],"--help",false) or stringEquals(cmdparams[a],"-h",false) or stringEquals(cmdparams[a],"--h",false) displayHelp()
elif stringEquals(cmdparams[a],"--about",false) or stringEquals(cmdparams[a],"-a",false) or stringEquals(cmdparams[a],"--a",false) displayAbout()
if strEquals(cmdparams[a],"--shell",false) or strEquals(cmdparams[a],"-su",false) if !isShell { isShell = true shell() } break
elif strEquals(cmdparams[a],"--help",false) or strEquals(cmdparams[a],"-h",false) or strEquals(cmdparams[a],"--h",false) displayHelp()
elif strEquals(cmdparams[a],"--about",false) or strEquals(cmdparams[a],"-a",false) or strEquals(cmdparams[a],"--a",false) displayAbout()
#Module or Environment
elif stringEquals(cmdparams[a],"--env",false) or stringEquals(cmdparams[a],"-e",false) type = "environment"
elif stringEquals(cmdparams[a],"--mod",false) or stringEquals(cmdparams[a],"-m",false) type = "module"
elif strEquals(cmdparams[a],"--env",false) or strEquals(cmdparams[a],"-e",false) type = "environment"
elif strEquals(cmdparams[a],"--mod",false) or strEquals(cmdparams[a],"-m",false) type = "module"
#Version and Attribute
elif stringEquals(cmdparams[a],"-v",false) or stringEquals(cmdparams[a],"--version",false) version = cmdparams[a++]
elif stringEquals(cmdparams[a],"-os",false) or stringEquals(cmdparams[a],"--system",false) ostype = cmdparams[a++]
elif stringEquals(cmdparams[a],"--upgrade",false) or stringEquals(cmdparams[a],"--update",false) or stringEquals(cmdparams[a],"-u",false) type = "upgrade"
elif strEquals(cmdparams[a],"-v",false) or strEquals(cmdparams[a],"--version",false) version = cmdparams[a++]
elif strEquals(cmdparams[a],"-os",false) or strEquals(cmdparams[a],"--system",false) ostype = cmdparams[a++]
elif strEquals(cmdparams[a],"--upgrade",false) or strEquals(cmdparams[a],"--update",false) or strEquals(cmdparams[a],"-u",false) type = "upgrade"
#Others
elif stringEquals(cmdparams[a],"-p",false) or stringEquals(cmdparams[a],"--path",false) simpleDistDirectory = cmdparams[a++] @simpleDistDirectory
elif stringEquals(cmdparams[a],"-t",false) or stringEquals(cmdparams[a],"--temp",false) deleteTemp = false
elif stringEquals(cmdparams[a],"-s",false) or stringEquals(cmdparams[a],"--show-info",false) showInfo = true
elif stringEquals(cmdparams[a],"-y",false) or stringEquals(cmdparams[a],"--yes",false) askPermission = false
elif strEquals(cmdparams[a],"-p",false) or strEquals(cmdparams[a],"--path",false) simpleDistDirectory = cmdparams[a++] @simpleDistDirectory
elif strEquals(cmdparams[a],"-t",false) or strEquals(cmdparams[a],"--temp",false) deleteTemp = false
elif strEquals(cmdparams[a],"-s",false) or strEquals(cmdparams[a],"--show-info",false) showInfo = true
elif strEquals(cmdparams[a],"-y",false) or strEquals(cmdparams[a],"--yes",false) askPermission = false
else package = cmdparams[a] end
}
package = replaceStr(package,"\","/")
if strContains(package,"github.com") or strContains(package,"/") {
grabFromGithub(package)
return
}
if ostype == "auto-detect" {
ostype = getOS()
}
Expand All @@ -113,11 +119,142 @@ block executeModular(cmdlen,cmdparams)
moduleEnviron(depConf,packageList)
}
if isShell { shell() else __exit__ }

block grabFromGithub(package)
if askPermission == true { askPermission = false }

packageName = lastStrAfterChar(package,"/")
branch_tag = "master"
packageType = "master"
downloadUrl = null
if strContains(packageName,":") {
pSplit = strSplit(packageName, ":")
if lengthOf(pSplit) > 2 {
throw("Invalid github repository. Check the ':' count. : "+package)
}
packageName = pSplit[0]
package = replaceStr(package,packageName+":"+pSplit[1],pSplit[0])
package = removeStr(package,":")
lastPart = pSplit[1]

pSplit1 = strSplit(lastPart, "-")
start = 1
preB = toLowerCase(pSplit1[0])
if preB == "version" or preB == "tag" {
packageType = "tag"
elif preB == "branch"
packageType = "branch"
else
value = replaceStr(lastPart,".","")
start = 0
if isDigit(value) {
packageType = "tag"
else
packageType = "branch"
}
}
branch_tag = ""
for a = start to lengthOf(pSplit1) - 1 {
branch_tag += pSplit1[a]
if a < lengthOf(pSplit1) - 1 {
branch_tag += "-"
}
}
}
if branch_tag == "master" {
packageType = "master"
}
stdout.println("Preparing to grab module from github...")
stdout.println("installing module from github might result to dependencies issues")
if !strContains(package,"github.com") {
package = "https://github.com/" + package
}
downloadUrl = package+"/archive/" + branch_tag + ".zip"
downloadablePackage = [
:name = packageName,
:download_url = downloadUrl,
:branch = branch_tag
]
downloadedPackage = new Download(downloadablePackage[:download_url])
downloadedPackage.saveLocation(tempDirectory+hash(downloadablePackage[:name])+branch_tag+".zip")
downloadedPackage.execute()
if downloadedPackage.exists() {
downloadedPackageZip = new Zip(downloadedPackage.absolutePath(),"r")
extractedPackage = new Directory(tempDirectory+hash(downloadablePackage[:name]+branch_tag))
#TODO : Create method to check if zip is a valid archive #throw if try to extract invalid archive
downloadedPackageZip.extractAll(extractedPackage.getPath())
extractedPath = null
try {
extractedPath = extractedPackage.listDirectories()[0].absolutePath()
catch
stderr.println("the module installation failed. Check package name")
if isShell { shell() else __exit__ }
}
if __exists(extractedPath+"/install.sim") {
modularCode = __readfile(extractedPath+"/install.sim")
executeCode(modularCode)
if !__is_local_variable("modular") {
modular = []
}
downloadablePackage[:title] = modular[:title]
downloadablePackage[:version] = modular[:version]
downloadablePackage[:date] = modular[:date]
downloadablePackage[:license] = modular[:license]
downloadablePackage[:website] = modular[:website]
downloadablePackage[:dynamicmodules] = modular[:dynamic_modules]
downloadablePackage[:module] = modular[:module]
downloadablePackage[:doc] = modular[:doc]
if modular[:pre_install_system] != null {
__exec(modular[:pre_install_system])
}
if modular[:module] != null and __dir_exists(extractedPath+downloadablePackage[:module]) {
moveContent(extractedPath+downloadablePackage[:module],modulesDirectory+"/"+modular[:module])
stdout.println("the module "+downloadablePackage[:name]+" has been installed")
else
if askPermission {
stdout.print("do you wish to install the module in the github.com folder : ") read response
else
response = "y"
}
if response == "yes" or response == "y" {
moveContent(extractedPath+downloadablePackage[:module],githubDirectory)
clearGithubResidual(githubDirectory)
#recordModuleInstallation(downloadablePackage) #do not record since it from github
stdout.println("the module "+downloadablePackage[:name]+" has been installed")
else
stderr.println("the module "+downloadablePackage[:name]+" installation cancelled")
}
}
if modular[:doc] != null and __dir_exists(extractedPath+downloadablePackage[:doc]) {
moveContent(extractedPath+downloadablePackage[:doc],documentationDirectory)
}
if modular[:post_install_system] != null {
__exec(modular[:post_install_system])
}
else
stdout.print("the module does not have an install.sim script \n")
if askPermission {
stdout.print("do you wish to install the module in the github.com folder : ") read response
else
response = "y"
}
if response == "yes" or response == "y" {
moveContent(extractedPath+downloadablePackage[:module],githubDirectory)
clearGithubResidual(githubDirectory)
#recordModuleInstallation(downloadablePackage) #do not record since it from github
stdout.println("the module "+downloadablePackage[:name]+" has been installed")
else
stderr.println("the module "+downloadablePackage[:name]+" installation cancelled")
}
}
if isShell { shell() else __exit__ }
}

block moduleEnviron(depConf,packageList)
localPackage = null
@"checking locally installed version of "+package+"..."
for a = 0 to lengthOf(packageList) {
pkgLen = lengthOf(packageList) - 1
for a = 0 to pkgLen {
if packageList[a][:name] == package {
localPackage = packageList[a]
@"local package: "+package+" "+type+" "+localPackage[:version]
Expand Down Expand Up @@ -233,11 +370,11 @@ block recordModuleInstallation(downloadedPackage)
:dynamicmodules = downloadedPackage[:dynamic_modules]
]
add(packageList,downloadedPackageList)
list = new List(packageList)
list = new List(downloadedPackageList)
depConf = new File(modulesDirectory+"/modules-dependencies.conf")
#@replaceString(depConf.readFileAsString(),"/* NEWMODULE */",","+crlf+tab+list.toString()+crlf+tab+"/**NEWMODULE**/")
newDep = replaceStr(depConf.readFileAsString(),"/* NEWMODULE */",","+nl+tab+list.toString()+"/* NEWMODULE */")
if depConf.exists() {
#depConf.write(list.toString())
depConf.write(newDep)
}

block getSupportingModulesInfo(initialPackage)
Expand All @@ -263,13 +400,13 @@ block loadPackageAndDep()
if packageJson == null {
@"Internet connection is required to install "+package+" "+type+" package"
if isShell { shell() else __exit__ }
elif stringContains(packageJson, "500 Internal Server Error")
elif strContains(packageJson, "500 Internal Server Error")
@"The server is experiencing a down time please report to <[email protected]>"
if isShell { shell() else __exit__ }
elif stringContains(packageJson, "Not Found")
elif strContains(packageJson, "Not Found")
@"The update link is broken please report this to <[email protected]>"
if isShell { shell() else __exit__ }
elif !stringContains(packageJson, '"value":')
elif !strContains(packageJson, '"value":')
@"The package address is incorrect please report to <[email protected]>"
if isShell { shell() else __exit__ }
}
Expand Down Expand Up @@ -313,13 +450,13 @@ block upgradeSimpleDistro()
upgradeJson = download(simpleUpdateUrl+"?os="+ostype)
if upgradeJson == null {
@"Internet connection is required to upgrade simple-lang"
elif stringContains(upgradeJson, "500 Internal Server Error")
elif strContains(upgradeJson, "500 Internal Server Error")
@"The server is experiencing a down time please report to <[email protected]>"
if isShell { shell() else __exit__ }
elif stringContains(upgradeJson, "Not Found")
elif strContains(upgradeJson, "Not Found")
@"The upgrade link is broken please report this to <[email protected]>"
if isShell { shell() else __exit__ }
elif !stringContains(upgradeJson, '"value"')
elif !strContains(upgradeJson, '"value"')
@"The upgrade address is incorrect please report to <[email protected]>"
if isShell { shell() else __exit__ }
else
Expand Down Expand Up @@ -370,9 +507,13 @@ block upgradeSimpleDistro()
}
}

block removeTempFiles(files)
block clearGithubResidual(githubDirectory)
dir = new Directory(githubDirectory)
removeTempFiles(dir.listFiles())

block removeTempFiles(files)
if deleteTemp {
for a = 0 to lengthOf(files) {
for a = 0 to lengthOf(files) - 1 {
if files[a].exists() { files[a].delete() }
}
}
Expand Down
Loading