Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
Support for running outside of GOPATH and include some binaries for L…
Browse files Browse the repository at this point in the history
…inux and Windows
  • Loading branch information
bristermitten committed Nov 2, 2020
1 parent af3b185 commit f23f73a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 11 deletions.
Binary file added bin/elara-linux-amd64
Binary file not shown.
Binary file added bin/elara-windows-amd64.exe
Binary file not shown.
15 changes: 15 additions & 0 deletions bin/elara.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace examples/main
import elara/std

struct Test {
String name
}

extend Test {
let b = 3
let print-name => print(name)
}

let test = Test("Test Struct")
test.print-name()
print(test.b)
9 changes: 9 additions & 0 deletions bin/stdlib/base.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace elara/std

let print = (Any msg) => Unit {
print-raw(msg + "\n")
}

let print-raw = (Any msg) => {
stdout.write(msg)
}
14 changes: 14 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
echo 'Cleaning Up...'
rm -rf bin/
mkdir bin
echo 'Moving Standard Library...'
cp -r stdlib bin/
cp elara.el bin/

echo 'Building Windows amd64...'
env GOOS=linux GOARCH=amd64 go build -o bin/elara-linux-amd64

echo 'Building Linux amd64...'
env GOOS=windows GOARCH=amd64 go build -o bin/elara-windows-amd64.exe

echo 'Done!'
33 changes: 23 additions & 10 deletions elara.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,37 @@ func main() {
func loadStdLib() {
goPath := os.Getenv("GOPATH")
filePath := path.Join(goPath, "stdlib/")
filepath.Walk(filePath, func(path string, info os.FileInfo, err error) error {
defer func() {
err := recover()
if err == nil {
return
}
//Maybe it's not present in GOPATH, let's try in working directory
cur, err := os.Executable()
if err != nil {
panic(err)
}
if info.IsDir() {
return nil
}
_, content := loadFile(path)
base.Execute(&path, string(content), false)
filePath = path.Join(filepath.Dir(cur), "stdlib/")
filepath.Walk(filePath, loadWalkedFile)
}()
filepath.Walk(filePath, loadWalkedFile)
}

func loadWalkedFile(path string, info os.FileInfo, err error) error {
if err != nil {
panic(err)
}
if info.IsDir() {
return nil
})
}
_, content := loadFile(path)
base.Execute(&path, string(content), false)
return nil
}

func loadFile(fileName string) (string, []byte) {
goPath := os.Getenv("GOPATH")
filePath := path.Join(goPath, fileName)

input, err := ioutil.ReadFile(filePath)
input, err := ioutil.ReadFile(fileName)

if err != nil {
panic(err)
Expand Down
1 change: 0 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package parser

import "C"
import (
"fmt"
"github.com/ElaraLang/elara/lexer"
Expand Down

0 comments on commit f23f73a

Please sign in to comment.