Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Compiling Features #133

Merged
merged 1 commit into from
Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/app/live-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/sys-global-observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down
25 changes: 8 additions & 17 deletions src/app/sys-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class SysRuntime {
this.jor1kgui.FocusTerm(tty);
}

startGccCompile(code, gccOptions, guiCallback) {
startBuild(buildCmd, guiCallback) {
if (!this.bootFinished) {
return 0;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/components/compiler-controls/compiler-controls.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<div class="row">
<div class="col-sm-10">
<div class="row">
<label class="col-sm-1 control-label" for="gccoptions"><small class="pull-right">gcc&nbsp;opts</small></label>
<label class="col-sm-1 control-label" for="buildcmd"><small class="pull-right">build&nbsp;cmd</small></label>
<div class="col-sm-11" data-bind="css: {'has-error': gccOptsError()}">
<input class="form-control input-sm" type="text" id="gccoptions" maxlen=256
data-bind="textInput: gccOptions, attr: {'data-content': gccOptsError() ? '<pre>' + gccOptsError() + '</pre>' : ''}"
<input class="form-control input-sm" type="text" id="buildcmd" maxlen=256
data-bind="textInput: buildCmd, attr: {'data-content': gccOptsError() ? '<pre>' + gccOptsError() + '</pre>' : ''}"
tabindex="0" data-toggle="popover" data-container="body" data-html="true" data-placement="auto top" data-trigger="focus">
</div>
</div>
<div class="row">
<label class="col-sm-1 control-label" for="cmdline"><small class="pull-right">args</small></label>
<label class="col-sm-1 control-label" for="execcmd"><small class="pull-right">exec</small></label>
<div class="col-sm-11">
<input class="form-control input-sm" type="text" id="cmdline" maxlen=256 data-bind="textInput: programArgs" placeholder="Program arguments">
<input class="form-control input-sm" type="text" id="execCmd" maxlen=256 data-bind="textInput: execCmd" placeholder="Program arguments">
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/compiler-controls/compiler-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
17 changes: 8 additions & 9 deletions src/components/play-activity-page/play-activity-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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' +
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down