Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Whiteknight/Rosella
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Dec 2, 2011
2 parents 2ec346a + 983058f commit 33c1acc
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 42 deletions.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ proxy: 2 Stable
query: 1 Stable
random: 1 Stable
reflect: 0 Alpha
repl: 0 Alpha
string: 1 Stable
template: 1 Stable
test: 3 Stable
Expand Down
24 changes: 14 additions & 10 deletions setup.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ function setup_stable_libraries(var rosella)
// to run setup.winxed (this script). This is the only rosella library
// which doesn't rely on Core.
setup_winxed_lib(rosella, "winxed", [],
"winxed/Distutils",
"winxed/Repl",
"winxed/repl/Commands",
"winxed/repl/CommandFuncs",
"winxed/repl/Compiler",
"winxed/repl/State",
"winxed/repl/View"
"winxed/Distutils"
);

// The Rosella "core" library. Does very little on its own but is
Expand Down Expand Up @@ -269,7 +263,8 @@ function setup_stable_libraries(var rosella)
"random/Random",
"random/RandomNumber",
"random/randomnumber/BoxMullerNormal",
"random/randomnumber/MersenneTwister"
"random/randomnumber/MersenneTwister",
"random/uuid/V4"
);

// Working with commandline arguments
Expand Down Expand Up @@ -340,12 +335,21 @@ function setup_experimental_libraries(var rosella)
setup_unstable_lib(rosella, "date", [],
"date/Doomsday"
);

setup_unstable_lib(rosella, "repl", ["Core"],
"repl/Repl",
"repl/Commands",
"repl/CommandFuncs",
"repl/Compiler",
"repl/State",
"repl/View"
);
}

