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
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,26 @@ More features will be implemented as time passes.
We recommend the [Tour of Go](https://go.dev/tour/welcome/1), which is written by the developers of the language themselves. It introduces the various elements of the programming language as well as their syntaxes, as the syntaxes may differ quite greatly from other programming languages.

For further exploration, we can download the language Go itself [here](https://go.dev/doc/install).

## Notes to self

### Heap

Heap class stores the following

- Memory: Array of 8 byte words
- Size: Total number of words in memory
- Unassigned: Unassigned memory
- Freelist: List of linked lists storing free blocks at that size
- Max Level: Largest block size power of 2 supported
- Temp roots: Temporary stack of root references
- Contexts: Queue to schedule execution contexts
- Blocked Contexts: Linked list of blocked execution contexts
- Mem Left: Tracks remaining memory
- Temp: Temp register to hold an address
- Debugger: Determine if debugger is activated

Addr stores the following

- Free Node: [1 bit free bit] [5 bits Level data] [29 bits Prev Node] [29 bits Next Node]
- Not-Free Node: [1 bit free bit] [5 bits Level data] [1 bit Mark & Sweep] [1 Byte Type Tag] [2 Bytes Payload - Depends on type]
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"d3-zoom": "^3.0.0",
"framer-motion": "^10.12.14",
"js-cookie": "^3.0.5",
"node": "^22.7.0",
"node": "^22.18.0",
"npm": "^11.5.2",
"peggy": "^4.1.1",
"react": "^18.2.0",
"react-cytoscapejs": "^2.0.0",
Expand All @@ -69,6 +70,7 @@
"seedrandom": "^3.0.5",
"util": "^0.12.5",
"uuid": "^9.0.0",
"yarn": "^1.22.22",
"zustand": "^4.5.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/go-virtual-machine-main/tests/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('Array Execution', () => {
`).output,
).toEqual('&[false true true]\n')
})

test('Array indexing with valid index works.', () => {
expect(
mainRunner(
Expand Down Expand Up @@ -648,5 +648,5 @@ describe('Array Execution', () => {
)
})
/*
*/
*/
})
10 changes: 7 additions & 3 deletions src/go-virtual-machine-main/tests/struct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('Struct tests', () => {
`).output,
).toEqual('{{Alice 25.5} 3934}\n')
})

test('Structs with 1 field work when supplied directly as arguments', () => {
expect(
codeRunner(`
Expand Down Expand Up @@ -2061,7 +2061,9 @@ describe('Struct tests', () => {
fmt.Println(a)
}
`).output,
).toEqual('[{[[34.25 0] [94.25 4.25]] 234} {[[11.5 34.5] [33.25 33.5]] 999}]\n')
).toEqual(
'[{[[34.25 0] [94.25 4.25]] 234} {[[11.5 34.5] [33.25 33.5]] 999}]\n',
)
})

