Skip to content

Commit

Permalink
remove error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
pufferfish101007 committed Jan 20, 2024
1 parent a0a6fbf commit a56ee9d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
32 changes: 16 additions & 16 deletions src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,15 @@ impl IrBlockVec for Vec<IrBlock> {
for (index, op) in self.iter().enumerate() {
if !type_stack.len() >= op.opcode().descriptor().inputs().len() {
hq_bug!(
"type stack not big enough (expected >={} items, got {}) (E019)",
"type stack not big enough (expected >={} items, got {})",
op.opcode().descriptor().inputs().len(),
type_stack.len()
)
};
for block_type in op.opcode().descriptor().inputs().iter().rev() {
let top_type = type_stack
.pop()
.ok_or(make_hq_bug!("couldn't pop from type stack (E020)"))?;
.ok_or(make_hq_bug!("couldn't pop from type stack"))?;
expected_outputs.push((top_type.0, *block_type))
}
if !matches!(op.opcode().descriptor().output(), BlockType::Stack) {
Expand All @@ -588,7 +588,7 @@ impl IrBlockVec for Vec<IrBlock> {
};
for (index, ty) in expected_outputs {
self.get_mut(index)
.ok_or(make_hq_bug!("ir block doesn't exist (E043)"))?
.ok_or(make_hq_bug!("ir block doesn't exist"))?
.set_expected_output(ty);
}
Ok(())
Expand Down Expand Up @@ -754,51 +754,51 @@ impl IrBlockVec for Vec<IrBlock> {
.ok_or(make_hq_bad_proj!("invalid project.json - missing field colorParam"))? {
Field::Value((v,)) | Field::ValueId(v, _) => v,
};
let val_varval = maybe_val.clone().ok_or(make_hq_bad_proj!("invalid project.json - null value for OPERATOR field (E039)"))?;
let val_varval = maybe_val.clone().ok_or(make_hq_bad_proj!("invalid project.json - null value for OPERATOR field"))?;
let VarVal::String(val) = val_varval else {
hq_bad_proj!("invalid project.json - expected colorParam field to be string");
};
vec![IrOpcode::text { TEXT: val }]
},
BlockOpcode::operator_mathop => {
let maybe_val = match block_info.fields.get("OPERATOR")
.ok_or(make_hq_bad_proj!("invalid project.json - missing field OPERATOR (E038)"))? {
.ok_or(make_hq_bad_proj!("invalid project.json - missing field OPERATOR"))? {
Field::Value((v,)) | Field::ValueId(v, _) => v,
};
let val_varval = maybe_val.clone().ok_or(make_hq_bad_proj!("invalid project.json - null value for OPERATOR field (E039)"))?;
let val_varval = maybe_val.clone().ok_or(make_hq_bad_proj!("invalid project.json - null value for OPERATOR field"))?;
let VarVal::String(val) = val_varval else {
hq_bad_proj!("invalid project.json - expected OPERATOR field to be string (E040)");
hq_bad_proj!("invalid project.json - expected OPERATOR field to be string");
};
vec![IrOpcode::operator_mathop {
OPERATOR: val,
}]
},
BlockOpcode::data_variable => {
let Field::ValueId(_val, maybe_id) = block_info.fields.get("VARIABLE")
.ok_or(make_hq_bad_proj!("invalid project.json - missing field VARIABLE (E023)"))? else {
hq_bad_proj!("invalid project.json - missing variable id for VARIABLE field (E024)");
.ok_or(make_hq_bad_proj!("invalid project.json - missing field VARIABLE"))? else {
hq_bad_proj!("invalid project.json - missing variable id for VARIABLE field");
};
let id = maybe_id.clone().ok_or(make_hq_bad_proj!("invalid project.json - null variable id for VARIABLE field (E025)"))?;
let id = maybe_id.clone().ok_or(make_hq_bad_proj!("invalid project.json - null variable id for VARIABLE field"))?;
vec![IrOpcode::data_variable {
VARIABLE: id,
}]
},
BlockOpcode::data_setvariableto => {
let Field::ValueId(_val, maybe_id) = block_info.fields.get("VARIABLE")
.ok_or(make_hq_bad_proj!("invalid project.json - missing field VARIABLE (E026)"))? else {
hq_bad_proj!("invalid project.json - missing variable id for VARIABLE field (E027)");
.ok_or(make_hq_bad_proj!("invalid project.json - missing field VARIABLE"))? else {
hq_bad_proj!("invalid project.json - missing variable id for VARIABLE field");
};
let id = maybe_id.clone().ok_or(make_hq_bad_proj!("invalid project.json - null variable id for VARIABLE field (E028)"))?;
let id = maybe_id.clone().ok_or(make_hq_bad_proj!("invalid project.json - null variable id for VARIABLE field"))?;
vec![IrOpcode::data_setvariableto {
VARIABLE: id,
}]
},
BlockOpcode::data_changevariableby => {
let Field::ValueId(_val, maybe_id) = block_info.fields.get("VARIABLE")
.ok_or(make_hq_bad_proj!("invalid project.json - missing field VARIABLE (E029)"))? else {
hq_bad_proj!("invalid project.json - missing variable id for VARIABLE field (E030)");
.ok_or(make_hq_bad_proj!("invalid project.json - missing field VARIABLE"))? else {
hq_bad_proj!("invalid project.json - missing variable id for VARIABLE field");
};
let id = maybe_id.clone().ok_or(make_hq_bad_proj!("invalid project.json - null id for VARIABLE field (E031)"))?;
let id = maybe_id.clone().ok_or(make_hq_bad_proj!("invalid project.json - null id for VARIABLE field"))?;
vec![
IrOpcode::data_variable {
VARIABLE: id.to_string(),
Expand Down
72 changes: 36 additions & 36 deletions src/targets/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn instructions(
context
.target_index
.try_into()
.map_err(|_| make_hq_bug!("target index out of bounds (E002)"))?,
.map_err(|_| make_hq_bug!("target index out of bounds"))?,
),
Call(func_indices::LOOKS_THINK),
]
Expand All @@ -53,7 +53,7 @@ fn instructions(
context
.target_index
.try_into()
.map_err(|_| make_hq_bug!("target index out of bounds (E003)"))?,
.map_err(|_| make_hq_bug!("target index out of bounds"))?,
),
Call(func_indices::LOOKS_SAY),
]
Expand Down Expand Up @@ -104,7 +104,7 @@ fn instructions(
}
}
.try_into()
.map_err(|_| make_hq_bug!("string index out of bounds (E022)"))?;
.map_err(|_| make_hq_bug!("string index out of bounds"))?;
if expected_output == Any {
actual_output = Any;
vec![
Expand All @@ -122,12 +122,12 @@ fn instructions(
.borrow()
.iter()
.position(|var| VARIABLE == var.id())
.ok_or(make_hq_bug!("couldn't find variable index (E033)"))?
.ok_or(make_hq_bug!("couldn't find variable index"))?
.try_into()
.map_err(|_| make_hq_bug!("variable index out of bounds (E034)"))?;
.map_err(|_| make_hq_bug!("variable index out of bounds"))?;
let var_offset: u64 = (byte_offset::VARS + 12 * var_index)
.try_into()
.map_err(|_| make_hq_bug!("variable offset out of bounds (E035)"))?;
.map_err(|_| make_hq_bug!("variable offset out of bounds"))?;
vec![
I32Const(0),
I32Load(MemArg {
Expand All @@ -149,12 +149,12 @@ fn instructions(
.borrow()
.iter()
.position(|var| VARIABLE == var.id())
.ok_or(make_hq_bug!("couldn't find variable index (E033)"))?
.ok_or(make_hq_bug!("couldn't find variable index"))?
.try_into()
.map_err(|_| make_hq_bug!("variable index out of bounds (E034)"))?;
.map_err(|_| make_hq_bug!("variable index out of bounds"))?;
let var_offset: u64 = (byte_offset::VARS + 12 * var_index)
.try_into()
.map_err(|_| make_hq_bug!("variable offset out of bounds (E035)"))?;
.map_err(|_| make_hq_bug!("variable offset out of bounds"))?;
vec![
LocalSet(step_func_locals::I64),
LocalSet(step_func_locals::I32),
Expand All @@ -180,12 +180,12 @@ fn instructions(
.borrow()
.iter()
.position(|var| VARIABLE == var.id())
.ok_or(make_hq_bug!("couldn't find variable index (E033)"))?
.ok_or(make_hq_bug!("couldn't find variable index"))?
.try_into()
.map_err(|_| make_hq_bug!("variable index out of bounds (E034)"))?;
.map_err(|_| make_hq_bug!("variable index out of bounds"))?;
let var_offset: u64 = (byte_offset::VARS + 12 * var_index)
.try_into()
.map_err(|_| make_hq_bug!("variable offset out of bounds (E035)"))?;
.map_err(|_| make_hq_bug!("variable offset out of bounds"))?;
vec![
LocalSet(step_func_locals::I64),
LocalSet(step_func_locals::I32),
Expand Down Expand Up @@ -433,7 +433,7 @@ fn instructions(
context
.target_index
.try_into()
.map_err(|_| make_hq_bug!("target index out of bounds (E003)"))?,
.map_err(|_| make_hq_bug!("target index out of bounds"))?,
),
Call(func_indices::PEN_SETCOLOR),
],
Expand All @@ -442,7 +442,7 @@ fn instructions(
context
.target_index
.try_into()
.map_err(|_| make_hq_bug!("target index out of bounds (E003)"))?,
.map_err(|_| make_hq_bug!("target index out of bounds"))?,
),
Call(func_indices::PEN_CHANGECOLORPARAM),
],
Expand All @@ -451,7 +451,7 @@ fn instructions(
context
.target_index
.try_into()
.map_err(|_| make_hq_bug!("target index out of bounds (E003)"))?,
.map_err(|_| make_hq_bug!("target index out of bounds"))?,
),
Call(func_indices::PEN_SETCOLORPARAM),
],
Expand All @@ -460,7 +460,7 @@ fn instructions(
context
.target_index
.try_into()
.map_err(|_| make_hq_bug!("target index out of bounds (E003)"))?,
.map_err(|_| make_hq_bug!("target index out of bounds"))?,
),
Call(func_indices::PEN_CHANGESIZE),
],
Expand All @@ -484,7 +484,7 @@ fn instructions(
context
.target_index
.try_into()
.map_err(|_| make_hq_bug!("target index out of bounds (E003)"))?,
.map_err(|_| make_hq_bug!("target index out of bounds"))?,
),
Call(func_indices::PEN_SETHUE),
],
Expand All @@ -493,7 +493,7 @@ fn instructions(
context
.target_index
.try_into()
.map_err(|_| make_hq_bug!("target index out of bounds (E003)"))?,
.map_err(|_| make_hq_bug!("target index out of bounds"))?,
),
Call(func_indices::PEN_CHANGEHUE),
],
Expand All @@ -515,7 +515,7 @@ fn instructions(
I32Load(MemArg {
offset: byte_offset::THREAD_NUM
.try_into()
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds (E009)"))?,
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds"))?,
align: 2,
memory_index: 0,
}),
Expand All @@ -532,7 +532,7 @@ fn instructions(
I32Load(MemArg {
offset: byte_offset::THREAD_NUM
.try_into()
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds (E010)"))?,
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds"))?,
align: 2,
memory_index: 0,
}),
Expand All @@ -541,7 +541,7 @@ fn instructions(
I32Store(MemArg {
offset: byte_offset::THREAD_NUM
.try_into()
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds (E011)"))?,
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds"))?,
align: 2,
memory_index: 0,
}),
Expand All @@ -564,7 +564,7 @@ fn instructions(
I32Const(
next_step_index
.try_into()
.map_err(|_| make_hq_bug!("step index out of bounds (E001)"))?,
.map_err(|_| make_hq_bug!("step index out of bounds"))?,
),
I32Store(MemArg {
offset: threads_offset,
Expand Down Expand Up @@ -608,7 +608,7 @@ fn instructions(
I32Load(MemArg {
offset: byte_offset::THREAD_NUM
.try_into()
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds (E009)"))?,
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds"))?,
align: 2,
memory_index: 0,
}),
Expand All @@ -625,7 +625,7 @@ fn instructions(
I32Load(MemArg {
offset: byte_offset::THREAD_NUM
.try_into()
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds (E010)"))?,
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds"))?,
align: 2,
memory_index: 0,
}),
Expand All @@ -634,7 +634,7 @@ fn instructions(
I32Store(MemArg {
offset: byte_offset::THREAD_NUM
.try_into()
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds (E011)"))?,
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds"))?,
align: 2,
memory_index: 0,
}),
Expand All @@ -660,7 +660,7 @@ fn instructions(
I32Const(
next_step_index
.try_into()
.map_err(|_| make_hq_bug!("step index out of bounds (E001)"))?,
.map_err(|_| make_hq_bug!("step index out of bounds"))?,
),
I32Store(MemArg {
offset: threads_offset,
Expand Down Expand Up @@ -1719,21 +1719,21 @@ impl TryFrom<IrProject> for WasmProject {
func.instruction(&Instruction::I32Load(MemArg {
offset: byte_offset::THREAD_NUM
.try_into()
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds (E015)"))?,
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds"))?,
align: 2,
memory_index: 0,
}));
func.instruction(&Instruction::I32Const(THREAD_BYTE_LEN));
func.instruction(&Instruction::I32Mul);
let thread_start_count: i32 = (*thread_start_counts.get(&start_type).unwrap_or(&0))
.try_into()
.map_err(|_| make_hq_bug!("start_type count out of bounds (E017)"))?;
.map_err(|_| make_hq_bug!("start_type count out of bounds"))?;
func.instruction(&Instruction::I32Const(thread_start_count * THREAD_BYTE_LEN));
func.instruction(&Instruction::I32Add);
func.instruction(&Instruction::I32Const(
index
.try_into()
.map_err(|_| make_hq_bug!("step func index out of bounds (E006)"))?,
.map_err(|_| make_hq_bug!("step func index out of bounds"))?,
));
func.instruction(&Instruction::I32Store(MemArg {
offset: (byte_offset::VARS as usize
Expand All @@ -1758,20 +1758,20 @@ impl TryFrom<IrProject> for WasmProject {
func.instruction(&Instruction::I32Load(MemArg {
offset: byte_offset::THREAD_NUM
.try_into()
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds (E012)"))?,
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds"))?,
align: 2,
memory_index: 0,
}));
func.instruction(&Instruction::I32Const(
count
.try_into()
.map_err(|_| make_hq_bug!("thread_start count out of bounds (E014)"))?,
.map_err(|_| make_hq_bug!("thread_start count out of bounds"))?,
));
func.instruction(&Instruction::I32Add);
func.instruction(&Instruction::I32Store(MemArg {
offset: byte_offset::THREAD_NUM
.try_into()
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds (E016)"))?,
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds"))?,
align: 2,
memory_index: 0,
}));
Expand All @@ -1782,7 +1782,7 @@ impl TryFrom<IrProject> for WasmProject {
tick_func.instruction(&Instruction::I32Load(MemArg {
offset: byte_offset::THREAD_NUM
.try_into()
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds (E013)"))?,
.map_err(|_| make_hq_bug!("THREAD_NUM out of bounds"))?,
align: 2,
memory_index: 0,
}));
Expand Down Expand Up @@ -1850,12 +1850,12 @@ impl TryFrom<IrProject> for WasmProject {
minimum: step_funcs
.len()
.try_into()
.map_err(|_| make_hq_bug!("step_funcs length out of bounds (E007)"))?,
.map_err(|_| make_hq_bug!("step_funcs length out of bounds"))?,
maximum: Some(
step_funcs
.len()
.try_into()
.map_err(|_| make_hq_bug!("step_funcs length out of bounds (E008)"))?,
.map_err(|_| make_hq_bug!("step_funcs length out of bounds"))?,
),
});

Expand All @@ -1864,7 +1864,7 @@ impl TryFrom<IrProject> for WasmProject {
minimum: string_consts
.len()
.try_into()
.map_err(|_| make_hq_bug!("string_consts len out of bounds (E037)"))?,
.map_err(|_| make_hq_bug!("string_consts len out of bounds"))?,
maximum: None,
});

Expand Down

0 comments on commit a56ee9d

Please sign in to comment.