Skip to content

Commit 38d90d1

Browse files
committed
Remove BindMethod opcode. It is really just BuildFunction+WriteAttribute
1 parent e71bdb0 commit 38d90d1

11 files changed

Lines changed: 44 additions & 125 deletions

File tree

compiler-lib/src/bc_reader.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,6 @@ impl BytecodeReader {
278278
haxby_opcodes::OPCODE_BUILD_STRUCT => Ok(Opcode::BuildStruct),
279279
haxby_opcodes::OPCODE_BUILD_ENUM => Ok(Opcode::BuildEnum),
280280
haxby_opcodes::OPCODE_BUILD_MIXIN => Ok(Opcode::BuildMixin),
281-
haxby_opcodes::OPCODE_BIND_METHOD => {
282-
let b0 = match self.read_u8() {
283-
Ok(b) => b,
284-
Err(_) => {
285-
return Err(DecodeError::InsufficientData);
286-
}
287-
};
288-
let w1 = match self.read_u16() {
289-
Ok(w) => w,
290-
Err(_) => {
291-
return Err(DecodeError::InsufficientData);
292-
}
293-
};
294-
Ok(Opcode::BindMethod(b0, w1))
295-
}
296281
haxby_opcodes::OPCODE_BIND_CASE => {
297282
let b0 = match self.read_u8() {
298283
Ok(b) => b,

compiler-lib/src/bc_writer.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ impl BytecodeWriter {
124124
Opcode::BuildStruct => self.write_u8(haxby_opcodes::OPCODE_BUILD_STRUCT),
125125
Opcode::BuildMixin => self.write_u8(haxby_opcodes::OPCODE_BUILD_MIXIN),
126126
Opcode::BuildEnum => self.write_u8(haxby_opcodes::OPCODE_BUILD_ENUM),
127-
Opcode::BindMethod(a, n) => self
128-
.write_u8(haxby_opcodes::OPCODE_BIND_METHOD)
129-
.write_u8(*a)
130-
.write_u16(*n),
131127
Opcode::BindCase(a, n) => self
132128
.write_u8(haxby_opcodes::OPCODE_BIND_CASE)
133129
.write_u8(*a)

compiler-lib/src/builder/compiler_opcodes.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ pub enum CompilerOpcode {
6666
BuildStruct,
6767
BuildEnum,
6868
BuildMixin,
69-
BindMethod(u8, u16),
7069
BindCase(u8, u16),
7170
IncludeMixin,
7271
NewEnumVal(bool, u16),
@@ -142,7 +141,6 @@ impl CompilerOpcode {
142141
Self::BuildStruct => false,
143142
Self::BuildEnum => false,
144143
Self::BuildMixin => false,
145-
Self::BindMethod(..) => false,
146144
Self::BindCase(..) => false,
147145
Self::IncludeMixin => false,
148146
Self::NewEnumVal(..) => false,
@@ -254,7 +252,6 @@ impl CompilerOpcode {
254252
Self::BuildStruct => VmOpcode::BuildStruct,
255253
Self::BuildEnum => VmOpcode::BuildEnum,
256254
Self::BuildMixin => VmOpcode::BuildMixin,
257-
Self::BindMethod(x, y) => VmOpcode::BindMethod(*x, *y),
258255
Self::BindCase(x, y) => VmOpcode::BindCase(*x, *y),
259256
Self::IncludeMixin => VmOpcode::IncludeMixin,
260257
Self::NewEnumVal(v, n) => {
@@ -337,7 +334,6 @@ impl std::fmt::Display for CompilerOpcode {
337334
BuildStruct => write!(f, "BuildStruct"),
338335
BuildEnum => write!(f, "BuildEnum"),
339336
BuildMixin => write!(f, "BuildMixin"),
340-
BindMethod(x, y) => write!(f, "BindMethod({}, {})", x, y),
341337
BindCase(x, y) => write!(f, "BindCase({}, {})", x, y),
342338
IncludeMixin => write!(f, "IncludeMixin"),
343339
NewEnumVal(has_payload, n) => write!(f, "NewEnumVal({}, {})", has_payload, n),

compiler-lib/src/do_compile/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ fn emit_method_decl_compile(md: &MethodDecl, params: &mut CompileParams) -> Comp
339339
.writer
340340
.get_current_block()
341341
.write_opcode_and_source_info(
342-
CompilerOpcode::BindMethod(
342+
CompilerOpcode::BuildFunction(
343343
if md.args.vararg {
344344
FUNC_ACCEPTS_VARARG
345345
} else {
@@ -350,10 +350,10 @@ fn emit_method_decl_compile(md: &MethodDecl, params: &mut CompileParams) -> Comp
350350
} else {
351351
0
352352
},
353-
name_idx,
354353
),
355354
md.loc.clone(),
356-
);
355+
)
356+
.write_opcode_and_source_info(CompilerOpcode::WriteAttribute(name_idx), md.loc.clone());
357357

358358
Ok(())
359359
}

compiler-lib/src/dump/opcodes.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,6 @@ pub fn opcode_prettyprint(
7070
<< symbol_best_repr(resolver, idx)
7171
<< "]"
7272
}
73-
Opcode::BindMethod(arg, idx) => {
74-
buffer
75-
<< "BIND_METHOD("
76-
<< arg
77-
<< ",@"
78-
<< idx
79-
<< ") ["
80-
<< const_best_repr(resolver, idx)
81-
<< "]"
82-
}
8373
Opcode::BindCase(arg, idx) => {
8474
buffer
8575
<< "BIND_CASE("

opcodes-lib/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ pub const OPCODE_STORE_UPLEVEL: u8 = 82;
6363
pub const OPCODE_BUILD_STRUCT: u8 = 83;
6464
pub const OPCODE_BUILD_ENUM: u8 = 84;
6565
pub const OPCODE_BUILD_MIXIN: u8 = 85;
66-
pub const OPCODE_BIND_METHOD: u8 = 86;
6766
pub const OPCODE_BIND_CASE: u8 = 87;
6867
pub const OPCODE_INCLUDE_MIXIN: u8 = 88;
6968
pub const OPCODE_NEW_ENUM_VAL: u8 = 89;
@@ -267,7 +266,6 @@ pub enum Opcode {
267266
BuildStruct,
268267
BuildEnum,
269268
BuildMixin,
270-
BindMethod(u8, u16),
271269
BindCase(u8, u16),
272270
IncludeMixin,
273271
NewEnumVal(u8, u16),
@@ -345,7 +343,6 @@ impl std::fmt::Display for Opcode {
345343
Self::BuildStruct => write!(f, "BUILD_STRUCT"),
346344
Self::BuildEnum => write!(f, "BUILD_ENUM"),
347345
Self::BuildMixin => write!(f, "BUILD_MIXIN"),
348-
Self::BindMethod(arg0, arg1) => write!(f, "BIND_M {arg0} @{arg1}"),
349346
Self::BindCase(arg0, arg1) => write!(f, "BIND_C {arg0} @{arg1}"),
350347
Self::IncludeMixin => write!(f, "INCLUDE_MIXIN"),
351348
Self::NewEnumVal(arg0, arg1) => write!(f, "NEW_ENUM_VAL {arg0} @{arg1}"),

vm-lib/src/builtins/runtime_error.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(super) fn insert_runtime_error_builtins(builtins: &mut VmGlobals) {
1616
let int = builtins.get_builtin_type_by_id(BuiltinTypeId::Int);
1717
let str = builtins.get_builtin_type_by_id(BuiltinTypeId::String);
1818

19-
let rt_err_enum = Enum::new_with_cases(
19+
let rt_err_enum = RuntimeValue::Type(RuntimeValueType::Enum(Enum::new_with_cases(
2020
"RuntimeError",
2121
&[
2222
EnumCase {
@@ -54,15 +54,18 @@ pub(super) fn insert_runtime_error_builtins(builtins: &mut VmGlobals) {
5454
payload_type: None,
5555
},
5656
],
57-
);
57+
)));
5858

59-
rt_err_enum.store_named_value(
59+
let _ = rt_err_enum.write_attribute(
6060
"ArgcMismatch",
6161
RuntimeValue::Type(RuntimeValueType::Struct(argc_mismatch)),
6262
);
6363

6464
builtins.register_builtin_type(
6565
haxby_opcodes::BuiltinTypeId::RuntimeError,
66-
RuntimeValueType::Enum(rt_err_enum),
66+
rt_err_enum
67+
.as_type()
68+
.expect("RuntimeError is a type")
69+
.clone(),
6770
);
6871
}

vm-lib/src/runtime_value/enumeration.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ impl Enum {
133133
self.imp.load_named_value(name)
134134
}
135135

136-
pub(crate) fn store_named_value(&self, name: &str, val: RuntimeValue) {
137-
self.imp.store_named_value(name, val);
138-
}
139-
140136
pub fn include_mixin(&self, mixin: &Mixin) {
141137
self.imp.include_mixin(mixin);
142138
}
@@ -174,7 +170,8 @@ impl Enum {
174170
{
175171
let t = T::default();
176172
let name = t.name().to_owned();
177-
self.store_named_value(&name, RuntimeValue::Function(Function::builtin_from(t)));
173+
self.imp
174+
.store_named_value(&name, RuntimeValue::Function(Function::builtin_from(t)));
178175
}
179176
}
180177

vm-lib/src/runtime_value/mixin.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ impl MixinImpl {
3030
}
3131
}
3232

33-
fn store_named_value(&self, name: &str, val: RuntimeValue) {
34-
self.entries.write(name, val);
35-
}
36-
3733
fn named_values(&self) -> Vec<String> {
3834
self.entries.keys().into_iter().collect()
3935
}
@@ -73,10 +69,6 @@ impl Mixin {
7369
self.imp.load_named_value(name)
7470
}
7571

76-
pub(crate) fn store_named_value(&self, name: &str, val: RuntimeValue) {
77-
self.imp.store_named_value(name, val);
78-
}
79-
8072
pub fn named_values(&self) -> Vec<String> {
8173
self.imp.named_values()
8274
}

vm-lib/src/runtime_value/structure.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ impl Struct {
7373
self.imp.load_named_value(name)
7474
}
7575

76-
pub(crate) fn store_named_value(&self, name: &str, val: RuntimeValue) {
77-
self.imp.store_named_value(name, val);
78-
}
79-
8076
pub fn include_mixin(&self, mixin: &Mixin) {
8177
self.imp.include_mixin(mixin);
8278
}
@@ -104,7 +100,8 @@ impl Struct {
104100
{
105101
let t = T::default();
106102
let name = t.name().to_owned();
107-
self.store_named_value(&name, RuntimeValue::Function(Function::builtin_from(t)));
103+
self.imp
104+
.store_named_value(&name, RuntimeValue::Function(Function::builtin_from(t)));
108105
}
109106

110107
pub fn extract_field<FnType, OkType>(

0 commit comments

Comments
 (0)