Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b720614
New slow source-of-truth resolver
softmattertheory Apr 20, 2026
90b7020
filter by types
softmattertheory Apr 21, 2026
eec8511
Resolve using specificity
softmattertheory Apr 21, 2026
06a1216
New resolver passes test suite
softmattertheory Apr 22, 2026
a5a6f60
Additional multiple dispatch tests
softmattertheory Apr 22, 2026
7e5cf05
Disable old resolver
softmattertheory Apr 22, 2026
d4ef841
Reorganize code
softmattertheory Apr 22, 2026
7a73b85
Minimal fast resolver
softmattertheory Apr 23, 2026
0971973
First stage of compiler, the analyzer
softmattertheory Apr 23, 2026
be3f4f5
Add index back in
softmattertheory Apr 23, 2026
8d855a0
Workable arity compiler
softmattertheory Apr 25, 2026
4c27a76
Simplify and clean arity checking
softmattertheory Apr 25, 2026
85013ff
Simplify arity checking in mf compiler
softmattertheory Apr 25, 2026
7ac7f82
Improve mf compiler error reporting
softmattertheory Apr 25, 2026
ecd1043
getuid instruction, disassembly and emitter
softmattertheory Apr 26, 2026
56599cd
Separate out arity case emission
softmattertheory Apr 26, 2026
3d8faad
Typed dispatch
softmattertheory Apr 27, 2026
6dbeca1
Fix resolvetypecase
softmattertheory Apr 27, 2026
8fe087c
Basic varg support
softmattertheory Apr 27, 2026
3d4823e
Remove old resolver
softmattertheory Apr 27, 2026
62c840f
Improvements to varg support
softmattertheory Apr 27, 2026
cfc45d0
Recursive metafunction compiler
softmattertheory Apr 29, 2026
ae0cc6d
metafunction_reduce
softmattertheory Apr 29, 2026
fd3a1ed
Compiler specialization of metafunctions
softmattertheory Apr 29, 2026
9ad8dc2
Harden signatures
softmattertheory Apr 29, 2026
37e65b1
Harden Complex signatures
softmattertheory Apr 29, 2026
c9e8477
Harden complex numbers through clearer signatures
softmattertheory Apr 29, 2026
d45bec8
Type hardening of builtin
softmattertheory Apr 30, 2026
0ff5ab0
Arctan
softmattertheory Apr 30, 2026
435550c
Metafunctionized apply
softmattertheory May 1, 2026
65e5ea8
Improve clarity of metafunction compiler
softmattertheory May 3, 2026
a26c9b9
Improve constructor metafunction signatures
softmattertheory May 3, 2026
351b972
Tighten JSON methods
softmattertheory May 3, 2026
280f99e
Harden signatures in System
softmattertheory May 3, 2026
9ef92b5
Harden Tuple signatures
softmattertheory May 3, 2026
4c1ee63
Improve List signatures and eliminate checks within method implementa…
softmattertheory May 3, 2026
9d6152f
Harden the String class
softmattertheory May 3, 2026
cab13da
Assign objectmetafunctiontype with core classes.
softmattertheory May 3, 2026
2b33c0a
Simplify String_split
softmattertheory May 3, 2026
b2d8530
Harden Range
softmattertheory May 3, 2026
715ba0a
More hardening of types
softmattertheory May 3, 2026
6cb8a83
Expand List_getindex
softmattertheory May 4, 2026
6cc73b5
Dictionary set operation signatures
softmattertheory May 4, 2026
1b8eb3b
Fix String_enumerate
softmattertheory May 4, 2026
1d749f2
Correct Matrix return type
softmattertheory May 4, 2026
a4e3260
Fix bug in metafunction_add
softmattertheory May 4, 2026
eeb379c
Improve metafunction_reduce
softmattertheory May 4, 2026
e906f09
Fix bug in comparespecificity
softmattertheory May 4, 2026
a8c9c36
Fix type inference in compile.c
softmattertheory May 4, 2026
8007a8d
fix comparespecificity
softmattertheory May 4, 2026
63b521c
Reduce only for exact types
softmattertheory May 4, 2026
0114c52
Additional tests and fix varray
softmattertheory May 6, 2026
87e8a4e
Fix incorrect signatures for some math functions
softmattertheory May 6, 2026
42cd69f
Function annotation cleanup
softmattertheory May 7, 2026
8fec42e
CFunction annotation
softmattertheory May 7, 2026
81e91b1
Fix issue with name ownership
softmattertheory May 12, 2026
6c3dbcf
Add missing selectors
softmattertheory May 13, 2026
546be39
Remove bytecodeoptimizer from some tests
softmattertheory May 20, 2026
67e3ecb
Merge branch 'dev' into newresolver
softmattertheory May 21, 2026
bf8833a
Fix string checks
softmattertheory May 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions src/builtin/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "sparse.h"
#include "geometry.h"

