| |
| /pliant/appli/interpreter.page |
| |
| 1 |
module "/pliant/language/compiler.pli" | |
| 2 |
module "/pliant/language/stream.pli" | |
| 3 |
module "/pliant/language/context.pli" | |
| 4 |
module "/pliant/admin/file.pli" | |
| 5 |
module "/pliant/language/ui/console.pli" | |
| 6 |
| |
| 7 |
constant execute_available os_api="linux" | |
| 8 |
| |
| 9 |
if execute_available | |
| 10 |
module "/pliant/admin/execute.pli" | |
| 11 |
| |
| 12 |
requires "administrator" | |
| 13 |
| |
| 14 |
| |
| 15 |
title "Pliant interpreter" | |
| 16 |
| |
| 17 |
var Str prog := options option "prog" Str | |
| 18 |
var Int level := options option "level" Int | |
| 19 |
if level=undefined | |
| 20 |
level := 1 | |
| 21 |
var Str mode := options option "mode" Str "admin" | |
| 22 |
| |
| 23 |
text_input "Your source code:[lf]" prog columns 80 rows 20 | |
| 24 |
if execute_available | |
| 25 |
input "Execute at debugging level: " level length 1 noeol | |
| 26 |
select " " mode | |
| 27 |
option "in another process" "another" | |
| 28 |
option "in this process" "this" | |
| 29 |
option "administration task" "admin" | |
| 30 |
button "Execute" noeol | |
| 31 |
goto_url http_request:path options "prog "+string:prog+" level "+string:level+" mode "+string:mode | |
| 32 |
| |
| 33 |
if prog<>"" | |
| 34 |
var Str tempprog := file_temporary | |
| 35 |
(var Stream temp) open tempprog out+safe | |
| 36 |
if mode="admin" | |
| 37 |
temp writeline "module [dq]/pliant/admin/file.pli[dq]" | |
| 38 |
temp writeline "module [dq]/pliant/admin/execute.pli[dq]" | |
| 39 |
if os_api="linux" | |
| 40 |
temp writeline "module [dq]/pliant/linux/schedule/process.pli[dq]" | |
| 41 |
temp writechars prog | |
| 42 |
temp close | |
| 43 |
var Str tempconsole := file_temporary | |
| 44 |
if not execute_available or mode<>"another" | |
| 45 |
var Link:List program :> new List | |
| 46 |
(var Stream temp) open tempprog in+safe | |
| 47 |
while not temp:atend | |
| 48 |
program append addressof:(new Str temp:readline) | |
| 49 |
pliant_compiler_semaphore request | |
| 50 |
console_redirect tempconsole | |
| 51 |
var Link:Module module :> new Module | |
| 52 |
module name := "interpreter" | |
| 53 |
module include the_module:"/pliant/language/basic/safe.pli" | |
| 54 |
error_push_record (var ErrorRecord e) error_filter_all | |
| 55 |
compile_text program module | |
| 56 |
var Str err := shunt e:id<>error_id_noerror e:message "" | |
| 57 |
e id := error_id_noerror | |
| 58 |
error_pull_record e | |
| 59 |
console_restore | |
| 60 |
pliant_compiler_semaphore release | |
| 61 |
if err<>"" | |
| 62 |
table columns 1 border 0 | |
| 63 |
cell color (color hsl 0 50 75) | |
| 64 |
text "Error message:" ; eol | |
| 65 |
cell color (color hsl 0 50 85) | |
| 66 |
fixed | |
| 67 |
text err | |
| 68 |
else | |
| 69 |
execute "/bin/pliant debug "+string:level+" module /pliant/install/minimal.pli module /pliant/language/ui/console.pli command console_redirect:[dq]"+tempconsole+"[dq] "+file_os_name:tempprog | |
| 70 |
para | |
| 71 |
table columns 1 border 0 | |
| 72 |
cell color (color hsl 60 50 75) | |
| 73 |
text "Output:" ; eol | |
| 74 |
cell color (color hsl 60 50 85) | |
| 75 |
(var Stream temp) open tempconsole in+safe | |
| 76 |
fixed | |
| 77 |
while not temp:atend | |
| 78 |
text temp:readline ; eol | |
| 79 |
temp close | |
| 80 |
para | |
| 81 |
table columns 1 border 0 | |
| 82 |
cell color (color hsl 30 50 75) | |
| 83 |
text "Listing:" | |
| 84 |
cell color (color hsl 30 50 85) | |
| 85 |
(var Stream temp) open tempprog in+safe | |
| 86 |
fixed | |
| 87 |
while not temp:atend | |
| 88 |
html "<font size=-3>" | |
| 89 |
text (string temp:line_number+1)+":" | |
| 90 |
html "</font>" | |
| 91 |
text " "+temp:readline ; eol | |
| 92 |
temp close | |
| 93 |
file_delete tempprog | |
| 94 |
file_delete tempconsole | |
| 95 |
| |
| |