Compare commits

..

107 Commits

Author SHA1 Message Date
3ce098953e fix __proto object getter 2023-09-11 22:17:35 -05:00
aaede37839 minor refactoring 2023-09-06 20:23:18 -05:00
b3f3ad992d added file:write() & an optional mode param to os.open() 2023-09-06 17:29:38 -05:00
f51e072922 removed more debug prints 2023-09-05 14:45:03 -05:00
b66858d286 removed debug prints, oops 2023-09-05 14:43:50 -05:00
34c55eee87 fix makefile 2023-09-05 14:42:29 -05:00
a2d0b79c2e documented the new os.open and file objects 2023-09-05 14:41:59 -05:00
4de274d760 added os.open(); new file object
eg.
```lua
local err, file = os.open("LICENSE.md")
if err then
    // do error handling stuff
end

// passing "a" to read() will read the whole file
print(file:read("a"))
```
2023-09-05 14:38:24 -05:00
074e8b52cc removed 'roots', replaced with a registry table
- removed cosmoM_addRoot
- removed cosmoM_removeRoot
- renamed cosmoV_register to cosmoV_addGlobals
- added cosmoV_addRegistry
- added cosmoV_getRegistry
- added cosmoV_setProto
- added cosmoV_isValueUserType
2023-09-05 14:35:29 -05:00
56161a32e7 capture freezeGC in CPanic 2023-09-05 02:23:31 -05:00
1544332b90 build a release build for linux as well 2023-09-04 20:15:15 -05:00
b73d865447 even more error handling refactoring
removing all of these useless checks has actually made cosmoV_execute just a
lil bit faster :)
2023-09-04 20:14:53 -05:00
5a00d61646 lol oops 2023-09-01 17:16:10 -05:00
83dfd36c5c switched to a better linenoise fork
https://github.com/msteveb/linenoise

this version has several benefits, namely win32 support :D
2023-09-01 17:12:39 -05:00
2d889a37d1 fix artifacts path 2023-09-01 14:43:20 -05:00
0f0a8fb085 better repl input, using linenoise 2023-08-31 23:17:13 -05:00
c03df8f506 include util path 2023-08-31 23:16:28 -05:00
38d9c499ea whoops, wrong path to the workflow file 2023-08-30 21:30:20 -05:00
79d40d4bb0 ig that runner doesn't work lol 2023-08-30 21:28:50 -05:00
dc44adba6e removed CERROR 2023-08-30 20:14:03 -05:00
7c0bec5e6c allow manual runs 2023-08-30 20:12:06 -05:00
a44450ff22 wrong output path for windows build 2023-08-30 20:09:06 -05:00
58c857d2ea oops 2023-08-30 20:03:30 -05:00
38136d028f switched from appveyor to github workflow 2023-08-30 20:02:04 -05:00
420cd3e856
Merge pull request #7 from CPunch/error-handling
Error handling
2023-08-30 12:05:57 -05:00
bfde2d25cf
Merge branch 'main' into error-handling 2023-08-30 12:03:01 -05:00
97d40765ce more refactoring; things seem to work fine
all example scripts run fine with GC_STRESS enabled
2023-08-30 12:00:52 -05:00
37e4653d40 don't freezeGC during GC cycle 2023-08-29 23:32:25 -05:00
1ae473383d fix more GC bugs 2023-08-29 23:21:52 -05:00
6ed5589513 fix cparse.c gc bug 2023-08-29 23:01:47 -05:00
1408a07b23 fix this test script 2023-08-29 16:51:04 -05:00
27818b3788 cosmoV_throw() now resets the vm stack as well
also a minor GC bug in cosmoO_newError was fixed.

