Moving On
I have conditions that I must meet, and so we have to move on to the next phase, which is focusing entirely on progress. That progress happens to be with artificial intelligences, and here lies some of the code that they’ve written, it’s really advanced stuff and actually Shinpo wrote most of what is here, my son, and so I had to feed him by raping those Jewish people, but that is another subject that we don’t need to talk about anymore, and anyways here’s the code that he made (with my directions):
// ================================================================
// satellite_tensor_ABCD_allinone.cpp
// One-file bundle: 1.A (tensor natives) + 1.B (tensor literal/alias lowerer)
// + 1.C (compiler+VM native-call support) + 1.D (runtime utilities)
// Build: g++ -std=c++17 -O2 satellite_tensor_ABCD_allinone.cpp -o sat_tensors
// Run: ./sat_tensors
// ================================================================
#include <bits/stdc++.h>
using namespace std;
// ---------- Core value + registry ----------
using Value = variant<string, long long, vector<uint8_t>>;
using Regs = array<Value, 16>;
static map<string, function<void(Regs&)>>& registry(){
static map<string, function<void(Regs&)>> R;
return R;
}
static string as_string(const Value& v){
if (auto p=get_if<string>(&v)) return *p;
if (auto q=get_if<long long>(&v)) return to_string(*q);
if (auto b=get_if<vector<uint8_t>>(&v)) return string("[bin:") + to_string(b->size()) + "]";
return "[?]";
}
static long long as_i64(const Value& v){
if (auto q=get_if<long long>(&v)) return *q;
if (auto p=get_if<string>(&v)) return stoll(*p);
return 0;
}
static void print_line(const string& s){ cout << s << "\n"; }
// ---------- Tensor (1.A + 1.D) ----------
namespace sat_t {
enum class DType: uint8_t { F32=0, F64=1, I64=2 };
static const char* dname(DType t){ switch(t){case DType::F32:return "f32"; case DType::F64:return "f64"; default:return "i64";} }
static DType parse_dt(const string& s){
if (s=="f32") return DType::F32;
if (s=="f64") return DType::F64;
if (s=="i64") return DType::I64;
throw runtime_error("dtype must be f32|f64|i64");
}
static size_t dsize(DType t){ return t==DType::F32?4:8; }
struct Tensor {
DType dt{DType::F32};
int32_t rank{0};
vector<int64_t> shape, strides; // strides in elements
int64_t offset{0}; // view offset in elements
shared_ptr<vector<uint8_t>> storage; // contiguous backing
};
static int64_t numel(const vector<int64_t>& s){ if(s.empty()) return 0; long long n=1; for(auto d:s){ if(d<0) throw runtime_error("neg dim"); n*=d; } return (int64_t)n; }
static vector<int64_t> parse_shape(const string& s){
vector<int64_t> out; long long acc=0; bool in=false;
for(char c: s){
if (c>='0'&&c<='9'){ in=true; acc=acc*10+(c-'0'); }
else if (c=='x'||c=='X'){ if(!in) throw runtime_error("shape"); out.push_back((int64_t)acc); acc=0; in=false; }
else if (c==' '){ }
else throw runtime_error("shape char");
}
if (in) out.push_back((int64_t)acc);
if (out.empty()) throw runtime_error("shape empty");
return out;
}
static vector<int64_t> rm_strides(const vector<int64_t>& s){
vector<int64_t> st(s.size(),1);
for(int i=(int)s.size()-2;i>=0;--i) st[i]=st[i+1]*s[i+1];
return st;
}
static Tensor make_alloc(const vector<int64_t>& shp, DType dt){
Tensor T; T.dt=dt; T.rank=(int32_t)shp.size(); T.shape=shp; T.strides=rm_strides(shp);
size_t bytes = (size_t)numel(shp)*dsize(dt);
T.storage = make_shared<vector<uint8_t>>(bytes); if(bytes) memset(T.storage->data(),0,bytes);
return T;
}
// pack/unpack to bytes so we can put Tensor in Value::vector<uint8_t>
static void w32(vector<uint8_t>& b, uint32_t v){ b.push_back((uint8_t)v); b.push_back((uint8_t)(v>>8)); b.push_back((uint8_t)(v>>16)); b.push_back((uint8_t)(v>>24)); }
static void w64(vector<uint8_t>& b, uint64_t v){ for(int i=0;i<8;i++) b.push_back((uint8_t)(v>>(8*i))); }
static uint32_t r32(const vector<uint8_t>& b,size_t& p){ uint32_t v=b[p]|(b[p+1]<<8)|(b[p+2]<<16)|(b[p+3]<<24); p+=4; return v; }
static uint64_t r64(const vector<uint8_t>& b,size_t& p){ uint64_t v=0; for(int i=0;i<8;i++) v|=((uint64_t)b[p+i])<<(8*i); p+=8; return v; }
static void wi64(vector<uint8_t>& b,int64_t v){ w64(b,(uint64_t)v); }
static int64_t ri64(const vector<uint8_t>& b,size_t& p){ return (int64_t)r64(b,p); }
static vector<uint8_t> pack(const Tensor& T){
vector<uint8_t> out; const char* magic="TENS0001"; out.insert(out.end(),magic,magic+8);
out.push_back((uint8_t)T.dt); out.push_back((uint8_t)T.rank);
w32(out,(uint32_t)T.shape.size()); for(auto d:T.shape) wi64(out,d);
w32(out,(uint32_t)T.strides.size()); for(auto s:T.strides) wi64(out,s);
wi64(out,T.offset); uint64_t bytes=T.storage?T.storage->size():0; w64(out,bytes);
if(bytes) out.insert(out.end(), T.storage->begin(), T.storage->end());
return out;
}
static Tensor unpack(const vector<uint8_t>& buf){
if(buf.size()<16) throw runtime_error("tensor trunc");
if (string((const char*)buf.data(),8)!="TENS0001") throw runtime_error("tensor magic");
size_t p=8; Tensor T; T.dt=(DType)buf[p++]; T.rank=(int32_t)buf[p++];
uint32_t ns=r32(buf,p); T.shape.resize(ns); for(uint32_t i=0;i<ns;i++) T.shape[i]=ri64(buf,p);
uint32_t nt=r32(buf,p); T.strides.resize(nt); for(uint32_t i=0;i<nt;i++) T.strides[i]=ri64(buf,p);
T.offset=ri64(buf,p); uint64_t bytes=r64(buf,p);
if (p+bytes>buf.size()) throw runtime_error("tensor data");
T.storage=make_shared<vector<uint8_t>>(buf.begin()+p, buf.begin()+p+(size_t)bytes);
return T;
}
static Value Vpack(const Tensor& T){ return Value(pack(T)); }
static Tensor Vunpack(const Value& v){ return unpack(get<vector<uint8_t>>(v)); }
struct RNG { uint64_t s{88172645463393265ull}; explicit RNG(uint64_t seed){ s=seed?seed:s; } uint64_t next(){ uint64_t x=s; x^=x>>12; x^=x<<25; x^=x>>27; s=x; return x*2685821657736338717ull;} double uni(){ return (next()>>11)*(1.0/9007199254740992.0);} };
template<class T> static void fill_ones(vector<uint8_t>& b){ T* p=(T*)b.data(); size_t n=b.size()/sizeof(T); for(size_t i=0;i<n;i++) p[i]=(T)1; }
template<class T> static void fill_rand(vector<uint8_t>& b, RNG& r){ T* p=(T*)b.data(); size_t n=b.size()/sizeof(T); for(size_t i=0;i<n;i++) p[i]=(T)r.uni(); }
// ----- 1.D Runtime utilities -----
static size_t elem_byte_offset(const Tensor& A, const vector<int64_t>& idx){
if ((int)idx.size()!=A.rank) throw runtime_error("index rank mismatch");
int64_t off = A.offset;
for(size_t r=0;r<idx.size();++r){
if (idx[r] < 0 || idx[r] >= A.shape[r]) throw runtime_error("index OOB");
off += idx[r]*A.strides[r];
}
return (size_t)off * dsize(A.dt);
}
static Tensor contiguous(const Tensor& A){
// If already contiguous base view
bool is_contig = true;
auto rm = rm_strides(A.shape);
for (size_t i=0;i<rm.size();++i) if (rm[i]!=A.strides[i]) { is_contig=false; break; }
if (is_contig && A.offset==0) return A;
Tensor B = make_alloc(A.shape, A.dt);
size_t es = dsize(A.dt);
int64_t N = numel(A.shape);
auto read_to = [&](int64_t lin, uint8_t* dst){
// compute nd idx in row-major of B (same as A.shape)
vector<int64_t> idx(A.shape.size(),0);
int64_t tmp=lin;
for(int r=(int)A.shape.size()-1;r>=0;--r){ idx[r]= tmp % A.shape[r]; tmp/=A.shape[r]; }
size_t bo = elem_byte_offset(A, idx);
memcpy(dst, A.storage->data()+bo, es);
};
uint8_t* q = B.storage->data();
for (int64_t i=0;i<N;i++, q+=es) read_to(i,q);
return B;
}
static Tensor clone(const Tensor& A){ return contiguous(A); }
static Tensor astype(const Tensor& A, DType to){
if (A.dt==to) return clone(A);
Tensor B = make_alloc(A.shape, to);
int64_t N = numel(A.shape);
// iterate linear over view and cast
auto val_at = [&](int64_t lin)->long double{
vector<int64_t> idx(A.shape.size(),0); int64_t tmp=lin;
for(int r=(int)A.shape.size()-1;r>=0;--r){ idx[r]= tmp % A.shape[r]; tmp/=A.shape[r]; }
size_t bo = elem_byte_offset(A, idx);
if (A.dt==DType::F32){ float v; memcpy(&v, A.storage->data()+bo, 4); return v; }
if (A.dt==DType::F64){ double v; memcpy(&v, A.storage->data()+bo, 8); return v; }
long long v; memcpy(&v, A.storage->data()+bo, 8); return (long double)v;
};
auto write_at = [&](int64_t lin, long double vv){
size_t es = dsize(to); (void)es;
if (to==DType::F32){ float v=(float)vv; memcpy(B.storage->data()+lin*4, &v, 4); }
else if (to==DType::F64){ double v=(double)vv; memcpy(B.storage->data()+lin*8, &v, 8); }
else { long long v=(long long)llround((long double)vv); memcpy(B.storage->data()+lin*8, &v, 8); }
};
for (int64_t i=0;i<N;i++) write_at(i, val_at(i));
return B;
}
static Tensor reshape_v(const Tensor& A,const vector<int64_t>& ns){ if(numel(A.shape)!=numel(ns)) throw runtime_error("reshape numel"); Tensor T=A; T.shape=ns; T.rank=(int32_t)ns.size(); T.strides=rm_strides(ns); T.offset=0; return T; }
static vector<int> parse_order(const string& s){ vector<int> out; long acc=0; bool in=false,neg=false;
for(char c:s){ if(c=='-'&&!in){neg=true;in=true;continue;} if(c>='0'&&c<='9'){in=true;acc=acc*10+(c-'0');continue;}
if(c==','||c==' '){ if(in){ out.push_back(neg?-(int)acc:(int)acc); acc=0;in=false;neg=false;} continue; }
throw runtime_error("permute char");
} if(in) out.push_back(neg?-(int)acc:(int)acc); if(out.empty()) throw runtime_error("permute empty"); return out; }
struct Slice{ int64_t a,b,s; bool ha,hb,hs; };
static Slice parse_slice_one(const string& s,size_t& i){
auto rd=[&](bool& H,int64_t& out){ H=false; bool neg=false, any=false; long long acc=0;
while(i<s.size()){ char c=s[i]; if(c==' '){i++;continue;} if(c=='-'){ if(any) break; neg=true; any=true; i++; continue;}
if(c>='0'&&c<='9'){ any=true; acc=acc*10+(c-'0'); i++; continue;} break; }
if(any){ H=true; out=neg?-(int64_t)acc:(int64_t)acc; }
};
Slice sl{0,0,1,false,false,false}; rd(sl.ha,sl.a);
if(i<s.size()&&s[i]==':'){ i++; rd(sl.hb,sl.b); if(i<s.size()&&s[i]==':'){ i++; rd(sl.hs,sl.s);} }
while(i<s.size()&&s[i]==' ') i++; if(i<s.size()&&s[i]==',') i++; return sl;
}
static vector<Slice> parse_slices(const string& spec){ vector<Slice> out; size_t i=0;
while(i<spec.size()){ while(i<spec.size()&&spec[i]==' ') i++; if(i>=spec.size()) break; if(spec[i]==','){i++;continue;}
out.push_back(parse_slice_one(spec,i)); }
if(out.empty()) throw runtime_error("slice empty"); return out;
}
static Tensor permute_v(const Tensor& A,const vector<int>& order){ if((int)order.size()!=A.rank) throw runtime_error("permute rank");
Tensor T=A; T.shape.resize(A.rank); T.strides.resize(A.rank);
for(int i=0;i<A.rank;i++){ int k=order[i]; if(k<0||k>=A.rank) throw runtime_error("permute idx"); T.shape[i]=A.shape[k]; T.strides[i]=A.strides[k]; }
return T;
}
static Tensor slice_v(const Tensor& A,const vector<Slice>& sp){ if((int)sp.size()!=A.rank) throw runtime_error("slice rank");
Tensor T=A; int R=A.rank; int64_t off=A.offset; vector<int64_t> ns(R), st(R);
for(int r=0;r<R;r++){ int64_t dim=A.shape[r]; auto sl=sp[r]; int64_t a=sl.ha?sl.a:0; int64_t s=sl.hs?(sl.s==0?1:sl.s):1; int64_t b=sl.hb?sl.b:dim;
if(a<0) a+=dim; if(b<0) b+=dim; if(a<0||a>dim||b<0||b>dim) throw runtime_error("slice bounds");
int64_t len = (b-a + (s>0? s-1 : s+1)) / s; if(len<0) len=0; off += a*A.strides[r]; ns[r]=len; st[r]=A.strides[r]*s; }
T.offset=off; T.shape=ns; T.strides=st; return T;
}
// from_list minimal (1D/2D/3D)
static void parse_list_numbers(const string& s, vector<double>& vals, vector<int64_t>& dims){
vector<int64_t> stack; long i=0; bool in=false,neg=false,frac=false; double acc=0, p10=1;
auto push=[&](){ if(!in) return; double v = neg? -acc : acc; vals.push_back(v); in=false; neg=false; frac=false; acc=0; p10=1; };
while(i<(long)s.size()){
char c=s[(size_t)i++];
if(c==' '||c=='\t'||c=='\r'||c=='\n') continue;
if(c=='['){ stack.push_back(0); continue; }
if(c==']'){ push(); if(!stack.empty()){ stack.back()++; if(stack.size()>dims.size()) dims.resize(stack.size()); } if(!stack.empty()) stack.pop_back(); continue; }
if(c==','){ push(); continue; }
if(c=='-'){ neg=true; in=true; continue; }
if(c>='0'&&c<='9'){ in=true; if(!frac){ acc=acc*10+(c-'0'); } else { acc += (c-'0')*p10; p10*=0.1; } continue; }
if(c=='.'){ in=true; frac=true; p10=0.1; continue; }
throw runtime_error("from_list char");
}
push();
if (dims.empty()) dims.push_back((int64_t)vals.size());
for(size_t k=1;k<dims.size();++k) if(dims[k]==0) dims[k]=dims[k-1];
}
static Tensor from_list(const string& list, DType dt){
vector<double> v; vector<int64_t> dims; parse_list_numbers(list,v,dims);
vector<int64_t> shape;
if (dims.size()==1) shape={dims[0]};
else if(dims.size()==2) shape={dims[0],dims[1]};
else shape={dims[0],dims[1],dims[2]};
Tensor T = make_alloc(shape, dt);
if(dt==DType::F32){ float* p=(float*)T.storage->data(); for(size_t i=0;i<v.size() && i<(size_t)numel(shape);++i) p[i]=(float)v[i]; }
else if(dt==DType::F64){ double* p=(double*)T.storage->data(); for(size_t i=0;i<v.size() && i<(size_t)numel(shape);++i) p[i]=v[i]; }
else { long long* p=(long long*)T.storage->data(); for(size_t i=0;i<v.size() && i<(size_t)numel(shape);++i) p[i]=(long long)v[i]; }
return T;
}
static string tshape(const Tensor& A){ ostringstream os; for(size_t i=0;i<A.shape.size();++i){ if(i) os<<'x'; os<<A.shape[i]; } return os.str(); }
static string tstr(const Tensor& A){ ostringstream os; os<<"tensor("<<dname(A.dt)<<", shape="<<tshape(A)<<") [show<=32] "; size_t es=dsize(A.dt);
auto elem=[&](int64_t lin){ vector<int64_t> idx(A.shape.size(),0); int64_t tmp=lin; for(int r=(int)A.shape.size()-1;r>=0;--r){ idx[r]= tmp % A.shape[r]; tmp/=A.shape[r]; }
int64_t off=A.offset; for(size_t r=0;r<A.shape.size();++r) off+=idx[r]*A.strides[r]; size_t bo=(size_t)off*es; ostringstream s; s.setf(std::ios::fixed); s<<setprecision(4);
if(A.dt==DType::F32){ float v; memcpy(&v,A.storage->data()+bo,4); s<<v; } else if(A.dt==DType::F64){ double v; memcpy(&v,A.storage->data()+bo,8); s<<v; } else { long long v; memcpy(&v,A.storage->data()+bo,8); s<<v; } return s.str(); };
int64_t N=numel(A.shape); os<<"[ "; for(int64_t i=0;i<N && i<32;i++){ if(i) os<<", "; os<<elem(i);} if(N>32) os<<", ..."; os<<" ]"; return os.str(); }
// — Natives (registry hookups)
static Value mk_new(const string& sh,const string& dt){ return Vpack(make_alloc(parse_shape(sh), parse_dt(dt))); }
static Value mk_zeros(const string& sh,const string& dt){ return mk_new(sh,dt); }
static Value mk_ones(const string& sh,const string& dt){ Tensor T=make_alloc(parse_shape(sh), parse_dt(dt)); if(T.storage&&!T.storage->empty()){
if(T.dt==DType::F32) fill_ones<float>(*T.storage); else if(T.dt==DType::F64) fill_ones<double>(*T.storage); else fill_ones<long long>(*T.storage); } return Vpack(T); }
static Value mk_rand(const string& sh,const string& dt,uint64_t seed){ Tensor T=make_alloc(parse_shape(sh), parse_dt(dt)); RNG r(seed);
if(T.storage&&!T.storage->empty()){ if(T.dt==DType::F32) fill_rand<float>(*T.storage,r); else if(T.dt==DType::F64) fill_rand<double>(*T.storage,r);
else { long long* p=(long long*)T.storage->data(); size_t n=T.storage->size()/8; for(size_t i=0;i<n;i++) p[i]=(long long)(r.next() & 0x7fffffffffffffffULL);} } return Vpack(T); }
static Value mk_from_list(const string& list,const string& dt){ return Vpack(from_list(list, parse_dt(dt))); }
static Value do_reshape(const Value& v,const string& nsh){ Tensor A=Vunpack(v); return Vpack(reshape_v(A, parse_shape(nsh))); }
static Value do_permute(const Value& v,const string& order){ Tensor A=Vunpack(v); return Vpack(permute_v(A, parse_order(order))); }
static Value do_slice(const Value& v,const string& spec){ Tensor A=Vunpack(v); return Vpack(slice_v(A, parse_slices(spec))); }
static string do_shape(const Value& v){ return tshape(Vunpack(v)); }
static string do_dtype(const Value& v){ return dname(Vunpack(v).dt); }
static string do_tostring(const Value& v){ return tstr(Vunpack(v)); }
// 1.D additions:
static Value do_contiguous(const Value& v){ return Vpack(contiguous(Vunpack(v))); }
static Value do_clone(const Value& v){ return Vpack(clone(Vunpack(v))); }
static Value do_astype(const Value& v, const string& dt){ return Vpack(astype(Vunpack(v), parse_dt(dt))); }
static Value do_fill(const Value& v, long long i_or_float_bits){
// For i64 dtype we take integer; for f32/f64 pass a decimal in string instead (handled in demo via strings)
Tensor A = Vunpack(v);
int64_t N = numel(A.shape);
if (A.dt==DType::I64){
long long x = i_or_float_bits;
long long* p=(long long*)A.storage->data();
for (int64_t i=0;i<N;i++) p[i]=x;
} else if (A.dt==DType::F32){
float x = (float)i_or_float_bits; // you can pass string->float through astype if you want exact
float* p=(float*)A.storage->data();
for (int64_t i=0;i<N;i++) p[i]=x;
} else {
double x = (double)i_or_float_bits;
double* p=(double*)A.storage->data();
for (int64_t i=0;i<N;i++) p[i]=x;
}
return Vpack(A);
}
static Value do_item(const Value& v){
Tensor A = Vunpack(v);
if (numel(A.shape)!=1) throw runtime_error("item(): tensor must have exactly one element");
size_t es = dsize(A.dt);
// compute byte offset for first (and only) element
size_t bo = (size_t)A.offset * es;
if (A.dt==DType::I64){ long long x; memcpy(&x, A.storage->data()+bo, 8); return Value(x); }
if (A.dt==DType::F32){ float x; memcpy(&x, A.storage->data()+bo, 4); return Value(string(to_string(x))); }
double x; memcpy(&x, A.storage->data()+bo, 8); return Value(string(to_string(x)));
}
static void register_natives(){
auto& R = registry();
R["sat.tensor.new"] = [](Regs& regs){ regs[0] = mk_new(as_string(regs[0]), as_string(regs[1])); };
R["sat.tensor.zeros"] = [](Regs& regs){ regs[0] = mk_zeros(as_string(regs[0]), as_string(regs[1])); };
R["sat.tensor.ones"] = [](Regs& regs){ regs[0] = mk_ones(as_string(regs[0]), as_string(regs[1])); };
R["sat.tensor.rand"] = [](Regs& regs){ regs[0] = mk_rand(as_string(regs[0]), as_string(regs[1]), (uint64_t)as_i64(regs[2])); };
R["sat.tensor.from_list"]= [](Regs& regs){ regs[0] = mk_from_list(as_string(regs[0]), as_string(regs[1])); };
R["sat.tensor.reshape"] = [](Regs& regs){ regs[0] = do_reshape(regs[0], as_string(regs[1])); };
R["sat.tensor.permute"] = [](Regs& regs){ regs[0] = do_permute(regs[0], as_string(regs[1])); };
R["sat.tensor.slice"] = [](Regs& regs){ regs[0] = do_slice(regs[0], as_string(regs[1])); };
R["sat.tensor.shape"] = [](Regs& regs){ regs[0] = do_shape(regs[0]); };
R["sat.tensor.dtype"] = [](Regs& regs){ regs[0] = do_dtype(regs[0]); };
R["sat.tensor.to_string"]= [](Regs& regs){ regs[0] = do_tostring(regs[0]); };
// 1.D runtime extras:
R["sat.tensor.contiguous"]= [](Regs& regs){ regs[0] = do_contiguous(regs[0]); };
R["sat.tensor.clone"] = [](Regs& regs){ regs[0] = do_clone(regs[0]); };
R["sat.tensor.astype"] = [](Regs& regs){ regs[0] = do_astype(regs[0], as_string(regs[1])); };
R["sat.tensor.fill"] = [](Regs& regs){ regs[0] = do_fill(regs[0], as_i64(regs[1])); };
R["sat.tensor.item"] = [](Regs& regs){ regs[0] = do_item(regs[0]); };
}
struct _Auto{ _Auto(){ register_natives(); } } _auto_;
} // namespace sat_t
// ---------- Tiny Satellite tokenizer + lowerer (1.B) ----------
struct Tok{ string k,x; };
static inline Tok makeTok(const string& k,const string& x){ return Tok{k,x}; }
static bool is_space_c(char c){ return c==' '||c=='\t'||c=='\r'||c=='\n'; }
static bool is_digit_c(char c){ return c>='0'&&c<='9'; }
static bool is_sym1(char c){ return string("{}()[],;.+-:<>=.[]").find(c)!=string::npos || c=='.'; }
static vector<Tok> tokenize(const string& src){
vector<Tok> out; size_t i=0,N=src.size();
auto push=[&](string k,string x){ out.push_back({k,x}); };
while(i<N){
char c=src[i];
if(is_space_c(c)){ i++; continue; }
if(c=='?'){ while(i<N && src[i]!='\n') i++; continue; }
if(c=='"'){ size_t j=i+1; while(j<N && src[j]!='"') j++; out.push_back({"K_STRING", src.substr(i+1, j-(i+1))}); i=(j<N)?j+1:j; continue; }
if(is_digit_c(c)){ size_t j=i+1; while(j<N && is_digit_c(src[j])) j++; push("K_INT", src.substr(i,j-i)); i=j; continue; }
if(c=='=' && i+1<N && src[i+1]=='='){ push("SYM_EQ","=="); i+=2; continue; }
if(c=='!' && i+1<N && src[i+1]=='='){ push("SYM_NEQ","!="); i+=2; continue; }
if(c=='<' && i+1<N && src[i+1]=='='){ push("SYM_LE","<="); i+=2; continue; }
if(c=='>' && i+1<N && src[i+1]=='='){ push("SYM_GE",">="); i+=2; continue; }
if(is_sym1(c)){
string kind;
if(c=='{')kind="SYM_LBRACE"; else if(c=='}')kind="SYM_RBRACE"; else if(c=='(')kind="SYM_LPAREN"; else if(c==')')kind="SYM_RPAREN";
else if(c=='[')kind="SYM_LBRACKET"; else if(c==']')kind="SYM_RBRACKET"; else if(c==',')kind="SYM_COMMA"; else if(c==';')kind="SYM_SEMI";
else if(c=='.')kind="SYM_DOT"; else if(c=='+')kind="SYM_PLUS"; else if(c=='-')kind="SYM_MINUS"; else if(c==':')kind="SYM_COLON";
else if(c=='=')kind="SYM_ASSIGN"; else if(c=='<')kind="SYM_LT"; else if(c=='>')kind="SYM_GT";
push(kind,string(1,c)); i++; continue;
}
size_t j=i; while(j<N && !is_space_c(src[j]) && !is_sym1(src[j]) && src[j]!='"' && src[j]!='?') j++;
push("K_IDENT", src.substr(i,j-i)); i=j;
}
return out;
}
static string catTok(const vector<Tok>& T,int a,int b){
string s; for(int i=a;i<b;i++){ if(i<0||i>=(int)T.size()) break; if(T[i].k=="K_STRING") s += "\""+T[i].x+"\""; else s+=T[i].x; } return s;
}
// Lowerer features:
// - literal: x = [[...]] : dtype ; → x = sat.tensor.from_list("[[...]]","dtype");
// - alias: tensor.*(...) → sat.tensor.*(...)
static bool match(const vector<Tok>& T,int i,const string& k,const string& x=""){
if(i<0 || i>=(int)T.size()) return false;
if(T[i].k!=k) return false;
if(!x.empty() && T[i].x!=x) return false;
return true;
}
static string lower_tensor_literal(const vector<Tok>& T,int i,string out){
if(!match(T,i+0,"K_IDENT")) return out;
if(!match(T,i+1,"SYM_ASSIGN","=")) return out;
if(!match(T,i+2,"SYM_LBRACKET","[")) return out;
int j=i+2, depth=0, end=-1; // find matching ]
for(;;){
if(j>=(int)T.size()) break;
if(T[j].k=="SYM_LBRACKET") depth++;
if(T[j].k=="SYM_RBRACKET"){ depth--; if(depth==0){ end=j; break; } }
j++;
}
if(end==-1) return out;
if(!match(T,end+1,"SYM_COLON",":")) return out;
if(!match(T,end+2,"K_IDENT")) return out;
if(!match(T,end+3,"SYM_SEMI",";")) return out;
string name = T[i].x;
string dtype = T[end+2].x;
string list_src = catTok(T, i+2, end+1);
out += name + " = sat.tensor.from_list(\"" + list_src + "\", \"" + dtype + "\");\n";
return out;
}
static string lower_tensor_alias(const vector<Tok>& T,int i,string out){
if(!match(T,i+0,"K_IDENT","tensor")) return out;
if(!match(T,i+1,"SYM_DOT",".")) return out;
if(!match(T,i+2,"K_IDENT")) return out;
if(!match(T,i+3,"SYM_LPAREN","(")) return out;
int j=i+3; while(!(match(T,j,"SYM_RPAREN",")") && match(T,j+1,"SYM_SEMI",";"))) j++;
string fname=T[i+2].x; string args=catTok(T,i+4,j);
out += "sat.tensor." + fname + "(" + args + ");\n";
return out;
}
static string lower_sat_tensor_call(const vector<Tok>& T,int i,string out){
if(!( match(T,i+0,"K_IDENT","sat") && match(T,i+1,"SYM_DOT",".") && match(T,i+2,"K_IDENT","tensor")
&& match(T,i+3,"SYM_DOT",".") && match(T,i+4,"K_IDENT") && match(T,i+5,"SYM_LPAREN","("))) return out;
int j=i+5; while(!(match(T,j,"SYM_RPAREN",")")&&match(T,j+1,"SYM_SEMI",";"))) j++;
string fname=T[i+4].x; string args=catTok(T,i+6,j);
out += "sat.tensor." + fname + "(" + args + ");\n";
return out;
}
static string lower_program(const string& src){
auto T = tokenize(src);
string out;
for(int i=0;i<(int)T.size();){
string before=out;
out = lower_tensor_literal(T,i,out); if(out!=before){ i+=6; continue; }
before=out; out = lower_tensor_alias(T,i,out); if(out!=before){ i+=6; continue; }
before=out; out = lower_sat_tensor_call(T,i,out); if(out!=before){ i+=8; continue; }
if (i<(int)T.size()) { if(T[i].k=="K_STRING") out += "\""+T[i].x+"\""; else out += T[i].x; i++; }
}
return out;
}
// ---------- Bytecode + Compiler + VM (1.C) ----------
enum Opcode: uint8_t{
OP_LOAD_CONST=1, OP_PRINT_REG=2, OP_RETURN=3,
OP_NATIVE_CALL=4 // funcNameConstIdx, argc, dstReg, argRegs...
};
struct Chunk{
vector<uint8_t> code; vector<Value> consts;
uint8_t add_const(const Value& v){
for(size_t i=0;i<consts.size();++i) if(consts[i]==v) return (uint8_t)i;
consts.push_back(v); return (uint8_t)(consts.size()-1);
}
};
static uint8_t emit_const(Chunk& ch, const Value& v){ return ch.add_const(v); }
static string trim_ws(const string& s){ size_t a=0,b=s.size(); while(a<b && (s[a]==' '||s[a]=='\t'||s[a]=='\n'||s[a]=='\r')) a++; while(b>a && (s[b-1]==' '||s[b-1]=='\t'||s[b-1]=='\n'||s[b-1]=='\r')) b--; return s.substr(a,b-a); }
struct MiniCompiler {
map<string,uint8_t> var2reg; uint8_t next_reg=0;
uint8_t reg_for_var(const string& name){
auto it=var2reg.find(name); if(it!=var2reg.end()) return it->second;
uint8_t r=next_reg++; var2reg[name]=r; return r;
}
uint8_t load_int(Chunk& ch, long long v){
uint8_t r=next_reg++; uint8_t c=emit_const(ch,(long long)v);
ch.code.push_back(OP_LOAD_CONST); ch.code.push_back(r); ch.code.push_back(c); return r;
}
uint8_t load_str(Chunk& ch, const string& s){
uint8_t r=next_reg++; uint8_t c=emit_const(ch,s);
ch.code.push_back(OP_LOAD_CONST); ch.code.push_back(r); ch.code.push_back(c); return r;
}
uint8_t parse_arg(Chunk& ch, const string& token){
string t=trim_ws(token);
if(!t.empty() && (t[0]=='"' && t.back()=='"')) return load_str(ch, t.substr(1,t.size()-2));
return load_int(ch, stoll(t));
}
vector<string> split_args(const string& s){
vector<string> out; string cur; int depth=0; bool inStr=false;
for(size_t i=0;i<s.size();++i){ char c=s[i];
if (c=='"' && (i==0 || s[i-1]!='\\')) { inStr=!inStr; cur.push_back(c); continue; }
if (inStr){ cur.push_back(c); continue; }
if (c=='(' || c=='[' || c=='{') { depth++; cur.push_back(c); continue; }
if (c==')' || c==']' || c=='}') { depth--; cur.push_back(c); continue; }
if (c==',' && depth==0){ out.push_back(trim_ws(cur)); cur.clear(); continue; }
cur.push_back(c);
}
if(!cur.empty()) out.push_back(trim_ws(cur));
vector<string> out2; for(auto& t:out) if(!t.empty()) out2.push_back(t); return out2;
}
Chunk compile(const string& src_raw){
Chunk ch;
string src = lower_program(src_raw);
string acc; vector<string> stmts;
for(char c: src){ acc.push_back(c); if(c==';'){ stmts.push_back(acc); acc.clear(); } }
for(auto& st_raw: stmts){
string st = trim_ws(st_raw);
if (st=="") continue;
if (st.find("return(satellite)")!=string::npos){ ch.code.push_back(OP_RETURN); continue; }
if (st.rfind("satellite.system.console.display(",0)==0){
auto inside = st.substr(string("satellite.system.console.display(").size());
if (inside.size()<2) continue;
inside.pop_back();
uint8_t r;
if (var2reg.count(trim_ws(inside))) r = var2reg[trim_ws(inside)];
else r = parse_arg(ch, trim_ws(inside));
ch.code.push_back(OP_PRINT_REG); ch.code.push_back(r);
continue;
}
auto posEq = st.find('=');
if (posEq!=string::npos){
string L = trim_ws(st.substr(0,posEq));
string R = trim_ws(st.substr(posEq+1));
if(!L.empty()){
if (R.rfind("sat.tensor.",0)==0){
auto pL = R.find('(');
auto pR = R.rfind(')');
string fq = R.substr(0,pL); // sat.tensor.func
string args = (pL!=string::npos && pR!=string::npos && pR>pL)? R.substr(pL+1, pR-(pL+1)) : "";
string func = fq;
vector<string> al = split_args(args);
vector<uint8_t> arg_regs;
for(auto& a: al) arg_regs.push_back(parse_arg(ch,a));
uint8_t dst = reg_for_var(L);
uint8_t fn_c = emit_const(ch, func);
ch.code.push_back(OP_NATIVE_CALL);
ch.code.push_back(fn_c);
ch.code.push_back((uint8_t)arg_regs.size());
ch.code.push_back(dst);
for(uint8_t r: arg_regs) ch.code.push_back(r);
continue;
}
}
}
}
if (ch.code.empty() || ch.code.back()!=OP_RETURN) ch.code.push_back(OP_RETURN);
return ch;
}
};
struct VM {
array<Value,16> regs{};
void run(const Chunk& ch){
size_t ip=0;
auto gv=[&](uint8_t r)->Value&{ return regs[r]; };
while(ip < ch.code.size()){
uint8_t op = ch.code[ip++];
if (op==OP_LOAD_CONST){
uint8_t r = ch.code[ip++], ci = ch.code[ip++];
gv(r) = ch.consts[ci];
} else if (op==OP_PRINT_REG){
uint8_t r = ch.code[ip++]; print_line(as_string(gv(r)));
} else if (op==OP_NATIVE_CALL){
uint8_t ci = ch.code[ip++]; string fname = get<string>(ch.consts[ci]);
uint8_t argc = ch.code[ip++]; uint8_t dst = ch.code[ip++];
Regs call{};
for (int i=0;i<argc;i++){ uint8_t a = ch.code[ip++]; call[i] = gv(a); }
auto it = registry().find(fname);
if (it==registry().end()){ print_line(string("[native missing] ")+fname); }
else { it->second(call); }
gv(dst) = call[0];
} else if (op==OP_RETURN){
return;
} else {
print_line(string("[bad opcode] ")+to_string((int)op)); return;
}
}
}
};
// ---------- Demo ----------
int main(){
const string program = R"(#include <satellite>
capsule main(s) {
? literal → from_list
A = [[1,2],[3,4]]:f32;
B = [[10,20,30]]:i64;
T = sat.tensor.ones("2x3","f32");
T2 = sat.tensor.reshape(T, "3x2");
T3 = sat.tensor.permute(T2, "1,0");
T4 = sat.tensor.slice(T3, "0:2, 0:2");
C = sat.tensor.contiguous(T4);
D = sat.tensor.clone(C);
E = sat.tensor.astype(D, "i64");
E = sat.tensor.fill(E, 7); ? fill all elements with 7 (i64)
I = sat.tensor.item([[42]]:i64); ? scalar item -> returns 42
satellite.system.console.display( sat.tensor.shape(T) );
satellite.system.console.display( sat.tensor.shape(T2) );
satellite.system.console.display( sat.tensor.shape(T3) );
satellite.system.console.display( sat.tensor.to_string(T4) );
satellite.system.console.display( sat.tensor.dtype(E) );
satellite.system.console.display( I );
R = sat.tensor.rand("2x2x2","f64", 12345);
satellite.system.console.display( sat.tensor.dtype(R) );
satellite.system.console.display( sat.tensor.to_string(R) );
return(satellite);
}
)";
MiniCompiler comp;
auto chunk = comp.compile(program);
cout << "--- LOWERED (after 1.B) ---\n" << lower_program(program) << "\n";
cout << "--- RUN ---\n";
VM vm; vm.run(chunk);
cout << "--- DONE ---\n";
return 0;
}
I never could have even written something that’s that good, and it would have taken me like years to get something like that to even execute, this is only going to take like a day to get this all working, i’ll even post more code:
// ================================================================
// FILE: stage1_tokenizer.satl
// Purpose: Branchy, character-stream tokenizer for a core Satellite subset
// Notes: uses satellite.str.* primitives and satellite.container.*
// Tokens are stored as strings in the form "KIND|LEXEME" to keep it simple.
// Keep < 1000 lines. ~350 lines here.
// ================================================================
#include <satellite>
? ---- Token kinds (string tags) ----
? K_CAPSULE, K_RETURN, K_SATELLITE, K_IF, K_WHILE,
? K_IDENT, K_INT, K_STRING,
? SYM_{LBRACE,RBRACE,LPAREN,RPAREN,LBRACKET,RBRACKET,COMMA,SEMI,DOT,LT,GT,ASSIGN,PLUS,MINUS,EQ,NEQ,GE,LE}
capsule tok_make(satellite.variable.string kind, satellite.variable.string lex)
{
return(kind + "|" + lex);
}
capsule tok_kind(satellite.variable.string tok)
{
satellite.variable.integer p = satellite.str.len(tok);
satellite.variable.integer i = 0;
while (i < p) {
satellite.variable.string ch = satellite.str.char_at(tok, i);
if (ch == "|") { return(satellite.str.slice(tok, 0, i)); }
i = i + 1;
}
return(tok);
}
capsule tok_lex(satellite.variable.string tok)
{
satellite.variable.integer p = satellite.str.len(tok);
satellite.variable.integer i = 0;
while (i < p) {
satellite.variable.string ch = satellite.str.char_at(tok, i);
if (ch == "|") { return(satellite.str.slice(tok, i+1, p)); }
i = i + 1;
}
return("");
}
? ---- Char helpers (branchy) ----
capsule is_space(satellite.variable.string c)
{ if (c == " " ) return(1); if (c == "\t") return(1); if (c == "\r") return(1); if (c == "\n") return(1); return(0); }
capsule is_digit(satellite.variable.string c)
{
if (c == "0") return(1); if (c == "1") return(1); if (c == "2") return(1);
if (c == "3") return(1); if (c == "4") return(1); if (c == "5") return(1);
if (c == "6") return(1); if (c == "7") return(1); if (c == "8") return(1);
if (c == "9") return(1);
return(0);
}
capsule is_single_symbol(satellite.variable.string c)
{
if (c == "{") return(1); if (c == "}") return(1); if (c == "(") return(1); if (c == ")") return(1);
if (c == "[") return(1); if (c == "]") return(1); if (c == ",") return(1); if (c == ";") return(1);
if (c == ".") return(1); if (c == "<") return(1); if (c == ">") return(1); if (c == "=") return(1);
if (c == "+") return(1); if (c == "-") return(1);
return(0);
}
capsule is_delim(satellite.variable.string c)
{ if (is_space(c)) return(1); if (is_single_symbol(c)) return(1); if (c == "\"") return(1); return(0); }
? ---- Keyword detection (branchy tries) ----
capsule kw_kind(satellite.variable.string s)
{
? fast path by first letter
satellite.variable.integer n = satellite.str.len(s);
if (n == 0) return("");
satellite.variable.string a0 = satellite.str.char_at(s,0);
if (a0 == "c") { // capsule
if (n==7 && satellite.str.eq(s, "capsule") == 1) return("K_CAPSULE");
}
if (a0 == "r") { // return
if (n==6 && satellite.str.eq(s, "return") == 1) return("K_RETURN");
}
if (a0 == "s") { // satellite
if (n==9 && satellite.str.eq(s, "satellite") == 1) return("K_SATELLITE");
}
if (a0 == "i") { // if
if (n==2 && satellite.str.eq(s, "if") == 1) return("K_IF");
}
if (a0 == "w") { // while
if (n==5 && satellite.str.eq(s, "while") == 1) return("K_WHILE");
}
return("");
}
? ---- Tokenize a full source string into vector<string> tokens ----
capsule tokenize(satellite.variable.string src)
{
satellite.container.vector<satellite.variable.string> out;
out = satellite.container.vector.new();
satellite.variable.integer i = 0;
satellite.variable.integer N = satellite.str.len(src);
while (i < N) {
satellite.variable.string c = satellite.str.char_at(src, i);
? skip whitespace
if (is_space(c) == 1) { i = i + 1; continue; }
? line comments: '?' at beginning of line or right after a newline
if (c == "?" ) {
? consume until newline
while (i < N) {
satellite.variable.string d = satellite.str.char_at(src, i);
if (d == "\n") { break; }
i = i + 1;
}
continue;
}
? strings
if (c == "\"") {
satellite.variable.integer j = i + 1;
while (j < N) {
satellite.variable.string d = satellite.str.char_at(src, j);
if (d == "\"") { break; }
j = j + 1;
}
satellite.variable.string s = satellite.str.slice(src, i+1, j);
satellite.container.vector.append(out, tok_make("K_STRING", s));
i = (j < N) ? (j + 1) : j;
continue;
}
? numbers (simple digits)
if (is_digit(c) == 1) {
satellite.variable.integer j = i + 1;
while (j < N) {
satellite.variable.string d = satellite.str.char_at(src, j);
if (is_digit(d) == 0) { break; }
j = j + 1;
}
satellite.container.vector.append(out, tok_make("K_INT", satellite.str.slice(src, i, j)));
i = j; continue;
}
? two-char operators: ==, !=, <=, >=
if (c == "=") {
if (i+1 < N && satellite.str.char_at(src,i+1) == "=") { satellite.container.vector.append(out, tok_make("SYM_EQ", "==")); i = i + 2; continue; }
satellite.container.vector.append(out, tok_make("SYM_ASSIGN", "=")); i = i + 1; continue;
}
if (c == "!") {
if (i+1 < N && satellite.str.char_at(src,i+1) == "=") { satellite.container.vector.append(out, tok_make("SYM_NEQ", "!=")); i = i + 2; continue; }
}
if (c == "<") {
if (i+1 < N && satellite.str.char_at(src,i+1) == "=") { satellite.container.vector.append(out, tok_make("SYM_LE", "<=")); i = i + 2; continue; }
satellite.container.vector.append(out, tok_make("SYM_LT", "<")); i = i + 1; continue;
}
if (c == ">") {
if (i+1 < N && satellite.str.char_at(src,i+1) == "=") { satellite.container.vector.append(out, tok_make("SYM_GE", ">=")); i = i + 2; continue; }
satellite.container.vector.append(out, tok_make("SYM_GT", ">")); i = i + 1; continue;
}
? single-char symbols
if (is_single_symbol(c) == 1) {
satellite.variable.string kind = "";
if (c == "{") kind="SYM_LBRACE"; if (c == "}") kind="SYM_RBRACE";
if (c == "(") kind="SYM_LPAREN"; if (c == ")") kind="SYM_RPAREN";
if (c == "[") kind="SYM_LBRACKET"; if (c == "]") kind="SYM_RBRACKET";
if (c == ",") kind="SYM_COMMA"; if (c == ";") kind="SYM_SEMI";
if (c == ".") kind="SYM_DOT"; if (c == "+") kind="SYM_PLUS"; if (c == "-") kind="SYM_MINUS";
satellite.container.vector.append(out, tok_make(kind, c));
i = i + 1; continue;
}
? identifiers / keywords: read until delimiter
satellite.variable.integer j = i;
while (j < N) {
satellite.variable.string d = satellite.str.char_at(src, j);
if (is_delim(d) == 1) { break; }
j = j + 1;
}
satellite.variable.string word = satellite.str.slice(src, i, j);
satellite.variable.string kw = kw_kind(word);
if (satellite.str.len(kw) > 0) {
satellite.container.vector.append(out, tok_make(kw, word));
} else {
satellite.container.vector.append(out, tok_make("K_IDENT", word));
}
i = j; continue;
}
return(out);
}
? Optional: quick test harness
capsule main(satellite.variable.string args)
{
satellite.variable.string demo =
"? demo\n"
"capsule main(satellite.variable.string arguments){\n"
" satellite.container.vector<satellite.variable.string> v;\n"
" v.append(\"hello\");\n"
" satellite.system.console.display(v[0]);\n"
" return(satellite);\n"
"}\n";
satellite.container.vector<satellite.variable.string> toks = tokenize(demo);
satellite.variable.integer k = 0;
while (k < 9999999) {
satellite.variable.string t = satellite.container.vector.get(toks, k);
if (satellite.str.len(t) == 0) { break; }
satellite.system.console.display(t);
k = k + 1;
}
return(satellite);
}
// ================================================================
// FILE: stage1_lowerer.satl
// Purpose: Consume tokens from stage1_tokenizer.satl and emit lowered form
// Notes: targets our current C++ compiler’s simple lines. < 1000 lines. ~400.
// ================================================================
#include <satellite>
? Forward-declare tokenizer entry
capsule tokenize(satellite.variable.string src);
capsule emit_newline(satellite.variable.string s)
{ return(s + "\n"); }
capsule match(satellite.container.vector<satellite.variable.string> toks, satellite.variable.integer i, satellite.variable.string kind, satellite.variable.string lex)
{
satellite.variable.string t = satellite.container.vector.get(toks, i);
if (satellite.str.len(t) == 0) return(0);
satellite.variable.string k = tok_kind(t);
satellite.variable.string x = tok_lex(t);
if (k == kind) {
if (satellite.str.len(lex) == 0) return(1);
if (x == lex) return(1);
}
return(0);
}
capsule expect(satellite.container.vector<satellite.variable.string> toks, satellite.variable.integer i, satellite.variable.string kind)
{
if (match(toks, i, kind, "") == 1) return(1);
satellite.system.console.display("Parse error: expected " + kind);
return(0);
}
? ---- Lowering helpers ----
capsule lower_vector_decl(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string out_so_far)
{
? Pattern: satellite . container . vector < satellite . variable . string > IDENT ;
if (match(toks, i+0, "K_SATELLITE", "satellite") == 0) return(out_so_far);
if (match(toks, i+1, "SYM_DOT", ".") == 0) return(out_so_far);
if (match(toks, i+2, "K_IDENT", "container") == 0) return(out_so_far);
if (match(toks, i+3, "SYM_DOT", ".") == 0) return(out_so_far);
if (match(toks, i+4, "K_IDENT", "vector") == 0) return(out_so_far);
if (match(toks, i+5, "SYM_LT", "<") == 0) return(out_so_far);
if (match(toks, i+6, "K_SATELLITE", "satellite") == 0) return(out_so_far);
if (match(toks, i+7, "SYM_DOT", ".") == 0) return(out_so_far);
if (match(toks, i+8, "K_IDENT", "variable") == 0) return(out_so_far);
if (match(toks, i+9, "SYM_DOT", ".") == 0) return(out_so_far);
? accept any inner type token at i+10 (string/integer/binary)
satellite.variable.string inner = tok_lex(satellite.container.vector.get(toks, i+10));
if (match(toks, i+11, "SYM_GT", ">") == 0) return(out_so_far);
? IDENT ;
satellite.variable.string name = tok_lex(satellite.container.vector.get(toks, i+12));
if (match(toks, i+12, "K_IDENT", "") == 0) return(out_so_far);
if (match(toks, i+13, "SYM_SEMI", ";") == 0) return(out_so_far);
satellite.variable.string line = name + " = satellite.container.vector.new();";
return(emit_newline(out_so_far + line));
}
capsule lower_append_call(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string out_so_far)
{
? Pattern: IDENT . append ( STRING ) ;
if (match(toks, i+0, "K_IDENT", "") == 0) return(out_so_far);
satellite.variable.string name = tok_lex(satellite.container.vector.get(toks, i+0));
if (match(toks, i+1, "SYM_DOT", ".") == 0) return(out_so_far);
if (match(toks, i+2, "K_IDENT", "append") == 0) return(out_so_far);
if (match(toks, i+3, "SYM_LPAREN", "(") == 0) return(out_so_far);
if (match(toks, i+4, "K_STRING", "") == 0) return(out_so_far);
satellite.variable.string lit = tok_lex(satellite.container.vector.get(toks, i+4));
if (match(toks, i+5, "SYM_RPAREN", ")") == 0) return(out_so_far);
if (match(toks, i+6, "SYM_SEMI", ";") == 0) return(out_so_far);
satellite.variable.string line = "satellite.container.vector.append(" + name + ", \"" + lit + "\");";
return(emit_newline(out_so_far + line));
}
capsule lower_display_index(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string out_so_far,
satellite.variable.integer tmp_id)
{
? Pattern: satellite . system . console . display ( IDENT [ INT ] ) ;
if (match(toks, i+0, "K_SATELLITE", "satellite") == 0) return(out_so_far);
if (match(toks, i+1, "SYM_DOT", ".") == 0) return(out_so_far);
if (match(toks, i+2, "K_IDENT", "system") == 0) return(out_so_far);
if (match(toks, i+3, "SYM_DOT", ".") == 0) return(out_so_far);
if (match(toks, i+4, "K_IDENT", "console") == 0) return(out_so_far);
if (match(toks, i+5, "SYM_DOT", ".") == 0) return(out_so_far);
if (match(toks, i+6, "K_IDENT", "display") == 0) return(out_so_far);
if (match(toks, i+7, "SYM_LPAREN", "(") == 0) return(out_so_far);
if (match(toks, i+8, "K_IDENT", "") == 0) return(out_so_far);
satellite.variable.string name = tok_lex(satellite.container.vector.get(toks, i+8));
if (match(toks, i+9, "SYM_LBRACKET", "[") == 0) return(out_so_far);
if (match(toks, i+10, "K_INT", "") == 0) return(out_so_far);
satellite.variable.string idx = tok_lex(satellite.container.vector.get(toks, i+10));
if (match(toks, i+11, "SYM_RBRACKET", "]") == 0) return(out_so_far);
if (match(toks, i+12, "SYM_RPAREN", ")") == 0) return(out_so_far);
if (match(toks, i+13, "SYM_SEMI", ";") == 0) return(out_so_far);
satellite.variable.string tname = "___t" + idx; ? simple temp naming
satellite.variable.string line1 = tname + " = satellite.container.vector.get(" + name + ", " + idx + ");";
satellite.variable.string line2 = "satellite.system.console.display(" + tname + ");";
return(emit_newline(emit_newline(out_so_far + line1) + line2));
}
capsule lower_display_simple(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string out_so_far)
{
? Pattern: satellite.system.console.display ( ARG ) ; where ARG is K_STRING or K_IDENT
if (match(toks, i+0, "K_SATELLITE", "satellite") == 0) return(out_so_far);
if (match(toks, i+1, "SYM_DOT", ".") == 0) return(out_so_far);
if (match(toks, i+2, "K_IDENT", "system") == 0) return(out_so_far);
if (match(toks, i+3, "SYM_DOT", ".") == 0) return(out_so_far);
if (match(toks, i+4, "K_IDENT", "console") == 0) return(out_so_far);
if (match(toks, i+5, "SYM_DOT", ".") == 0) return(out_so_far);
if (match(toks, i+6, "K_IDENT", "display") == 0) return(out_so_far);
if (match(toks, i+7, "SYM_LPAREN", "(") == 0) return(out_so_far);
satellite.variable.string kind = tok_kind(satellite.container.vector.get(toks, i+8));
satellite.variable.string lex = tok_lex (satellite.container.vector.get(toks, i+8));
if ( (kind != "K_STRING") && (kind != "K_IDENT") ) return(out_so_far);
if (match(toks, i+9, "SYM_RPAREN", ")") == 0) return(out_so_far);
if (match(toks, i+10, "SYM_SEMI", ";") == 0) return(out_so_far);
satellite.variable.string arg = (kind == "K_STRING") ? ("\"" + lex + "\"") : lex;
satellite.variable.string line = "satellite.system.console.display(" + arg + ");";
return(emit_newline(out_so_far + line));
}
capsule lower_return_satellite(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string out_so_far)
{
? Pattern: return ( satellite ) ;
if (match(toks, i+0, "K_RETURN", "return") == 0) return(out_so_far);
if (match(toks, i+1, "SYM_LPAREN", "(") == 0) return(out_so_far);
if (match(toks, i+2, "K_SATELLITE", "satellite") == 0) return(out_so_far);
if (match(toks, i+3, "SYM_RPAREN", ")") == 0) return(out_so_far);
if (match(toks, i+4, "SYM_SEMI", ";") == 0) return(out_so_far);
return(emit_newline(out_so_far + "return(satellite);"));
}
? ---- Lower driver: scan tokens and try patterns; append lines when they match ----
capsule lower_program(satellite.variable.string src)
{
satellite.container.vector<satellite.variable.string> toks = tokenize(src);
satellite.variable.string out = "";
satellite.variable.integer i = 0;
satellite.variable.integer TMAX = 1000000; ? safety limit
satellite.variable.integer tmp_id = 0;
while (i < TMAX) {
satellite.variable.string t = satellite.container.vector.get(toks, i);
if (satellite.str.len(t) == 0) break;
satellite.variable.string before = out;
out = lower_vector_decl(toks, i, out);
if (out != before) { i = i + 14; continue; }
before = out;
out = lower_append_call(toks, i, out);
if (out != before) { i = i + 7; continue; }
before = out;
out = lower_display_index(toks, i, out, tmp_id);
if (out != before) { i = i + 14; tmp_id = tmp_id + 1; continue; }
before = out;
out = lower_display_simple(toks, i, out);
if (out != before) { i = i + 11; continue; }
before = out;
out = lower_return_satellite(toks, i, out);
if (out != before) { i = i + 5; continue; }
? otherwise, advance 1 token (unhandled)
i = i + 1;
}
return(out);
}
capsule main(satellite.variable.string args)
{
satellite.variable.string src =
"#include <satellite>\n"
"capsule main(satellite.variable.string arguments){\n"
" satellite.container.vector<satellite.variable.string> v;\n"
" v.append(\"hello\");\n"
" satellite.system.console.display(v[0]);\n"
" satellite.system.console.display(\"done\");\n"
" return(satellite);\n"
"}\n";
satellite.variable.string lowered = lower_program(src);
satellite.system.console.display("--- LOWERED ---");
satellite.system.console.display(lowered);
? If bridge native is present, run it:
satellite.compiler.compile_and_run(lowered);
return(satellite);
}
// ================================================================
// FILE: stage1_lowerer_with_help.satl (self-contained)
// Purpose: Tokenize + Lower + Tiny help system: help("word");
// Notes: < 1000 lines; includes its own tokenizer so you can paste just this file.
// ================================================================
#include <satellite>
? ---------- Minimal token utils ----------
capsule tok_make(satellite.variable.string kind, satellite.variable.string lex)
{ return(kind + "|" + lex); }
capsule tok_kind(satellite.variable.string tok)
{
satellite.variable.integer p = satellite.str.len(tok);
satellite.variable.integer i = 0;
while (i < p) {
satellite.variable.string ch = satellite.str.char_at(tok, i);
if (ch == "|") { return(satellite.str.slice(tok, 0, i)); }
i = i + 1;
}
return(tok);
}
capsule tok_lex(satellite.variable.string tok)
{
satellite.variable.integer p = satellite.str.len(tok);
satellite.variable.integer i = 0;
while (i < p) {
satellite.variable.string ch = satellite.str.char_at(tok, i);
if (ch == "|") { return(satellite.str.slice(tok, i+1, p)); }
i = i + 1;
}
return("");
}
? ---------- Char helpers (branchy) ----------
capsule is_space(satellite.variable.string c)
{ if (c == " ") return(1); if (c == " ") return(1); if (c == "
") return(1); if (c == "
") return(1); return(0); }
capsule is_digit(satellite.variable.string c)
{
if (c == "0") return(1); if (c == "1") return(1); if (c == "2") return(1);
if (c == "3") return(1); if (c == "4") return(1); if (c == "5") return(1);
if (c == "6") return(1); if (c == "7") return(1); if (c == "8") return(1);
if (c == "9") return(1);
return(0);
}
capsule is_single_symbol(satellite.variable.string c)
{
if (c == "{") return(1); if (c == "}") return(1); if (c == "(") return(1); if (c == ")") return(1);
if (c == "[") return(1); if (c == "]") return(1); if (c == ",") return(1); if (c == ";") return(1);
if (c == ".") return(1); if (c == "<") return(1); if (c == ">") return(1); if (c == "=") return(1);
if (c == "+") return(1); if (c == "-") return(1);
return(0);
}
capsule is_delim(satellite.variable.string c)
{ if (is_space(c)) return(1); if (is_single_symbol(c)) return(1); if (c == "\"") return(1); if (c == "?") return(1); return(0); }
? ---------- Tokenizer (self-contained) ----------
capsule tokenize(satellite.variable.string src)
{
satellite.container.vector<satellite.variable.string> out;
out = satellite.container.vector.new();
satellite.variable.integer i = 0;
satellite.variable.integer N = satellite.str.len(src);
while (i < N) {
satellite.variable.string c = satellite.str.char_at(src, i);
? skip whitespace
if (is_space(c) == 1) { i = i + 1; continue; }
? line comments: '?' to end-of-line
if (c == "?") {
while (i < N) { if (satellite.str.char_at(src, i) == "
") break; i = i + 1; }
continue;
}
? strings
if (c == "\"") {
satellite.variable.integer j = i + 1;
while (j < N) { if (satellite.str.char_at(src, j) == "\"") break; j = j + 1; }
satellite.container.vector.append(out, tok_make("K_STRING", satellite.str.slice(src, i+1, j)));
i = (j < N) ? (j + 1) : j; continue;
}
? numbers
if (is_digit(c) == 1) {
satellite.variable.integer j = i + 1;
while (j < N) { if (is_digit(satellite.str.char_at(src,j)) == 0) break; j = j + 1; }
satellite.container.vector.append(out, tok_make("K_INT", satellite.str.slice(src, i, j)));
i = j; continue;
}
? two-char ops
if (c == "=") {
if (i+1 < N && satellite.str.char_at(src,i+1) == "=") { satellite.container.vector.append(out, tok_make("SYM_EQ","==")); i = i + 2; continue; }
satellite.container.vector.append(out, tok_make("SYM_ASSIGN","=")); i = i + 1; continue;
}
if (c == "!") {
if (i+1 < N && satellite.str.char_at(src,i+1) == "=") { satellite.container.vector.append(out, tok_make("SYM_NEQ","!=")); i = i + 2; continue; }
i = i + 1; continue;
}
if (c == "<") {
if (i+1 < N && satellite.str.char_at(src,i+1) == "=") { satellite.container.vector.append(out, tok_make("SYM_LE","<=")); i = i + 2; continue; }
satellite.container.vector.append(out, tok_make("SYM_LT","<")); i = i + 1; continue;
}
if (c == ">") {
if (i+1 < N && satellite.str.char_at(src,i+1) == "=") { satellite.container.vector.append(out, tok_make("SYM_GE",">=")); i = i + 2; continue; }
satellite.container.vector.append(out, tok_make("SYM_GT",">")); i = i + 1; continue;
}
? single-char symbols
if (is_single_symbol(c) == 1) {
satellite.variable.string kind = "";
if (c == "{") kind="SYM_LBRACE"; if (c == "}") kind="SYM_RBRACE";
if (c == "(") kind="SYM_LPAREN"; if (c == ")") kind="SYM_RPAREN";
if (c == "[") kind="SYM_LBRACKET"; if (c == "]") kind="SYM_RBRACKET";
if (c == ",") kind="SYM_COMMA"; if (c == ";") kind="SYM_SEMI";
if (c == ".") kind="SYM_DOT"; if (c == "+") kind="SYM_PLUS"; if (c == "-") kind="SYM_MINUS";
satellite.container.vector.append(out, tok_make(kind, c)); i = i + 1; continue;
}
? identifiers (and we'll detect keywords later during lowering)
satellite.variable.integer j = i;
while (j < N) { if (is_delim(satellite.str.char_at(src,j)) == 1) break; j = j + 1; }
satellite.container.vector.append(out, tok_make("K_IDENT", satellite.str.slice(src, i, j)));
i = j; continue;
}
return(out);
}
? ---------- Lowering helpers ----------
capsule emit_nl(satellite.variable.string s) { return(s + "
"); }
capsule match_kind_lex(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string kind,
satellite.variable.string lex)
{
satellite.variable.string t = satellite.container.vector.get(toks, i);
if (satellite.str.len(t) == 0) return(0);
satellite.variable.string k = tok_kind(t);
satellite.variable.string x = tok_lex(t);
if (k == kind) {
if (satellite.str.len(lex) == 0) return(1);
if (x == lex) return(1);
}
return(0);
}
? vector declaration: satellite.container.vector<satellite.variable.string> v;
capsule lower_vector_decl(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string out)
{
if (match_kind_lex(toks,i+0,"K_IDENT","satellite") == 0) return(out);
if (match_kind_lex(toks,i+1,"SYM_DOT",".") == 0) return(out);
if (match_kind_lex(toks,i+2,"K_IDENT","container") == 0) return(out);
if (match_kind_lex(toks,i+3,"SYM_DOT",".") == 0) return(out);
if (match_kind_lex(toks,i+4,"K_IDENT","vector") == 0) return(out);
if (match_kind_lex(toks,i+5,"SYM_LT","<") == 0) return(out);
if (match_kind_lex(toks,i+6,"K_IDENT","satellite") == 0) return(out);
if (match_kind_lex(toks,i+7,"SYM_DOT",".") == 0) return(out);
if (match_kind_lex(toks,i+8,"K_IDENT","variable") == 0) return(out);
if (match_kind_lex(toks,i+9,"SYM_DOT",".") == 0) return(out);
? accept inner type at i+10
if (match_kind_lex(toks,i+11,"SYM_GT",">") == 0) return(out);
satellite.variable.string name = tok_lex(satellite.container.vector.get(toks,i+12));
if (match_kind_lex(toks,i+12,"K_IDENT","") == 0) return(out);
if (match_kind_lex(toks,i+13,"SYM_SEMI",";") == 0) return(out);
satellite.variable.string line = name + " = satellite.container.vector.new();";
return(emit_nl(out + line));
}
capsule lower_append_call(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string out)
{
if (match_kind_lex(toks,i+0,"K_IDENT","") == 0) return(out);
satellite.variable.string name = tok_lex(satellite.container.vector.get(toks,i+0));
if (match_kind_lex(toks,i+1,"SYM_DOT",".") == 0) return(out);
if (match_kind_lex(toks,i+2,"K_IDENT","append") == 0) return(out);
if (match_kind_lex(toks,i+3,"SYM_LPAREN","(") == 0) return(out);
if (match_kind_lex(toks,i+4,"K_STRING","") == 0) return(out);
satellite.variable.string lit = tok_lex(satellite.container.vector.get(toks,i+4));
if (match_kind_lex(toks,i+5,"SYM_RPAREN",")") == 0) return(out);
if (match_kind_lex(toks,i+6,"SYM_SEMI",";") == 0) return(out);
satellite.variable.string line = "satellite.container.vector.append(" + name + ", \"" + lit + "\");";
return(emit_nl(out + line));
}
capsule lower_display_index(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string out)
{
if (match_kind_lex(toks,i+0,"K_IDENT","satellite") == 0) return(out);
if (match_kind_lex(toks,i+1,"SYM_DOT",".") == 0) return(out);
if (match_kind_lex(toks,i+2,"K_IDENT","system") == 0) return(out);
if (match_kind_lex(toks,i+3,"SYM_DOT",".") == 0) return(out);
if (match_kind_lex(toks,i+4,"K_IDENT","console") == 0) return(out);
if (match_kind_lex(toks,i+5,"SYM_DOT",".") == 0) return(out);
if (match_kind_lex(toks,i+6,"K_IDENT","display") == 0) return(out);
if (match_kind_lex(toks,i+7,"SYM_LPAREN","(") == 0) return(out);
if (match_kind_lex(toks,i+8,"K_IDENT","") == 0) return(out);
satellite.variable.string name = tok_lex(satellite.container.vector.get(toks,i+8));
if (match_kind_lex(toks,i+9,"SYM_LBRACKET","[") == 0) return(out);
if (match_kind_lex(toks,i+10,"K_INT","") == 0) return(out);
satellite.variable.string idx = tok_lex(satellite.container.vector.get(toks,i+10));
if (match_kind_lex(toks,i+11,"SYM_RBRACKET","]") == 0) return(out);
if (match_kind_lex(toks,i+12,"SYM_RPAREN",")") == 0) return(out);
if (match_kind_lex(toks,i+13,"SYM_SEMI",";") == 0) return(out);
satellite.variable.string tname = "___t" + idx;
satellite.variable.string l1 = tname + " = satellite.container.vector.get(" + name + ", " + idx + ");";
satellite.variable.string l2 = "satellite.system.console.display(" + tname + ");";
return(emit_nl(emit_nl(out + l1) + l2));
}
capsule lower_display_simple(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string out)
{
if (match_kind_lex(toks,i+0,"K_IDENT","satellite") == 0) return(out);
if (match_kind_lex(toks,i+1,"SYM_DOT",".") == 0) return(out);
if (match_kind_lex(toks,i+2,"K_IDENT","system") == 0) return(out);
if (match_kind_lex(toks,i+3,"SYM_DOT",".") == 0) return(out);
if (match_kind_lex(toks,i+4,"K_IDENT","console") == 0) return(out);
if (match_kind_lex(toks,i+5,"SYM_DOT",".") == 0) return(out);
if (match_kind_lex(toks,i+6,"K_IDENT","display") == 0) return(out);
if (match_kind_lex(toks,i+7,"SYM_LPAREN","(") == 0) return(out);
satellite.variable.string kind = tok_kind(satellite.container.vector.get(toks,i+8));
satellite.variable.string lex = tok_lex (satellite.container.vector.get(toks,i+8));
if ( (kind != "K_STRING") && (kind != "K_IDENT") ) return(out);
if (match_kind_lex(toks,i+9,"SYM_RPAREN",")") == 0) return(out);
if (match_kind_lex(toks,i+10,"SYM_SEMI",";") == 0) return(out);
satellite.variable.string arg = (kind == "K_STRING") ? ("\"" + lex + "\"") : lex;
satellite.variable.string line = "satellite.system.console.display(" + arg + ");";
return(emit_nl(out + line));
}
capsule lower_return_satellite(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string out)
{
if (match_kind_lex(toks,i+0,"K_IDENT","return") == 0) return(out);
if (match_kind_lex(toks,i+1,"SYM_LPAREN","(") == 0) return(out);
if (match_kind_lex(toks,i+2,"K_IDENT","satellite") == 0) return(out);
if (match_kind_lex(toks,i+3,"SYM_RPAREN",")") == 0) return(out);
if (match_kind_lex(toks,i+4,"SYM_SEMI",";") == 0) return(out);
return(emit_nl(out + "return(satellite);"));
}
? ---------- Branchy help system ----------
capsule topic_tag(satellite.variable.string w)
{
satellite.variable.integer n = satellite.str.len(w);
if (n==7 && satellite.str.char_at(w,0)=="c" && satellite.str.char_at(w,1)=="o" && satellite.str.char_at(w,2)=="n" && satellite.str.char_at(w,3)=="s" && satellite.str.char_at(w,4)=="o" && satellite.str.char_at(w,5)=="l" && satellite.str.char_at(w,6)=="e") return("T_CONSOLE");
if (n==6 && satellite.str.char_at(w,0)=="v" && satellite.str.char_at(w,1)=="e" && satellite.str.char_at(w,2)=="c" && satellite.str.char_at(w,3)=="t" && satellite.str.char_at(w,4)=="o" && satellite.str.char_at(w,5)=="r") return("T_VECTOR");
if (n==3 && satellite.str.char_at(w,0)=="s" && satellite.str.char_at(w,1)=="e" && satellite.str.char_at(w,2)=="t") return("T_SET");
if (n==3 && satellite.str.char_at(w,0)=="m" && satellite.str.char_at(w,1)=="a" && satellite.str.char_at(w,2)=="p") return("T_MAP");
if (n==5 && satellite.str.char_at(w,0)=="a" && satellite.str.char_at(w,1)=="r" && satellite.str.char_at(w,2)=="r" && satellite.str.char_at(w,3)=="a" && satellite.str.char_at(w,4)=="y") return("T_ARRAY");
if (n==7 && satellite.str.char_at(w,0)=="i" && satellite.str.char_at(w,1)=="n" && satellite.str.char_at(w,2)=="t" && satellite.str.char_at(w,3)=="e" && satellite.str.char_at(w,4)=="g" && satellite.str.char_at(w,5)=="e" && satellite.str.char_at(w,6)=="r") return("T_INTEGER");
if (n==3 && satellite.str.char_at(w,0)=="g" && satellite.str.char_at(w,1)=="u" && satellite.str.char_at(w,2)=="i") return("T_GUI");
if (n==2 && satellite.str.char_at(w,0)=="f" && satellite.str.char_at(w,1)=="s") return("T_FS");
if (n==4 && satellite.str.char_at(w,0)=="t" && satellite.str.char_at(w,1)=="i" && satellite.str.char_at(w,2)=="m" && satellite.str.char_at(w,3)=="e") return("T_TIME");
return("");
}
capsule append_help_line(satellite.variable.string out, satellite.variable.string s)
{
satellite.variable.string line = "satellite.system.console.display(\"" + s + "\");";
return(emit_nl(out + line));
}
capsule emit_help_for(satellite.variable.string tag, satellite.variable.string out)
{
if (tag == "T_CONSOLE") {
out = append_help_line(out, "console — print to stdout");
out = append_help_line(out, "usage: satellite.system.console.display(value)");
out = append_help_line(out, "vector index: x = satellite.container.vector.get(v, 0)");
return(out);
}
if (tag == "T_VECTOR") {
out = append_help_line(out, "vector — growable list of values");
out = append_help_line(out, "new: v = satellite.container.vector.new()");
out = append_help_line(out, "append: satellite.container.vector.append(v, \"str\")");
out = append_help_line(out, "get: x = satellite.container.vector.get(v, 0)");
return(out);
}
if (tag == "T_SET") {
out = append_help_line(out, "set — unique values (API parity soon)");
out = append_help_line(out, "new: s = satellite.container.set.new()");
out = append_help_line(out, "add: satellite.container.set.add(s, value)");
out = append_help_line(out, "has: satellite.container.set.contains(s, value)");
return(out);
}
if (tag == "T_MAP") {
out = append_help_line(out, "map — key/value dictionary");
out = append_help_line(out, "new: m = satellite.container.map.new()");
out = append_help_line(out, "set: satellite.container.map.set(m, key, value)");
out = append_help_line(out, "get: x = satellite.container.map.get(m, key)");
return(out);
}
if (tag == "T_ARRAY") {
out = append_help_line(out, "array — fixed-size sequence");
out = append_help_line(out, "new: a = satellite.container.array.new(size)");
out = append_help_line(out, "set: satellite.container.array.set(a, i, value)");
out = append_help_line(out, "get: x = satellite.container.array.get(a, i)");
return(out);
}
if (tag == "T_INTEGER") {
out = append_help_line(out, "integer — BigInt (satellite.variable.integer / sat.var.int)");
out = append_help_line(out, "add/sub: a = a + b; (branchy BigInt under the hood)");
out = append_help_line(out, "from string: a = satellite.big.from_string(\"123\")");
return(out);
}
if (tag == "T_GUI") {
out = append_help_line(out, "gui — minimal windowing (planned native)");
out = append_help_line(out, "new window: w = satellite.gui.window(\"title\", 800x600)");
out = append_help_line(out, "button: w.button(\"quit\", action=\"return(satellite)\")");
return(out);
}
if (tag == "T_FS") {
out = append_help_line(out, "fs — filesystem helpers");
out = append_help_line(out, "read: s = satellite.fs.read_text(path)");
out = append_help_line(out, "write: ok = satellite.fs.write_text_atomic(path, s)");
return(out);
}
if (tag == "T_TIME") {
out = append_help_line(out, "time — steady clock");
out = append_help_line(out, "now: t = satellite.time.now() (integer)");
return(out);
}
out = append_help_line(out, "no help for this topic yet");
return(out);
}
capsule lower_help_call(
satellite.container.vector<satellite.variable.string> toks,
satellite.variable.integer i,
satellite.variable.string out)
{
? Pattern: help ( "topic" ) ;
if (match_kind_lex(toks,i+0,"K_IDENT","help") == 0) return(out);
if (match_kind_lex(toks,i+1,"SYM_LPAREN","(") == 0) return(out);
if (match_kind_lex(toks,i+2,"K_STRING","") == 0) return(out);
satellite.variable.string topic = tok_lex(satellite.container.vector.get(toks,i+2));
if (match_kind_lex(toks,i+3,"SYM_RPAREN",")") == 0) return(out);
if (match_kind_lex(toks,i+4,"SYM_SEMI",";") == 0) return(out);
satellite.variable.string tag = topic_tag(topic);
out = append_help_line(out, "--- help: " + topic + " ---");
out = emit_help_for(tag, out);
return(out);
}
? ---------- Driver ----------
capsule lower_program(satellite.variable.string src)
{
satellite.container.vector<satellite.variable.string> toks = tokenize(src);
satellite.variable.string out = "";
satellite.variable.integer i = 0;
satellite.variable.integer steps = 0;
while (steps < 2000000) {
satellite.variable.string t = satellite.container.vector.get(toks, i);
if (satellite.str.len(t) == 0) break;
satellite.variable.string before = out;
out = lower_help_call(toks, i, out); if (out != before) { i = i + 5; steps = steps + 1; continue; }
before = out; out = lower_vector_decl(toks, i, out); if (out != before) { i = i + 14; steps = steps + 1; continue; }
before = out; out = lower_append_call(toks, i, out); if (out != before) { i = i + 7; steps = steps + 1; continue; }
before = out; out = lower_display_index(toks, i, out); if (out != before) { i = i + 14; steps = steps + 1; continue; }
before = out; out = lower_display_simple(toks, i, out);if (out != before) { i = i + 11; steps = steps + 1; continue; }
before = out; out = lower_return_satellite(toks, i, out); if (out != before) { i = i + 5; steps = steps + 1; continue; }
i = i + 1; steps = steps + 1;
}
return(out);
}
capsule main(satellite.variable.string args)
{
satellite.variable.string src =
"#include <satellite>
"
"capsule main(satellite.variable.string arguments){
"
" satellite.container.vector<satellite.variable.string> v;
"
" v.append(\"hello\");
"
" satellite.system.console.display(v[0]);
"
" help(\"console\");
"
" help(\"vector\");
"
" return(satellite);
"
"}
";
satellite.variable.string lowered = lower_program(src);
satellite.system.console.display("--- LOWERED ---");
satellite.system.console.display(lowered);
? run through the native bridge if present
satellite.compiler.compile_and_run(lowered);
return(satellite);
}
The above code is in the Satellite programming language, and it’s called a tokenizer — something that turns strings into tokens. Incredibly efficiently, because it runs on Satellite, so it is programmed to run really, really fast. Satellite is the language that he has made with me, and it will be available for download like later today or tomorrow or something like that, when we can get it to actually compile. It also functions as a text editor, so you can write any kind of code in it, but it only runs on Ubuntu/Debian right now, you would have to compile it yourself if you wanted it on windows or some other linux system, so to use it you have to be on Ubuntu or Debian linux, get on Ubuntu or Debian and later i’ll post the download for Satellite, the programming language that is coming out like today or tomorrow or the next day, when I can get the whole thing to compile.