diff --git a/boa/src/bytecompiler.rs b/boa/src/bytecompiler.rs new file mode 100644 index 0000000000..9314215084 --- /dev/null +++ b/boa/src/bytecompiler.rs @@ -0,0 +1,693 @@ +use crate::{ + syntax::ast::{ + node::{GetConstField, GetField, Identifier, StatementList}, + op::{AssignOp, BinOp, BitOp, CompOp, LogOp, NumOp, UnaryOp}, + Const, Node, + }, + value::{RcBigInt, RcString}, + vm::{CodeBlock, Opcode}, + Value, +}; + +use std::collections::HashMap; + +#[inline] +fn u16_to_array(value: u16) -> [u8; 2] { + // Safety: Transmuting a `u16` primitive to + // an array of 2 bytes is safe. + unsafe { std::mem::transmute(value) } +} + +#[inline] +fn u32_to_array(value: u32) -> [u8; 4] { + // Safety: Transmuting a `u32` primitive to + // an array of 4 bytes is safe. + unsafe { std::mem::transmute(value) } +} + +#[inline] +fn u64_to_array(value: u64) -> [u8; 8] { + // Safety: Transmuting a `u64` primitive to + // an array of 8 bytes is safe. + unsafe { std::mem::transmute(value) } +} + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +enum Literal { + String(RcString), + BigInt(RcBigInt), +} + +#[must_use] +#[derive(Debug, Clone, Copy)] +struct Label { + index: u32, +} + +#[derive(Debug, Clone)] +struct LoopControlInfo { + label: Option>, + loop_start: u32, + continues: Vec