-
Notifications
You must be signed in to change notification settings - Fork 0
Running your programs
To run your programs, we must first build the output of our program and send it to output.py (output.txt for languages other than Python). After that, we can run output.py.
from pythonOne import *
program = Program("py")
program.set_current_program()
with start():
printit(str_("Hello World!"))
program.build()
This program doesn't print Hello World!. Instead, it creates another program that prints Hello World!. We must first run this program to create output.py:
% python example.py
To see the program print "Hello World!" we must run output.py:
% python output.py
Hello World!
pythonOne is compiling-style, rather interpreter-style. In other words, pythonOne runs programs not by running each statement, but instead converting each statement to a statement of a specific language and adding the converted state to the output, which you can run if it's Python. For example, printit(str_("Hello World!")) is print("Hello World!") in Python, but it's also Console.Writeline("Hello World!") in C#. Let's take a look at the output the example programs generates:
# This is the output, not the program. Remember, this is the output, not the program.
import pickle
import time
import threading
### Main
print("Hello World!")
All the imports are created when we created the program using program = Program("py"). The ### Main is generated when we call start(). print("Hello World!") is added when we use printit(str_("Hello World!")) If we wanted have program generate C# code, we would replace program = Program("py") with program = Program("cs").
When we run the program with this modification, we get some different output code (that looks like the language aliens program in to those who aren't familiar with Object-Oriented languages) in output.txt:
public static void Main() {
Console.WriteLine("Hello World!");
}
The public static void Main() { is generated when we call start(). Console.WriteLine("Hello World!"); is added when we use printit(str_("Hello World!")). } is generated when we exit the start() context manager.