Permalink
Browse files

Some type stuuuuuuff

  • Loading branch information...
1 parent 3aba7b2 commit 6e09358c8c0a4db3e1b638de9a582ca8f6f165cc @JarrettBillingsley committed May 27, 2012
Showing with 56 additions and 18 deletions.
  1. +1 −1 croc/api_debug.d
  2. +2 −2 croc/api_interpreter.d
  3. +1 −1 croc/ex.d
  4. +1 −1 croc/interpreter.d
  5. +2 −2 croc/stdlib_docs.d
  6. +15 −10 croc/types.d
  7. +34 −1 samples/simple.croc
View
@@ -194,7 +194,7 @@ debug
for(uword i = wholeStack ? 0 : tmp; i < top; i++)
{
// ORDER CROCVALUE TYPE
- if(t.stack[i].type >= 0 && t.stack[i].type <= CrocValue.Type.max)
+ if(t.stack[i].type >= CrocValue.Type.FirstUserType && t.stack[i].type <= CrocValue.Type.LastUserType)
{
pushToString(t, i, true);
pushTypeString(t, i);
View
@@ -85,7 +85,7 @@ word getTypeMT(CrocThread* t, CrocValue.Type type)
mixin(FuncNameMix);
// ORDER CROCVALUE TYPE
- if(!(type >= CrocValue.Type.Null && type <= CrocValue.Type.FuncDef))
+ if(!(type >= CrocValue.Type.FirstUserType && type <= CrocValue.Type.LastUserType))
{
if(type >= CrocValue.Type.min && type <= CrocValue.Type.max)
throwStdException(t, "TypeException", __FUNCTION__ ~ " - Cannot get metatable for type '{}'", CrocValue.typeStrings[type]);
@@ -112,7 +112,7 @@ void setTypeMT(CrocThread* t, CrocValue.Type type)
mixin(apiCheckNumParams!("1"));
// ORDER CROCVALUE TYPE
- if(!(type >= CrocValue.Type.Null && type <= CrocValue.Type.FuncDef))
+ if(!(type >= CrocValue.Type.FirstUserType && type <= CrocValue.Type.LastUserType))
{
if(type >= CrocValue.Type.min && type <= CrocValue.Type.max)
throwStdException(t, "TypeException", __FUNCTION__ ~ " - Cannot set metatable for type '{}'", CrocValue.typeStrings[type]);
View
@@ -1704,7 +1704,7 @@ Checks that the parameter at the given index is of the given type.
void checkParam(CrocThread* t, word index, CrocValue.Type type)
{
// ORDER CROCVALUE TYPE
- assert(type >= CrocValue.Type.Null && type <= CrocValue.Type.FuncDef, "invalid type");
+ assert(type >= CrocValue.Type.FirstUserType && type <= CrocValue.Type.LastUserType, "invalid type");
checkAnyParam(t, index);
View
@@ -2418,7 +2418,7 @@ void loadPtr(CrocThread* t, ref CrocValue* ptr)
CrocNamespace* getMetatable(CrocThread* t, CrocValue.Type type)
{
// ORDER CROCVALUE TYPE
- assert(type >= CrocValue.Type.Null && type <= CrocValue.Type.FuncDef);
+ assert(type >= CrocValue.Type.FirstUserType && type <= CrocValue.Type.LastUserType);
return t.vm.metaTabs[type];
}
View
@@ -70,8 +70,8 @@ uword _doc_(CrocThread* t)
checkAnyParam(t, 1);
// ORDER CROCVALUE TYPE
- if(type(t, 1) <= CrocValue.Type.String)
- paramTypeError(t, 1, "non-string object type");
+ if(type(t, 1) < CrocValue.Type.FirstRefType)
+ paramTypeError(t, 1, "reference type");
checkParam(t, 2, CrocValue.Type.Table);
View
@@ -173,34 +173,39 @@ align(1) struct CrocValue
Float,
/** ditto */
Char,
-
/** ditto */
String, // 5
+
/** ditto */
Table,
/** ditto */
Array,
/** ditto */
- Memblock,
+ Memblock, // 10
/** ditto */
Function,
/** ditto */
- Class, // 10
+ Class,
/** ditto */
Instance,
/** ditto */
Namespace,
/** ditto */
- Thread,
+ Thread, // 15
/** ditto */
NativeObj,
/** ditto */
- WeakRef, // 15
+ WeakRef,
/** ditto */
FuncDef,
// Internal types
- Upvalue
+ Upvalue,
+
+ // Other
+ FirstRefType = Type.String,
+ FirstUserType = Type.Null,
+ LastUserType = Type.FuncDef
}
package:
@@ -211,8 +216,10 @@ package:
Type.Int: "int",
Type.Float: "float",
Type.Char: "char",
-
Type.String: "string",
+ Type.NativeObj: "nativeobj",
+ Type.WeakRef: "weakref",
+
Type.Table: "table",
Type.Array: "array",
Type.Memblock: "memblock",
@@ -221,8 +228,6 @@ package:
Type.Instance: "instance",
Type.Namespace: "namespace",
Type.Thread: "thread",
- Type.NativeObj: "nativeobj",
- Type.WeakRef: "weakref",
Type.FuncDef: "funcdef",
Type.Upvalue: "upvalue"
@@ -387,7 +392,7 @@ package:
bool isObject()
{
- return type >= Type.String;
+ return type >= Type.FirstRefType;
}
GCObject* toGCObject()
View
@@ -8,6 +8,39 @@ function main()
t.outputItem(docsOf(console), "")
}
+
+
+// local docTables = hash.WeakKeyTable()
+//
+// function _doc_(
+// val: table|array|memblock|function|class|instance|namespace|thread|funcdef,
+// doctable: table,
+// vararg)
+// {
+// local d = doctable
+//
+// for(i: 0 .. #vararg)
+// {
+// local idx = vararg[i]
+//
+// if(!isInt(idx))
+// throw TypeException(format("_doc_ - Parameter {} expected to be 'int', not '{}'", i + 2, typeof(idx)))
+//
+// d = d.children[idx]
+// }
+//
+// docTables[val] = d
+// return val
+// }
+//
+// function docsOf(val) =
+// docTables[val]
+
+
+
+
+
+
import exceptions:
TypeException,
ValueException,
@@ -687,7 +720,7 @@ class BaseDocOutput
function outputItem(doctable: table, parentFQN: string)
{
:beginItem(doctable, parentFQN)
-
+
if(doctable.dittos)
{
foreach(d; doctable.dittos)

0 comments on commit 6e09358

Please sign in to comment.