diff --git a/src/app/live-edit.js b/src/app/live-edit.js index 13d78dc4..09c2d84e 100644 --- a/src/app/live-edit.js +++ b/src/app/live-edit.js @@ -64,19 +64,16 @@ class LiveEdit { if (result.exitCode === 0) { SysGlobalObservables.compileStatus(result.stats.warning > 0 ? 'Warnings' : 'Success'); - this.runtime.startProgram('program', SysGlobalObservables.programArgs()); + this.runtime.sendExecCmd(SysGlobalObservables.execCmd()); } else { SysGlobalObservables.compileStatus('Failed'); } } - runCode(code, gccOptions) { - if (code.length === 0 || code.indexOf('\x03') >= 0 || code.indexOf('\x04') >= 0) { - return; - } + runCode(buildCmd) { var callback = this.processGccCompletion.bind(this); SysGlobalObservables.compileStatus('Compiling'); - this.runtime.startGccCompile(code, gccOptions, callback); + this.runtime.startBuild(buildCmd, callback); } } diff --git a/src/app/sys-global-observables.js b/src/app/sys-global-observables.js index a4b154a4..4d07bc22 100644 --- a/src/app/sys-global-observables.js +++ b/src/app/sys-global-observables.js @@ -3,11 +3,11 @@ import ko from 'knockout'; export var vmState = ko.observable(''); export var compileStatus = ko.observable(''); -export var gccOptions = ko.observable(''); -export var programArgs = ko.observable(''); - export var focusTerm = ko.observable((tty) => {}); -export var runCode = ko.observable((code, gccOptions) => {}); +export var runCode = ko.observable((gccOptions) => {}); + +export var buildCmd = ko.observable(''); +export var execCmd = ko.observable(''); export var lastGccOutput = ko.observable(''); export var gccOptsError = ko.observable(''); diff --git a/src/app/sys-runtime.js b/src/app/sys-runtime.js index 0242d8d3..1d33d3f6 100644 --- a/src/app/sys-runtime.js +++ b/src/app/sys-runtime.js @@ -126,7 +126,7 @@ class SysRuntime { this.jor1kgui.FocusTerm(tty); } - startGccCompile(code, gccOptions, guiCallback) { + startBuild(buildCmd, guiCallback) { if (!this.bootFinished) { return 0; } @@ -173,12 +173,7 @@ class SysRuntime { }; - this.sendKeys('tty0', '\x03\ncd ~;rm program.c program 2>/dev/null\n'); - - this.sendTextFile('program.c', code); - - var cmd = 'echo \\#\\#\\#GCC_COMPILE\\#\\#\\#;clear;gcc ' + gccOptions + - ' program.c -o program; echo GCC_EXIT_CODE: $?; echo \\#\\#\\#GCC_COMPILE_FINISHED\\#\\#\\#' + + var cmd = 'echo \\#\\#\\#GCC_COMPILE\\#\\#\\#;clear;pwd;'+ buildCmd +'; echo GCC_EXIT_CODE: $?; echo \\#\\#\\#GCC_COMPILE_FINISHED\\#\\#\\#' + this.compileTicket + '.;clear\n'; this.expecting = this.sendKeys('tty0', cmd, 'GCC_COMPILE_FINISHED###' + this.compileTicket + '.', compileCb); @@ -217,20 +212,16 @@ class SysRuntime { }); } - startProgram(filename, cmdargs) { - if (!filename) { + sendExecCmd(cmd) { + if (!cmd) { return; } - if (filename[0] !== '/' && filename[0] !== '.') { - filename = './' + filename.replace(' ', '\\ '); + if (cmd[0] !== '/' && cmd[0] !== '.') { + cmd = './' + cmd.replace(' ', '\\ '); } - cmdargs = cmdargs.replace('\\', '\\\\').replace('\n', '\\n'); + cmd = cmd.replace('\\', '\\\\').replace('\n', '\\n'); // Don't \x03 ; it interrupts the clear command - this.sendKeys('tty0', '\n' + filename + ' ' + cmdargs + '\n'); - } - - sendTextFile(filename, contents) { - this.sendKeys('tty0', '\nstty raw\ndd ibs=1 of=' + filename + ' count=' + contents.length + '\n' + contents + '\nstty -raw\n'); + this.sendKeys('tty0', '\n' + cmd + '\n'); } // Used to broadcast 'putchar' and 'ready' events diff --git a/src/components/compiler-controls/compiler-controls.html b/src/components/compiler-controls/compiler-controls.html index 9dd0481e..b5413a3a 100644 --- a/src/components/compiler-controls/compiler-controls.html +++ b/src/components/compiler-controls/compiler-controls.html @@ -2,17 +2,17 @@
- +
-
- +
- +
diff --git a/src/components/compiler-controls/compiler-controls.js b/src/components/compiler-controls/compiler-controls.js index ae76ceff..fe95aad4 100644 --- a/src/components/compiler-controls/compiler-controls.js +++ b/src/components/compiler-controls/compiler-controls.js @@ -5,8 +5,8 @@ import { notify } from 'app/notifications'; class CompilerControls { constructor(params) { this.gccOptsError = params.gccOptsError; - this.gccOptions = params.gccOptions; - this.programArgs = params.programArgs; + this.buildCmd = params.buildCmd; + this.execCmd = params.execCmd; this.compileStatus = params.compileStatus; this.compileBtnTooltip = params.compileBtnTooltip; diff --git a/src/components/play-activity-page/play-activity-page.js b/src/components/play-activity-page/play-activity-page.js index ae4b40dc..44a1bcab 100644 --- a/src/components/play-activity-page/play-activity-page.js +++ b/src/components/play-activity-page/play-activity-page.js @@ -19,8 +19,8 @@ class PlayActivityPage { setParamsFromActivity(playActivity) { this.editorParams.initialEditorText = playActivity.code; - this.compilerParams.gccOptions(playActivity.gccOptions || ''); - this.compilerParams.programArgs(playActivity.programCommandLineArgs || ''); + this.compilerParams.buildCmd(playActivity.buildCmd || ''); + this.compilerParams.execCmd(playActivity.execCmd || ''); if (playActivity.docFile) { this.doc = { @@ -45,8 +45,8 @@ class PlayActivityPage { '}\n' + ''; - this.compilerParams.gccOptions('-lm -Wall -fmax-errors=10 -Wextra'); - this.compilerParams.programArgs(''); + this.compilerParams.buildCmd('gcc -lm -Wall -fmax-errors=10 -Wextra program.c -o program'); + this.compilerParams.execCmd('./program'); this.doc = { text: '# Welcome\n' + @@ -90,8 +90,8 @@ class PlayActivityPage { setCompilerParams() { this.compilerParams = { - gccOptions: SysGlobalObservables.gccOptions, - programArgs: SysGlobalObservables.programArgs, + buildCmd: SysGlobalObservables.buildCmd, + execCmd: SysGlobalObservables.execCmd, compileStatus: SysGlobalObservables.compileStatus, lastGccOutput: SysGlobalObservables.lastGccOutput, gccOptsError: SysGlobalObservables.gccOptsError, @@ -114,9 +114,8 @@ class PlayActivityPage { this.editorParams.editorTextGetter = ko.observable(() => ''); var compile = () => { - var code = (this.editorParams.editorTextGetter())(); - var gccOptions = this.compilerParams.gccOptions(); - (SysGlobalObservables.runCode())(code, gccOptions); + var buildCmd = this.compilerParams.buildCmd(); + (SysGlobalObservables.runCode())(buildCmd); }; this.compilerParams.compileCallback = compile;