-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dd/sails-gprimitives
- Loading branch information
Showing
35 changed files
with
1,135 additions
and
1,029 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# no-svcs-prog | ||
|
||
Most basic program without services to get you started |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "no-svcs-prog-app" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
sails-rtl.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![no_std] | ||
|
||
use sails_rtl::gstd::gprogram; | ||
|
||
#[derive(Default)] | ||
pub struct Program; | ||
|
||
#[gprogram] | ||
impl Program { | ||
pub fn new() -> Self { | ||
Self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "no-svcs-prog" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
no-svcs-prog-app = { path = "../app" } | ||
sails-rtl.workspace = true | ||
|
||
[build-dependencies] | ||
gwasm-builder.workspace = true | ||
no-svcs-prog-app = { path = "../app" } | ||
sails-idl-gen.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use no_svcs_prog_app::Program; | ||
use sails_idl_gen::program; | ||
use std::{env, fs::File, path::PathBuf}; | ||
|
||
fn main() { | ||
gwasm_builder::build(); | ||
|
||
let manifest_dir_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
|
||
let idl_file_path = manifest_dir_path.join("no-svcs-prog.idl"); | ||
|
||
let idl_file = File::create(idl_file_path).unwrap(); | ||
|
||
program::generate_idl::<Program>(idl_file).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
constructor { | ||
New : (); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#![no_std] | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
pub use no_svcs_prog_app::wasm::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './parser.js'; | ||
export * from './visitor.js'; | ||
export { Program, Ctor, CtorFunc } from './program.js'; | ||
export { Service, ServiceFunc, ServiceEvent } from './service.js'; | ||
export { TypeDef } from './types.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { FuncParam, Service } from './service.js'; | ||
import { Type, WithDef } from './types.js'; | ||
import { getName } from './util.js'; | ||
import { Base } from './visitor.js'; | ||
|
||
export class Program { | ||
private _services: Service[]; | ||
private _types: Map<number, Type>; | ||
private _context: Map<number, WithDef>; | ||
private _ctor: Ctor; | ||
|
||
constructor() { | ||
this._services = []; | ||
this._types = new Map(); | ||
this._context = new Map(); | ||
} | ||
|
||
addService(service: Service) { | ||
this._services.push(service); | ||
} | ||
|
||
addType(type: Type) { | ||
const id = type.rawPtr; | ||
this._types.set(id, type); | ||
this._context.set(id, type); | ||
return id; | ||
} | ||
|
||
get services(): Service[] { | ||
return this._services; | ||
} | ||
|
||
get ctor(): Ctor { | ||
return this._ctor; | ||
} | ||
|
||
getType(id: number): Type { | ||
return this._types.get(id); | ||
} | ||
|
||
getContext(id: number): any { | ||
return this._context.get(id); | ||
} | ||
|
||
addContext(id: number, ctx: any) { | ||
this._context.set(id, ctx); | ||
} | ||
|
||
get types(): Type[] { | ||
return Array.from(this._types.values()); | ||
} | ||
|
||
getTypeByName(name: string): Type { | ||
const types = this.types.filter((type) => type.name === name); | ||
if (types.length > 1) throw new Error(`multiple types found with name ${name}`); | ||
if (types.length === 0) throw new Error(`no type found with name ${name}`); | ||
|
||
return types[0]; | ||
} | ||
|
||
addCtor(ctor: Ctor) { | ||
this._ctor = ctor; | ||
} | ||
} | ||
|
||
export class Ctor extends Base { | ||
public readonly funcs: CtorFunc[]; | ||
|
||
constructor(ptr: number, memory: WebAssembly.Memory) { | ||
super(ptr, memory); | ||
|
||
this.funcs = []; | ||
} | ||
|
||
addFunc(func: CtorFunc) { | ||
this.funcs.push(func); | ||
} | ||
} | ||
|
||
export class CtorFunc extends Base { | ||
private _params: Map<number, FuncParam>; | ||
public readonly name: string; | ||
|
||
constructor(ptr: number, memory: WebAssembly.Memory) { | ||
super(ptr, memory); | ||
|
||
const { name, offset } = getName(ptr, this.offset, memory); | ||
this.name = name; | ||
this.offset = offset; | ||
|
||
this._params = new Map(); | ||
} | ||
|
||
addFuncParam(ptr: number, param: FuncParam) { | ||
this._params.set(ptr, param); | ||
} | ||
|
||
get params(): FuncParam[] { | ||
if (this._params.size === 0) return []; | ||
|
||
return Array.from(this._params.values()); | ||
} | ||
} |
Oops, something went wrong.