MCPcopy Create free account
hub / github.com/arcjet/gravity / emit

Method emit

cmd/gravity/src/codegen/func.rs:120–1489  ·  view source on GitHub ↗
(
        &mut self,
        resolve: &Resolve,
        inst: &Instruction<'_>,
        operands: &mut Vec<Self::Operand>,
        results: &mut Vec<Self::Operand>,
    )

Source from the content-addressed store, hash-verified

118 type Operand = Operand;
119
120 fn emit(
121 &mut self,
122 resolve: &Resolve,
123 inst: &Instruction<'_>,
124 operands: &mut Vec<Self::Operand>,
125 results: &mut Vec<Self::Operand>,
126 ) {
127 let iter_element = "e";
128 let iter_base = "base";
129 // Hoist to avoid borrow-checker conflict with `quote_in! { self.body => ... }`.
130 let module_handle = self.module_handle();
131
132 match inst {
133 Instruction::GetArg { nth } => {
134 let arg = &format!("arg{nth}");
135 self.push_arg(arg);
136 results.push(Operand::SingleValue(arg.into()));
137 }
138 Instruction::ConstZero { tys } => {
139 for _ in tys.iter() {
140 results.push(Operand::Literal("0".into()))
141 }
142 }
143 Instruction::StringLower { realloc: None } => todo!("implement instruction: {inst:?}"),
144 Instruction::StringLower {
145 realloc: Some(realloc_name),
146 } => {
147 let tmp = self.tmp();
148 let ptr = &format!("ptr{tmp}");
149 let len = &format!("len{tmp}");
150 let err = &format!("err{tmp}");
151 let default = &format!("default{tmp}");
152 let memory = &format!("memory{tmp}");
153 let realloc = &format!("realloc{tmp}");
154 let operand = &operands[0];
155 match self.direction {
156 Direction::Export => {
157 quote_in! { self.body =>
158 $['\r']
159 $memory := i.module.Memory()
160 $realloc := i.module.ExportedFunction($(quoted(*realloc_name)))
161 $ptr, $len, $err := writeString(ctx, $operand, $memory, $realloc)
162 $(match &self.result {
163 GoResult::Anon(GoType::ValueOrError(typ)) => {
164 if $err != nil {
165 var $default $(typ.as_ref())
166 return $default, $err
167 }
168 }
169 GoResult::Anon(GoType::Error) => {
170 if $err != nil {
171 return $err
172 }
173 }
174 GoResult::Anon(_) | GoResult::Empty => {
175 $(comment(&["The return type doesn't contain an error so we panic if one is encountered"]))
176 if $err != nil {
177 panic($err)

Callers

nothing calls this directly

Calls 9

resolve_typeFunction · 0.85
resolve_wasm_typeFunction · 0.85
qualified_type_nameFunction · 0.85
case_dispatch_nameFunction · 0.85
case_dispatch_kindFunction · 0.85
module_handleMethod · 0.80
push_argMethod · 0.80
tmpMethod · 0.80
pop_blockMethod · 0.80

Tested by

no test coverage detected