Skip to content

Instantly share code, notes, and snippets.

@plvhx
Created January 22, 2023 14:41
Show Gist options
  • Save plvhx/41b16863f16386cff3d69b8f133dabe2 to your computer and use it in GitHub Desktop.
Save plvhx/41b16863f16386cff3d69b8f133dabe2 to your computer and use it in GitHub Desktop.
ohm sample script
namespace foobar
module [
ohm.encoding.json
ohm.util.io
ohm.lang.types.String
org.project.foo
org.project.bar
ohm.native.syscall
]
interface Global {
public def getFoo(): string;
public def getBar(): string;
}
abstract class Base implements Global {
abstract public def getFoo(): string;
abstract public def getBar(): string;
}
class Foo<T> extends Base {
@var
private prop foo: T;
@var
private prop bar: T;
@override
public def getFoo(): T {
return self.foo;
}
@override
public def getBar(): T {
return self.bar;
}
public def serialize(): T {
return io.format($"foo: {}, bar: {}", self.getFoo(), self.getBar());
}
public def toString(): T {
return self.serialize();
}
}
@main
def runner(): Nothing {
foo = new Foo<String>()
io.printf($"{}\n", foo); // this will output "foo: <whatever>, bar: <whatever>" followed by trailing newline :)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment