Skip to content

Commit

Permalink
experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
atdt committed Jan 31, 2016
1 parent e184093 commit f01bf33
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
29 changes: 17 additions & 12 deletions js/SNOBOL/mem.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ SNOBOL.isInt32 = function isInteger( v ) {
return i32[0] === v;
};

SNOBOL.SymbolTable = function () {};
SNOBOL.SymbolTable.prototype = {};

function nearlyEqual( a, b ) {
return a === b || Math.abs( a - b ) < 0.001;
}
Expand Down Expand Up @@ -61,27 +58,35 @@ VM.prototype.alloc = function ( size ) {
return ptr;
};

SNOBOL.VM.prototype.define = function ( symbol, value ) {
this.symbols[ symbol ] = this.mem.length;
this.mem.push( value );
}

VM.prototype.$ = VM.prototype.resolve = function ( key ) {
if ( this.symbols[ key ] === undefined ) {
var ptr = this.symbols[ key ], val = this.mem[ ptr ];

if ( ptr === undefined || val === undefined ) {
throw new ReferenceError( key );
}
return this.symbols[ key ];

return val;
};


VM.prototype.reset = function () {
this.instructionPointer = null;
this.symbols = new SNOBOL.SymbolTable();
this.symbols = {};
this.mem = [];
this.callbacks = [];
this.units = {};
this.indent = 0;

// this.alloc( this.STSIZE * 3 );
this.alloc( 9000 );
this.CSTACK = this.d( 'CSTACK' );
this.OSTACK = this.d( 'OSTACK' );
this.STACK = this.$( 'STACK' );
this.symbols.CSTACK = this.d().ptr;
this.symbols.OSTACK = this.d().ptr;
this.symbols.STACK = this.alloc( 1000 );

this.CSTACK = this.d( this.symbols.CSTACK );
this.OSTACK = this.d( this.symbols.OSTACK );

SNOBOL.sil.ISTACK.call( this );
};
10 changes: 5 additions & 5 deletions js/SNOBOL/sil.js
Original file line number Diff line number Diff line change
Expand Up @@ -1480,16 +1480,15 @@ sil.INCRV = function ( $DESCR, N ) {
// 1. See also ENDEX.
sil.INIT = function () {
// initialize SNOBOL4 run
var dynamicStorageSize = D * 16384,
dynamicStoragePtr = this.alloc( dynamicStorageSize ),
var dynamicStorageSize = D * 1000,

FRSGPT = this.d( 'FRSGPT' ),
HDSGPT = this.d( 'HDSGPT' ),
TLSGP1 = this.d( 'TLSGP1' );

this.timeStart = new Date().getTime();
FRSGPT.addr = dynamicStoragePtr;
HDSGPT.addr = dynamicStoragePtr;
FRSGPT.addr = this.alloc( dynamicStorageSize );
HDSGPT.addr = FRSGPT.addr;
TLSGP1.addr = this.alloc( dynamicStorageSize );
};

Expand Down Expand Up @@ -3973,14 +3972,15 @@ sil.STREAM = function ( $SPEC1, $SPEC2, TABLE, ERROR, RUNOUT, SLOC ) {
L = SPEC2.length;


/*
var tableName;
for ( var k in SNOBOL.SymbolTable.prototype ) {
if ( SNOBOL.SymbolTable.prototype[k] === TABLE ) {
tableName = k;
}
}

console.log( 'STREAM: %s using %s', JSON.stringify( str ), tableName );
*/

for ( I = 1; I <= str.length; I++ ) {
J = I;
Expand Down
13 changes: 6 additions & 7 deletions js/SNOBOL/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ for ( var i = 1; i <= CHAR_MAX; i++ ) {
ALPHA += String.fromCharCode(i);
}

SNOBOL.SymbolTable = function () {};
SNOBOL.SymbolTable.prototype = {
SNOBOL.programSymbols = {
// MDATA
ALPHA : ALPHA,
AMPST : '&',
Expand Down Expand Up @@ -41,10 +40,10 @@ SNOBOL.SymbolTable.prototype = {
PARMS : -1,

// Misc
OSTACK : 2000 * D,
CSTACK : 2001 * D,
STACK : 2002 * D,
OBSIZ : 256, // Needed for bootstrapping tests, but actually defined in SIL
// OSTACK : 2000 * D,
// CSTACK : 2001 * D,
// STACK : 2002 * D,
// OBSIZ : 256, // Needed for bootstrapping tests, but actually defined in SIL
// STSIZE : 1000, // ditto
};

Expand Down Expand Up @@ -294,5 +293,5 @@ SNOBOL.syntaxTables = {
};

Object.keys( SNOBOL.syntaxTables ).forEach( function ( tableName ) {
SNOBOL.SymbolTable.prototype[ tableName ] = SNOBOL.syntaxTables[ tableName ];
SNOBOL.programSymbols[ tableName ] = SNOBOL.syntaxTables[ tableName ];
} );
31 changes: 16 additions & 15 deletions js/SNOBOL/vm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

var SNOBOL = require( './base' );
var SNOBOL = require( './base' ),
assert = require( 'assert' );

var DATA_ASSEMBLY_MACROS = [
'ARRAY', 'BUFFER', 'DESCR',
Expand Down Expand Up @@ -63,10 +64,12 @@ SNOBOL.VM.prototype.exec = function ( label, macro, argsCallback ) {
}

if ( label !== null ) {
assert( this.symbols[ label ] !== undefined );
if ( returnValue === undefined ) {
returnValue = currentInstruction;
}
this.symbols[ label ] = returnValue;
var ptr = this.symbols[ label ];
this.mem[ ptr ] = returnValue;
}
};

Expand All @@ -83,10 +86,17 @@ SNOBOL.VM.prototype.jmp = function ( loc ) {
SNOBOL.VM.prototype.run = function ( program ) {
var args, status, loc, stmt, label;

for ( var i = 0; i < program.length; i++ ) {
label = program[ i ][ 0 ];
if ( label !== null ) {
this.symbols[ label ] = i;
var sym;
var i;

for ( sym in SNOBOL.programSymbols ) {
this.define( sym, SNOBOL.programSymbols[sym] );
}

for ( i = 0; i < program.length; i++ ) {
sym = program[ i ][ 0 ];
if ( sym !== null ) {
this.define( sym, i );
}
}

Expand All @@ -104,9 +114,6 @@ SNOBOL.VM.prototype.run = function ( program ) {
this.instructionPointer = 0;

while ( this.instructionPointer >= 0 && this.instructionPointer < program.length ) {
if ( this.instructionPointer === 3608 ) {
throw new Error();
}
loc = this.instructionPointer;
args = program[ loc ];
status = this.exec.apply( this, args );
Expand All @@ -122,18 +129,12 @@ SNOBOL.VM.prototype.run = function ( program ) {
};

SNOBOL.VM.prototype.d = function ( ptr ) {
if ( typeof ptr === 'number' && ptr < 6000 ) {
ptr = this.mem[ ptr ];
}
return ptr instanceof SNOBOL.Descriptor
? ptr
: new SNOBOL.Descriptor( this, ptr );
};

SNOBOL.VM.prototype.s = function ( ptr ) {
if ( typeof ptr === 'number' && ptr < 6000 ) {
ptr = this.mem[ ptr ];
}
return ptr instanceof SNOBOL.Specifier
? ptr
: new SNOBOL.Specifier( this, ptr );
Expand Down

0 comments on commit f01bf33

Please sign in to comment.