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

Commit f23f73a

Browse files
committed
Support for running outside of GOPATH and include some binaries for Linux and Windows
1 parent af3b185 commit f23f73a

File tree

7 files changed

+61
-11
lines changed

7 files changed

+61
-11
lines changed

bin/elara-linux-amd64

2.85 MB
Binary file not shown.

bin/elara-windows-amd64.exe

3 MB
Binary file not shown.

bin/elara.el

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace examples/main
2+
import elara/std
3+
4+
struct Test {
5+
String name
6+
}
7+
8+
extend Test {
9+
let b = 3
10+
let print-name => print(name)
11+
}
12+
13+
let test = Test("Test Struct")
14+
test.print-name()
15+
print(test.b)

bin/stdlib/base.el

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace elara/std
2+
3+
let print = (Any msg) => Unit {
4+
print-raw(msg + "\n")
5+
}
6+
7+
let print-raw = (Any msg) => {
8+
stdout.write(msg)
9+
}

build.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
echo 'Cleaning Up...'
2+
rm -rf bin/
3+
mkdir bin
4+
echo 'Moving Standard Library...'
5+
cp -r stdlib bin/
6+
cp elara.el bin/
7+
8+
echo 'Building Windows amd64...'
9+
env GOOS=linux GOARCH=amd64 go build -o bin/elara-linux-amd64
10+
11+
echo 'Building Linux amd64...'
12+
env GOOS=windows GOARCH=amd64 go build -o bin/elara-windows-amd64.exe
13+
14+
echo 'Done!'

elara.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,37 @@ func main() {
3838
func loadStdLib() {
3939
goPath := os.Getenv("GOPATH")
4040
filePath := path.Join(goPath, "stdlib/")
41-
filepath.Walk(filePath, func(path string, info os.FileInfo, err error) error {
41+
defer func() {
42+
err := recover()
43+
if err == nil {
44+
return
45+
}
46+
//Maybe it's not present in GOPATH, let's try in working directory
47+
cur, err := os.Executable()
4248
if err != nil {
4349
panic(err)
4450
}
45-
if info.IsDir() {
46-
return nil
47-
}
48-
_, content := loadFile(path)
49-
base.Execute(&path, string(content), false)
51+
filePath = path.Join(filepath.Dir(cur), "stdlib/")
52+
filepath.Walk(filePath, loadWalkedFile)
53+
}()
54+
filepath.Walk(filePath, loadWalkedFile)
55+
}
56+
57+
func loadWalkedFile(path string, info os.FileInfo, err error) error {
58+
if err != nil {
59+
panic(err)
60+
}
61+
if info.IsDir() {
5062
return nil
51-
})
63+
}
64+
_, content := loadFile(path)
65+
base.Execute(&path, string(content), false)
66+
return nil
5267
}
5368

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

58-
input, err := ioutil.ReadFile(filePath)
71+
input, err := ioutil.ReadFile(fileName)
5972

6073
if err != nil {
6174
panic(err)

parser/parser.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package parser
22

3-
import "C"
43
import (
54
"fmt"
65
"github.com/ElaraLang/elara/lexer"

0 commit comments

Comments
 (0)