OILS / demo / old / ovm2 / run.sh View on Github | oilshell.org

119 lines, 76 significant
1#!/usr/bin/env bash
2#
3# Demo of new OVM.
4#
5# Usage:
6# ./run.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12source build/common.sh # for $CLANGXX, etc
13
14readonly FIB_I='opy/gold/fib_iterative.py'
15readonly FIB_R='opy/gold/fib_recursive.py'
16
17fib-dis() {
18 local py=${1:-opy/gold/fib_iterative.py}
19 bin/opyc dis $py
20}
21
22# TODO: Show graph output
23fib-cfg() {
24 bin/opyc cfg $FIB_I
25}
26
27gen-opcodes() {
28 local out=_tmp/opcode.h
29 PYTHONPATH=opy opy/lib/opcode_gen.py > $out
30 echo "Wrote $out"
31}
32
33# Helper function.
34run-ovm() {
35 local bin=_tmp/ovm2
36
37 #local SANITIZER_FLAGS='-fsanitize=address -g'
38 local SANITIZER_FLAGS='-fsanitize=undefined -g'
39
40 $CLANGXX -std=c++11 -Wall -I _tmp $SANITIZER_FLAGS -o $bin ovm2/main.cc
41 set -x
42 $bin "$@"
43}
44
45# TODO: Make this a test. This tickled a memory error.
46bad-oheap() {
47 run-ovm opy/gold/hello_py3.py
48}
49
50# Python VM.
51fib-byterun() {
52 local bytecode=_tmp/fib_iterative.pyc
53 bin/opyc compile $FIB_I $bytecode
54 BYTERUN_SUMMARY=1 bin/opyc run $bytecode
55}
56
57# A stripped down Python version.
58fib-ovm-prototype() {
59 VM_SUMMARY=1 bin/opyc run-ovm $FIB_I
60}
61
62compile-iterative() {
63 local out=_tmp/fib_iterative.ovm2
64 bin/opyc compile-ovm $FIB_I $out
65 ls -l $out
66}
67
68compile-recursive() {
69 local out=_tmp/fib_recursive.ovm2
70 bin/opyc compile $FIB_R _tmp/fib_recursive.pyc
71
72 bin/opyc compile-ovm $FIB_R $out
73 ls -l $out
74}
75
76# Run ovm2/main.cc
77ovm2-main() {
78 local py=${1:-$FIB_I}
79 local bytecode=_tmp/$(basename $py '.py').ovm2
80 bin/opyc compile-ovm $py $bytecode
81 run-ovm $bytecode
82}
83
84# This works
85hello-py3() {
86 ovm2-main opy/gold/hello_py3.py
87}
88
89# This tickled a couple bugs
90continue_() {
91 ovm2-main opy/gold/continue_.py
92}
93
94# This works
95fib-iterative() {
96 ovm2-main $FIB_I
97}
98
99compare-compiler() {
100 local py=$FIB_I
101 bin/opyc compile $py _tmp/c2.pyc
102 bin/opyc compile-ovm $py _tmp/ovm.pyc
103 ls -l _tmp/{c2,ovm}.pyc
104
105 # NOTE: The OVM versions fail because it's not valid bytecode.
106 bin/opyc dis-md5 _tmp/c2.pyc
107 bin/opyc dis-md5 _tmp/ovm.pyc
108
109 bin/opyc dis _tmp/c2.pyc > _tmp/c2.txt
110 bin/opyc dis _tmp/ovm.pyc > _tmp/ovm.txt
111 diff -u _tmp/{c2,ovm}.txt
112}
113
114# NOTE: Iterative one isn't hooked up.
115fib-recursive-callgraph() {
116 PYTHONPATH=. CALLGRAPH=1 opy/gold/fib_recursive.py
117}
118
119"$@"