#troubles with making my own programming language

1 messages · Page 1 of 1 (latest)

primal heath
#

forwarded from #programming-discussion

#

@primal merlin , @manic bobcat

#

for anyone else here

#

i need help debugging that

#

the compiler produces these list of instructions from the code above:

#
vm.Instruction{ .type = vm.Instruction.Type.LABEL, .values = { fib } }
vm.Instruction{ .type = vm.Instruction.Type.STORE, .values = { 0 } }
vm.Instruction{ .type = vm.Instruction.Type.LOAD, .values = { 0 } }
vm.Instruction{ .type = vm.Instruction.Type.PUSH, .values = { 2 } }
vm.Instruction{ .type = vm.Instruction.Type.LESS, .values = {  } }
vm.Instruction{ .type = vm.Instruction.Type.NOT, .values = {  } }
vm.Instruction{ .type = vm.Instruction.Type.IFJMP, .values = { 9 } }
vm.Instruction{ .type = vm.Instruction.Type.LOAD, .values = { 0 } }
vm.Instruction{ .type = vm.Instruction.Type.RET, .values = {  } }
vm.Instruction{ .type = vm.Instruction.Type.LOAD, .values = { 0 } }
vm.Instruction{ .type = vm.Instruction.Type.PUSH, .values = { 1 } }
vm.Instruction{ .type = vm.Instruction.Type.SUB, .values = {  } }
vm.Instruction{ .type = vm.Instruction.Type.CALL, .values = { fib } }
vm.Instruction{ .type = vm.Instruction.Type.LOAD, .values = { 0 } }
vm.Instruction{ .type = vm.Instruction.Type.PUSH, .values = { 2 } }
vm.Instruction{ .type = vm.Instruction.Type.SUB, .values = {  } }
vm.Instruction{ .type = vm.Instruction.Type.CALL, .values = { fib } }
vm.Instruction{ .type = vm.Instruction.Type.ADD, .values = {  } }
vm.Instruction{ .type = vm.Instruction.Type.RET, .values = {  } }
vm.Instruction{ .type = vm.Instruction.Type.END_LABEL, .values = {  } }
vm.Instruction{ .type = vm.Instruction.Type.PUSH, .values = { 2 } }
vm.Instruction{ .type = vm.Instruction.Type.CALL, .values = { fib } }
vm.Instruction{ .type = vm.Instruction.Type.LOG, .values = {  } }
vm.Instruction{ .type = vm.Instruction.Type.EXIT, .values = {  } }```
primal merlin
#

try adding

more debug logs as it's being run

#

somewhere a value isn't done incorrectly

i suspect around returning and passing that as a value to the add

#

it's hard to tell

primal heath
#

hmm

#

I do not like the store instruction

#

fib(3)

manic bobcat
#

This might be a problem with local scopes

#

You might treat all n as the same thing

#

And they are not

primal heath
#

yea...

manic bobcat
#

That's why I liked implementing knight-lang

#

It has no concept of local scope

#

Every variable is global

#

And functions don't take args (but they don't actually exist tho)

primal merlin
#

the reason mine has been taking a while to get going is the bytecode requires you assign each variable name an id and finding out if it's global or local ahead of time

primal heath
#

i dont like the store here

manic bobcat
#

Popping would delete the argument

primal heath
#

yeah sorry

#

i meant..

#

like

#

dont store maybe?

manic bobcat
#

Probably

#

But keeping it on the stack also doesn't sound too easy

#

Since you'd need to understand when to swap or do stuff like under or rot

#

Coming from forth terms

primal heath
#

call should do the store

manic bobcat
#

What's the store argument?

primal heath
#

WAIT

#

I DID IT

#

THE SCOPE COPYING DID NOT COPY VARIABLES

#

OMG

primal merlin
#

yippee

primal heath
#

HOLY

#

but I have so much memory leaks

#

lol

#

i had to use c_allocator instead of gpa

#

so my stdout didn't get bombarded

primal merlin
#

did u consider freeing the memory when it was done being used

#

(i'm joking)