Skip to content

Commit

Permalink
Merge pull request #276 from Morpho-lang/dev
Browse files Browse the repository at this point in the history
v0.6.1 initial PR
  • Loading branch information
softmattertheory authored Oct 25, 2024
2 parents 9a638f8 + 45531a5 commit 537e7b0
Show file tree
Hide file tree
Showing 158 changed files with 4,660 additions and 609 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/NoNanBoxing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: No NANBoxing

on:
push:
branches: [ "main" ]
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "dev" ]

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Build

on:
push:
branches: [ "main" ]
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "dev" ]

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/buildandtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Build and Test

on:
push:
branches: [ "main" ]
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "dev" ]

jobs:
build:
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/buildandtestmultithreaded.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: TestMultiThreaded

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main", "dev" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: configure
run: |
sudo apt update
sudo apt install libsuitesparse-dev
sudo apt install liblapacke-dev
sudo apt install libunistring-dev
python -m pip install --upgrade pip
python -m pip install regex colored
- name: make
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
sudo make install
sudo mkdir /usr/local/lib/morpho
- name: getcli
run: |
git clone https://github.com/Morpho-lang/morpho-cli.git
cd morpho-cli
mkdir build
cd build
cmake ..
sudo make install
- name: test
run: |
cd test
python3 test.py -c -m
54 changes: 54 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Examples

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main", "dev" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: configure
run: |
sudo apt update
sudo apt install libglfw3-dev
sudo apt install povray
sudo apt install libfreetype6-dev
sudo apt install fonts-freefont-ttf
sudo apt install libsuitesparse-dev
sudo apt install liblapacke-dev
sudo apt install libunistring-dev
python -m pip install --upgrade pip
python -m pip install regex colored
- name: make
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
sudo make install
sudo mkdir /usr/local/lib/morpho
- name: getcli
run: |
git clone https://github.com/Morpho-lang/morpho-cli.git
cd morpho-cli
mkdir build
cd build
cmake ..
sudo make install
- name: morphoview
run: |
git clone https://github.com/morpho-lang/morpho-morphoview.git
cd morpho-morphoview
mkdir build
cd build
cmake ..
sudo make install
- name: test
run: |
cd examples
python3 examples.py -c
4 changes: 2 additions & 2 deletions .github/workflows/nonanboxing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: No NANBoxing

on:
push:
branches: [ "main" ]
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "dev" ]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dkms.conf
.entitlements
.vscode/settings.json

test/FailedTests.txt
test/FailedTests*.txt
*.png
*.out
manual/src/manual.lyx~
Expand Down
34 changes: 34 additions & 0 deletions benchmark/Metafunction/metafunction.morpho
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Call a meta function


fn f(Int x) { return x }

fn f(Float x) { return x }

fn f(String x) { return x }

fn g(x) { return x }

var a = "Hello"

var n = 10000000

var start = System.clock()
for (i in 1..n) {
g(1)
g(2.0)
g(a)
}
var end = System.clock()

print "Regular function ${end-start}"

var start = System.clock()
for (i in 1..n) {
f(1)
f(2.0)
f(a)
}
var end = System.clock()

print "Metafunction ${end-start}"
9 changes: 6 additions & 3 deletions examples/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

sys.path.append('../test')
ext = "morpho"
command = 'morpho5'
command = 'morpho6'
stk = '@stacktrace'
err = '@error'

Expand Down Expand Up @@ -63,11 +63,11 @@ def getoutput(filepath):
lines[i+1]=stk
# and remove them
return list(filter(lambda x: x!=stk, lines))

def run(file,testLog,CI):
ret = 1
print(file+":", end=" ")


# Create a temporary file in the same directory
tmp = file + '.out'

Expand Down Expand Up @@ -118,8 +118,11 @@ def run(file,testLog,CI):

# look for a command line arguement that says
# this is being run for continous integration
CI = sys.argv == '-c'