test('Array of declared structs containing 2D arrays as the later field work', () => {
Expand Down Expand Up @@ -2104,7 +2106,9 @@ describe('Struct tests', () => {
fmt.Println(a)
}
`).output,
).toEqual('[{234 [[34.25 0] [94.25 4.25]]} {999 [[11.5 34.5] [33.25 33.5]]}]\n')
).toEqual(
'[{234 [[34.25 0] [94.25 4.25]]} {999 [[11.5 34.5] [33.25 33.5]]}]\n',
)
})

// Large test cases due to heavy recursion during parsing, requires PeggyJS parser optimisation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ export class FunctionDeclarationToken extends Token {
const type = this.func.compile(compiler)
this.pushInstruction(
compiler,
new LoadVariableInstruction(frame_idx, var_idx, this.name.identifier, type),
new LoadVariableInstruction(
frame_idx,
var_idx,
this.name.identifier,
type,
),
)
this.pushInstruction(compiler, new StoreInstruction())
return new NoType()
Expand Down Expand Up @@ -168,13 +173,15 @@ export class ShortVariableDeclarationToken extends DeclarationToken {
frame_idx,
var_idx,
identifier,
expressionTypes
expressionTypes,
)
}
if (
compiler.instructions[j] instanceof StoreStructFieldInstruction
) {
const oldInstruction = compiler.instructions[j] as StoreStructFieldInstruction
const oldInstruction = compiler.instructions[
j
] as StoreStructFieldInstruction
compiler.instructions[j] = new StoreStructFieldInstruction(
oldInstruction.index,
oldInstruction.order,
Expand All @@ -185,7 +192,9 @@ export class ShortVariableDeclarationToken extends DeclarationToken {
if (
compiler.instructions[j] instanceof StoreArrayElementInstruction
) {
const oldInstruction = compiler.instructions[j] as StoreArrayElementInstruction
const oldInstruction = compiler.instructions[
j
] as StoreArrayElementInstruction
compiler.instructions[j] = new StoreArrayElementInstruction(
oldInstruction.index,
true,
Expand Down Expand Up @@ -214,7 +223,12 @@ export class ShortVariableDeclarationToken extends DeclarationToken {
// again, just to decouple the instructions from nested structs/multi-dimensional arrays
this.pushInstruction(
compiler,
new LoadVariableInstruction(frame_idx, var_idx, identifier, expressionTypes),
new LoadVariableInstruction(
frame_idx,
var_idx,
identifier,
expressionTypes,
),
)
} else if (
expressionTypes instanceof PointerType &&
Expand All @@ -230,17 +244,31 @@ export class ShortVariableDeclarationToken extends DeclarationToken {
// or is it already done. If it is already done, we skip this step
// at this point, instruction stack should look like:
// StoreStuctField/ArrayElement, LoadVariable, Unary
if (compiler.instructions[compiler.instructions.length - 3] instanceof StoreStructFieldInstruction
|| compiler.instructions[compiler.instructions.length - 3] instanceof StoreArrayElementInstruction
if (
compiler.instructions[compiler.instructions.length - 3] instanceof
StoreStructFieldInstruction ||
compiler.instructions[compiler.instructions.length - 3] instanceof
StoreArrayElementInstruction
) {
compiler.instructions[compiler.instructions.length - 2] =
new LoadVariableInstruction(frame_idx, var_idx, identifier, expressionTypes)
compiler.instructions[compiler.instructions.length - 1] = new NoInstruction()
new LoadVariableInstruction(
frame_idx,
var_idx,
identifier,
expressionTypes,
)
compiler.instructions[compiler.instructions.length - 1] =
new NoInstruction()
}
}
this.pushInstruction(
compiler,
new LoadVariableInstruction(frame_idx, var_idx, identifier, expressionTypes),
new LoadVariableInstruction(
frame_idx,
var_idx,
identifier,
expressionTypes,
),
)
this.pushInstruction(compiler, new StoreInstruction())
}
Expand Down Expand Up @@ -335,13 +363,15 @@ export class VariableDeclarationToken extends DeclarationToken {
frame_idx,
var_idx,
identifier,
expressionTypes
expressionTypes,
)
}
if (
compiler.instructions[j] instanceof StoreStructFieldInstruction
) {
const oldInstruction = compiler.instructions[j] as StoreStructFieldInstruction
const oldInstruction = compiler.instructions[
j
] as StoreStructFieldInstruction
compiler.instructions[j] = new StoreStructFieldInstruction(
oldInstruction.index,
oldInstruction.order,
Expand All @@ -352,7 +382,9 @@ export class VariableDeclarationToken extends DeclarationToken {
if (
compiler.instructions[j] instanceof StoreArrayElementInstruction
) {
const oldInstruction = compiler.instructions[j] as StoreArrayElementInstruction
const oldInstruction = compiler.instructions[
j
] as StoreArrayElementInstruction
compiler.instructions[j] = new StoreArrayElementInstruction(
oldInstruction.index,
true,
Expand Down Expand Up @@ -401,7 +433,12 @@ export class VariableDeclarationToken extends DeclarationToken {
// instruction correction for arrays and structs
this.pushInstruction(
compiler,
new LoadVariableInstruction(frame_idx, var_idx, identifier, expressionTypes),
new LoadVariableInstruction(
frame_idx,
var_idx,
identifier,
expressionTypes,
),
)
this.pushInstruction(compiler, new StoreInstruction())
}
Expand Down Expand Up @@ -452,7 +489,12 @@ export class ConstantDeclarationToken extends DeclarationToken {
compiler.type_environment.addType(var_name, expressionType)
this.pushInstruction(
compiler,
new LoadVariableInstruction(frame_idx, var_idx, var_name, expressionType),
new LoadVariableInstruction(
frame_idx,
var_idx,
var_name,
expressionType,
),
)
this.pushInstruction(compiler, new StoreInstruction())
}
Expand All @@ -479,7 +521,12 @@ function handleReturnType(
}
compiler.type_environment.addType(identifier, expressionTypes.types[j])
compiler.instructions.push(
new LoadVariableInstruction(frame_idx, var_idx, identifier, expressionTypes.types[j]),
new LoadVariableInstruction(
frame_idx,
var_idx,
identifier,
expressionTypes.types[j],
),
)
compiler.instructions.push(new StoreInstruction())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export class CallToken extends PrimaryExpressionModifierToken {
}

const argumentTypes = this.expressions.map((e) => {
const type = e.compile(compiler);
const type = e.compile(compiler)
// NoInstruction is inserted to separate each argument
// for the purposes of handling different structs or arrays
compiler.instructions.push(new NoInstruction())
Expand Down
Loading
Loading