function setup_utilities(var rosella)
{
var utilities = {
"winxed_repl" : ["winxed_repl", ["Core"]],
"winxed_repl" : ["winxed_repl", ["Core", "Repl"]],
"test_all_lib" : ["rosella_test_all_lib", ["Core", "FileSystem", "Template", "CommandLine"]],
"test_template" : ["rosella_test_template", ["Core", "FileSystem", "Template", "CommandLine"]],
"mk_winxed_header" : ["winxed_mk_header", ["Core", "FileSystem", "CommandLine"]],
Expand All @@ -360,7 +364,7 @@ function setup_utilities(var rosella)
string pir_file = dest_prefix + dest_file_base + ".pir";
string pbc_file = dest_prefix + dest_file_base + ".pbc";

var files = [];
var files = ["src/include/Builtins.winxed"];
var includes = utilities[util_source][1];
for (string include in includes)
push(files, "src/include/" + include + ".winxed");
Expand Down
24 changes: 24 additions & 0 deletions src/include/Repl.winxed
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Rosella {
class Repl;
}

namespace Rosella.Repl {
class CommandEngine;
class Compiler;
class State;
class View;
}

namespace Rosella.Repl.CommandFuncs {
extern function quit;
extern function help;
extern function codeon;
extern function codeoff;
extern function showpre;
extern function addpre;
}

function __load_repl[anon, load, init]()
{
Rosella.load_bytecode_file("rosella/repl.pbc", "load");
}
16 changes: 16 additions & 0 deletions src/random/uuid/V4.winxed
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Rosella.Random.UUID.V4
{
function get()
{
var rand = Rosella.Random.default_uniform_random();
string hex[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
string s[] = [];
for (int i = 0; i < 36; i++)
s[i] = hex[int(rand.get_range(0, 16))];
s[14] = hex[4];
int s19 = (int(rand.get_range(0, 16)) & 0x03) | 0x08;
s[19] = hex[s19];
s[8] = s[13] = s[18] = s[23] = "-";
return join("", s);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Rosella.Winxed.Repl.CommandFuncs
namespace Rosella.Repl.CommandFuncs
{
function quit (var state, string args)
{
Expand All @@ -7,7 +7,7 @@ namespace Rosella.Winxed.Repl.CommandFuncs

function help (var state, string args)
{
state.view.show_message("Just type of winxed code!");
state.view.show_message("Just type some winxed code!");
}

function codeon (var state, string args)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Rosella.Winxed.Repl.CommandEngine
class Rosella.Repl.CommandEngine
{
function CommandEngine()
{
Expand Down Expand Up @@ -26,7 +26,7 @@ class Rosella.Winxed.Repl.CommandEngine

function run_command(string cmd, string args, var state)
{
var ns_name = ["Rosella", "Winxed", "Repl", "CommandFuncs"];
var ns_name = ["Rosella", "Repl", "CommandFuncs"];
var func_ns = get_hll_namespace(ns_name);
var func = func_ns.find_sub(cmd);
if (func == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Rosella.Winxed.Repl.Compiler
class Rosella.Repl.Compiler
{
var compiler;
var count;
Expand Down Expand Up @@ -28,7 +28,7 @@ class Rosella.Winxed.Repl.Compiler
function __REPL_line_%d(var state) {
var result = null;
%s;
%s;
result = %s;
return result;
}
:>>
Expand Down
10 changes: 5 additions & 5 deletions src/winxed/Repl.winxed → src/unstable/repl/Repl.winxed
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Rosella.Winxed.Repl
class Rosella.Repl
{
var compiler;
var commands;
Expand All @@ -12,19 +12,19 @@ class Rosella.Winxed.Repl
var view [named,optional], int has_view [opt_flag])
{
if (!has_cmds)
commands = new Rosella.Winxed.Repl.CommandEngine();
commands = new Rosella.Repl.CommandEngine();
self.commands = commands;

if (!has_comp)
compiler = new Rosella.Winxed.Repl.Compiler();
compiler = new Rosella.Repl.Compiler();
self.compiler = compiler;

if (!has_view)
view = new Rosella.Winxed.Repl.View();
view = new Rosella.Repl.View();
self.view = view;

if (!has_state)
state = new Rosella.Winxed.Repl.State();
state = new Rosella.Repl.State();
self.state = state;
self.state.set_view(self.view);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Rosella.Winxedl.Repl.State
class Rosella.Repl.State
{
var keep_running;
var data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Rosella.Winxed.Repl.View
class Rosella.Repl.View
{
const int MAX_BACKTRACE_LINES = 5;
const string PROMPT = "\nWinxed-Rosella> ";
Expand Down Expand Up @@ -80,4 +80,8 @@ class Rosella.Winxed.Repl.View
self.__printf("\t>>> Result = '%s'\n", result);
}

function show_message(string msg)
{
self.__printf(msg);
}
}
34 changes: 15 additions & 19 deletions src/utilities/winxed_repl.winxed
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
function main[main](var args)
{
load_bytecode("rosella/core.pbc");
load_bytecode("rosella/winxed.pbc");

using Rosella.get_version_hash;
var version_hash = get_version_hash();
for (string library in version_hash)
load_bytecode("rosella/" + library + ".pbc");
//using Rosella.get_version_hash;
//var version_hash = get_version_hash();
//for (string library in version_hash)
//load_bytecode("rosella/" + library + ".pbc");

show_preamble();

// TODO: Use CommandLine library to parse args.
if (elements(args) <= 1)
run_repl();
else if (args[1] == "--help")
Expand All @@ -33,35 +31,33 @@ Winxed/Rosella REPL

function show_versions()
{
using Rosella.get_version_hash;
using Rosella.get_version;
// TODO: Show the Winxed compiler version, or versions of any other compilers
// loaded
// TODO: When the String library gets more stable, use this for prettiness
//using Rosella.String.pad_right;

var version_hash = get_version_hash();
var version_hash = Rosella.Version.get_version_hash();
say("Rosella library version information:");
for (string library in version_hash) {
var ver = get_version(library);
var ver = Rosella.Version.get_version(library);
//library = pad_right(library, 10);
say(sprintf("\t%s : %d (%s)", [library, ver.version_number, ver.state]));
Rosella.IO.sayf("\t%s : %d (%s)", library, ver.version_number, ver.state);
}
}

function show_preamble()
{
using Rosella.get_version;
var winxed_version = get_version("winxed");
var core_version = get_version("core");
say(sprintf(<<:
var winxed_version = Rosella.Version.get_version("repl");
Rosella.IO.sayf(<<:
Winxed REPL with Rosella
Version %d %s
Type 'quit' or 'exit(0)' to quit
Type '%%quit' or 'exit(0)' to quit
:>>
, [winxed_version.version_number, winxed_version.state]));
, winxed_version.version_number, winxed_version.state);
}

function run_repl()
{
var repl = new Rosella.Winxed.Repl();
var repl = new Rosella.Repl();
repl.run_loop();
}

0 comments on commit 33c1acc

Please sign in to comment.