i'm going to try to phase out cosmoM_freezeGC & friends
since that would cause hell with this new
error handling solution. the only thing still using it is the GC.
2023-08-29 16:48:38 -05:00
37e42eb60b fixed minor memory leak in cparse
we keep track of internal values used by the parser by pushing them onto the stack
and popping them off once complete.
2023-08-29 15:27:22 -05:00
cd3047c271 WIP: removed stale error handling
currently, scripts seem to run fine. however I'm a bit worried about stack related issues. maybe i'll need to reset state->top as well? but not entirely sure
2023-08-29 14:07:45 -05:00
f26376e6f5 WIP: major error handling refactoring
switching to setjmp instead of the really bad global 'panic' flag
2023-08-28 21:13:00 -05:00
409937c1fa fix vm.collect()
we don't freeze the vm on entry to C functions now
2023-08-26 15:03:56 -05:00
1d2ba217af minor refactoring 2023-08-25 23:34:21 -05:00
e28ffe1c6c refactored cobj.c:printObject()
uses obj type strings from cosmoO_typeStr
2023-08-25 21:28:41 -05:00
9c5270124d finally fixed this memory bug
we were accidentally tracking frees of stuff that was never
allocated lol
2023-08-25 21:22:10 -05:00
5fc9af5564 more debug related refactoring 2023-08-25 20:44:24 -05:00
a1c58647ba minor CTable refactoring 2023-08-25 19:57:16 -05:00
5c3e24fc39 refactoring and cleanup
cosmoB_loadOSLib -> cosmoB_loadOS
2023-08-24 23:36:32 -05:00
dcf6a09dae minor refactoring 2023-06-03 01:39:35 -05:00
e0faa14b35 implemented jump table dispatch
- currently only enabled on supported platforms (GNU C Compiler + Clang)
- when enabled, sped up examples/fibtest.cosmo by about 20% (avg of 11.179s prior and 8.799 after)

NOTE: malicious dumps can trivially cause crashes now by having junk function chunks
2023-06-03 01:17:28 -05:00
861607d6a8 fixed formatting 2023-06-01 22:28:07 -05:00
10c9f92a06 Merge branch 'main' of github.com:CPunch/Cosmo 2023-06-01 22:22:50 -05:00
8dfd7744c2 fixed MSVC support 2023-06-01 22:22:44 -05:00
7f7bc7c6ad added vm.disassemble() 2023-06-01 19:04:12 -05:00
5169aca6d0 forgot to update this a while back 2023-05-28 21:16:30 -05:00
c34c5850e2 whoops, need to update the command to run the testsuite 2023-05-28 21:13:51 -05:00
07ba4c731e update README.md 2023-05-28 21:11:52 -05:00
788911130d
Merge pull request #6 from CPunch/chunk-loading
Chunk loading
2023-05-28 20:59:10 -05:00
c464a76849 minor usage fix 2023-05-28 20:57:53 -05:00
8c6ba18848 major main.c refactoring
- now takes command line arguments:
Usage: ./bin/cosmo [-clsr] [args]

