feat(rfc-cm): baseline P0-P3 compute machine, stdlib and resource slices
Implements the first vertical slices of RFC-CM-0001/0002 on top of a113d89:
- P1: opaque Memory regions (64 KiB pages, budgets, grow-only), byte
read/write, Memory-index place assignment, wire/host-boundary rejection.
- CM-A04/A05: value-semantics List/Map/Text/Table primitives and the
recoverable Result map convention.
- CM-A06: opaque Resource handles, resource.open/read/write/close, stdout
write, granted project-file read and buffered write, strict fail-closed.
- CM-A07 Compat-A: explicit .mq.md format/utf8/io chain matching builtin
print for the covered value types; builtin remains default.
- P2 fixtures: allocators, list/tree/graph/hash, integer codecs, UTF-8
encode/decode, CSV/JSON subsets, table filter/sort/join, bytecode VM.
- ADRs 0022-0027, spec updates, evidence reports and 68 semantic goldens.
Gate: cargo fmt --check, clippy -D warnings, 407 tests passed.
This commit is contained in:
1 parent
a113d89496
commit
92bfbf2568
127 files changed
+11351
-141
No files matched your search
@@ -167,6 +167,144 @@ const FS_WRITE: Builtin = Builtin {
|
||||
named_only: false,
|
||||
effectful: true,
|
||||
};
|
||||
const MEMORY_NEW: Builtin = Builtin {
|
||||
name: "memory.new",
|
||||
aliases: &[],
|
||||
params: &[req("initial_pages"), req("max_pages")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const MEMORY_SIZE: Builtin = Builtin {
|
||||
name: "memory.size",
|
||||
aliases: &[],
|
||||
params: &[req("memory")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const MEMORY_GROW: Builtin = Builtin {
|
||||
name: "memory.grow",
|
||||
aliases: &[],
|
||||
params: &[req("memory"), req("pages")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const LIST_APPEND: Builtin = Builtin {
|
||||
name: "list.append",
|
||||
aliases: &[],
|
||||
params: &[req("list"), req("value")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const LIST_CONCAT: Builtin = Builtin {
|
||||
name: "list.concat",
|
||||
aliases: &[],
|
||||
params: &[req("left"), req("right")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const MAP_KEYS: Builtin = Builtin {
|
||||
name: "map.keys",
|
||||
aliases: &[],
|
||||
params: &[req("map")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const MAP_HAS: Builtin = Builtin {
|
||||
name: "map.has",
|
||||
aliases: &[],
|
||||
params: &[req("map"), req("key")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const MAP_GET: Builtin = Builtin {
|
||||
name: "map.get",
|
||||
aliases: &[],
|
||||
params: &[req("map"), req("key")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const MAP_SET: Builtin = Builtin {
|
||||
name: "map.set",
|
||||
aliases: &[],
|
||||
params: &[req("map"), req("key"), req("value")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const MAP_REMOVE: Builtin = Builtin {
|
||||
name: "map.remove",
|
||||
aliases: &[],
|
||||
params: &[req("map"), req("key")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const TEXT_CODEPOINTS: Builtin = Builtin {
|
||||
name: "text.codepoints",
|
||||
aliases: &[],
|
||||
params: &[req("text")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const TEXT_FROM_CODEPOINT: Builtin = Builtin {
|
||||
name: "text.from_codepoint",
|
||||
aliases: &[],
|
||||
params: &[req("codepoint")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const TABLE_COLUMNS: Builtin = Builtin {
|
||||
name: "table.columns",
|
||||
aliases: &[],
|
||||
params: &[req("table")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const TABLE_ROW: Builtin = Builtin {
|
||||
name: "table.row",
|
||||
aliases: &[],
|
||||
params: &[req("table"), req("row")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
const RESOURCE_OPEN: Builtin = Builtin {
|
||||
name: "resource.open",
|
||||
aliases: &[],
|
||||
params: &[req("kind"), req("descriptor"), req("rights")],
|
||||
named_only: false,
|
||||
effectful: true,
|
||||
};
|
||||
const RESOURCE_READ: Builtin = Builtin {
|
||||
name: "resource.read",
|
||||
aliases: &[],
|
||||
params: &[
|
||||
req("handle"),
|
||||
req("memory"),
|
||||
req("offset"),
|
||||
req("max_bytes"),
|
||||
],
|
||||
named_only: false,
|
||||
effectful: true,
|
||||
};
|
||||
const RESOURCE_WRITE: Builtin = Builtin {
|
||||
name: "resource.write",
|
||||
aliases: &[],
|
||||
params: &[req("handle"), req("memory"), req("offset"), req("length")],
|
||||
named_only: false,
|
||||
effectful: true,
|
||||
};
|
||||
const RESOURCE_CLOSE: Builtin = Builtin {
|
||||
name: "resource.close",
|
||||
aliases: &[],
|
||||
params: &[req("handle")],
|
||||
named_only: false,
|
||||
effectful: true,
|
||||
};
|
||||
const TABLE_CELL: Builtin = Builtin {
|
||||
name: "table.cell",
|
||||
aliases: &[],
|
||||
params: &[req("table"), req("row"), req("column")],
|
||||
named_only: false,
|
||||
effectful: false,
|
||||
};
|
||||
|
||||
/// All builtins known to the language. Host availability is decided at call
|
||||
/// time by the capability layer, not here.
|
||||
@@ -188,6 +326,25 @@ pub const BUILTINS: &[Builtin] = &[
|
||||
FOREIGN_CALL,
|
||||
FS_READ,
|
||||
FS_WRITE,
|
||||
MEMORY_NEW,
|
||||
MEMORY_SIZE,
|
||||
MEMORY_GROW,
|
||||
LIST_APPEND,
|
||||
LIST_CONCAT,
|
||||
MAP_KEYS,
|
||||
MAP_HAS,
|
||||
MAP_GET,
|
||||
MAP_SET,
|
||||
MAP_REMOVE,
|
||||
TEXT_CODEPOINTS,
|
||||
TEXT_FROM_CODEPOINT,
|
||||
TABLE_COLUMNS,
|
||||
TABLE_ROW,
|
||||
TABLE_CELL,
|
||||
RESOURCE_OPEN,
|
||||
RESOURCE_READ,
|
||||
RESOURCE_WRITE,
|
||||
RESOURCE_CLOSE,
|
||||
];
|
||||
|
||||
/// Find a builtin by canonical name or alias.
|
||||
|
||||
@@ -224,16 +224,51 @@ pub struct Function {
|
||||
pub body: Vec<Stmt>,
|
||||
}
|
||||
|
||||
/// Writable place of an assignment (ADR-0022).
|
||||
///
|
||||
/// The Markdown surface is unchanged: both variants are `strong` nodes whose
|
||||
/// payload contains `target = expression`. `Local` rebinds a frame slot;
|
||||
/// `Index` writes one byte into an addressable runtime `Memory` region and is
|
||||
/// rejected for every other base value.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(tag = "place", rename_all = "snake_case")]
|
||||
pub enum PlaceTarget {
|
||||
/// Local slot rebinding.
|
||||
Local {
|
||||
/// Target name.
|
||||
name: String,
|
||||
/// Span of the target name.
|
||||
name_span: Span,
|
||||
},
|
||||
/// `base[index] = value`; only a `Memory` base is writable.
|
||||
Index {
|
||||
/// Base expression, evaluated first.
|
||||
base: Expr,
|
||||
/// Index expression, evaluated second.
|
||||
index: Expr,
|
||||
/// Span from the base start through the closing `]`.
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
impl PlaceTarget {
|
||||
/// Best known source span of the place.
|
||||
pub fn span(&self) -> Span {
|
||||
match self {
|
||||
PlaceTarget::Local { name_span, .. } => *name_span,
|
||||
PlaceTarget::Index { span, .. } => *span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An executable statement.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(tag = "stmt", rename_all = "snake_case")]
|
||||
pub enum Stmt {
|
||||
/// Local assignment (`strong` node with `name = expr`).
|
||||
/// Assignment to a local slot or a `Memory` index.
|
||||
Assign {
|
||||
/// Target name.
|
||||
name: String,
|
||||
/// Span of the target name (approximated by the payload span).
|
||||
name_span: Span,
|
||||
/// Writable place.
|
||||
target: PlaceTarget,
|
||||
/// Value expression.
|
||||
value: Expr,
|
||||
/// Span of the whole statement.
|
||||
|
||||
Reference in new issue
Block a user