File size: 2,028 Bytes
753d525
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import streamlit as st  # type: ignore[import]
import sys
import io

# Import your core compiler pipeline logic safely
from main import compile_code

# Page styling
st.set_page_config(page_title="Custom Mini-Compiler IDE", page_icon="πŸ’»", layout="wide")

st.title("πŸ’» Custom Mini-Compiler & CPU Architecture Simulator")
st.markdown("""

This IDE tokenizes, parses, structurally analyzes, optimizes, and executes a custom programming language down to simulated hardware registers.

---

""")

# Layout split: Left side for code input, Right side for pipeline visualization
col1, col2 = st.columns([1, 1])

with col1:
    st.subheader("πŸ“ Source Code Editor")
    # Default presentation script
    default_code = """{\n  int a = 10;\n  int b = 20;\n  float w = 3.3 + 3.2;\n  int c = a + b;\n  print(c);\n}"""
    user_code = st.text_area("Enter your custom source code here:", value=default_code, height=350)
    
    compile_btn = st.button("πŸš€ Compile and Run Code", type="primary", use_container_width=True)

with col2:
    st.subheader("βš™οΈ Compiler Pipeline Terminal Output")
    
    if compile_btn:
        # Capture stdout console print statements directly from your main.py
        old_stdout = sys.stdout
        new_stdout = io.StringIO()
        sys.stdout = new_stdout
        
        try:
            # Run your exact core compiler execution path
            compile_code(user_code)
            output = new_stdout.getvalue()
        except Exception as e:
            output = f"Runtime Crash Error: {str(e)}"
        finally:
            sys.stdout = old_stdout
            
        # Display the terminal logs cleanly in a code block
        if output.strip():
            st.code(output, language="text")
        else:
            st.info("Compilation completed silently. (No print functions were called inside the parsed AST block).")
    else:
        st.info("Click 'Compile and Run Code' to pass the source string through the execution toolchain.")