aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2025-09-24 23:48:16 +0000
committerrtk0c <[email protected]>2025-10-15 20:28:15 +0000
commitab49edbb106c25b980bac0227a3db55b74378784 (patch)
tree9c692af3a095be9374fc9775c35d47ff5acc04e1
parentc4564f9f5c28abe8913c569374a7d778a6473210 (diff)
lua literals loading draft, and contemplations on the bigger picture Cm language
-rw-r--r--cm.lua38
-rw-r--r--cm/ex02.decl2
-rw-r--r--cm/ex03.cm38
-rw-r--r--cm_decl_parse.lua0
4 files changed, 78 insertions, 0 deletions
diff --git a/cm.lua b/cm.lua
index e69de29..42fd532 100644
--- a/cm.lua
+++ b/cm.lua
@@ -0,0 +1,38 @@
+-- Cm: name inspired by "C meta(language)", but it's not really a metalangauge (whatever this means) of C (or anything else)
+
+local function LateResolveType(name)
+end
+
+local function TypeTagger(tag)
+ return function(props)
+ props._tag = tag
+ return props
+ end
+end
+
+local cm_env_fns = {
+ _namespace = 0, -- TODO
+ _t = LateResolveType,
+ _struct = TypeTagger("struct"),
+ _union = TypeTagger("union"),
+ _alias = TypeTagger("alias"),
+}
+local cm_env_metatable = {__index = cm_env_fns}
+
+---@param fn function
+---@return table
+function LoadCmLua(fn)
+ local env = {}
+ setmetatable(env, cm_env_metatable)
+
+ local old_fenv = getfenv(fn)
+ setfenv(fn, env)
+ pcall(fn)
+ setfenv(fn, old_fenv)
+
+ return env
+end
+
+function LoadCmDecl(src)
+ -- TODO
+end
diff --git a/cm/ex02.decl b/cm/ex02.decl
index 394d446..d695e33 100644
--- a/cm/ex02.decl
+++ b/cm/ex02.decl
@@ -1,3 +1,5 @@
+// Declarations only version of Cm (like mojo/protobuf? not sure)
+
// assume special receiver (as opposed to smalltalk/objC style message passing)
// -- actually, on second thought, this has nothing to do with dispatching (and smalltalk is single dispatch)
// -- (no touching multiple dispatch since that's equivalent to reinventing a new language)
diff --git a/cm/ex03.cm b/cm/ex03.cm
new file mode 100644
index 0000000..34275df
--- /dev/null
+++ b/cm/ex03.cm
@@ -0,0 +1,38 @@
+// Hypothetical, fully ledged version of Cm, at compile time, using a superset of the runtime language
+// with macros, and an escape hatch into native code (C or whatever)
+
+// Language structurally, a bit like Nim:
+// - the scripting language itself
+// - macros, which are functions from language itself operating on special AST values at compile time
+// - (NEW) native escape hatch, kind of literate programming style, expanding into native program source code at compile time
+
+// So the compile procedure is as follows:
+// - build interpreter (native source code) from source
+// - init interpreter
+// - load program source code, evaluate to produce
+// - an environment image (bytecode of scripting constructs), and
+// - native program source (text of things produced by native escape hatch, plus interpreter source code itself, plus auto generated bindings)
+// - build native program
+// And run procedure is:
+// - init interpreter (<- the PE/mach-o/ELF entrypoint here)
+// - init native program parts (<- i.e. the escape hatches don't generate an actual main() func, instead a customly named init() func that gets called by the generated machinery)
+// - load bindings
+// - load environment image
+// - run native program entrypoint
+// The order of native program entrypoint vs. environment loading might be reversed. Depending on how it makes sense.
+// Or maybe there will be 2 parts, the native program *init* and *start*. Former would be like the _mainCRTStartup() that initializes global variables, etc.
+
+// REQUIREMENT FOR NATIVE PROGRAM SOURCE:
+// Must be nicely readable.
+// We plan on completely reusing the traditional native program debuggers, e.g. GDB for debugging
+// The interpreter can then have its own debugging system
+// Problem: How to do mixed language debugging? like stepping into a native function, this is a lot of work/hacks to wrap on top of e.g. GDB
+// SIDE THOUGHT:
+// should bindings be baked into the environment image (i.e. design the bytecode format to include this? however it should be done; can't really imagine it now?)
+// or should they be generated e.g. `bind_function("func_name", &func_written_in_C);`?
+
+// terminology akin to Janet (from _Janet for Mortals_):
+// compile: evaluating the program sources to produce an environment
+// runtime: evaluating the environment
+
+
diff --git a/cm_decl_parse.lua b/cm_decl_parse.lua
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cm_decl_parse.lua