-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
52 additions
and
4 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
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,31 @@ | ||
#!/bin/sh | ||
|
||
# compile .wb code -> intermediate representation -> transpile to simple Python | ||
# outputs to the terminal not a file | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "" | ||
echo "Usage: $0 <filename.wb> (you may also omit the .wb extension)" | ||
echo "For example:" | ||
echo " $0 programs/pow.wb > programs/pow.py" | ||
echo " python3 programs/pow.py" | ||
echo "" | ||
exit 1 | ||
fi | ||
|
||
FILEPATH="$1" | ||
# remove extension if present (will assume .wb) | ||
FILEPATH=${FILEPATH%.*} | ||
FILE=$(BASENAME $FILEPATH) | ||
|
||
BLUE="\033[1;34m" | ||
RESETCOLOR="\033[0m" | ||
|
||
# echo simplified version of commands run, without all the relative path prefixes | ||
echo "${BLUE}python3 compile_to_python.py $FILE.wb$RESETCOLOR" | ||
python3 compiler/compile_to_python.py $FILEPATH.wb | ||
|
||
# Versions that write to file directly (not used) | ||
#echo "${BLUE}python3 compile_to_python.py $FILE.wb > ${FILE}_gen.py$RESETCOLOR" | ||
#python3 compiler/compile_to_python.py $FILEPATH.wb > ${FILEPATH}_gen.py | ||
|
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,17 @@ | ||
# original source: programs/pow.wb | ||
# created by gen_python.py (work in progress) | ||
def pow(x, n): | ||
out = 1 | ||
i = 0 | ||
while (i < n): | ||
out = (out * x) | ||
i = (i + 1) | ||
return out | ||
|
||
def main(): | ||
x = pow(3, 4) | ||
print(x) | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
main() |
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