Skip to content

Commit

Permalink
Merge branch 'discretization' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
softmattertheory committed Jun 6, 2024
2 parents d5485a2 + 60cdd47 commit 10f2d3f
Show file tree
Hide file tree
Showing 21 changed files with 1,188 additions and 423 deletions.
73 changes: 33 additions & 40 deletions src/builtin/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
#include "functiondefs.h"
#include "file.h"
#include "system.h"
#include "geometry.h"
#include "classes.h"

#include "mesh.h"
#include "selection.h"
#include "functional.h"
#include "field.h"

/* **********************************************************************
* Global data
* ********************************************************************** */
Expand Down Expand Up @@ -60,20 +56,20 @@ void builtin_init(objectbuiltinfunction *func) {
bool builtin_enumerateloop(vm *v, value obj, builtin_loopfunction fn, void *ref) {
value enumerate=MORPHO_NIL;
value count=MORPHO_NIL, in=MORPHO_INTEGER(-1), val=MORPHO_NIL;

if (morpho_lookupmethod(obj, enumerateselector, &enumerate)) {
if (!morpho_invoke(v, obj, enumerate, 1, &in, &count)) return false;
if (!MORPHO_ISINTEGER(count)) return false;

for (indx i=0; i<MORPHO_GETINTEGERVALUE(count); i++) {
in=MORPHO_INTEGER(i);

if (!morpho_invoke(v, obj, enumerate, 1, &in, &val)) return false;

if (!(*fn) (v, i, val, ref)) return false;
}
}

return true;
}

Expand All @@ -88,15 +84,15 @@ bool builtin_options(vm *v, int nargs, value *args, int *nfixed, int noptions, .
va_list optlist;
va_start(optlist, noptions);
int nposn=nargs;

for (unsigned int i=1; i<=nargs; i++) {
if (MORPHO_ISSAME(args[i], vm_optmarker)) { nposn=i-1; break; }
}

for (unsigned int i=0; i<noptions; i++) {
value symbol = va_arg(optlist, value);
value *dest = va_arg(optlist, value*);

for (int k=nposn+2; k<nargs; k+=2) {
if (MORPHO_ISSAME(symbol, args[k])) {
*dest = args[k+1];
Expand All @@ -106,9 +102,9 @@ bool builtin_options(vm *v, int nargs, value *args, int *nfixed, int noptions, .
// TODO: Should raise an error for unexpected options here by looking for arguments that are strings and unmanaged?
}
if (nfixed) *nfixed = nposn; // Exclude register 0

va_end(optlist);

return true;
}

Expand Down Expand Up @@ -183,23 +179,23 @@ value builtin_addfunction(char *name, builtinfunction func, builtinfunctionflags
objectbuiltinfunction *new = (objectbuiltinfunction *) object_new(sizeof(objectbuiltinfunction), OBJECT_BUILTINFUNCTION);
value out = MORPHO_NIL;
varray_valuewrite(&builtin_objects, MORPHO_OBJECT(new));

if (new) {
builtin_init(new);
new->function=func;
new->name=object_stringfromcstring(name, strlen(name));
new->flags=flags;
out = MORPHO_OBJECT(new);

value selector = dictionary_intern(&builtin_symboltable, new->name);

if (dictionary_get(_currentfunctiontable, new->name, NULL)) {
UNREACHABLE("Redefinition of function in same extension [in builtin.c]");
}

dictionary_insert(_currentfunctiontable, selector, out);
}

return out;
}

Expand All @@ -225,16 +221,16 @@ value builtin_addclass(char *name, builtinclassentry desc[], value superclass) {
objectclass *new = object_newclass(label);
varray_valuewrite(&builtin_objects, MORPHO_OBJECT(new));
objectclass *superklass = NULL;

if (!new) return MORPHO_NIL;

/** Copy methods from superclass */
if (MORPHO_ISCLASS(superclass)) {
superklass = MORPHO_GETCLASS(superclass);
dictionary_copy(&superklass->methods, &new->methods);
new->superclass=superklass;
}

for (unsigned int i=0; desc[i].name!=NULL; i++) {
if (desc[i].type==BUILTIN_METHOD) {
objectbuiltinfunction *newmethod = (objectbuiltinfunction *) object_new(sizeof(objectbuiltinfunction), OBJECT_BUILTINFUNCTION);
Expand Down Expand Up @@ -268,13 +264,13 @@ value builtin_addclass(char *name, builtinclassentry desc[], value superclass) {
} else dictionary_insert(&new->methods, selector, method);
}
}

if (dictionary_get(_currentclasstable, label, NULL)) {
UNREACHABLE("Redefinition of class in same extension [in builtin.c]");
}

dictionary_insert(_currentclasstable, label, MORPHO_OBJECT(new));

return MORPHO_OBJECT(new);
}

Expand Down Expand Up @@ -323,18 +319,18 @@ void builtin_initialize(void) {
dictionary_init(&builtin_classtable);
dictionary_init(&builtin_symboltable);
varray_valueinit(&builtin_objects);

builtin_setfunctiontable(&builtin_functiontable);
builtin_setclasstable(&builtin_classtable);

// Initialize core object types
objectstringtype=object_addtype(&objectstringdefn);
objectclasstype=object_addtype(&objectclassdefn);
objectbuiltinfunctiontype=object_addtype(&objectbuiltinfunctiondefn);

/* Initialize builtin classes and functions */
instance_initialize(); // Must initialize first so that Object exists

string_initialize(); // Classes
function_initialize();
metafunction_initialize();
Expand All @@ -349,27 +345,24 @@ void builtin_initialize(void) {
complex_initialize();
err_initialize();
tuple_initialize();

float_initialize();// Veneer classes
int_initialize();

file_initialize();
system_initialize();
json_initialize();

// Initialize function definitions
functiondefs_initialize();

// Initialize linear algebra
matrix_initialize();
sparse_initialize();

// Initialize geometry
mesh_initialize();
selection_initialize();
field_initialize();
functional_initialize();

geometry_initialize();

morpho_addfinalizefn(builtin_finalize);
}

Expand Down
4 changes: 1 addition & 3 deletions src/builtin/functiondefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
#include "builtin.h"
#include "common.h"
#include "matrix.h"
#include "mesh.h"
#include "field.h"
#include "selection.h"
#include "geometry.h"
#include "cmplx.h"

#ifndef M_PI
Expand Down
14 changes: 9 additions & 5 deletions src/geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
target_sources(morpho
PRIVATE
field.c field.h
functional.c functional.h
integrate.c integrate.h
mesh.c mesh.h
selection.c selection.h
discretization.c discretization.h
field.c field.h
functional.c functional.h
geometry.c geometry.h
integrate.c integrate.h
mesh.c mesh.h
selection.c selection.h
)

target_sources(morpho
INTERFACE
FILE_SET public_headers
TYPE HEADERS
FILES
discretization.h
field.h
functional.h
geometry.h
integrate.h
mesh.h
selection.h
Expand Down
Loading

0 comments on commit 10f2d3f

Please sign in to comment.