Skip to content

Commit

Permalink
Merge pull request mozart#135 from yjaradin/fixBufferSwitching
Browse files Browse the repository at this point in the history
Added support for switching OPI buffer to emulator
  • Loading branch information
sjrd committed Feb 9, 2014
2 parents 2f2d000 + d737f2d commit f4322eb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
4 changes: 3 additions & 1 deletion opi/opi/Emacs.oz
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ export
getOPI: GetOPI
condSend: CondSend
interface: CompilerInterfaceEmacs
attentionPrefix: MSG_ERROR
define
TimeoutToConfigBar = 200
TimeoutToUpdateBar = TimeoutToConfigBar

MSG_ERROR = [17]

local
MSG_ERROR = [17]

class TextSocket from Open.socket Open.text
prop final
Expand Down
3 changes: 2 additions & 1 deletion opi/opi/OPI.oz
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import
OS(getEnv)
Open(file)
Compiler(engine)
Emacs(interface)
Emacs(interface attentionPrefix)
OPIEnv(full)
export
compiler: OPICompiler
Expand All @@ -54,6 +54,7 @@ define
end

{Property.put 'oz.standalone' false}
{Property.put 'errors.prefix' Emacs.attentionPrefix}

OPICompiler = {New Compiler.engine init()}
{OPICompiler enqueue(mergeEnv(OPIEnv.full))}
Expand Down
9 changes: 9 additions & 0 deletions vm/vm/main/modules/modsystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ public:
ozVSGet(vm, value, valueBufSize, valueStr);

auto& stream = boolToStdErr ? std::cerr : std::cout;

if (boolToStdErr) {
StableNode* prefix = vm->getPropertyRegistry().config.errorPrefix;
size_t prefixBufSize = ozVSLengthForBuffer(vm, *prefix);
std::string prefixStr;
ozVSGet(vm, *prefix, prefixBufSize, prefixStr);
stream << prefixStr;
}

stream << valueStr;
if (boolNewLine)
stream << std::endl;
Expand Down
1 change: 1 addition & 0 deletions vm/vm/main/properties-decl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public:

// Errors
StableNode* defaultExceptionHandler;
StableNode* errorPrefix;
bool errorsDebug;
nativeint errorsDepth;
nativeint errorsWidth;
Expand Down
13 changes: 11 additions & 2 deletions vm/vm/main/properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void PropertyRegistry::initConfig(VM vm) {

// Errors

config.defaultExceptionHandler = new (vm) StableNode;
config.defaultExceptionHandler->init(vm, buildNil(vm));
config.defaultExceptionHandler = new (vm) StableNode(vm, buildNil(vm));
config.errorPrefix = new (vm) StableNode(vm, buildNil(vm));

config.errorsDebug = true;
config.errorsDepth = 10;
Expand Down Expand Up @@ -93,6 +93,15 @@ void PropertyRegistry::registerPredefined(VM vm) {
}
);

registerProp(vm, "errors.prefix",
[this] (VM vm) -> UnstableNode {
return { vm, *config.errorPrefix };
},
[this] (VM vm, RichNode value) {
config.errorPrefix = value.getStableRef(vm);
}
);

registerReadWriteProp(vm, "errors.debug", config.errorsDebug);
registerReadWriteProp(vm, "errors.depth", config.errorsDepth);
registerReadWriteProp(vm, "errors.width", config.errorsWidth);
Expand Down
2 changes: 2 additions & 0 deletions vm/vm/main/properties.hh
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ void PropertyRegistry::gCollect(GC gc) {

gc->copyStableRef(config.defaultExceptionHandler,
config.defaultExceptionHandler);
gc->copyStableRef(config.errorPrefix,
config.errorPrefix);
}

}
Expand Down

0 comments on commit f4322eb

Please sign in to comment.