CI = False
for arg in sys.argv:
if arg == '-c': # if the argument is -c, then we are running in CI mode
CI = True

files=glob.glob('**/**.'+ext, recursive=True)
with open("FailedExamples.txt",'w') as testLog:
Expand Down
20 changes: 20 additions & 0 deletions help/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ See also `Object`.

[showsubtopics]: # (subtopics)

## Methods
[tagmethods]: # (methods)

Classes in morpho can define *methods* to manipulate the objects defined by the class. Like functions, multiple implementations can be defined that accept different parameter types [see also topic: `signature`]:

class Foo {
a(List x) { print "A list!" }
a(String x) { print "A string!" }
a(Matrix x) { print "A matrix!" }
}

Having created an object with the class,

var x = Foo()

the correct implementation is selected at runtime:

x.a([1,2]) // expect: A list!
x.a("Hello") // expect: A string!

## Is
[tagis]: # (is)

Expand Down
2 changes: 2 additions & 0 deletions help/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Errors
[tagerror]: # (error)
[tagerrors]: # (errors)
[tagerrors]: # (throw)
[tagerrors]: # (warning)

When an error occurs in running a morpho program, an error message is displayed together with an explanation of where in the program that the error happened.

Expand Down
65 changes: 65 additions & 0 deletions help/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ Once a function has been defined you can evaluate it like any other morpho funct

print sqr(2)

Functions can accept optional parameters:

fn fun(x, quiet=true ) { if (!quiet) print "Loud!" }

Morpho functions can also be defined to restrict the type of accepted parameters:

fn f(List x) { print "A list!" }

Multiple implementations can be defined that accept different numbers of parameters and parameter types:

fn f() { print "No parameters!" }
fn f(String x) { print "A string!" }
fn f(Tuple x) { print "A tuple!" }

The correct implementation is then selected at runtime:

f("Hello World!") // expect: A string!

[show]: # (subtopics)

## Variadic
Expand Down Expand Up @@ -57,6 +75,8 @@ Each optional parameter must be defined with a default value (here `1`). The fun
func() // a == 1 due to default value
func(a=2) // a == 2 supplied by the user

Note that optional parameters may not be typed.

## Return
[tagreturn]: # (return)

Expand All @@ -69,6 +89,51 @@ The `return` keyword is used to exit from a function, optionally passing a given

by returning early if `n<2`, otherwise returning the result by recursively calling itself.

## Signature
[tagsignature]: # (signature)

The *signature* of a function is a list of the types of arguments in its definition:

fn f(x) {} // Accepts one parameter of any type
fn f(x,y) {} // Accepts two parameters of any type
fn f(List x, y) {} // The first parameter must be a list
fn f(List x, List y) {} // Both parameters must be lists

While you can define multiple implementations of a function that accept different parameter types, you can only define one implementation with a unique signature.

Note that optional and variadic parameters are not typed.

# Multiple dispatch
[tagmultiple]: # (multiple)
[tagdispatch]: # (dispatch)
[tagmultipledispatch]: # (multipledispatch)

Morpho supports *multiple dispatch*, whereby you can define several implementations of a function that accept different types:

fn f(List x) { return "Accepts a list" }
fn f(String x) { return "Accepts a string" }

Morpho chooses the appropriate implementation at runtime:

f([1,2,3]) // Selects the List implementation

Any classes you define can be used as types:

class A {}
class B is A {}
class C is B {}

fn f(A x) { return "A" }
fn f(B x) { return "B" }

Morpho selects the *closest match*, so that:

print f(A()) // expect: A
print f(B()) // expect: B
print f(C()) // expect: B

Class `C` inherits from both `B` and `A`, but because it directly inherits from `B`, that's the closer match.

# Closures
[tagclosures]: # (closures)
[tagclosure]: # (closure)
Expand Down
Loading

0 comments on commit 537e7b0

Please sign in to comment.