Giter VIP home page Giter VIP logo

Comments (9)

hchiam avatar hchiam commented on June 20, 2024

try using timer to see line number steps/goto's

from please.

hchiam avatar hchiam commented on June 20, 2024

"end function" not working:

After checking goto_stack's functions' local_variables and index_called_froms, it seems that actually end function (for user-defined functions) needs to act more like return function --> otherwise once the interpreter gets to the end of the function, it keeps reading, instead of going to where it might have been called from.

from please.

hchiam avatar hchiam commented on June 20, 2024

Maybe move functions from variable_dictionary to goto_stack?

from please.

hchiam avatar hchiam commented on June 20, 2024

check_function(): i = function.index_called_from = None <-- goto_stack = [...] but goto_stack[-1][1].index_called_from = None

from please.

hchiam avatar hchiam commented on June 20, 2024

Issue found: Tracked index_called_from for each item in goto_stack: for some reason all recursive instances have the same index_called_from (they should have different index_called_from's; i.e. the first call should have been made outside the function).

Possible fix(es):

  • Make deep copy? (understand pass by ref/val/other)
  • A separate stack/list of indices?

from please.

hchiam avatar hchiam commented on June 20, 2024

Problem 1: When trying to assign a function output to a variable, it seems the variable is created in the global variable_dictionary instead of the local function local_variables, and
Problem 2: the value does not seem to be passed along.

  • Correct debug output at line 3: output_variable = answer, output_value = 1; i.e. answer = 1.
  • Example incorrect debug output at line 7: answer = None.
  • Example incorrect debug output at line 8: output_value = None.
  • Example incorrect print output at line 15: step 3: output = None.

Test 0c98e2c with:

please define function fibonacci with number
    please if variable number equals zero then return zero
    please if variable number equals one then return one
    please assign variable number minus one to subresult
    please assign use function fibonacci on variable subresult to variable answer
        please note assign use function fibonacci on variable number minus one to variable answer
    please print answer = variable answer
    please return variable answer
please end function
please assign use function fibonacci with zero to variable output
please print step 1: output = variable output
please assign use function fibonacci with one to variable output
please print step 2: output = variable output
please assign use function fibonacci with two to variable output
please print step 3: output = variable output

from please.

hchiam avatar hchiam commented on June 20, 2024

should output:

step 1: output = zero
step 2: output = 1
answer = 1
step 3: output = 1

from please.

hchiam avatar hchiam commented on June 20, 2024

not quite closed: test with:

please define function fibonacci with number
    please if variable number equals zero then return zero
    please if variable number equals one then return one
    please assign variable number minus one to subresult
    please assign use function fibonacci on variable subresult to variable answer
        please note assign use function fibonacci on variable number minus one to variable answer
    please print answer = variable answer
    please return variable answer
please end function
please assign use function fibonacci with zero to variable output
please print step 1: output = variable output
please assign use function fibonacci with one to variable output
please print step 2: output = variable output
please assign use function fibonacci with two to variable output
please print step 3: output = variable output
please assign use function fibonacci with three to variable output
please print step 4: output = variable output

this incorrectly outputs:

step 1: output = zero
step 2: output = 1
answer = 1
step 3: output = 1
answer = 1
answer = 1
step 4: output = 1

when it should output:

step 1: output = zero
step 2: output = 1
step 3: output = 1
step 4: output = 2

[EDIT:]
Actually, with the code above as-is, it's not actually fibonacci --> the output IS CORRECT.

What does not work is using two recursive calls within the function (even if assigning to separate variables first).

from please.

hchiam avatar hchiam commented on June 20, 2024

v0.1.0 Interpreter --> v0.2.0 Transformer (translates to Python code)

from please.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.