Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jou on embedded #561

Open
Akuli opened this issue Jan 8, 2025 · 4 comments
Open

Jou on embedded #561

Akuli opened this issue Jan 8, 2025 · 4 comments
Labels
big A lot of work to implement feature

Comments

@Akuli
Copy link
Owner

Akuli commented Jan 8, 2025

From DMs with @Moosems:

screenshot-1736346404

This will probably require:

  • changes to compiler (supporting different architectures, in LLVM and when linking)
  • changes to the language (if WINDOWS: doesn't really make sense on embedded)
  • documentation
@Moosems
Copy link

Moosems commented Jan 8, 2025

A special embedded api for pinout would likely be necessary as well

@Akuli Akuli added feature big A lot of work to implement labels Jan 14, 2025
@Moosems
Copy link

Moosems commented Jan 27, 2025

How does target compilation work right now?

@Akuli
Copy link
Owner Author

Akuli commented Jan 28, 2025

Very much hard-coded / always using whatever system the compiler is running on:

jou/compiler/target.jou

Lines 25 to 49 in 2b33658

@public
def init_target() -> None:
LLVMInitializeX86TargetInfo()
LLVMInitializeX86Target()
LLVMInitializeX86TargetMC()
LLVMInitializeX86AsmParser()
LLVMInitializeX86AsmPrinter()
if MACOS:
# Support the new M1 macs. This will enable the target also on x86_64
# macs, but it doesn't matter.
LLVMInitializeAArch64TargetInfo()
LLVMInitializeAArch64Target()
LLVMInitializeAArch64TargetMC()
LLVMInitializeAArch64AsmParser()
LLVMInitializeAArch64AsmPrinter()
if WINDOWS:
# LLVM's default is x86_64-pc-windows-msvc
target.triple = "x86_64-pc-windows-gnu"
else:
triple = LLVMGetDefaultTargetTriple()
assert strlen(triple) < sizeof target.triple
strcpy(target.triple, triple)
LLVMDisposeMessage(triple)

@Akuli
Copy link
Owner Author

Akuli commented Jan 28, 2025

Another problem is that 64-bitness is hard-coded into various places. C's size_t type is 32-bit or 64-bit depending on the platform. Jou assumes it is 64-bit.

For example, consider the strlen() function:

Image

In Jou, it returns long, and Jou's long is always 64 bit:

jou/stdlib/str.jou

Lines 25 to 27 in 2b33658

# Calculate the length of a string in bytes. Note that strlen("ö") == 2, for example.
@public
declare strlen(s: byte*) -> long

See also #304.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
big A lot of work to implement feature
Projects
None yet
Development

No branches or pull requests

2 participants