Skip to content

Commit

Permalink
Wrapper scripts, README
Browse files Browse the repository at this point in the history
  • Loading branch information
icegoat9 committed Jan 10, 2025
1 parent a9a6546 commit 84f57c0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ programs/pow.exe // computes and prints 3 ^ (2 + 2) = 81
./run.sh programs/pow.wb // combines both of the above steps
```

And a work-in-progress prototype that partially compiles a program, then transpiles it to Python, as a quick way of sanity-checking program logic for more complex programs.
And a work-in-progress prototype that partially compiles a program, then transpiles it to a minimal subset of Python, as a quick way of sanity-checking program logic for more complex programs.
```
gen_python.sh programs/pow.wb
./gen_python.sh programs/pow.wb
```


Expand Down
2 changes: 1 addition & 1 deletion compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ $# -eq 0 ]; then
echo ""
echo "Usage: $0 <filename.wb> (you may also omit the .wb extension)"
echo "For example:"
echo " ./compile.sh programs/test_programs/program1.wb"
echo " $0 programs/test_programs/program1.wb"
echo " programs/test_programs/program1.exe"
echo ""
exit 1
Expand Down
31 changes: 31 additions & 0 deletions gen_python.sh
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

17 changes: 17 additions & 0 deletions programs/pow_gen.py
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()
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ $# -eq 0 ]; then
echo ""
echo "Usage: $0 <filename.wb> (you may also omit the .wb extension)"
echo "For example:"
echo " ./run.sh programs/test_programs/program1.wb"
echo " $0 programs/test_programs/program1.wb"
echo ""
exit 1
fi
Expand Down

0 comments on commit 84f57c0

Please sign in to comment.