Skip to content

Commit

Permalink
Revert "Merge branch 'discretization' into dev"
Browse files Browse the repository at this point in the history
This reverts commit 10f2d3f, reversing
changes made to d5485a2.
  • Loading branch information
softmattertheory committed Jun 6, 2024
1 parent 10f2d3f commit 1ad9511
Show file tree
Hide file tree
Showing 21 changed files with 423 additions and 1,188 deletions.
73 changes: 40 additions & 33 deletions src/builtin/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
#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 @@ -56,20 +60,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 @@ -84,15 +88,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 @@ -102,9 +106,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 @@ -179,23 +183,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 @@ -221,16 +225,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 @@ -264,13 +268,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 @@ -319,18 +323,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 @@ -345,24 +349,27 @@ 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
geometry_initialize();

mesh_initialize();
selection_initialize();
field_initialize();
functional_initialize();

morpho_addfinalizefn(builtin_finalize);
}

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

#ifndef M_PI
Expand Down
14 changes: 5 additions & 9 deletions src/geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
target_sources(morpho
PRIVATE
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
field.c field.h
functional.c functional.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 1ad9511

Please sign in to comment.