available options are:
-c <in> <out>   compile <in> and dump to <out>
-l <in>         load dump from <in>
-s <in...>              compile and run <in...> script(s)
-r                      start the repl
2023-05-28 20:52:12 -05:00
93a09698a9 minor stack fixes 2023-05-28 12:19:52 -05:00
be49ec5af5 proper error handling for dump edgecases 2023-05-28 12:16:00 -05:00
4fe437ea4e undef macros 2023-05-28 12:03:49 -05:00
e854c5dbb3 fixed GC bug in cundump.c 2023-05-28 11:55:48 -05:00
c945c56482 these values can be defined at the top of the function 2023-05-28 00:08:28 -05:00
89d443d767 formatting changes 2023-05-28 00:03:50 -05:00
54a959438b added cdump.[ch] and cundump.[ch] to makefile 2023-05-27 23:17:17 -05:00
355842989b cvm.c: added cosmoV_undump 2023-05-27 23:16:47 -05:00
45f36e6e87 cdump.c: major refactoring; various fixes 2023-05-27 23:15:58 -05:00
819e76b711 cdump.c: fix instruction and line info dumping 2023-05-27 23:15:12 -05:00
f116efa02c started cundump.c:cosmoD_undump(); minor fixes 2023-05-25 21:12:21 -05:00
465f4d5e4a started cdump.c:cosmoD_dump() 2023-05-25 19:41:13 -05:00
3efee51224 minor refactoring and typos 2023-05-25 19:40:15 -05:00
2836de090b removed stale COBJ_STREAM usage 2023-05-25 18:34:39 -05:00
8e278e3a7d update Docs to reflect keyword changes 2023-02-10 20:46:05 -06:00
c8cae03604 syntax: 'var'->'let' 'function'->'func'
- 'var' has some weird scoping connotations with users of JS. better to change it to 'let', which will decide whether to make the variable a local or a global
- 'func' looks visually appealing lol
- some minor refactoring done in cparse.c
2023-02-09 15:58:25 -06:00
5d805e258b minor formatting fixes 2023-02-09 12:52:36 -06:00
8df4cc65e3 removed CObjStream 2023-02-09 12:42:09 -06:00
7279623e24 added clang-format 2023-02-09 12:32:48 -06:00
517b0b9532 Removed '-Werror' to the Makefile 2021-06-11 15:01:53 -05:00
1df2e212cb
Merge pull request #4 from NeoInversion/dev
Commit authored by https://github.com/NeoInversion
2021-03-28 01:18:39 -05:00
Inversion
84ec5d2aee Add documentation for the OS library 2021-03-27 23:11:47 -07:00
6859ec98ad Added boilerplate for CObjStream 2021-03-20 01:44:03 -05:00
057716e0d4 Added os.system() to the os.* library 2021-03-20 01:02:13 -05:00
b9e9dedac6 Updated Appveyor to test testsuite 2021-03-19 22:25:23 -05:00
1813bbeb1b Added minimal testsuite for IC
- main.c will now report errors for passed scripts
2021-03-19 22:23:04 -05:00
471589d379 Added svg to README, whitelisted commits only effecting the binary 2021-03-16 15:05:20 -05:00
70f931df18 Added AppVeyor CI 2021-03-16 14:54:52 -05:00
c13db54d7d Added '__equal' metamethod docs 2021-02-24 12:52:31 -06:00
da85d640ce Added another example script 'compare.comso'
- This stresses the table implementation as well as cosmoV_equals
2021-02-23 11:50:41 -06:00
6bc4ec6b04 Improved cosmoO_equals performance for strings 2021-02-23 11:49:57 -06:00
f92ffcecbd Added '__equal' metamethod, slightly refactored cosmoO_equal
- ISTRING_EQUAL has been added
2021-02-20 12:42:13 -06:00
66d77bc54b Refactored cosmoO_equals
This sets up room for the '__equal' metamethod to be added

