Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions compiler-lib/src/bc_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,6 @@ impl BytecodeReader {
haxby_opcodes::OPCODE_BUILD_STRUCT => Ok(Opcode::BuildStruct),
haxby_opcodes::OPCODE_BUILD_ENUM => Ok(Opcode::BuildEnum),
haxby_opcodes::OPCODE_BUILD_MIXIN => Ok(Opcode::BuildMixin),
haxby_opcodes::OPCODE_BIND_METHOD => {
let b0 = match self.read_u8() {
Ok(b) => b,
Err(_) => {
return Err(DecodeError::InsufficientData);
}
};
let w1 = match self.read_u16() {
Ok(w) => w,
Err(_) => {
return Err(DecodeError::InsufficientData);
}
};
Ok(Opcode::BindMethod(b0, w1))
}
haxby_opcodes::OPCODE_BIND_CASE => {
let b0 = match self.read_u8() {
Ok(b) => b,
Expand Down
4 changes: 0 additions & 4 deletions compiler-lib/src/bc_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ impl BytecodeWriter {
Opcode::BuildStruct => self.write_u8(haxby_opcodes::OPCODE_BUILD_STRUCT),
Opcode::BuildMixin => self.write_u8(haxby_opcodes::OPCODE_BUILD_MIXIN),
Opcode::BuildEnum => self.write_u8(haxby_opcodes::OPCODE_BUILD_ENUM),
Opcode::BindMethod(a, n) => self
.write_u8(haxby_opcodes::OPCODE_BIND_METHOD)
.write_u8(*a)
.write_u16(*n),
Opcode::BindCase(a, n) => self
.write_u8(haxby_opcodes::OPCODE_BIND_CASE)
.write_u8(*a)
Expand Down
4 changes: 0 additions & 4 deletions compiler-lib/src/builder/compiler_opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ pub enum CompilerOpcode {
BuildStruct,
BuildEnum,
BuildMixin,
BindMethod(u8, u16),
BindCase(u8, u16),
IncludeMixin,
NewEnumVal(bool, u16),
Expand Down Expand Up @@ -142,7 +141,6 @@ impl CompilerOpcode {
Self::BuildStruct => false,
Self::BuildEnum => false,
Self::BuildMixin => false,
Self::BindMethod(..) => false,
Self::BindCase(..) => false,
Self::IncludeMixin => false,
Self::NewEnumVal(..) => false,
Expand Down Expand Up @@ -254,7 +252,6 @@ impl CompilerOpcode {
Self::BuildStruct => VmOpcode::BuildStruct,
Self::BuildEnum => VmOpcode::BuildEnum,
Self::BuildMixin => VmOpcode::BuildMixin,
Self::BindMethod(x, y) => VmOpcode::BindMethod(*x, *y),
Self::BindCase(x, y) => VmOpcode::BindCase(*x, *y),
Self::IncludeMixin => VmOpcode::IncludeMixin,
Self::NewEnumVal(v, n) => {
Expand Down Expand Up @@ -337,7 +334,6 @@ impl std::fmt::Display for CompilerOpcode {
BuildStruct => write!(f, "BuildStruct"),
BuildEnum => write!(f, "BuildEnum"),
BuildMixin => write!(f, "BuildMixin"),
BindMethod(x, y) => write!(f, "BindMethod({}, {})", x, y),
BindCase(x, y) => write!(f, "BindCase({}, {})", x, y),
IncludeMixin => write!(f, "IncludeMixin"),
NewEnumVal(has_payload, n) => write!(f, "NewEnumVal({}, {})", has_payload, n),
Expand Down
6 changes: 3 additions & 3 deletions compiler-lib/src/do_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ fn emit_method_decl_compile(md: &MethodDecl, params: &mut CompileParams) -> Comp
.writer
.get_current_block()
.write_opcode_and_source_info(
CompilerOpcode::BindMethod(
CompilerOpcode::BuildFunction(
if md.args.vararg {
FUNC_ACCEPTS_VARARG
} else {
Expand All @@ -350,10 +350,10 @@ fn emit_method_decl_compile(md: &MethodDecl, params: &mut CompileParams) -> Comp
} else {
0
},
name_idx,
),
md.loc.clone(),
);
)
.write_opcode_and_source_info(CompilerOpcode::WriteAttribute(name_idx), md.loc.clone());

Ok(())
}
Expand Down
10 changes: 0 additions & 10 deletions compiler-lib/src/dump/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ pub fn opcode_prettyprint(
<< symbol_best_repr(resolver, idx)
<< "]"
}
Opcode::BindMethod(arg, idx) => {
buffer
<< "BIND_METHOD("
<< arg
<< ",@"
<< idx
<< ") ["
<< const_best_repr(resolver, idx)
<< "]"
}
Opcode::BindCase(arg, idx) => {
buffer
<< "BIND_CASE("
Expand Down
15 changes: 7 additions & 8 deletions native-libs/file/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ struct MutableFile {
}

fn throw_io_error(the_struct: &Struct, message: String) -> crate::vm::ExecutionResult<RunloopExit> {
let io_error = the_struct.extract_field("IOError", |f| f.as_object().cloned())?;
io_error.write("message", RuntimeValue::String(message.into()));
Ok(RunloopExit::Exception(VmException::from_value(
RuntimeValue::Object(io_error),
)))
let io_error = the_struct.extract_field("IOError", |f| f.as_struct().cloned())?;
let io_error = RuntimeValue::Object(Object::new(&io_error));
let _ = io_error.write_attribute("message", RuntimeValue::String(message.into()));
Ok(RunloopExit::Exception(VmException::from_value(io_error)))
}

#[derive(Default)]
Expand All @@ -92,9 +91,9 @@ impl BuiltinFunctionImpl for New {
file: RefCell::new(file),
};
let file_obj = OpaqueValue::new(file);
let aria_file_obj = Object::new(&the_struct);
aria_file_obj.write("__file", RuntimeValue::Opaque(file_obj));
frame.stack.push(RuntimeValue::Object(aria_file_obj));
let aria_file_obj = RuntimeValue::Object(Object::new(&the_struct));
let _ = aria_file_obj.write_attribute("__file", RuntimeValue::Opaque(file_obj));
frame.stack.push(aria_file_obj);
Ok(RunloopExit::Ok(()))
}
Err(e) => throw_io_error(&the_struct, format!("Failed to open file: {e}")),
Expand Down
60 changes: 26 additions & 34 deletions native-libs/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ impl haxby_vm::runtime_value::function::BuiltinFunctionImpl for RequestGet {

match client.send() {
Ok(r) => {
let response_obj = Object::new(&this_response);
response_obj.write(
let response_obj = RuntimeValue::Object(Object::new(&this_response));
let _ = response_obj.write_attribute(
"status_code",
haxby_vm::runtime_value::RuntimeValue::Integer(
(r.status().as_u16() as i64).into(),
Expand All @@ -57,38 +57,34 @@ impl haxby_vm::runtime_value::function::BuiltinFunctionImpl for RequestGet {
]);
header_list.append(RuntimeValue::List(header_kvp));
}
response_obj.write("headers", RuntimeValue::List(header_list));
let _ = response_obj.write_attribute("headers", RuntimeValue::List(header_list));
match r.text() {
Ok(content) => {
response_obj.write("content", RuntimeValue::String(content.into()));
let _ = response_obj
.write_attribute("content", RuntimeValue::String(content.into()));
}
_ => {
let error_obj = Object::new(&this_error);
error_obj.write(
let error_obj = RuntimeValue::Object(Object::new(&this_error));
let _ = error_obj.write_attribute(
"msg",
RuntimeValue::String("content is not a valid String".into()),
);
let result_err = vm
.globals
.create_result_err(RuntimeValue::Object(error_obj))?;
let result_err = vm.globals.create_result_err(error_obj)?;
frame.stack.push(result_err);
return ExecutionResult::Ok(haxby_vm::vm::RunloopExit::Ok(()));
}
}

let result_ok = vm
.globals
.create_result_ok(RuntimeValue::Object(response_obj.clone()))?;
let result_ok = vm.globals.create_result_ok(response_obj.clone())?;

frame.stack.push(result_ok);
Ok(haxby_vm::vm::RunloopExit::Ok(()))
}
Err(e) => {
let error_obj = Object::new(&this_error);
error_obj.write("msg", RuntimeValue::String(e.to_string().into()));
let result_err = vm
.globals
.create_result_err(RuntimeValue::Object(error_obj))?;
let error_obj = RuntimeValue::Object(Object::new(&this_error));
let _ =
error_obj.write_attribute("msg", RuntimeValue::String(e.to_string().into()));
let result_err = vm.globals.create_result_err(error_obj)?;

frame.stack.push(result_err);
ExecutionResult::Ok(haxby_vm::vm::RunloopExit::Ok(()))
Expand Down Expand Up @@ -148,8 +144,8 @@ impl haxby_vm::runtime_value::function::BuiltinFunctionImpl for RequestPost {

match client.send() {
Ok(r) => {
let response_obj = Object::new(&this_response);
response_obj.write(
let response_obj = RuntimeValue::Object(Object::new(&this_response));
let _ = response_obj.write_attribute(
"status_code",
haxby_vm::runtime_value::RuntimeValue::Integer(
(r.status().as_u16() as i64).into(),
Expand All @@ -163,39 +159,35 @@ impl haxby_vm::runtime_value::function::BuiltinFunctionImpl for RequestPost {
]);
header_list.append(RuntimeValue::List(header_kvp));
}
response_obj.write("headers", RuntimeValue::List(header_list));
let _ = response_obj.write_attribute("headers", RuntimeValue::List(header_list));
match r.text() {
Ok(content) => {
response_obj.write("content", RuntimeValue::String(content.into()));
let _ = response_obj
.write_attribute("content", RuntimeValue::String(content.into()));
}
_ => {
let error_obj = Object::new(&this_error);
error_obj.write(
let error_obj = RuntimeValue::Object(Object::new(&this_error));
let _ = error_obj.write_attribute(
"msg",
RuntimeValue::String("content is not a valid String".into()),
);
let result_err = vm
.globals
.create_result_err(RuntimeValue::Object(error_obj))?;
let result_err = vm.globals.create_result_err(error_obj)?;

frame.stack.push(result_err);
return ExecutionResult::Ok(haxby_vm::vm::RunloopExit::Ok(()));
}
}

let result_ok = vm
.globals
.create_result_ok(RuntimeValue::Object(response_obj.clone()))?;
let result_ok = vm.globals.create_result_ok(response_obj.clone())?;

frame.stack.push(result_ok);
Ok(haxby_vm::vm::RunloopExit::Ok(()))
}
Err(e) => {
let error_obj = Object::new(&this_error);
error_obj.write("msg", RuntimeValue::String(e.to_string().into()));
let result_err = vm
.globals
.create_result_err(RuntimeValue::Object(error_obj))?;
let error_obj = RuntimeValue::Object(Object::new(&this_error));
let _ =
error_obj.write_attribute("msg", RuntimeValue::String(e.to_string().into()));
let result_err = vm.globals.create_result_err(error_obj)?;

frame.stack.push(result_err);
ExecutionResult::Ok(haxby_vm::vm::RunloopExit::Ok(()))
Expand Down
13 changes: 6 additions & 7 deletions native-libs/path/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ fn new_from_path<P: AsRef<std::path::Path>>(
};

let path_obj = OpaqueValue::new(pb);
let aria_obj = Object::new(the_struct);
aria_obj.write("__path", RuntimeValue::Opaque(path_obj));
RuntimeValue::Object(aria_obj)
let aria_obj = RuntimeValue::Object(Object::new(the_struct));
let _ = aria_obj.write_attribute("__path", RuntimeValue::Opaque(path_obj));
aria_obj
}

fn create_path_result_err(
Expand All @@ -43,11 +43,10 @@ fn create_path_result_err(
) -> Result<RuntimeValue, VmErrorReason> {
let path_error = path_struct.extract_field("Error", |field| field.as_struct().cloned())?;

let path_error = Object::new(&path_error);
path_error.write("msg", RuntimeValue::String(message.into()));
let path_error = RuntimeValue::Object(Object::new(&path_error));
let _ = path_error.write_attribute("msg", RuntimeValue::String(message.into()));

vm.globals
.create_result_err(RuntimeValue::Object(path_error))
vm.globals.create_result_err(path_error)
}

fn mut_path_from_aria(aria_object: &Object) -> Result<Rc<MutablePath>, VmErrorReason> {
Expand Down
12 changes: 6 additions & 6 deletions native-libs/platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ impl BuiltinFunctionImpl for GetPlatformInfo {
let linux_info = linux_info
.as_struct()
.ok_or(VmErrorReason::UnexpectedVmState)?;
let linux_info = Object::new(linux_info);
linux_info.write(
let linux_info = RuntimeValue::Object(Object::new(linux_info));
let _ = linux_info.write_attribute(
"kernel_version",
RuntimeValue::String(kernel_version.into()),
);
Expand All @@ -42,7 +42,7 @@ impl BuiltinFunctionImpl for GetPlatformInfo {
.ok_or(VmErrorReason::UnexpectedVmState)?;

let linux_enum_instance = platform_enum
.make_value(linux_case, Some(RuntimeValue::Object(linux_info)))
.make_value(linux_case, Some(linux_info))
.ok_or(VmErrorReason::UnexpectedVmState)?;

frame
Expand Down Expand Up @@ -78,15 +78,15 @@ impl BuiltinFunctionImpl for GetPlatformInfo {
let mac_info = mac_info
.as_struct()
.ok_or(VmErrorReason::UnexpectedVmState)?;
let mac_info = Object::new(mac_info);
mac_info.write("os_build", RuntimeValue::String(mac_version.into()));
let mac_info = RuntimeValue::Object(Object::new(mac_info));
let _ = mac_info.write_attribute("os_build", RuntimeValue::String(mac_version.into()));

let mac_case = platform_enum
.get_idx_of_case("macOS")
.ok_or(VmErrorReason::UnexpectedVmState)?;

let mac_enum_instance = platform_enum
.make_value(mac_case, Some(RuntimeValue::Object(mac_info)))
.make_value(mac_case, Some(mac_info))
.ok_or(VmErrorReason::UnexpectedVmState)?;

frame.stack.push(RuntimeValue::EnumValue(mac_enum_instance));
Expand Down
24 changes: 12 additions & 12 deletions native-libs/regex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ fn create_regex_error(
.as_struct()
.ok_or(VmErrorReason::UnexpectedType)?;

let regex_error = Object::new(regex_error);
regex_error.write("msg", RuntimeValue::String(message.into()));
let regex_error = RuntimeValue::Object(Object::new(regex_error));
let _ = regex_error.write_attribute("msg", RuntimeValue::String(message.into()));

Ok(RuntimeValue::Object(regex_error))
Ok(regex_error)
}

#[derive(Default)]
Expand All @@ -51,11 +51,11 @@ impl BuiltinFunctionImpl for New {

let rust_regex_obj = OpaqueValue::new(rust_regex_obj);

let aria_regex_obj = Object::new(&the_struct);
aria_regex_obj.write("__pattern", RuntimeValue::Opaque(rust_regex_obj));
aria_regex_obj.write("pattern", RuntimeValue::String(the_pattern));
let aria_regex_obj = RuntimeValue::Object(Object::new(&the_struct));
let _ = aria_regex_obj.write_attribute("__pattern", RuntimeValue::Opaque(rust_regex_obj));
let _ = aria_regex_obj.write_attribute("pattern", RuntimeValue::String(the_pattern));

frame.stack.push(RuntimeValue::Object(aria_regex_obj));
frame.stack.push(aria_regex_obj);
Ok(RunloopExit::Ok(()))
}

Expand Down Expand Up @@ -134,11 +134,11 @@ impl BuiltinFunctionImpl for Matches {

let matches_list = List::default();
for m in matches {
let match_obj = Object::new(&match_struct_type);
match_obj.write("start", RuntimeValue::Integer(m.0.into()));
match_obj.write("len", RuntimeValue::Integer(m.1.into()));
match_obj.write("value", RuntimeValue::String(m.2.into()));
matches_list.append(RuntimeValue::Object(match_obj));
let match_obj = RuntimeValue::Object(Object::new(&match_struct_type));
let _ = match_obj.write_attribute("start", RuntimeValue::Integer(m.0.into()));
let _ = match_obj.write_attribute("len", RuntimeValue::Integer(m.1.into()));
let _ = match_obj.write_attribute("value", RuntimeValue::String(m.2.into()));
matches_list.append(match_obj);
}

frame.stack.push(RuntimeValue::List(matches_list));
Expand Down
3 changes: 0 additions & 3 deletions opcodes-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub const OPCODE_STORE_UPLEVEL: u8 = 82;
pub const OPCODE_BUILD_STRUCT: u8 = 83;
pub const OPCODE_BUILD_ENUM: u8 = 84;
pub const OPCODE_BUILD_MIXIN: u8 = 85;
pub const OPCODE_BIND_METHOD: u8 = 86;
pub const OPCODE_BIND_CASE: u8 = 87;
pub const OPCODE_INCLUDE_MIXIN: u8 = 88;
pub const OPCODE_NEW_ENUM_VAL: u8 = 89;
Expand Down Expand Up @@ -267,7 +266,6 @@ pub enum Opcode {
BuildStruct,
BuildEnum,
BuildMixin,
BindMethod(u8, u16),
BindCase(u8, u16),
IncludeMixin,
NewEnumVal(u8, u16),
Expand Down Expand Up @@ -345,7 +343,6 @@ impl std::fmt::Display for Opcode {
Self::BuildStruct => write!(f, "BUILD_STRUCT"),
Self::BuildEnum => write!(f, "BUILD_ENUM"),
Self::BuildMixin => write!(f, "BUILD_MIXIN"),
Self::BindMethod(arg0, arg1) => write!(f, "BIND_M {arg0} @{arg1}"),
Self::BindCase(arg0, arg1) => write!(f, "BIND_C {arg0} @{arg1}"),
Self::IncludeMixin => write!(f, "INCLUDE_MIXIN"),
Self::NewEnumVal(arg0, arg1) => write!(f, "NEW_ENUM_VAL {arg0} @{arg1}"),
Expand Down
Loading