Initial commit
commit
8d900204e7
|
@ -0,0 +1,29 @@
|
|||
# greet.b
|
||||
implement GreetImproved;
|
||||
|
||||
include "arg.m";
|
||||
include "sys.m";
|
||||
include "draw.m";
|
||||
sys: Sys;
|
||||
arg: Arg;
|
||||
|
||||
GreetImproved: module {
|
||||
init: fn(ctxt: ref Draw->Context, args: list of string);
|
||||
};
|
||||
|
||||
greet: fn(name: string): string;
|
||||
|
||||
greet(name: string): string {
|
||||
return "Hello, " + name + "\n";
|
||||
}
|
||||
|
||||
init (ctxt: ref Draw->Context, args: list of string) {
|
||||
sys = load Sys Sys->PATH;
|
||||
arg = load Arg Arg->PATH;
|
||||
|
||||
arg->init(args);
|
||||
input := arg->arg();
|
||||
|
||||
sys->print("%s", greet(input));
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
# greet_function.b
|
||||
implement Functions;
|
||||
|
||||
include "sys.m";
|
||||
include "draw.m";
|
||||
sys: Sys;
|
||||
|
||||
Functions: module {
|
||||
init: fn(ctxt: ref Draw->Context, args: list of string);
|
||||
|
||||
};
|
||||
|
||||
greet: fn(text: string): string;
|
||||
|
||||
greet(myname: string): string {
|
||||
return "Hello " + myname + "\n";
|
||||
}
|
||||
|
||||
init (ctxt: ref Draw->Context, args: list of string) {
|
||||
sys = load Sys Sys->PATH;
|
||||
sys->print("%s", greet("Marvin"));
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
# hello_world.b
|
||||
|
||||
implement HelloWorld;
|
||||
|
||||
include "sys.m";
|
||||
include "draw.m";
|
||||
sys: Sys;
|
||||
|
||||
HelloWorld: module {
|
||||
init: fn(ctxt: ref Draw->Context, args: list of string);
|
||||
};
|
||||
|
||||
init(ctxt: ref Draw->Context, args: list of string) {
|
||||
sys = load Sys Sys->PATH;
|
||||
|
||||
sys->print("Hello, World!\n");
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
# hello_world_var.b
|
||||
# ...
|
||||
init(ctxt: ref Draw->Context, args: list of string) {
|
||||
text: con "Hello, World!\n";
|
||||
sys = load Sys Sys->PATH;
|
||||
|
||||
sys->print(text);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
implement Command;
|
||||
|
||||
include "sys.m";
|
||||
include "draw.m";
|
||||
sys: Sys;
|
||||
|
||||
Command: module {
|
||||
init: fn (ctxt: ref Draw->Context, argv: list of string);
|
||||
};
|
||||
sys = load Sys Sys->PATH;
|
||||
args = tl args; # skip over program name
|
||||
for (s := ""; args != nil; args = tl args)
|
||||
s += " " + hd args;
|
||||
|
||||
if (s != "") # something was stored in s
|
||||
sys->print("%s\n", s[1:]);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
Arg : module
|
||||
{
|
||||
PATH: con "/dis/lib/arg.dis";
|
||||
|
||||
init: fn(argv: list of string);
|
||||
setusage: fn(usage: string);
|
||||
usage: fn();
|
||||
opt: fn(): int;
|
||||
arg: fn(): string;
|
||||
earg: fn(): string;
|
||||
|
||||
progname: fn(): string;
|
||||
argv: fn(): list of string;
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
SELF: con "$self"; # Language support for loading my instance
|
||||
|
||||
Sys: module
|
||||
{
|
||||
PATH: con "$Sys";
|
||||
#...
|
||||
print: fn(s: string, *): int;
|
||||
#...
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
implement RealAddition;
|
||||
|
||||
include "sys.m";
|
||||
include "draw.m";
|
||||
sys: Sys;
|
||||
|
||||
RealAddition: module {
|
||||
init: fn(ctxt: ref Draw->Context, args: list of string);
|
||||
};
|
||||
|
||||
add: fn(num1: real, num2: real): real;
|
||||
add(num1: real, num2: real): real {
|
||||
return num1 + num2;
|
||||
}
|
||||
|
||||
init (ctxt: ref Draw->Context, args: list of string) {
|
||||
sys = load Sys Sys->PATH;
|
||||
sys->print("%f", add(2.2, 4.0));
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
# plus-function.b
|
||||
implement IntAddition;
|
||||
|
||||
include "sys.m";
|
||||
include "draw.m";
|
||||
sys: Sys;
|
||||
|
||||
IntAddition: module {
|
||||
init: fn(ctxt: ref Draw->Context, args: list of string);
|
||||
};
|
||||
|
||||
add: fn(num1: int, num2: int): int;
|
||||
add(num1: int, num2: int): int {
|
||||
return num1 + num2;
|
||||
}
|
||||
|
||||
init (ctxt: ref Draw->Context, args: list of string) {
|
||||
sys = load Sys Sys->PATH;
|
||||
sys->print("%d", add(2, 4));
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
# string-addition.b
|
||||
# Include statements and declaration have been left out, same as previous code snippets
|
||||
|
||||
init (ctxt: ref Draw->Context, args: list of string) {
|
||||
sys = load Sys Sys->PATH;
|
||||
|
||||
num1: con "1";
|
||||
num2: con "2";
|
||||
|
||||
sys->print(num1 + num2);
|
||||
}
|
Loading…
Reference in New Issue