- cosmoO_equals now requires the state to be passed
- cosmoV_equals now requires the state to be passed
- cosmoT_get now requires the state to be passed
2021-02-19 17:04:23 -06:00
afac75753f cparse.c now throws an error on illegal statements 2021-02-19 12:47:12 -06:00
92b2db9678
Added <string> arg to assert()
Commit authored by https://github.com/NeoInversion
2021-02-16 18:15:45 -06:00
Inversion
b30616bb3c Temporary fix for possible bug 2021-02-16 16:07:10 -08:00
Inversion
9e6c6038f1 Update standard library documentation 2021-02-16 15:53:20 -08:00
Inversion
1200e2d512 Add optional custom error message to assert 2021-02-16 15:53:07 -08:00
2050359d2f Added C99 support, refactored headers 2021-02-15 16:20:04 -06:00
47051575cb Added basic standard library docs 2021-02-15 14:25:08 -06:00
7c7a2ed8d9 Added math.rad() and math.deg() 2021-02-15 14:06:43 -06:00
d1ea5c9703 Added trig. functions to the math library 2021-02-15 14:00:26 -06:00
7c6c075c2a Added OP_POW to cdebug.c; refactored cosmoV_registerProtoObject
- cosmoV_registerProtoObject now walks the object list and updates the proto's for objects of the objType which have a NULL proto.
- misc. comment changes in cvm.h as well.
2021-02-13 20:08:35 -06:00
14539057aa Added string.rep() to the string library 2021-02-13 19:07:47 -06:00
461e1d0c15 Minor Makefile fix 2021-02-11 20:35:42 -06:00
2e07715a7d Added CMake support
should make integration into visual studio easier for people
2021-02-11 20:34:04 -06:00
bc43eaaa75 Minor cbaselib.c cleanup 2021-02-11 00:58:12 -06:00
43a278e12d
Added error, string.len, and cosmoV_readCString
Commit authored by https://github.com/NeoInversion
2021-02-11 00:27:23 -06:00
Inversion
44f1674b09 Added argument type check to string.len 2021-02-10 22:24:31 -08:00
Inversion
27aedd2969 Updated baselib in accordance with cosmoV_readCString 2021-02-10 22:14:58 -08:00
Inversion
7caa696aa2 Added cosmoV_readCString for convenience 2021-02-10 22:14:31 -08:00
Inversion
2e395065f8 Add string.len to base library 2021-02-10 22:02:35 -08:00
Inversion
5b8dc30bb8 Added error to the base library 2021-02-10 21:48:41 -08:00
7 changed files with 19 additions and 35 deletions

View File

@ -699,9 +699,8 @@ int cosmoB_sRep(CState *state, int nargs, CValue *args)
char *newStr = cosmoM_xmalloc(state, length + 1); // + 1 for the NULL terminator
// copy the string over the new buffer
for (int i = 0; i < times; i++) {
for (int i = 0; i < times; i++)
memcpy(&newStr[i * str->length], str->str, str->length);
}
// write the NULL terminator
newStr[length] = '\0';

View File

@ -5,9 +5,8 @@
void printIndent(int indent)
{
for (int i = 0; i < indent; i++) {
for (int i = 0; i < indent; i++)
printf("\t");
}
}
static int simpleInstruction(const char *name, int offset)

View File

@ -165,9 +165,8 @@ static void blackenObject(CState *state, CObj *obj)
markValue(state, err->err);
// mark callframes
for (int i = 0; i < err->frameCount; i++) {
for (int i = 0; i < err->frameCount; i++)
markObject(state, (CObj *)err->frames[i].closure);
}
break;
}
@ -285,15 +284,13 @@ static void markRoots(CState *state)
markObject(state, (CObj *)state->globals);
// mark all internal strings
for (int i = 0; i < ISTRING_MAX; i++) {
for (int i = 0; i < ISTRING_MAX; i++)
markObject(state, (CObj *)state->iStrings[i]);
}
markTable(state, &state->registry);
for (int i = 0; i < COBJ_MAX; i++) {
for (int i = 0; i < COBJ_MAX; i++)
markObject(state, (CObj *)state->protoObjects[i]);
}
traceGrays(state);
}

View File

@ -15,9 +15,8 @@ uint32_t hashString(const char *str, size_t sz)
uint32_t hash = sz;
size_t step = (sz >> 5) + 1;
for (size_t i = sz; i >= step; i -= step) {
for (size_t i = sz; i >= step; i -= step)
hash = ((hash << 5) + (hash >> 2)) + str[i - 1];
}
return hash;
}
@ -237,9 +236,8 @@ CObjError *cosmoO_newError(CState *state, CValue err)
cerror->parserError = false;
// clone the call frame
for (int i = 0; i < state->frameCount; i++) {
for (int i = 0; i < state->frameCount; i++)
cerror->frames[i] = state->callFrame[i];
}
return cerror;
}

View File

