-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ksx: Partially implement recursive descent compilation
This commit implements the relatively easier part of the recursive descent compiler which is to just continually compile the given lines until there are no more ksx statements. This does choke however when two files create a circular reference. I have added a recursion limit of 6 (which may actually be too low) to catch this possible condition. Python actually chokes at some point too, but it takes a while and I'd rather catch it sooner (also prefer giving a more friendly error message). I attempted to use a hash of the file contents to track whether we have already compiled that file, but that is not working because the thing being hashed is accumulating each compilation step, so it changes. Anyways, recursion is hard, and this still needs some work, but it's usable enough as long as you don't have any circular references. Related to issue #7
- Loading branch information
Showing
8 changed files
with
199 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// this file imports another file | ||
function test_language_features { | ||
parameter vessel is ship. | ||
|
||
// get shortcut variables to vessel velocity and altitude | ||
set v to vessel:velocity:surface:mag. | ||
set h to vessel:altitude. | ||
|
||
// always be moving | ||
if v < 0.1 { | ||
stage. | ||
} | ||
|
||
// if vessel has reached target altitude, reboot and allow bootloader to | ||
// decide next action | ||
if h > 80000 { | ||
reboot. | ||
} | ||
|
||
set steering to heading(90, get_pitch_for_state()). | ||
set throttle to get_throttle_for_twr(1.9). | ||
} | ||
|
||
// yes this is stupid, no I do not care | ||
function make_assertion { | ||
parameter testParam. | ||
|
||
return testParam = True. | ||
} | ||
|
||
function make_neg_assertion { | ||
parameter testParam. | ||
|
||
return testParam <> True. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
print test_function(). | ||
|
||
function test_function { | ||
// need to make this do something... | ||
} | ||
|
||
function dont_really_care_function { | ||
// this function intentionally blank | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// this file imports another file | ||
@ksx import ("import_pure_kerboscript"). | ||
|
||
function make_neg_assertion { | ||
parameter testParam. | ||
|
||
return testParam <> True. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@ksx import ("pure_kerboscript"). | ||
|
||
// yes this is stupid, no I do not care | ||
function make_assertion { | ||
parameter testParam. | ||
|
||
return testParam = True. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@ksx import ("reference_loop_2"). | ||
|
||
function test_function { | ||
// need to make this do something... | ||
} | ||
|
||
function dont_really_care_function { | ||
// this function intentionally blank | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@ksx import ("reference_loop_1"). | ||
|
||
print test_function(). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters