Skip to content

Commit

Permalink
remove frames usage for operations inside of subroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed Jul 27, 2022
1 parent 91b095e commit 8c56f69
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 336 deletions.
342 changes: 146 additions & 196 deletions src/checker/compiler.h

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions src/checker/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ namespace ts::checker {
result.subroutines.push_back({.name = name, .address = address});
break;
}
case OP::FrameReturnJump:
case OP::Jump: {
auto address = vm::readInt32(bin, i + 1);
params += fmt::format(" [{}, +{}]", startI + address, address);
Expand All @@ -123,18 +122,19 @@ namespace ts::checker {
break;
}
case OP::Main: {
auto address = vm::readUint32(bin, i + 1);
params += fmt::format(" [{}, +{}]", startI + address, address);
vm::eatParams(op, &i);
result.subroutines.push_back({.name = "main", .address = address});
newSubRoutine = true;
break;
}
case OP::Return: {
newSubRoutine = true;
break;
}
case OP::Distribute:
case OP::Distribute: {
params += fmt::format(" &{} [{}, +{}]", vm::readUint16(bin, i + 1), startI + vm::readUint32(bin, i + 3), vm::readUint32(bin, i + 3));
vm::eatParams(op, &i);
newLine = true;
break;
}
case OP::JumpCondition: {
params += fmt::format(" [{}]", startI + vm::readUint32(bin, i + 1));
vm::eatParams(op, &i);
Expand Down Expand Up @@ -167,8 +167,13 @@ namespace ts::checker {
vm::eatParams(op, &i);
break;
}
case OP::Union:
case OP::Tuple:
case OP::TemplateLiteral:
case OP::ObjectLiteral:
case OP::Slots:
case OP::Loads: {
params += fmt::format(" &{}:{}", vm::readUint16(bin, i + 1), vm::readUint16(bin, i + 3));
params += fmt::format(" {}", vm::readUint16(bin, i + 1));
vm::eatParams(op, &i);
break;
}
Expand Down
24 changes: 14 additions & 10 deletions src/checker/instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ namespace ts::instructions {
enum OP {
Noop,
Jump, //arbitrary jump, used at the beginning to jump over storage-data (storage-data's addresses are constant)
FrameReturnJump,
Halt,
SourceMap, //one parameter (size uint32). all subsequent bytes withing the given size is a map op:pos:end, each uint32
Main, //marks end of meta-data section (subroutine metadata + storage data). has one parameter that points to the actual main code.
Main, //marks end of meta-data section (subroutine metadata + storage data). after this the body section with all subroutine ops follow.

Never,
Any,
Expand Down Expand Up @@ -70,14 +69,21 @@ namespace ts::instructions {
Instantiate, //instantiates a type on the stack (FunctionRef for example), ExpressionWithTypeArguments

/**
* Stack parameter. For each JS variable, JS function, as well as type variables (mapped-type variable for example).
* Reserved new stack entries to be used as type variables.
*
* Parameters:
* 1. address on initial stack frame, which should contain its name as a string.
* 3. modifier: const
* 2. position in source code. necessary to determine if a reference is made to a const symbol before it was defined.
* 1 parameter indicating how many stack entries will be reserved.
*/
Var,
Slots,

///**
// * Stack parameter. For each JS variable, JS function, as well as type variables (mapped-type variable for example).
// *
// * Parameters:
// * 1. address on initial stack frame, which should contain its name as a string.
// * 3. modifier: const
// * 2. position in source code. necessary to determine if a reference is made to a const symbol before it was defined.
// */
//Var,

/**
* Makes sure that in the current variable slot is a type placed if nothing was provided as parameter.
Expand All @@ -93,8 +99,6 @@ namespace ts::instructions {
TypeArgumentDefault, //one parameter with the address of the subroutine of the default value

TypeArgumentConstraint, //expects an entry on the stack
TypeVariable,


TemplateLiteral,

Expand Down
3 changes: 0 additions & 3 deletions src/checker/module2.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ namespace ts::vm2 {
const string code = ""; //for diagnostic messages only

vector<ModuleSubroutine> subroutines;
unsigned int mainAddress;
unsigned int sourceMapAddress;
unsigned int sourceMapAddressEnd;

Expand Down Expand Up @@ -188,8 +187,6 @@ namespace ts::vm2 {
break;
}
case OP::Main: {
module->mainAddress = vm::readUint32(bin, i + 1);
module->subroutines.push_back(ModuleSubroutine("main", module->mainAddress, 0));
return;
}
}
Expand Down
19 changes: 14 additions & 5 deletions src/checker/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ namespace ts::vm {
*i += 4 + 4 + 1;
break;
}
case OP::Main:
case OP::FrameReturnJump:
case OP::Main: {
break;
}
case OP::Jump: {
*i += 4;
break;
Expand All @@ -84,9 +85,12 @@ namespace ts::vm {
*i += 4;
break;
}
case OP::Set:
case OP::TypeArgumentDefault:
case OP::Distribute: {
*i += 2 + 4;
break;
}
case OP::Set:
case OP::TypeArgumentDefault: {
*i += 4;
break;
}
Expand All @@ -102,12 +106,17 @@ namespace ts::vm {
*i += 2;
break;
}
case OP::Union:
case OP::Tuple:
case OP::TemplateLiteral:
case OP::ObjectLiteral:
case OP::Slots:
case OP::CallExpression: {
*i += 2;
break;
}
case OP::Loads: {
*i += 4;
*i += 2;
break;
}
case OP::Parameter:
Expand Down
Loading

0 comments on commit 8c56f69

Please sign in to comment.