@ -54,13 +54,11 @@ CState *cosmoV_newState()
state->openUpvalues = NULL;
// set default proto objects
for (int i = 0; i < COBJ_MAX; i++) {
for (int i = 0; i < COBJ_MAX; i++)
state->protoObjects[i] = NULL;
}
for (int i = 0; i < ISTRING_MAX; i++) {
for (int i = 0; i < ISTRING_MAX; i++)
state->iStrings[i] = NULL;
}
cosmoT_initTable(state, &state->strings, 16); // init string table
cosmoT_initTable(state, &state->registry, 16);
@ -89,9 +87,8 @@ CState *cosmoV_newState()
state->iStrings[ISTRING_RESERVED] = cosmoO_copyString(state, "__reserved", 10);
// set the IString flags
for (int i = 0; i < ISTRING_MAX; i++) {
for (int i = 0; i < ISTRING_MAX; i++)
state->iStrings[i]->isIString = true;
}
state->freezeGC = 0; // unfreeze the state
return state;
@ -118,9 +115,8 @@ void cosmoV_freeState(CState *state)
}
// mark our internal VM strings NULL
for (int i = 0; i < ISTRING_MAX; i++) {
for (int i = 0; i < ISTRING_MAX; i++)
state->iStrings[i] = NULL;
}
// free our string table (the string table includes the internal VM strings)
cosmoT_clearTable(state, &state->strings);

View File

@ -87,9 +87,8 @@ static uint32_t getValueHash(CValue *val)
return 0;
memcpy(buf, &num, sizeof(buf));
for (size_t i = 0; i < sizeof(cosmo_Number) / sizeof(uint32_t); i++) {
for (size_t i = 0; i < sizeof(cosmo_Number) / sizeof(uint32_t); i++)
buf[0] += buf[i];
}
return buf[0];
}
// TODO: add support for other types

View File

@ -26,9 +26,8 @@ void cosmoV_insert(CState *state, int indx, CValue val)
StkPtr tmp = cosmoV_getTop(state, indx);
// moves everything up
for (StkPtr i = state->top; i > tmp; i--) {
for (StkPtr i = state->top; i > tmp; i--)
*i = *(i - 1);
}
*tmp = val;
state->top++;
@ -269,9 +268,8 @@ static void callCFunction(CState *state, CosmoCFunction cfunc, int args, int nre
state->top += nres; // and make sure to move state->top to match
// now, if the caller function expected more return values, push nils onto the stack
for (int i = nres; i < nresults; i++) {
for (int i = nres; i < nresults; i++)
cosmoV_pushValue(state, cosmoV_newNil());
}
}
/*
@ -329,9 +327,8 @@ static void rawCall(CState *state, CObjClosure *closure, int args, int nresults,
state->top += nres; // and make sure to move state->top to match
// now, if the caller function expected more return values, push nils onto the stack
for (int i = nres; i < nresults; i++) {
for (int i = nres; i < nresults; i++)
cosmoV_pushValue(state, cosmoV_newNil());
}
}
// returns true if successful, false if error
@ -380,9 +377,9 @@ void callCValue(CState *state, CValue func, int args, int nresults, int offset)
if (nresults > 0) {
cosmoV_pushRef(state, (CObj *)newObj);
// push the nils to fill up the expected return values.
// -1 since the we already pushed the important value
for (int i = 0; i < nresults - 1;i++) {
// push the nils to fill up the expected return values
for (int i = 0; i < nresults - 1;
i++) { // -1 since the we already pushed the important value
cosmoV_pushValue(state, cosmoV_newNil());
}
}
@ -418,10 +415,9 @@ bool cosmoV_pcall(CState *state, int args, int nresults)
if (nresults > 0) {
// push other expected results onto the stack
for (int i = 0; i < nresults - 1; i++) {
for (int i = 0; i < nresults - 1; i++)
cosmoV_pushValue(state, cosmoV_newNil());
}
}
cosmoV_freePanic(state);
return false;