Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't do recursive call: move function names to a goto_stack *dictionary*? #46

Closed
hchiam opened this issue May 10, 2017 · 9 comments
Closed

Comments

@hchiam
Copy link
Owner

hchiam commented May 10, 2017

Test with https://github.com/hchiam/please/blob/06f686e6dc1793e5bea88c024c7a63b3f46d02e5/text.txt

And then test that nothing else broke with https://github.com/hchiam/please/blob/master/library/expected_output.md

Variables to fix:
goto_stack: append(), pop(), [-1]
goto_locations in check_for() for current_loop

@hchiam
Copy link
Owner Author

hchiam commented May 15, 2017

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

@hchiam
Copy link
Owner Author

hchiam commented May 16, 2017

"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.

@hchiam
Copy link
Owner Author

hchiam commented May 16, 2017

Maybe move functions from variable_dictionary to goto_stack?

@hchiam
Copy link
Owner Author

hchiam commented May 16, 2017

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

@hchiam
Copy link
Owner Author

hchiam commented May 16, 2017

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?

@hchiam hchiam closed this as completed in 0c98e2c May 17, 2017
@hchiam
Copy link
Owner Author

hchiam commented May 17, 2017

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

@hchiam hchiam reopened this May 17, 2017
@hchiam
Copy link
Owner Author

hchiam commented May 17, 2017

should output:

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

@hchiam hchiam closed this as completed in 3fc4c76 May 17, 2017
@hchiam
Copy link
Owner Author

hchiam commented May 17, 2017

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).

@hchiam
Copy link
Owner Author

hchiam commented May 19, 2017

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

@hchiam hchiam closed this as completed May 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant