Skip to content

Cmake tidy post stackless#490

Draft
pedro-w wants to merge 8 commits intoIoLanguage:masterfrom
pedro-w:cmake-tidy-post-stackless
Draft

Cmake tidy post stackless#490
pedro-w wants to merge 8 commits intoIoLanguage:masterfrom
pedro-w:cmake-tidy-post-stackless

Conversation

@pedro-w
Copy link
Contributor

@pedro-w pedro-w commented Mar 9, 2026

Description

  • Tidy up the CMake build system
    • Make use of features in current CMake that weren't in CMake when the scripts were first written
    • Removed duplicated definitions
    • The .io files in libs/iovm/io are now dependencies, so CMake notices when they've been edited
    • Went with CMake's structure within the build dir rather than fighting it
    • Note because of the above, the executable are now in (build dir)/tools rather than (build dir)/_build/binaries
  • Fix some errors in MSVC/Windows that affect the new 'stackless' io implementation
    • Note there still seems to be a problem with the MSYS64 (i.e. gcc build)
    • Note there are lots of warnings still, mostly because sizeof(long) != sizeof(a pointer) on MSVC

I'm putting this as draft for now to get any comments. I am aware the forthcoming changes on the main branch will have a big impact on all this.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring

Testing

  • All existing tests pass
  • Added new tests for the changes
  • Tested on the following platforms:
    • Linux
    • macOS (Intel)
    • macOS (Apple Silicon)
    • Windows
    • Other:

Use CMake features that have been added since the files were first written.
Accept CMake's defaults for file locations as far as possible
Some of the .io files have changed names
One .c file is not to be compiled
This was because a function returning bool was being cast
to a function returning int. On Intel, MSVC returns a bool
only in the AL register, but returns an int in EAX, therefore
if the callee returned false (i.e. 0 in AL) the caller would
see 0 in the low byte and 'junk' in the high 3 bytes. If that
junk was non-zero, an if statement would take the true branch.

£include <stdbool.h>
£include <stdio.h>

bool test(int v) {
  if (v >= 1000)
    return true;
  return false;
}

typedef int(testf)(int);

£define T(v)                                                                   \
  if (tt(v))                                                                   \
    printf("%d >= 1000\n", v);                                                 \
  else                                                                         \
    printf("%d < 1000\n", v)

int main(int argc, char *argv[]) {
  testf *tt = (testf *)test;
  T(500);
  T(1000);
  T(2000);
  return 0;
}

Surprisingly prints

500 >= 1000
1000 >= 1000
2000 >= 1000

(note I replaced octothorpe with £ because of git)
Because the cache uses a PointerHash, it relies
on identical string literals having the same address
(i.e. constant merging). Unfortunately it seems they
do not get merged in MSVC, at least on lower optimization
levels.
Previously were returning IONIL but UArray is not an IoObject.
(caused compile error in GCC)
@stevedekorte
Copy link
Member

Hey Peter, thanks for the cmake fixes/improvements. I should have mentioned when I shared my wasm links that the wasm branch removes the addons, libcoroutine, and cmake entirely. I'm concerned merging of this patch could make the merge of the wasm branch into main more difficult. What do you think?

@pedro-w
Copy link
Contributor Author

pedro-w commented Mar 9, 2026

For sure, if cmake is going, there's no need to update that, and (this is where I don't know enough about wasm) any target-specific fixes also are obsolete - you just need to make it work for the WASM 'runtime'. Is that correct?

@pedro-w
Copy link
Contributor Author

pedro-w commented Mar 9, 2026

Is the WASM branch imminent? If so, might as well hold off on this and see if there's anything useful left in it after WASM has been merged.

@stevedekorte
Copy link
Member

Yeah, I think we just need it to work on WASM with a JS bridge if the focus is on web-native dev, with node as a server platform. Instantly, we'll have access to roughly 2 million pure JS NPM packages, plus a huge set of browser APIs for everything from WebGL, WebGPU, Geolocation, WebSockets, etc.

@stevedekorte
Copy link
Member

I'm guessing ETA for wasm merge into main is a few weeks or less.

@stevedekorte
Copy link
Member

Also planning to merge the Io web page repo into the Io source repo and redo the docs and add a bunch of web demos.

@pedro-w
Copy link
Contributor Author

pedro-w commented Mar 10, 2026

Wow, busy time ahead! Just wondering, would an io-to-javascript transpiler do the same job? (like Coffeescript if you remember that)

@stevedekorte
Copy link
Member

Unfortunately not AFAICS, as there are features like coroutines and futures which can't be translated to JS without building a language within it, which is a lot more than transpiling.

@stevedekorte
Copy link
Member

stevedekorte commented Mar 10, 2026

I've been thinking about this and maybe it could retain proper (persistable) coroutines and still be (with a few tricks) performant despite being an interpreter implemented in JS . Maybe an IoScript would work!

@PedroBatista
Copy link
Contributor

@pedro-w It builds on macOS ( Intel )
Intel(R) Core(TM) i5-2415M CPU @ 2.30GHz
ProductName: Mac OS X
ProductVersion: 10.15.5
BuildVersion: 19F101

It passes most correctness tests but it run into some weirdness on SequenceTest.io


Running: SequenceTest.io
zsh: floating point exception  /Users/Pedro/Desktop/stackless/io/build/_build/binaries/io run.io

I managed to trace it back to lines 394 and 395 on testToBase(). I guess the problem is somewhere in the implementation of assertRaisesException(), not really the test code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants