aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 07:28:39 +0000
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 07:28:39 +0000
commit7451eb090d890fb5ea5e4d40627a1b4df15a49de (patch)
tree357bdf4b528e860bffa688865306f656b788d2c2 /src/core
parentanalyzer: close the ownership gaps that stopped the compiler compiling itself (diff)
build: embed images with #embed, keep everything generated in build/
the cores take their genome in with c23 #embed through src/core/genome.h, so images are plain little-endian word files (genome.bin) instead of generated c headers. zc0 writes that format, mkgenome checks an image against its map and shows a compiler's diagnostics when it gets them, and the javascript vm and the editor's vm host read the same files. src/tools/findcc.sh picks a compiler with #embed (clang 19 or gcc 15). zc gets an embed declaration, embed "file" as [type] name, for globals and locals: a byte string by default, char*, numbers read little-endian, and arrays of numbers. the compiler and language server carry their library and source texts through it, so embed.sh and the text it spliced into compiler.zc are gone. make writes executables to build/bin, the default map to build/core/map, the web page to build/web and the extension staging to build/vsix, and the genome now rebuilds when its sources change. the test suite lays out its own map and bootstrap and reads nothing from build/. also: rt.put_s of a byte string in zc0 images, retained function sources no longer count as live objects, a missing include no longer cascades into undefined-name errors, consecutive comment lines join into one hover paragraph, and stale test fixtures follow the include format.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core.c8
-rw-r--r--src/core/genome.h35
-rw-r--r--src/core/memmap.h34
3 files changed, 36 insertions, 41 deletions
diff --git a/src/core/core.c b/src/core/core.c
index 3a1d0ca..dc50644 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -58,13 +58,7 @@
#include <sys/mman.h>
#include <ucontext.h>
#endif
-#ifdef USE_LSP_GENOME
-#include "lsp_genome.h"
-#elif defined(GENOME_H)
-#include GENOME_H
-#else
#include "genome.h"
-#endif
#include "memmap.h"
#include "fops.h"
#include "bops.h"
@@ -6208,7 +6202,7 @@ int main(int argc, char **argv)
fprintf(stderr, "zy: genome does not fit\n");
return 1;
}
- memcpy(m + GORG, genome, sizeof genome);
+ for (int g = 0; g < GLEN; g++) m[GORG + g] = genome_word(g);
m[ZFP + 6] = FBOT; m[ZFP + 7] = FTOP; m[ZFP + 8] = 1024;
#ifdef ZYJIT
{
diff --git a/src/core/genome.h b/src/core/genome.h
new file mode 100644
index 0000000..9d0ff96
--- /dev/null
+++ b/src/core/genome.h
@@ -0,0 +1,35 @@
+/* the genome: the image a core boots, embedded into the core when it is
+ compiled. an image is a file of little-endian 64-bit words placed at GORG,
+ as written by zc0 or by src/tools/build.zc and checked by mkgenome. the
+ build keeps every image in build/, never in the tree.
+
+ GENOME_FILE names the image. it defaults to "genome.bin" (or
+ "lsp_genome.bin" with USE_LSP_GENOME) and is found next to this header,
+ then in the directories given with --embed-dir, so that option selects
+ which image a core carries. the file needs a compiler with c23
+ #embed (clang 19 or gcc 15 and later).
+
+ no libc here: the microcore includes this on bare metal. */
+#ifndef GENOME_H_INCLUDED
+#define GENOME_H_INCLUDED
+#include <stdint.h>
+#ifndef GENOME_FILE
+#ifdef USE_LSP_GENOME
+#define GENOME_FILE "lsp_genome.bin"
+#else
+#define GENOME_FILE "genome.bin"
+#endif
+#endif
+static const unsigned char genome_image[] = {
+#embed GENOME_FILE
+};
+/* the image's length in words */
+#define GLEN ((int)(sizeof genome_image / 8))
+/* word i of the image, independent of the host's byte order */
+static int64_t genome_word(int i)
+{
+ const unsigned char *b = genome_image + (long)i * 8;
+ return (int64_t)((uint64_t)b[0] | (uint64_t)b[1] << 8 | (uint64_t)b[2] << 16 | (uint64_t)b[3] << 24
+ | (uint64_t)b[4] << 32 | (uint64_t)b[5] << 40 | (uint64_t)b[6] << 48 | (uint64_t)b[7] << 56);
+}
+#endif
diff --git a/src/core/memmap.h b/src/core/memmap.h
deleted file mode 100644
index cc768d4..0000000
--- a/src/core/memmap.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* generated by src/tools/genmap for the default profile. do not edit. */
-#ifndef MEMMAP_H
-#define MEMMAP_H
-#define PW 0x1D5000
-#define CODE_END 0x80000
-#define HEAP_LO 0x1D5000
-#define HEAP_HI 0x235000
-#define HEAP_GROW 1
-#ifndef MW
-#define MW 0x8000000
-#endif
-#if MW < HEAP_HI
-#error MW is below the end of the initial heap
-#endif
-#define ZFP 0x90000
-#ifdef GORG
-#if GORG != 0x114100
-#error genome GORG does not match this map
-#endif
-#else
-#define GORG 0x114100
-#endif
-#define FBOT 0x174100
-#define FTOP 0x1B4100
-#define RS0 0x1B4100
-#define MARK0 0x1C4100
-#define MARKN 0x8000
-#define DSLO 0x1CC100
-#define DSHI 0x1D4FF0
-#define DS0 DSHI
-#define SYSGATE (ZFP + 2)
-#define DSLIM (DSLO + 1100)
-#define RSLIM (MARK0 - 8)
-#endif