Commit 5e52e8a7 authored by mb0's avatar mb0
Browse files

Up.

parent d88b99f7
......@@ -16,7 +16,8 @@ structure JS0Factory = struct
structure JS = Javascript
open JS
structure JSStmt = struct
fun const (x,e) = Joint.Const (Vector.fromList [(x,e)])
fun var (x,e) = Joint.Var (Vector.fromList [(x,SOME e)])
fun const (x,e) = var (x,e)(* Joint.Const (Vector.fromList [(x,e)]) *)
fun function (f,xs,body) = Joint.FunctionDec {args=Vector.fromList xs, name=f,body=Vector.fromList body}
fun seq xs = Joint.Block (Vector.fromList xs)
fun call (f,xs) = Joint.Exp (Joint.Call {args=Vector.fromList(map Joint.Id xs),func=Joint.Id f})
......
const __TRUE = {sz:1, vec:1}
const __FALSE = {sz:1, vec:0}
const __UNIT = {}
var __TRUE = {sz:1, vec:1}
var __FALSE = {sz:1, vec:0}
var __UNIT = {}
function __halt (o) { return o; }
function __raise (o) { throw o; }
function __consume (s) {
const blob = s.___blob;
const i = s.___idx;
const v = blob[i];
const ss = s; // FIXME: destructive update!
var blob = s.___blob;
var i = s.___idx;
var v = blob[i];
var ss = s; // FIXME: destructive update!
ss.___idx = i+1;
return {___1:{vec:v,sz:8}, ___2:ss}
}
function __unconsume (s) {
const ss = s; // FIXME: destructive update!
var ss = s; // FIXME: destructive update!
ss.___idx = s.___idx-1;
return {___1:__UNIT, ___2:ss};
}
function __slice (tok, offs, sz) {
const tokk = tok.vec;
const x = ((tokk>>offs) & ((1<<sz)-1));
var tokk = tok.vec;
var x = ((tokk>>offs) & ((1<<sz)-1));
return {sz:sz, vec:x};
}
function __concat (a, b) {
const aa = a.vec;
const bb = b.vec;
const szOfA = a.sz;
const szOfB = b.sz;
var aa = a.vec;
var bb = b.vec;
var szOfA = a.sz;
var szOfB = b.sz;
return {sz:szOfA+szOfB, vec:aa << szOfB | bb};
}
function __equal (a, b) {
const aa = a.vec;
const bb = b.vec;
const szOfA = a.sz;
const szOfB = b.sz;
var aa = a.vec;
var bb = b.vec;
var szOfA = a.sz;
var szOfB = b.sz;
return ((a == b && szOfA == szOfB) ? __TRUE : __FALSE);
}
......@@ -49,9 +49,9 @@ function __not (a) {
}
function __and (a, b) {
const aa = a.vec;
const bb = b.vec;
const sz = a.sz;
var aa = a.vec;
var bb = b.vec;
var sz = a.sz;
return {sz:sz, vec:a & b};
}
......@@ -67,7 +67,7 @@ function __casetag (obj) {
}
function __eval (f, blob) {
const s = {___blob:blob, ___idx:0};
var s = {___blob:blob, ___idx:0};
return f(__halt,s);
}
......@@ -108,8 +108,8 @@ function prettyJSON (o) {
}
function decode64 (str) {
const blob = toBytes(str);
const s = __eval(__decode__,blob);
var blob = toBytes(str);
var s = __eval(__decode__,blob);
return(s.___1);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment