From 5124eb80701523ac16928219e9a1031eded128ef Mon Sep 17 00:00:00 2001 From: rtk0c Date: Wed, 24 Sep 2025 01:09:38 +0000 Subject: metalanguage design (both lua literals and DSL) --- cm.lua | 0 cm/ex01.lua | 20 ++++++++++++++++++++ cm/ex02.decl | 20 ++++++++++++++++++++ plan.txt | 0 tablgen.lua | 5 +++++ 5 files changed, 45 insertions(+) create mode 100644 cm.lua create mode 100644 cm/ex01.lua create mode 100644 cm/ex02.decl create mode 100644 plan.txt create mode 100644 tablgen.lua diff --git a/cm.lua b/cm.lua new file mode 100644 index 0000000..e69de29 diff --git a/cm/ex01.lua b/cm/ex01.lua new file mode 100644 index 0000000..feaf876 --- /dev/null +++ b/cm/ex01.lua @@ -0,0 +1,20 @@ +-- Environment is loaded with the utils (as metatable.__index) +-- Global vars (aka properties on env) will be read as decls + +-- name implied by property key here +Bar = _struct({ + -- _t: Loads another type by its name. Return the type, or a placeholder if the type is not yet available + -- Useful recursive definitions + -- Undefined type errors generated on the referential resolution pass (i.e. not immediately) + field1 = _t("i32"), + field2 = _t("string"), + -- Deferred loading as described above + compound_field = _t("Foo"), +}) + +uint32 = _alias("u32") + +-- Note, defined after Bar! +Foo = _struct({ + n = _t("i32"), +}) diff --git a/cm/ex02.decl b/cm/ex02.decl new file mode 100644 index 0000000..394d446 --- /dev/null +++ b/cm/ex02.decl @@ -0,0 +1,20 @@ +// 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) +// overloading discouraged, because runtime has to do extra work dispatching +// declare functions outside, with `this` keyword marking receiver +// - in C, func -> prefixed with reciever type, 1st arg is reciever pointer +// - in C++, func -> member function +// - lua (or whatever else), reciever type correspondingly + +Foo { + data +} + +// C: mangling +// C++: overloading +// Lua: generate binding with type detection based dispatcher +fn some_function(this: Foo, arg: i32) +fn some_function(this: Foo) + +// alternative: use S-expression, get rid of parsing step? diff --git a/plan.txt b/plan.txt new file mode 100644 index 0000000..e69de29 diff --git a/tablgen.lua b/tablgen.lua new file mode 100644 index 0000000..ae8a4fb --- /dev/null +++ b/tablgen.lua @@ -0,0 +1,5 @@ +local F = {} + +function F:WriteFuncDecl(func_name, ret, arg) + -- TODO +end -- cgit v1.3.1