Skip to content
Open
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
2 changes: 1 addition & 1 deletion COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,6 @@ implemented nor are there plans to implement due to differences between the impl
| ⚫️ | `setmetatable(value, table)` | Interesting thing to note is that this is _not_ the base library `setmetatable`, as `debug.setmetatable`'s first argument accepts any Lua value, while `setmetatable`'s first argument _must_ be a table. | |
| ⚫️ | `setupvalue(f, up, value)` | | |
| ⚫️ | `setuservalue(udata, value, n)` | | |
| ⚫️ | `traceback([thread,][message, level])` | | |
| 🔵 | `traceback([thread,][message, level])` | | |
| ⚫️ | `upvalueid(f, n)` | | |
| ⚫️ | `upvaluejoin(f1, n1, f2, n2)` | | |
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ that are usable from safe Rust. It achieves this by combining two things:
that such pointers are isolated to a single root object, and to guarantee
that, outside an active call to `mutate`, all such pointers are either
reachable from the root object or are safe to collect.

## Stackless VM

The `mutate` based GC API means that long running calls to `mutate` can be
Expand Down Expand Up @@ -235,7 +235,6 @@ very much WIP, so ensuring this is done correctly is an ongoing effort.
generate and the VM sorely needs optimization (very little effort has gone
here so far).
* Error messages that don't make you want to cry
* Stack traces
* Debugger
* Aggressive optimization and *real* effort towards matching or beating (or
even just being within a respectable distance of) PUC-Rio Lua's performance
Expand Down
6 changes: 6 additions & 0 deletions src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum CompilerError {
pub struct FunctionPrototype<'gc> {
pub chunk_name: String<'gc>,
pub reference: FunctionRef<String<'gc>>,
pub parameters: boxed::Box<[String<'gc>], MetricsAlloc<'gc>>,
pub fixed_params: u8,
pub has_varargs: bool,
pub stack_size: u16,
Expand Down Expand Up @@ -65,6 +66,10 @@ impl<'gc> FunctionPrototype<'gc> {
) -> FunctionPrototype<'gc> {
let alloc = MetricsAlloc::new(mc);

let mut parameters_vec = vec::Vec::new_in(alloc.clone());
parameters_vec.extend(compiled_function.parameters.iter().map(map_string));
let parameters = parameters_vec.into_boxed_slice();

let mut constants = vec::Vec::new_in(alloc.clone());
constants.extend(
compiled_function
Expand Down Expand Up @@ -95,6 +100,7 @@ impl<'gc> FunctionPrototype<'gc> {
.reference
.as_string_ref()
.map_strings(map_string),
parameters,
fixed_params: compiled_function.fixed_params,
has_varargs: compiled_function.has_varargs,
stack_size: compiled_function.stack_size,
Expand Down
26 changes: 15 additions & 11 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl<S> FunctionRef<S> {
#[collect(no_drop)]
pub struct CompiledPrototype<S> {
pub reference: FunctionRef<S>,
pub parameters: Vec<S>,
pub fixed_params: u8,
pub has_varargs: bool,
pub stack_size: u16,
Expand All @@ -132,6 +133,7 @@ impl<S> CompiledPrototype<S> {
) -> CompiledPrototype<S2> {
CompiledPrototype {
reference: this.reference.map_strings(f),
parameters: this.parameters.into_iter().map(f).collect(),
fixed_params: this.fixed_params,
has_varargs: this.has_varargs,
stack_size: this.stack_size,
Expand Down Expand Up @@ -183,6 +185,7 @@ struct Compiler<S: StringInterner> {

struct CompilerFunction<S> {
reference: FunctionRef<S>,
parameters: Vec<S>,

constants: Vec<Constant<S>>,
constant_table: HashMap<IdenticalConstant<S>, ConstantIndex16>,
Expand Down Expand Up @@ -804,14 +807,14 @@ impl<S: StringInterner> Compiler<S> {
parameters.extend_from_slice(&function_statement.definition.parameters);

self.new_prototype(
FunctionRef::Named(name.clone(), self.current_function.current_line_number),
FunctionRef::Named(name.clone(), function_statement.definition.line_number),
&parameters,
function_statement.definition.has_varargs,
&function_statement.definition.body,
)?
} else {
self.new_prototype(
FunctionRef::Named(name.clone(), self.current_function.current_line_number),
FunctionRef::Named(name.clone(), function_statement.definition.line_number),
&function_statement.definition.parameters,
function_statement.definition.has_varargs,
&function_statement.definition.body,
Expand Down Expand Up @@ -1091,7 +1094,7 @@ impl<S: StringInterner> Compiler<S> {
let proto = self.new_prototype(
FunctionRef::Named(
local_function.name.clone(),
self.current_function.current_line_number,
local_function.definition.line_number,
),
&local_function.definition.parameters,
local_function.definition.has_varargs,
Expand Down Expand Up @@ -1185,7 +1188,7 @@ impl<S: StringInterner> Compiler<S> {
function: &FunctionDefinition<S::String>,
) -> Result<ExprDescriptor<S::String>, CompileErrorKind> {
let proto = self.new_prototype(
FunctionRef::Expression(self.current_function.current_line_number),
FunctionRef::Expression(function.line_number),
&function.parameters,
function.has_varargs,
&function.body,
Expand Down Expand Up @@ -2477,14 +2480,9 @@ impl<S: Clone> CompilerFunction<S> {
parameters: &[S],
has_varargs: bool,
) -> Result<CompilerFunction<S>, CompileErrorKind> {
let current_line_number = match reference {
FunctionRef::Named(_, ln) => ln,
FunctionRef::Expression(ln) => ln,
FunctionRef::Chunk => LineNumber(0),
};

let mut function = CompilerFunction {
reference,
parameters: parameters.to_vec(),
constants: Vec::new(),
constant_table: HashMap::default(),
upvalues: Vec::new(),
Expand All @@ -2499,8 +2497,13 @@ impl<S: Clone> CompilerFunction<S> {
pending_jumps: Vec::new(),
operations: Vec::new(),
operation_lines: Vec::new(),
current_line_number,
current_line_number: LineNumber(0),
};
function.set_line_number(match &function.reference {
FunctionRef::Named(_, ln) => *ln,
FunctionRef::Expression(ln) => *ln,
FunctionRef::Chunk => LineNumber(0),
});

let fixed_params: u8 = parameters
.len()
Expand Down Expand Up @@ -2556,6 +2559,7 @@ impl<S: Clone> CompilerFunction<S> {

Ok(CompiledPrototype {
reference: self.reference,
parameters: self.parameters,
fixed_params: self.fixed_params,
has_varargs: self.has_varargs,
stack_size: self.register_allocator.stack_size(),
Expand Down
19 changes: 12 additions & 7 deletions src/compiler/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ pub struct SuffixedExpression<S> {

#[derive(Debug, Clone)]
pub struct FunctionDefinition<S> {
pub line_number: LineNumber,
pub parameters: Vec<S>,
pub has_varargs: bool,
pub body: Block<S>,
Expand Down Expand Up @@ -584,7 +585,7 @@ impl<S: StringInterner> Parser<'_, S> {
}

fn parse_function_statement(&mut self) -> Result<FunctionStatement<S::String>, ParseError> {
self.expect_next(Token::Function)?;
let line_number = self.expect_next(Token::Function)?;

let name = self.expect_name()?.inner;
let mut fields = Vec::new();
Expand All @@ -604,7 +605,7 @@ impl<S: StringInterner> Parser<'_, S> {
}
}

let definition = self.parse_function_definition()?;
let definition = self.parse_function_definition(line_number)?;

Ok(FunctionStatement {
name,
Expand All @@ -617,10 +618,10 @@ impl<S: StringInterner> Parser<'_, S> {
fn parse_local_function_statement(
&mut self,
) -> Result<LocalFunctionStatement<S::String>, ParseError> {
self.expect_next(Token::Function)?;
let line_number = self.expect_next(Token::Function)?;

let name = self.expect_name()?.inner;
let definition = self.parse_function_definition()?;
let definition = self.parse_function_definition(line_number)?;

Ok(LocalFunctionStatement { name, definition })
}
Expand Down Expand Up @@ -828,8 +829,8 @@ impl<S: StringInterner> Parser<'_, S> {
}
Token::LeftBrace => SimpleExpression::TableConstructor(self.parse_table_constructor()?),
Token::Function => {
self.take_next()?;
SimpleExpression::Function(self.parse_function_definition()?)
let line_number = self.take_next()?.line_number;
SimpleExpression::Function(self.parse_function_definition(line_number)?)
}
_ => SimpleExpression::Suffixed(self.parse_suffixed_expression()?),
})
Expand Down Expand Up @@ -965,7 +966,10 @@ impl<S: StringInterner> Parser<'_, S> {
Ok(SuffixedExpression { primary, suffixes })
}

fn parse_function_definition(&mut self) -> Result<FunctionDefinition<S::String>, ParseError> {
fn parse_function_definition(
&mut self,
line_number: LineNumber,
) -> Result<FunctionDefinition<S::String>, ParseError> {
self.expect_next(Token::LeftParen)?;

let mut parameters = Vec::new();
Expand Down Expand Up @@ -1002,6 +1006,7 @@ impl<S: StringInterner> Parser<'_, S> {
self.expect_next(Token::End)?;

Ok(FunctionDefinition {
line_number,
parameters,
has_varargs,
body,
Expand Down
Loading