Skip to content

Commit

Permalink
Fix minor compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Sep 4, 2023
1 parent b984944 commit 18cc25e
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 28 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ jobs:
- run: |
msg="${{ github.event.release.tag_name }}"
echo "VERSION=${msg:1}" >> $GITHUB_ENV
- run: the install
- run: the build src
- run: the compile build/result --platform=linux && mv a.out cli-core-linux && sleep 1
- run: the compile build/result --platform=macos --arch=arm64 && mv a.out cli-core-macos-arm64 && sleep 1
- run: the compile build/result --platform=macos --arch=x86_64 && mv a.out cli-core-macos-x86_64 && sleep 1
- run: the compile build/result --platform=windows && mv a.out cli-core-windows && sleep 1
- run: build.out install
- run: build.out compile build/result --platform=linux && mv a.out cli-core-linux && sleep 1
- run: build.out compile build/result --platform=macos --arch=arm64 && mv a.out cli-core-macos-arm64 && sleep 1
- run: build.out compile build/result --platform=macos --arch=x86_64 && mv a.out cli-core-macos-x86_64 && sleep 1
- run: build.out compile build/result --platform=windows && mv a.out cli-core-windows && sleep 1
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
- run: sudo apt-get update
- run: sudo apt-get install valgrind
- run: the install
- run: the build src
- run: the compile build/result && mv a.out b.out
- run: build.out compile build/result && mv a.out b.out
- run: valgrind ./b.out -h
- run: valgrind ./b.out -v
- run: valgrind ./b.out build test
Expand Down
Binary file added build.out
Binary file not shown.
2 changes: 1 addition & 1 deletion package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ packages:
the/parser: 0.3.2
the/testing: 0.3.0
the/yaml: 0.3.0
the/zip: 0.1.4
the/zip: 0.1.5
2 changes: 0 additions & 2 deletions src/command
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export fn command (compiler: str, action: str, path: str, outputPath: str, qs: s

if !fs_existsSync(filePath) {
throw error_NewError("File '" + filePath + "' does not exists")
} elif !fs_isFileSync(filePath) {
throw error_NewError("Path '" + filePath + "' is not a file")
}

if (action == "lex" || action == "parse") && compiler.empty {
Expand Down
8 changes: 3 additions & 5 deletions src/compile
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
import zip from "the/zip"

export fn request (url: str, path: str) buffer_Buffer {
archivePath := path + ".zip"
zip(archivePath, path)

archivePath := path + path_SEP + "file.zip"
zip(archivePath, "*", cwd: path)
data := fs_readFileSync(archivePath)

headers := [
request_Header{name: "authorization", value: "pELerETRaVeYHEne"},
request_Header{name: "content-type", value: "application/octet-stream"}
request_Header{name: "content-type", value: "application/zip"}
]

mut req := request_open("POST", url, headers: headers, data: data)
res := req.read()
req.close()

fs_rmSync(path)
fs_rmSync(archivePath)

if res.status != 200 {
Expand Down
22 changes: 15 additions & 7 deletions src/main
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const VERSION_NUM := "0.13.3"
const VERSION_NAME := "Enidora"

main {
cwd := process_cwd()
mut args := Args{lineLength: 70}
defaultOutput := os_NAME == "Windows" ? "a.exe" : "a.out"

Expand Down Expand Up @@ -82,7 +83,7 @@ main {
arg.command == "test"
) {
action = arg.command
actionArgument = fs_isAbsoluteSync(arg.value) ? arg.value : process_cwd() + path_SEP + arg.value
actionArgument = fs_isAbsoluteSync(arg.value) ? arg.value : cwd + path_SEP + arg.value
} elif (
arg.command == "install" ||
arg.command == "script" ||
Expand All @@ -103,7 +104,7 @@ main {
paths := mapStr(arg.value.split(","), (it: str, idx: int) -> str { return it.trim() })
excludePaths.merge(paths)
} elif arg.option == "output" {
outputPath = fs_isAbsoluteSync(arg.value) ? arg.value : process_cwd() + path_SEP + arg.value
outputPath = fs_isAbsoluteSync(arg.value) ? arg.value : cwd + path_SEP + arg.value
} elif arg.option == "platform" {
platform = arg.value
} elif arg.option == "run-args" {
Expand All @@ -123,12 +124,15 @@ main {
process_exit(0)
}

qs := "?v=" + version + "&p=" + platform + (arch.empty ? arch : "&a=" + arch)
mut qs := "?v=" + version
qs += "&p=" + platform
qs += (arch.empty ? arch : "&a=" + arch)

if action == "compile" || action == "lex" || action == "parse" || action == "run" {
commandAction := action == "run" ? "compile" : action
mut runner := Runner_init(actionArgument, excludePaths)
command(compiler, commandAction, runner.inputPath, outputPath, qs)
qs += "&m=" + actionArgument.slice(cwd.len + path_SEP.len)
command(compiler, commandAction, runner.outputDir, outputPath, qs)

if action == "run" {
cmd := outputPath + (runArgs.empty ? "" : " " + runArgs)
Expand All @@ -137,7 +141,10 @@ main {
}

runner.deinit()
fs_rmSync(outputPath)

if action != "compile" {
fs_rmSync(outputPath)
}
} elif action == "install" || action == "uninstall" || action == "update" {
mut packager := Packager_init()

Expand All @@ -157,7 +164,7 @@ main {

packager.deinit()
} elif action == "script" {
packageYAMLPath := process_cwd() + path_SEP + "package.yml"
packageYAMLPath := cwd + path_SEP + "package.yml"

if !fs_existsSync(packageYAMLPath) {
throw error_NewError("File `package.yml` was not found")
Expand All @@ -183,7 +190,8 @@ main {
}
} elif action == "test" {
mut tester := Tester_init(actionArgument, excludePaths)
command(compiler, "compile", tester.inputPath, tester.outputPath, qs)
qs += "&m=__the__main__"
command(compiler, "compile", tester.outputDir, tester.outputPath, qs)

stdout := process_runSync(tester.outputPath)
print(stdout.str(), terminator: "")
Expand Down
4 changes: 2 additions & 2 deletions src/parser
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export fn collectTestFunctionNames (path: str) str[] {
}

export fn collectUsedPaths (paths: str[]) str[] {
cwd := process_cwd()
mut result: str[]

loop i := 0; i < paths.len; i++ {
file := parse(paths[i])
dir := path_dirname(paths[i])
result.push(file.path)

mut importPaths: str[]
Expand All @@ -55,7 +55,7 @@ export fn collectUsedPaths (paths: str[]) str[] {
source := sourceLiteral.value

if [".", "/"].contains(source.slice(0, 1)) {
sourcePath := fs_isAbsoluteSync(source) ? source : cwd + path_SEP + source
sourcePath := fs_isAbsoluteSync(source) ? source : dir + path_SEP + source
importPaths.push(sourcePath)
}
})
Expand Down
8 changes: 7 additions & 1 deletion src/runner
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import collectUsedPaths from "./parser"
import ensurePathDirectory, excludePaths, removeDirectorySync, scandirDeepSync from "./utils"
import ensurePathDirectory, excludePaths, removeDirectorySync from "./utils"

export obj Runner {
cwd: str
Expand Down Expand Up @@ -35,6 +35,12 @@ export obj Runner {

ensurePathDirectory(self.outputDir + self.targetPath.slice(cwdLen))
fs_copyFileSync(self.targetPath, self.inputPath)

packageYamlPath := self.cwd + path_SEP + "package.yml"

if fs_existsSync(packageYamlPath) {
fs_copyFileSync(packageYamlPath, self.outputDir + path_SEP + "package.yml")
}
}

fn deinit (self: ref Self) {
Expand Down
6 changes: 6 additions & 0 deletions src/tester
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export obj Tester {
mainContent := mainFileImports + os_EOL + mainFile
self.outputPath = self.outputDir + path_SEP + "a." + (os_NAME == "Windows" ? "exe" : "out")
fs_writeFileSync(self.inputPath, mainContent.toBuffer())

packageYamlPath := self.cwd + path_SEP + "package.yml"

if fs_existsSync(packageYamlPath) {
fs_copyFileSync(packageYamlPath, self.outputDir + path_SEP + "package.yml")
}
}

fn deinit (self: ref Self) {
Expand Down
19 changes: 17 additions & 2 deletions src/utils
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ export fn removeDirectorySync (path: str) {
}

export fn scandirDeepSync (path: str) str[] {
// todo canonical needed
return []
files := fs_scandirSync(path)
filesLen := files.len
mut result: str[]

loop i := 0; i < filesLen; i++ {
file := files[i] as str
filePath := path + path_SEP + file
pathValid := !file.contains(".")

if pathValid && fs_isFileSync(filePath) {
result.push(filePath)
} elif pathValid && fs_isDirectorySync(filePath) {
result.merge(scandirDeepSync(filePath))
}
}

return result
}

0 comments on commit 18cc25e

Please sign in to comment.