extern objecttypedefn objectmetafunctiondefn;

/* **********************************************************************
* Global data
* ********************************************************************** */
Expand Down Expand Up @@ -52,7 +54,7 @@ void builtin_init(objectbuiltinfunction *func) {

/** Clear an objectbuiltinfunction */
void builtin_clear(objectbuiltinfunction *func) {
morpho_freeobject(func->name);
if (MORPHO_ISOBJECT(func->name)) object_freeifunmanaged(MORPHO_GETOBJECT(func->name));
signature_clear(&func->sig);
}

Expand Down Expand Up @@ -126,15 +128,6 @@ bool builtin_options(vm *v, int nargs, value *args, int *nfixed, int noptions, .
return true;
}

/** Tests whether an object is callable */
bool builtin_iscallable(value val) {
return (MORPHO_ISOBJECT(val) && (MORPHO_ISFUNCTION(val) ||
MORPHO_ISCLOSURE(val) ||
MORPHO_ISINVOCATION(val) ||
MORPHO_ISBUILTINFUNCTION(val) ||
MORPHO_ISMETAFUNCTION(val)));
}

/* **********************************************************************
* object_builtinfunction definition
* ********************************************************************** */
Expand Down Expand Up @@ -294,10 +287,16 @@ bool morpho_addfunction(char *name, char *signature, builtinfunction func, built
new->flags=flags;

new->name=object_stringfromcstring(name, strlen(name));
if (!name) goto morpho_addfunction_cleanup;
if (!MORPHO_ISSTRING(new->name)) goto morpho_addfunction_cleanup;

// Parse function signature if provided
if (signature) builtin_addparsesignature(signature, &new->sig);

value selector = dictionary_intern(&builtin_symboltable, new->name);
if (MORPHO_ISNIL(selector)) goto morpho_addfunction_cleanup;
if (!MORPHO_ISSAME(selector, new->name)) morpho_freeobject(new->name);
new->name=selector;
builtin_bindobject(MORPHO_GETOBJECT(selector));

value newfn = MORPHO_OBJECT(new);

Expand All @@ -313,7 +312,6 @@ bool morpho_addfunction(char *name, char *signature, builtinfunction func, built

morpho_addfunction_cleanup:
if (new) {
builtin_clear(new);
object_free((object *) new);
}

Expand Down Expand Up @@ -369,10 +367,19 @@ bool morpho_addclass(char *name, builtinclassentry desc[], int nparents, value *
newmethod->function=desc[i].function;
newmethod->klass=new;
newmethod->name=object_stringfromcstring(desc[i].name, strlen(desc[i].name));
if (!MORPHO_ISSTRING(newmethod->name)) { success=false; break; }
newmethod->flags=desc[i].flags;
if (desc[i].signature) builtin_addparsesignature(desc[i].signature, &newmethod->sig);

dictionary_intern(&builtin_symboltable, newmethod->name);
value selector = dictionary_intern(&builtin_symboltable, newmethod->name);
if (MORPHO_ISNIL(selector)) {
object_free((object *) newmethod);
success=false;
break;
}
if (!MORPHO_ISSAME(selector, newmethod->name)) morpho_freeobject(newmethod->name);
newmethod->name=selector;
builtin_bindobject(MORPHO_GETOBJECT(selector));
value method = MORPHO_OBJECT(newmethod);

builtin_bindobject((object *) newmethod);
Expand Down Expand Up @@ -456,6 +463,7 @@ void builtin_initialize(void) {
objectclasstype=object_addtype(&objectclassdefn);
objectstringtype=object_addtype(&objectstringdefn);
objectbuiltinfunctiontype=object_addtype(&objectbuiltinfunctiondefn);
objectmetafunctiontype=object_addtype(&objectmetafunctiondefn);

varray__sigparseinit(&sigparseworklist);

Expand Down Expand Up @@ -514,7 +522,7 @@ void builtin_initialize(void) {
UNREACHABLE("Unable to finalize builtin metafunctions.");
}
error_clear(&err);

morpho_addfinalizefn(builtin_finalize);
}

Expand Down
37 changes: 28 additions & 9 deletions src/builtin/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,34 @@ bool builtin_parsesignatures(void);
/** Flags that describe properties of the built in function */
typedef unsigned int builtinfunctionflags;

#define BUILTIN_FLAGSEMPTY 0

#define MORPHO_FN_FLAGSEMPTY (0)
#define MORPHO_FN_PUREFN (1<<1) // Pure function: no side effects
#define MORPHO_FN_CONSTRUCTOR (1<<2) // Constructor function
#define MORPHO_FN_REENTRANT (1<<3) // Function that re-enters the vm, e.g. but using morph_call
#define MORPHO_FN_OPTARGS (1<<4) // Function that has optional arguments
/* Annotation policy:
* - MORPHO_FN_FLAGSEMPTY means unknown or legacy-unreviewed; optimizers should stay conservative.
* - MORPHO_FN_NONE means the function has been reviewed and has no special semantic annotation.
* - MORPHO_FN_PUREFN means pure on normal return: deterministic for constant inputs with no mutation,
* I/O, VM re-entry, thread-local dependence, or multithreaded execution.
* - Functions that allocate returned objects should generally carry MORPHO_FN_ALLOCATES|MORPHO_FN_THROWS,
* because object construction / wrap-and-bind may fail.
* - MORPHO_FN_MUTATES is reserved for externally observable mutation, not internal caching.
* - MORPHO_FN_IO includes reads from process, filesystem, or platform state.
* - MORPHO_FN_NONDETERMINISTIC is reserved for genuinely unstable results such as RNG-like behavior.
*/

#define MORPHO_FN_FLAGSEMPTY (0) // Unknown or legacy-unreviewed flags: optimizer should assume any annotation may apply
#define MORPHO_FN_NONE (1<<0) // Function has been reviewed and has no special semantic annotations

#define BUILTIN_FLAGSEMPTY MORPHO_FN_FLAGSEMPTY

#define MORPHO_FN_PUREFN (1<<1) // Pure on normal return: deterministic for constant inputs, no mutation, I/O or re-entry
#define MORPHO_FN_CONSTRUCTOR (1<<2) // Constructor function
#define MORPHO_FN_REENTRANT (1<<3) // Function that re-enters the vm, e.g. by using morpho_call
#define MORPHO_FN_OPTARGS (1<<4) // Function reads VM optional/named arguments
#define MORPHO_FN_THROWS (1<<5) // Function may raise a runtime error
#define MORPHO_FN_ALLOCATES (1<<6) // Function may allocate and return/bind new objects
#define MORPHO_FN_MUTATES (1<<7) // Function may mutate receiver, arguments, or runtime-visible state
#define MORPHO_FN_IO (1<<8) // Function performs externally observable I/O or system interaction
#define MORPHO_FN_NONDETERMINISTIC (1<<9) // Function may return different results for the same inputs
#define MORPHO_FN_THREADLOCAL (1<<10) // Function depends on or mutates VM thread-local state
#define MORPHO_FN_MULTITHREADED (1<<11) // Function may execute work across multiple threads

/** Type of C function that implements a built in Morpho function */
typedef value (*builtinfunction) (vm *v, int nargs, value *args);
Expand Down Expand Up @@ -139,8 +160,6 @@ value builtin_internsymbolascstring(char *symbol);
bool builtin_checksymbol(value symbol);

bool builtin_options(vm *v, int nargs, value *args, int *nfixed, int noptions, ...);
bool builtin_iscallable(value val);

bool builtin_enumerateloop(vm *v, value obj, builtin_loopfunction fn, void *ref);

/* -------------------------------------------------------
Expand Down
Loading
Loading