MCPcopy Create free account
hub / github.com/WasmVM/WasmVM / parse_constexpr

Method parse_constexpr

src/lib/parse/ParseContext.cpp:544–562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

542// ── Const expression ──────────────────────────────────────────────────────────
543
544ConstInstr ParseContext::parse_constexpr() {
545 bool parenthesized = (tok_.peek().type == TokenType::LParen);
546 if (parenthesized) tok_.consume(); // '('
547 Token kw = tok_.expect(TokenType::Keyword, "const expression");
548 ConstInstr result;
549 if (kw.text == "i32.const") result = ConstInstr{Instr::I32_const(parse_i32())};
550 else if (kw.text == "i64.const") result = ConstInstr{Instr::I64_const(parse_i64())};
551 else if (kw.text == "f32.const") result = ConstInstr{Instr::F32_const(parse_f32())};
552 else if (kw.text == "f64.const") result = ConstInstr{Instr::F64_const(parse_f64())};
553 else if (kw.text == "ref.null") {
554 Token ref = tok_.expect(TokenType::Keyword, "func/extern");
555 result = ConstInstr{Instr::Ref_null(ref.text == "func" ? RefType::funcref : RefType::externref)};
556 }
557 else if (kw.text == "ref.func") result = ConstInstr{Instr::Ref_func(parse_funcidx())};
558 else if (kw.text == "global.get") result = ConstInstr{Instr::Global_get(parse_globalidx())};
559 else throw Exception::Parse("unknown const expression '" + kw.text + "'", {kw.line, kw.column});
560 if (parenthesized) tok_.expect(TokenType::RParen);
561 return result;
562}
563
564ConstInstr ParseContext::parse_elemexpr() {
565 tok_.expect(TokenType::LParen);

Callers

nothing calls this directly

Calls 9

I32_constClass · 0.85
I64_constClass · 0.85
F32_constClass · 0.85
F64_constClass · 0.85
Ref_nullClass · 0.85
ParseClass · 0.85
peekMethod · 0.80
expectMethod · 0.80
consumeMethod · 0.45

Tested by

no test coverage detected